Fossil SCM

Implement changes option parser and default logic, still need to implement filtering

andygoth 2016-11-05 21:25 UTC andygoth-changes
Commit cc3baab8ad31895d6c4bef0be0c24999c1fbe7f7
1 file changed +124 -10
+124 -10
--- src/checkin.c
+++ src/checkin.c
@@ -20,10 +20,44 @@
2020
*/
2121
#include "config.h"
2222
#include "checkin.h"
2323
#include <assert.h>
2424
25
+/*
26
+** Change filter options.
27
+*/
28
+enum {
29
+ /* Zero-based bit indexes. */
30
+ CB_EDITED , CB_UPDATED , CB_CHANGED, CB_MISSING , CB_ADDED , CB_DELETED,
31
+ CB_RENAMED, CB_CONFLICT, CB_META , CB_UNMODIFIED, CB_EXTRA , CB_MERGE ,
32
+ CB_RELPATH, CB_SHA1SUM , CB_HEADER , CB_VERBOSE , CB_CLASSIFY,
33
+
34
+ /* Bitmask values. */
35
+ C_EDITED = 1 << CB_EDITED,
36
+ C_UPDATED = 1 << CB_UPDATED,
37
+ C_CHANGED = 1 << CB_CHANGED, /* Resembles CB_EDITED|CB_UPDATED. */
38
+ C_MISSING = 1 << CB_MISSING,
39
+ C_ADDED = 1 << CB_ADDED,
40
+ C_DELETED = 1 << CB_DELETED,
41
+ C_RENAMED = 1 << CB_RENAMED,
42
+ C_CONFLICT = 1 << CB_CONFLICT,
43
+ C_META = 1 << CB_META,
44
+ C_UNMODIFIED = 1 << CB_UNMODIFIED,
45
+ C_EXTRA = 1 << CB_EXTRA,
46
+ C_MERGE = 1 << CB_MERGE,
47
+ C_FILTER = C_EDITED | C_UPDATED | C_CHANGED | C_MISSING | C_ADDED
48
+ | C_DELETED | C_RENAMED | C_CONFLICT | C_META | C_UNMODIFIED
49
+ | C_EXTRA | C_MERGE,
50
+ C_ALL = C_FILTER & ~(C_CHANGED | C_EXTRA | C_MERGE),
51
+ C_RELPATH = 1 << CB_RELPATH,
52
+ C_SHA1SUM = 1 << CB_SHA1SUM,
53
+ C_HEADER = 1 << CB_HEADER,
54
+ C_VERBOSE = 1 << CB_VERBOSE,
55
+ C_CLASSIFY = 1 << CB_CLASSIFY,
56
+ C_DEFAULT = (C_ALL & ~C_UNMODIFIED) | C_MERGE | C_CLASSIFY,
57
+};
58
+
2559
/*
2660
** Generate text describing all changes. Prepend zPrefix to each line
2761
** of output.
2862
**
2963
** We assume that vfile_check_signature has been run.
@@ -219,13 +253,17 @@
219253
** the end of the report. The --no-merge option is useful to display the
220254
** default set of changed files without the merge contributors.
221255
**
222256
** If change type classification is enabled, each output line starts with
223257
** a code describing the file's change type, e.g. EDITED or RENAMED. It
224
-** is enabled by default except when exactly one filter option (besides
225
-** --merge or --no-merge) is used. The default can be overridden by the
226
-** --classify or --no-classify options.
258
+** is enabled by default unless exactly one change type is selected. For
259
+** the purposes of determining the default, --changed counts as selecting
260
+** one change type. The default can be overridden by the --classify or
261
+** --no-classify options.
262
+**
263
+** If both --merge and --no-merge are used, --no-merge has priority. The
264
+** same is true of --classify and --no-classify.
227265
**
228266
** The "fossil changes --extra" command is equivalent to "fossil extras".
229267
**
230268
** General options:
231269
** --abs-paths Display absolute pathnames.
@@ -255,21 +293,97 @@
255293
** --no-merge Do not display merge contributors.
256294
**
257295
** See also: extras, ls, status
258296
*/
259297
void changes_cmd(void){
260
- int useSha1sum = find_option("sha1sum", 0, 0)!=0;
261
- int showHdr = find_option("header",0,0)!=0;
262
- int verboseFlag = find_option("verbose","v",0)!=0;
263
- int cwdRelative = 0;
298
+ /* Affirmative and negative flag option tables. */
299
+ static const struct {
300
+ const char *option;
301
+ unsigned mask;
302
+ } flagDefs[] = {
303
+ {"edited" , C_EDITED }, {"updated" , C_UPDATED },
304
+ {"changed" , C_CHANGED }, {"missing" , C_MISSING },
305
+ {"added" , C_ADDED }, {"deleted" , C_DELETED },
306
+ {"renamed" , C_RENAMED }, {"conflict" , C_CONFLICT },
307
+ {"meta" , C_META }, {"unmodified" , C_UNMODIFIED},
308
+ {"all" , C_ALL }, {"extra" , C_EXTRA },
309
+ {"merge" , C_MERGE }, {"sha1sum" , C_SHA1SUM },
310
+ {"header" , C_HEADER }, {"v" , C_VERBOSE },
311
+ {"verbose" , C_VERBOSE }, {"classify" , C_CLASSIFY },
312
+ }, noFlagDefs[] = {
313
+ {"no-merge", C_MERGE }, {"no-classify", C_CLASSIFY },
314
+ };
315
+
316
+#ifdef FOSSIL_DEBUG
317
+ static const char *const bits[] = {
318
+ "EDITED", "UPDATED", "CHANGED", "MISSING", "ADDED", "DELETED", "RENAMED",
319
+ "CONFLICT", "META", "UNMODIFIED", "EXTRA", "MERGE", "RELPATH", "SHA1SUM",
320
+ "HEADER", "VERBOSE", "CLASSIFY",
321
+ };
322
+#endif
323
+
324
+ unsigned flags = 0;
325
+ int i;
326
+
327
+ /* Load affirmative flag options. */
328
+ for( i=0; i<count(flagDefs); ++i ){
329
+ if( find_option(flagDefs[i].option, 0, 0) ){
330
+ flags |= flagDefs[i].mask;
331
+ }
332
+ }
333
+
334
+ /* If no filter options are specified, enable defaults. */
335
+ if( !(flags & C_FILTER) ){
336
+ flags |= C_DEFAULT;
337
+ }
338
+
339
+ /* If more than one filter is enabled, enable classification. This is tricky.
340
+ * Having one filter means flags masked by C_FILTER is a power of two. If a
341
+ * number masked by one less than itself is zero, it's either zero or a power
342
+ * of two. It's already known to not be zero because of the above defaults.
343
+ * Unlike --all, at this point in the code, --changed is treated as a single
344
+ * filter, i.e. it only sets one bit. If masking flags against itself less
345
+ * one and C_FILTER yields nonzero, it has more than one C_FILTER bit set, so
346
+ * classification should be turned on. */
347
+ if( flags & (flags-1) & C_FILTER ){
348
+ flags |= C_CLASSIFY;
349
+ }
350
+
351
+ /* Now that the --classify default is decided, convert --changed to be
352
+ * --edited plus --updated. */
353
+ if( flags & C_CHANGED ){
354
+ flags = (flags | C_EDITED | C_UPDATED) & ~C_CHANGED;
355
+ }
356
+
357
+ /* Negative flag options override defaults applied above. */
358
+ for( i=0; i<count(noFlagDefs); ++i ){
359
+ if( find_option(noFlagDefs[i].option, 0, 0) ){
360
+ flags &= ~noFlagDefs[i].mask;
361
+ }
362
+ }
363
+
264364
db_must_be_within_tree();
265
- cwdRelative = determine_cwd_relative_option();
266365
267
- /* We should be done with options.. */
366
+ /* Relative path flag determination is done by a shared function. */
367
+ if( determine_cwd_relative_option() ){
368
+ flags |= C_RELPATH;
369
+ }
370
+
371
+#ifdef FOSSIL_DEBUG
372
+ for( i=0; i<count(bits); ++i ){
373
+ if( flags & (1 << i) ){
374
+ printf("%s ", bits[i]);
375
+ }
376
+ }
377
+ printf("\n");
378
+#endif
379
+
380
+ /* We should be done with options. */
268381
verify_all_options();
269382
270
- print_changes(useSha1sum, showHdr, verboseFlag, cwdRelative);
383
+ print_changes(flags & C_SHA1SUM, flags & C_HEADER,
384
+ flags & C_VERBOSE, flags & C_RELPATH);
271385
}
272386
273387
/*
274388
** COMMAND: status
275389
**
276390
--- src/checkin.c
+++ src/checkin.c
@@ -20,10 +20,44 @@
20 */
21 #include "config.h"
22 #include "checkin.h"
23 #include <assert.h>
24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25 /*
26 ** Generate text describing all changes. Prepend zPrefix to each line
27 ** of output.
28 **
29 ** We assume that vfile_check_signature has been run.
@@ -219,13 +253,17 @@
219 ** the end of the report. The --no-merge option is useful to display the
220 ** default set of changed files without the merge contributors.
221 **
222 ** If change type classification is enabled, each output line starts with
223 ** a code describing the file's change type, e.g. EDITED or RENAMED. It
224 ** is enabled by default except when exactly one filter option (besides
225 ** --merge or --no-merge) is used. The default can be overridden by the
226 ** --classify or --no-classify options.
 
 
 
 
227 **
228 ** The "fossil changes --extra" command is equivalent to "fossil extras".
229 **
230 ** General options:
231 ** --abs-paths Display absolute pathnames.
@@ -255,21 +293,97 @@
255 ** --no-merge Do not display merge contributors.
256 **
257 ** See also: extras, ls, status
258 */
259 void changes_cmd(void){
260 int useSha1sum = find_option("sha1sum", 0, 0)!=0;
261 int showHdr = find_option("header",0,0)!=0;
262 int verboseFlag = find_option("verbose","v",0)!=0;
263 int cwdRelative = 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
264 db_must_be_within_tree();
265 cwdRelative = determine_cwd_relative_option();
266
267 /* We should be done with options.. */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
268 verify_all_options();
269
270 print_changes(useSha1sum, showHdr, verboseFlag, cwdRelative);
 
271 }
272
273 /*
274 ** COMMAND: status
275 **
276
--- src/checkin.c
+++ src/checkin.c
@@ -20,10 +20,44 @@
20 */
21 #include "config.h"
22 #include "checkin.h"
23 #include <assert.h>
24
25 /*
26 ** Change filter options.
27 */
28 enum {
29 /* Zero-based bit indexes. */
30 CB_EDITED , CB_UPDATED , CB_CHANGED, CB_MISSING , CB_ADDED , CB_DELETED,
31 CB_RENAMED, CB_CONFLICT, CB_META , CB_UNMODIFIED, CB_EXTRA , CB_MERGE ,
32 CB_RELPATH, CB_SHA1SUM , CB_HEADER , CB_VERBOSE , CB_CLASSIFY,
33
34 /* Bitmask values. */
35 C_EDITED = 1 << CB_EDITED,
36 C_UPDATED = 1 << CB_UPDATED,
37 C_CHANGED = 1 << CB_CHANGED, /* Resembles CB_EDITED|CB_UPDATED. */
38 C_MISSING = 1 << CB_MISSING,
39 C_ADDED = 1 << CB_ADDED,
40 C_DELETED = 1 << CB_DELETED,
41 C_RENAMED = 1 << CB_RENAMED,
42 C_CONFLICT = 1 << CB_CONFLICT,
43 C_META = 1 << CB_META,
44 C_UNMODIFIED = 1 << CB_UNMODIFIED,
45 C_EXTRA = 1 << CB_EXTRA,
46 C_MERGE = 1 << CB_MERGE,
47 C_FILTER = C_EDITED | C_UPDATED | C_CHANGED | C_MISSING | C_ADDED
48 | C_DELETED | C_RENAMED | C_CONFLICT | C_META | C_UNMODIFIED
49 | C_EXTRA | C_MERGE,
50 C_ALL = C_FILTER & ~(C_CHANGED | C_EXTRA | C_MERGE),
51 C_RELPATH = 1 << CB_RELPATH,
52 C_SHA1SUM = 1 << CB_SHA1SUM,
53 C_HEADER = 1 << CB_HEADER,
54 C_VERBOSE = 1 << CB_VERBOSE,
55 C_CLASSIFY = 1 << CB_CLASSIFY,
56 C_DEFAULT = (C_ALL & ~C_UNMODIFIED) | C_MERGE | C_CLASSIFY,
57 };
58
59 /*
60 ** Generate text describing all changes. Prepend zPrefix to each line
61 ** of output.
62 **
63 ** We assume that vfile_check_signature has been run.
@@ -219,13 +253,17 @@
253 ** the end of the report. The --no-merge option is useful to display the
254 ** default set of changed files without the merge contributors.
255 **
256 ** If change type classification is enabled, each output line starts with
257 ** a code describing the file's change type, e.g. EDITED or RENAMED. It
258 ** is enabled by default unless exactly one change type is selected. For
259 ** the purposes of determining the default, --changed counts as selecting
260 ** one change type. The default can be overridden by the --classify or
261 ** --no-classify options.
262 **
263 ** If both --merge and --no-merge are used, --no-merge has priority. The
264 ** same is true of --classify and --no-classify.
265 **
266 ** The "fossil changes --extra" command is equivalent to "fossil extras".
267 **
268 ** General options:
269 ** --abs-paths Display absolute pathnames.
@@ -255,21 +293,97 @@
293 ** --no-merge Do not display merge contributors.
294 **
295 ** See also: extras, ls, status
296 */
297 void changes_cmd(void){
298 /* Affirmative and negative flag option tables. */
299 static const struct {
300 const char *option;
301 unsigned mask;
302 } flagDefs[] = {
303 {"edited" , C_EDITED }, {"updated" , C_UPDATED },
304 {"changed" , C_CHANGED }, {"missing" , C_MISSING },
305 {"added" , C_ADDED }, {"deleted" , C_DELETED },
306 {"renamed" , C_RENAMED }, {"conflict" , C_CONFLICT },
307 {"meta" , C_META }, {"unmodified" , C_UNMODIFIED},
308 {"all" , C_ALL }, {"extra" , C_EXTRA },
309 {"merge" , C_MERGE }, {"sha1sum" , C_SHA1SUM },
310 {"header" , C_HEADER }, {"v" , C_VERBOSE },
311 {"verbose" , C_VERBOSE }, {"classify" , C_CLASSIFY },
312 }, noFlagDefs[] = {
313 {"no-merge", C_MERGE }, {"no-classify", C_CLASSIFY },
314 };
315
316 #ifdef FOSSIL_DEBUG
317 static const char *const bits[] = {
318 "EDITED", "UPDATED", "CHANGED", "MISSING", "ADDED", "DELETED", "RENAMED",
319 "CONFLICT", "META", "UNMODIFIED", "EXTRA", "MERGE", "RELPATH", "SHA1SUM",
320 "HEADER", "VERBOSE", "CLASSIFY",
321 };
322 #endif
323
324 unsigned flags = 0;
325 int i;
326
327 /* Load affirmative flag options. */
328 for( i=0; i<count(flagDefs); ++i ){
329 if( find_option(flagDefs[i].option, 0, 0) ){
330 flags |= flagDefs[i].mask;
331 }
332 }
333
334 /* If no filter options are specified, enable defaults. */
335 if( !(flags & C_FILTER) ){
336 flags |= C_DEFAULT;
337 }
338
339 /* If more than one filter is enabled, enable classification. This is tricky.
340 * Having one filter means flags masked by C_FILTER is a power of two. If a
341 * number masked by one less than itself is zero, it's either zero or a power
342 * of two. It's already known to not be zero because of the above defaults.
343 * Unlike --all, at this point in the code, --changed is treated as a single
344 * filter, i.e. it only sets one bit. If masking flags against itself less
345 * one and C_FILTER yields nonzero, it has more than one C_FILTER bit set, so
346 * classification should be turned on. */
347 if( flags & (flags-1) & C_FILTER ){
348 flags |= C_CLASSIFY;
349 }
350
351 /* Now that the --classify default is decided, convert --changed to be
352 * --edited plus --updated. */
353 if( flags & C_CHANGED ){
354 flags = (flags | C_EDITED | C_UPDATED) & ~C_CHANGED;
355 }
356
357 /* Negative flag options override defaults applied above. */
358 for( i=0; i<count(noFlagDefs); ++i ){
359 if( find_option(noFlagDefs[i].option, 0, 0) ){
360 flags &= ~noFlagDefs[i].mask;
361 }
362 }
363
364 db_must_be_within_tree();
 
365
366 /* Relative path flag determination is done by a shared function. */
367 if( determine_cwd_relative_option() ){
368 flags |= C_RELPATH;
369 }
370
371 #ifdef FOSSIL_DEBUG
372 for( i=0; i<count(bits); ++i ){
373 if( flags & (1 << i) ){
374 printf("%s ", bits[i]);
375 }
376 }
377 printf("\n");
378 #endif
379
380 /* We should be done with options. */
381 verify_all_options();
382
383 print_changes(flags & C_SHA1SUM, flags & C_HEADER,
384 flags & C_VERBOSE, flags & C_RELPATH);
385 }
386
387 /*
388 ** COMMAND: status
389 **
390

Keyboard Shortcuts

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