Fossil SCM

Make new --verbose commit option code compliant with Fossil style, and minor refactoring of the verboseFlag logic to cohere related global aCommitFile memory (de)allocation and make more readable.

jamsek 2021-01-30 03:40 dev-ci-verbose
Commit 8f41701eb0291b7a8ec1f88b7ba325fdeb53910bda66e7d2eac4ca8e8fcd788f
2 files changed +23 -20 +11 -8
+23 -20
--- src/checkin.c
+++ src/checkin.c
@@ -1237,14 +1237,15 @@
12371237
int i, n;
12381238
char *z;
12391239
n = blob_size(&line);
12401240
z = blob_buffer(&line);
12411241
for(i=0; i<n && fossil_isspace(z[i]); i++){}
1242
- if (!fossil_strncmp(
1242
+ if( fossil_strncmp(
12431243
"# NOTE: The below diff is not inserted into the commit message.\n",
1244
- z, n))
1244
+ z, n)==0 ){
12451245
break;
1246
+ }
12461247
if( i<n && z[i]=='#' ) continue;
12471248
if( i<n || blob_size(pComment)>0 ){
12481249
blob_appendf(pComment, "%b", &line);
12491250
}
12501251
}
@@ -1329,39 +1330,41 @@
13291330
"#\n"
13301331
"# All merged-in branches will be closed due to the --integrate flag\n"
13311332
"#\n", -1
13321333
);
13331334
}
1334
- if (p->verboseFlag) {
1335
- FileDirList *diffFiles;
1335
+ if( p->verboseFlag ){
1336
+ blob_append(&prompt,
1337
+ "#\n"
1338
+ "# NOTE: The below diff is not inserted into the commit message.\n\n",
1339
+ -1
1340
+ );
13361341
if( g.aCommitFile ){
1337
- int i = 0;
1338
- diffFiles = fossil_malloc_zero((g.argc - 1) * sizeof(*diffFiles));
1339
- for (i = 0; g.aCommitFile[i] != 0; ++i) {
1342
+ FileDirList *diffFiles;
1343
+ int i;
1344
+ diffFiles = fossil_malloc_zero((g.argc-1) * sizeof(*diffFiles));
1345
+ for( i=0; g.aCommitFile[i]!=0; ++i ){
13401346
diffFiles[i].zName = db_text(0,
13411347
"SELECT pathname FROM vfile WHERE id=%d", g.aCommitFile[i]);
1342
- if (!strcmp(diffFiles[i].zName , ".")) {
1348
+ if( fossil_strcmp(diffFiles[i].zName, "." )==0 ){
13431349
diffFiles[0].zName[0] = '.';
13441350
diffFiles[0].zName[1] = 0;
13451351
break;
13461352
}
13471353
diffFiles[i].nName = strlen(diffFiles[i].zName);
13481354
diffFiles[i].nUsed = 0;
13491355
}
1350
- }
1351
- blob_append_full(&prompt, "#\n"
1352
- "# NOTE: The below diff is not inserted into the commit message.\n\n",
1353
- -1);
1354
- diff_against_disk(0, 0, diff_get_binary_glob(),
1355
- db_get_boolean("diff-binary", 1), 0,
1356
- g.aCommitFile ? diffFiles : 0, &prompt
1357
- );
1358
- if (g.aCommitFile && diffFiles) {
1359
- int i;
1360
- for (i = 0; diffFiles[i].zName; ++i)
1356
+ diff_against_disk(0, 0, diff_get_binary_glob(),
1357
+ db_get_boolean("diff-binary", 1),
1358
+ 0, diffFiles, &prompt);
1359
+ for( i=0; diffFiles[i].zName; ++i ){
13611360
fossil_free(diffFiles[i].zName);
1361
+ }
13621362
fossil_free(diffFiles);
1363
+ }else{
1364
+ diff_against_disk(0, 0, diff_get_binary_glob(),
1365
+ db_get_boolean("diff-binary", 1), 0, 0, &prompt);
13631366
}
13641367
}
13651368
prompt_for_user_comment(pComment, &prompt);
13661369
blob_reset(&prompt);
13671370
}
@@ -2232,11 +2235,11 @@
22322235
sCiInfo.zColor = find_option("bgcolor",0,1);
22332236
sCiInfo.zBrClr = find_option("branchcolor",0,1);
22342237
sCiInfo.closeFlag = find_option("close",0,0)!=0;
22352238
sCiInfo.integrateFlag = find_option("integrate",0,0)!=0;
22362239
sCiInfo.zMimetype = find_option("mimetype",0,1);
2237
- sCiInfo.verboseFlag = find_option("verbose", "v", 0) != 0;
2240
+ sCiInfo.verboseFlag = find_option("verbose", "v", 0)!=0;
22382241
while( (zTag = find_option("tag",0,1))!=0 ){
22392242
if( zTag[0]==0 ) continue;
22402243
sCiInfo.azTag = fossil_realloc((void*)sCiInfo.azTag,
22412244
sizeof(char*)*(nTag+2));
22422245
sCiInfo.azTag[nTag++] = zTag;
22432246
--- src/checkin.c
+++ src/checkin.c
@@ -1237,14 +1237,15 @@
1237 int i, n;
1238 char *z;
1239 n = blob_size(&line);
1240 z = blob_buffer(&line);
1241 for(i=0; i<n && fossil_isspace(z[i]); i++){}
1242 if (!fossil_strncmp(
1243 "# NOTE: The below diff is not inserted into the commit message.\n",
1244 z, n))
1245 break;
 
1246 if( i<n && z[i]=='#' ) continue;
1247 if( i<n || blob_size(pComment)>0 ){
1248 blob_appendf(pComment, "%b", &line);
1249 }
1250 }
@@ -1329,39 +1330,41 @@
1329 "#\n"
1330 "# All merged-in branches will be closed due to the --integrate flag\n"
1331 "#\n", -1
1332 );
1333 }
1334 if (p->verboseFlag) {
1335 FileDirList *diffFiles;
 
 
 
 
1336 if( g.aCommitFile ){
1337 int i = 0;
1338 diffFiles = fossil_malloc_zero((g.argc - 1) * sizeof(*diffFiles));
1339 for (i = 0; g.aCommitFile[i] != 0; ++i) {
 
1340 diffFiles[i].zName = db_text(0,
1341 "SELECT pathname FROM vfile WHERE id=%d", g.aCommitFile[i]);
1342 if (!strcmp(diffFiles[i].zName , ".")) {
1343 diffFiles[0].zName[0] = '.';
1344 diffFiles[0].zName[1] = 0;
1345 break;
1346 }
1347 diffFiles[i].nName = strlen(diffFiles[i].zName);
1348 diffFiles[i].nUsed = 0;
1349 }
1350 }
1351 blob_append_full(&prompt, "#\n"
1352 "# NOTE: The below diff is not inserted into the commit message.\n\n",
1353 -1);
1354 diff_against_disk(0, 0, diff_get_binary_glob(),
1355 db_get_boolean("diff-binary", 1), 0,
1356 g.aCommitFile ? diffFiles : 0, &prompt
1357 );
1358 if (g.aCommitFile && diffFiles) {
1359 int i;
1360 for (i = 0; diffFiles[i].zName; ++i)
1361 fossil_free(diffFiles[i].zName);
 
1362 fossil_free(diffFiles);
 
 
 
1363 }
1364 }
1365 prompt_for_user_comment(pComment, &prompt);
1366 blob_reset(&prompt);
1367 }
@@ -2232,11 +2235,11 @@
2232 sCiInfo.zColor = find_option("bgcolor",0,1);
2233 sCiInfo.zBrClr = find_option("branchcolor",0,1);
2234 sCiInfo.closeFlag = find_option("close",0,0)!=0;
2235 sCiInfo.integrateFlag = find_option("integrate",0,0)!=0;
2236 sCiInfo.zMimetype = find_option("mimetype",0,1);
2237 sCiInfo.verboseFlag = find_option("verbose", "v", 0) != 0;
2238 while( (zTag = find_option("tag",0,1))!=0 ){
2239 if( zTag[0]==0 ) continue;
2240 sCiInfo.azTag = fossil_realloc((void*)sCiInfo.azTag,
2241 sizeof(char*)*(nTag+2));
2242 sCiInfo.azTag[nTag++] = zTag;
2243
--- src/checkin.c
+++ src/checkin.c
@@ -1237,14 +1237,15 @@
1237 int i, n;
1238 char *z;
1239 n = blob_size(&line);
1240 z = blob_buffer(&line);
1241 for(i=0; i<n && fossil_isspace(z[i]); i++){}
1242 if( fossil_strncmp(
1243 "# NOTE: The below diff is not inserted into the commit message.\n",
1244 z, n)==0 ){
1245 break;
1246 }
1247 if( i<n && z[i]=='#' ) continue;
1248 if( i<n || blob_size(pComment)>0 ){
1249 blob_appendf(pComment, "%b", &line);
1250 }
1251 }
@@ -1329,39 +1330,41 @@
1330 "#\n"
1331 "# All merged-in branches will be closed due to the --integrate flag\n"
1332 "#\n", -1
1333 );
1334 }
1335 if( p->verboseFlag ){
1336 blob_append(&prompt,
1337 "#\n"
1338 "# NOTE: The below diff is not inserted into the commit message.\n\n",
1339 -1
1340 );
1341 if( g.aCommitFile ){
1342 FileDirList *diffFiles;
1343 int i;
1344 diffFiles = fossil_malloc_zero((g.argc-1) * sizeof(*diffFiles));
1345 for( i=0; g.aCommitFile[i]!=0; ++i ){
1346 diffFiles[i].zName = db_text(0,
1347 "SELECT pathname FROM vfile WHERE id=%d", g.aCommitFile[i]);
1348 if( fossil_strcmp(diffFiles[i].zName, "." )==0 ){
1349 diffFiles[0].zName[0] = '.';
1350 diffFiles[0].zName[1] = 0;
1351 break;
1352 }
1353 diffFiles[i].nName = strlen(diffFiles[i].zName);
1354 diffFiles[i].nUsed = 0;
1355 }
1356 diff_against_disk(0, 0, diff_get_binary_glob(),
1357 db_get_boolean("diff-binary", 1),
1358 0, diffFiles, &prompt);
1359 for( i=0; diffFiles[i].zName; ++i ){
 
 
 
 
 
 
 
1360 fossil_free(diffFiles[i].zName);
1361 }
1362 fossil_free(diffFiles);
1363 }else{
1364 diff_against_disk(0, 0, diff_get_binary_glob(),
1365 db_get_boolean("diff-binary", 1), 0, 0, &prompt);
1366 }
1367 }
1368 prompt_for_user_comment(pComment, &prompt);
1369 blob_reset(&prompt);
1370 }
@@ -2232,11 +2235,11 @@
2235 sCiInfo.zColor = find_option("bgcolor",0,1);
2236 sCiInfo.zBrClr = find_option("branchcolor",0,1);
2237 sCiInfo.closeFlag = find_option("close",0,0)!=0;
2238 sCiInfo.integrateFlag = find_option("integrate",0,0)!=0;
2239 sCiInfo.zMimetype = find_option("mimetype",0,1);
2240 sCiInfo.verboseFlag = find_option("verbose", "v", 0)!=0;
2241 while( (zTag = find_option("tag",0,1))!=0 ){
2242 if( zTag[0]==0 ) continue;
2243 sCiInfo.azTag = fossil_realloc((void*)sCiInfo.azTag,
2244 sizeof(char*)*(nTag+2));
2245 sCiInfo.azTag[nTag++] = zTag;
2246
+11 -8
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -109,14 +109,15 @@
109109
** Print the "Index:" message that patches wants to see at the top of a diff.
110110
*/
111111
void diff_print_index(const char *zFile, u64 diffFlags, Blob *diffBlob){
112112
if( (diffFlags & (DIFF_SIDEBYSIDE|DIFF_BRIEF|DIFF_NUMSTAT))==0 ){
113113
char *z = mprintf("Index: %s\n%.66c\n", zFile, '=');
114
- if (!diffBlob)
114
+ if( !diffBlob ){
115115
fossil_print("%s", z);
116
- else
116
+ }else{
117117
blob_appendf(diffBlob, "%s", z);
118
+ }
118119
fossil_free(z);
119120
}
120121
}
121122
122123
/*
@@ -146,14 +147,15 @@
146147
(w-n2)/2, '=', n2, zRight, (w-n2+1)/2, '=');
147148
}
148149
}else{
149150
z = mprintf("--- %s\n+++ %s\n", zLeft, zRight);
150151
}
151
- if (!diffBlob)
152
+ if( !diffBlob ){
152153
fossil_print("%s", z);
153
- else
154
+ }else{
154155
blob_appendf(diffBlob, "%s", z);
156
+ }
155157
fossil_free(z);
156158
}
157159
158160
/*
159161
** Show the difference between two files, one in memory and one on disk.
@@ -209,19 +211,20 @@
209211
}else{
210212
text_diff(pFile1, &file2, &out, 0, diffFlags);
211213
}
212214
if( blob_size(&out) ){
213215
if( diffFlags & DIFF_NUMSTAT ){
214
- if (!diffBlob)
216
+ if( !diffBlob ){
215217
fossil_print("%s %s\n", blob_str(&out), zName);
216
- else
218
+ }else{
217219
blob_appendf(diffBlob, "%s %s\n", blob_str(&out), zName);
220
+ }
218221
}else{
219
- if (!diffBlob) {
222
+ if( !diffBlob ){
220223
diff_print_filenames(zName, zName2, diffFlags, 0);
221224
fossil_print("%s\n", blob_str(&out));
222
- } else {
225
+ }else{
223226
diff_print_filenames(zName, zName2, diffFlags, diffBlob);
224227
blob_appendf(diffBlob, "%s\n", blob_str(&out));
225228
}
226229
}
227230
}
228231
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -109,14 +109,15 @@
109 ** Print the "Index:" message that patches wants to see at the top of a diff.
110 */
111 void diff_print_index(const char *zFile, u64 diffFlags, Blob *diffBlob){
112 if( (diffFlags & (DIFF_SIDEBYSIDE|DIFF_BRIEF|DIFF_NUMSTAT))==0 ){
113 char *z = mprintf("Index: %s\n%.66c\n", zFile, '=');
114 if (!diffBlob)
115 fossil_print("%s", z);
116 else
117 blob_appendf(diffBlob, "%s", z);
 
118 fossil_free(z);
119 }
120 }
121
122 /*
@@ -146,14 +147,15 @@
146 (w-n2)/2, '=', n2, zRight, (w-n2+1)/2, '=');
147 }
148 }else{
149 z = mprintf("--- %s\n+++ %s\n", zLeft, zRight);
150 }
151 if (!diffBlob)
152 fossil_print("%s", z);
153 else
154 blob_appendf(diffBlob, "%s", z);
 
155 fossil_free(z);
156 }
157
158 /*
159 ** Show the difference between two files, one in memory and one on disk.
@@ -209,19 +211,20 @@
209 }else{
210 text_diff(pFile1, &file2, &out, 0, diffFlags);
211 }
212 if( blob_size(&out) ){
213 if( diffFlags & DIFF_NUMSTAT ){
214 if (!diffBlob)
215 fossil_print("%s %s\n", blob_str(&out), zName);
216 else
217 blob_appendf(diffBlob, "%s %s\n", blob_str(&out), zName);
 
218 }else{
219 if (!diffBlob) {
220 diff_print_filenames(zName, zName2, diffFlags, 0);
221 fossil_print("%s\n", blob_str(&out));
222 } else {
223 diff_print_filenames(zName, zName2, diffFlags, diffBlob);
224 blob_appendf(diffBlob, "%s\n", blob_str(&out));
225 }
226 }
227 }
228
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -109,14 +109,15 @@
109 ** Print the "Index:" message that patches wants to see at the top of a diff.
110 */
111 void diff_print_index(const char *zFile, u64 diffFlags, Blob *diffBlob){
112 if( (diffFlags & (DIFF_SIDEBYSIDE|DIFF_BRIEF|DIFF_NUMSTAT))==0 ){
113 char *z = mprintf("Index: %s\n%.66c\n", zFile, '=');
114 if( !diffBlob ){
115 fossil_print("%s", z);
116 }else{
117 blob_appendf(diffBlob, "%s", z);
118 }
119 fossil_free(z);
120 }
121 }
122
123 /*
@@ -146,14 +147,15 @@
147 (w-n2)/2, '=', n2, zRight, (w-n2+1)/2, '=');
148 }
149 }else{
150 z = mprintf("--- %s\n+++ %s\n", zLeft, zRight);
151 }
152 if( !diffBlob ){
153 fossil_print("%s", z);
154 }else{
155 blob_appendf(diffBlob, "%s", z);
156 }
157 fossil_free(z);
158 }
159
160 /*
161 ** Show the difference between two files, one in memory and one on disk.
@@ -209,19 +211,20 @@
211 }else{
212 text_diff(pFile1, &file2, &out, 0, diffFlags);
213 }
214 if( blob_size(&out) ){
215 if( diffFlags & DIFF_NUMSTAT ){
216 if( !diffBlob ){
217 fossil_print("%s %s\n", blob_str(&out), zName);
218 }else{
219 blob_appendf(diffBlob, "%s %s\n", blob_str(&out), zName);
220 }
221 }else{
222 if( !diffBlob ){
223 diff_print_filenames(zName, zName2, diffFlags, 0);
224 fossil_print("%s\n", blob_str(&out));
225 }else{
226 diff_print_filenames(zName, zName2, diffFlags, diffBlob);
227 blob_appendf(diffBlob, "%s\n", blob_str(&out));
228 }
229 }
230 }
231

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button