@matheusbsbs / matheus-bagliano / commits / 7594c4b2d7
Fork 0

rev-list option parser fix.

The big option parser unification broke rev-list the big way; this makes it use options from the parsed revs structure. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Apr 15, 2006 at 23:48 UTC 7594c4b2d7cc81f806453402aefe1bf71ae6dd53
1 file changed +23 -59
rev-list.c
+23 -59
@@ -39,24 +39,20 @@ static const char rev_list_usage[] =
39 struct rev_info revs;
40
41 static int bisect_list = 0;
42 -static int verbose_header = 0;
43 -static int abbrev = DEFAULT_ABBREV;
44 -static int abbrev_commit = 0;
42 static int show_timestamp = 0;
43 static int hdr_termination = 0;
47 -static const char *commit_prefix = "";
48 -static enum cmit_fmt commit_format = CMIT_FMT_RAW;
44
45 static void show_commit(struct commit *commit)
46 {
47 if (show_timestamp)
48 printf("%lu ", commit->date);
54 - if (commit_prefix[0])
55 - fputs(commit_prefix, stdout);
49 + if (*revs.header_prefix)
50 + fputs(revs.header_prefix, stdout);
51 if (commit->object.flags & BOUNDARY)
52 putchar('-');
58 - if (abbrev_commit && abbrev)
59 - fputs(find_unique_abbrev(commit->object.sha1, abbrev), stdout);
53 + if (revs.abbrev_commit && revs.abbrev)
54 + fputs(find_unique_abbrev(commit->object.sha1, revs.abbrev),
55 + stdout);
56 else
57 fputs(sha1_to_hex(commit->object.sha1), stdout);
58 if (revs.parents) {
@@ -78,14 +74,16 @@ static void show_commit(struct commit *commit)
74 parents = parents->next)
75 parents->item->object.flags &= ~TMP_MARK;
76 }
81 - if (commit_format == CMIT_FMT_ONELINE)
77 + if (revs.commit_format == CMIT_FMT_ONELINE)
78 putchar(' ');
79 else
80 putchar('\n');
81
86 - if (verbose_header) {
82 + if (revs.verbose_header) {
83 static char pretty_header[16384];
88 - pretty_print_commit(commit_format, commit, ~0, pretty_header, sizeof(pretty_header), abbrev);
84 + pretty_print_commit(revs.commit_format, commit, ~0,
85 + pretty_header, sizeof(pretty_header),
86 + revs.abbrev);
87 printf("%s%c", pretty_header, hdr_termination);
88 }
89 fflush(stdout);
@@ -297,58 +295,16 @@ int main(int argc, const char **argv)
295 struct commit_list *list;
296 int i;
297
298 + init_revisions(&revs);
299 + revs.abbrev = 0;
300 + revs.commit_format = CMIT_FMT_UNSPECIFIED;
301 argc = setup_revisions(argc, argv, &revs, NULL);
302
303 for (i = 1 ; i < argc; i++) {
304 const char *arg = argv[i];
305
305 - /* accept -<digit>, like traditilnal "head" */
306 - if ((*arg == '-') && isdigit(arg[1])) {
307 - revs.max_count = atoi(arg + 1);
308 - continue;
309 - }
310 - if (!strcmp(arg, "-n")) {
311 - if (++i >= argc)
312 - die("-n requires an argument");
313 - revs.max_count = atoi(argv[i]);
314 - continue;
315 - }
316 - if (!strncmp(arg,"-n",2)) {
317 - revs.max_count = atoi(arg + 2);
318 - continue;
319 - }
306 if (!strcmp(arg, "--header")) {
321 - verbose_header = 1;
322 - continue;
323 - }
324 - if (!strcmp(arg, "--no-abbrev")) {
325 - abbrev = 0;
326 - continue;
327 - }
328 - if (!strcmp(arg, "--abbrev")) {
329 - abbrev = DEFAULT_ABBREV;
330 - continue;
331 - }
332 - if (!strcmp(arg, "--abbrev-commit")) {
333 - abbrev_commit = 1;
334 - continue;
335 - }
336 - if (!strncmp(arg, "--abbrev=", 9)) {
337 - abbrev = strtoul(arg + 9, NULL, 10);
338 - if (abbrev && abbrev < MINIMUM_ABBREV)
339 - abbrev = MINIMUM_ABBREV;
340 - else if (40 < abbrev)
341 - abbrev = 40;
342 - continue;
343 - }
344 - if (!strncmp(arg, "--pretty", 8)) {
345 - commit_format = get_commit_format(arg+8);
346 - verbose_header = 1;
347 - hdr_termination = '\n';
348 - if (commit_format == CMIT_FMT_ONELINE)
349 - commit_prefix = "";
350 - else
351 - commit_prefix = "commit ";
307 + revs.verbose_header = 1;
308 continue;
309 }
310 if (!strcmp(arg, "--timestamp")) {
@@ -362,6 +318,14 @@ int main(int argc, const char **argv)
318 usage(rev_list_usage);
319
320 }
321 + if (revs.commit_format != CMIT_FMT_UNSPECIFIED) {
322 + /* The command line has a --pretty */
323 + hdr_termination = '\n';
324 + if (revs.commit_format == CMIT_FMT_ONELINE)
325 + revs.header_prefix = "";
326 + else
327 + revs.header_prefix = "commit ";
328 + }
329
330 list = revs.commits;
331
@@ -371,7 +335,7 @@ int main(int argc, const char **argv)
335 revs.diff)
336 usage(rev_list_usage);
337
374 - save_commit_buffer = verbose_header;
338 + save_commit_buffer = revs.verbose_header;
339 track_object_refs = 0;
340
341 prepare_revision_walk(&revs);