@matheusbsbs / matheus-bagliano / commits / cd2bdc5309
Fork 0

Common option parsing for "git log --diff" and friends

This basically does a few things that are sadly somewhat interdependent, and nontrivial to split out - get rid of "struct log_tree_opt" The fields in "log_tree_opt" are moved into "struct rev_info", and all users of log_tree_opt are changed to use the rev_info struct instead. - add the parsing for the log_tree_opt arguments to "setup_revision()" - make setup_revision set a flag (revs->diff) if the diff-related arguments were used. This allows "git log" to decide whether it wants to show diffs or not. - make setup_revision() also initialize the diffopt part of rev_info (which we had from before, but we just didn't initialize it) - make setup_revision() do all the "finishing touches" on it all (it will do the proper flag combination logic, and call "diff_setup_done()") Now, that was the easy and straightforward part. The slightly more involved part is that some of the programs that want to use the new-and-improved rev_info parsing don't actually want _commits_, they may want tree'ish arguments instead. That meant that I had to change setup_revision() to parse the arguments not into the "revs->commits" list, but into the "revs->pending_objects" list. Then, when we do "prepare_revision_walk()", we walk that list, and create the sorted commit list from there. This actually cleaned some stuff up, but it's the less obvious part of the patch, and re-organized the "revision.c" logic somewhat. It actually paves the way for splitting argument parsing _entirely_ out of "revision.c", since now the argument parsing really is totally independent of the commit walking: that didn't use to be true, since there was lots of overlap with get_commit_reference() handling etc, now the _only_ overlap is the shared (and trivial) "add_pending_object()" thing. However, I didn't do that file split, just because I wanted the diff itself to be smaller, and show the actual changes more clearly. If this gets accepted, I'll do further cleanups then - that includes the file split, but also using the new infrastructure to do a nicer "git diff" etc. Even in this form, it actually ends up removing more lines than it adds. It's nice to note how simple and straightforward this makes the built-in "git log" command, even though it continues to support all the diff flags too. It doesn't get much simpler that this. I think this is worth merging soonish, because it does allow for future cleanup and even more sharing of code. However, it obviously touches "revision.c", which is subtle. I've tested that it passes all the tests we have, and it passes my "looks sane" detector, but somebody else should also give it a good look-over. [jc: squashed the original and three "oops this too" updates, with another fix-up.] Signed-off-by: Linus Torvalds <torvalds@osdl.org> Signed-off-by: Junio C Hamano <junkio@cox.net>

Linus Torvalds committed Apr 14, 2006 at 16:52 UTC cd2bdc5309461034e5cc58e1d3e87535ed9e093b
6 files changed +218 -227
diff-tree.c
+41 -50
@@ -3,7 +3,7 @@
3 #include "commit.h"
4 #include "log-tree.h"
5
6 -static struct log_tree_opt log_tree_opt;
6 +static struct rev_info log_tree_opt;
7
8 static int diff_tree_commit_sha1(const unsigned char *sha1)
9 {
@@ -62,47 +62,18 @@ int main(int argc, const char **argv)
62 {
63 int nr_sha1;
64 char line[1000];
65 - unsigned char sha1[2][20];
66 - const char *prefix = setup_git_directory();
67 - static struct log_tree_opt *opt = &log_tree_opt;
65 + struct object *tree1, *tree2;
66 + static struct rev_info *opt = &log_tree_opt;
67 + struct object_list *list;
68 int read_stdin = 0;
69
70 git_config(git_diff_config);
71 nr_sha1 = 0;
72 - init_log_tree_opt(opt);
72 + argc = setup_revisions(argc, argv, opt, NULL);
73
74 - for (;;) {
75 - int opt_cnt;
76 - const char *arg;
74 + while (--argc > 0) {
75 + const char *arg = *++argv;
76
78 - argv++;
79 - argc--;
80 - arg = *argv;
81 - if (!arg)
82 - break;
83 -
84 - if (*arg != '-') {
85 - if (nr_sha1 < 2 && !get_sha1(arg, sha1[nr_sha1])) {
86 - nr_sha1++;
87 - continue;
88 - }
89 - break;
90 - }
91 -
92 - opt_cnt = log_tree_opt_parse(opt, argv, argc);
93 - if (opt_cnt < 0)
94 - usage(diff_tree_usage);
95 - else if (opt_cnt) {
96 - argv += opt_cnt - 1;
97 - argc -= opt_cnt - 1;
98 - continue;
99 - }
100 -
101 - if (!strcmp(arg, "--")) {
102 - argv++;
103 - argc--;
104 - break;
105 - }
77 if (!strcmp(arg, "--stdin")) {
78 read_stdin = 1;
79 continue;
@@ -110,18 +81,36 @@ int main(int argc, const char **argv)
81 usage(diff_tree_usage);
82 }
83
113 - if (opt->combine_merges)
114 - opt->ignore_merges = 0;
115 -
116 - /* We can only do dense combined merges with diff output */
117 - if (opt->dense_combined_merges)
118 - opt->diffopt.output_format = DIFF_FORMAT_PATCH;
119 -
120 - if (opt->diffopt.output_format == DIFF_FORMAT_PATCH)
121 - opt->diffopt.recursive = 1;
122 -
123 - diff_tree_setup_paths(get_pathspec(prefix, argv), opt);
124 - diff_setup_done(&opt->diffopt);
84 + /*
85 + * NOTE! "setup_revisions()" will have inserted the revisions
86 + * it parsed in reverse order. So if you do
87 + *
88 + * git-diff-tree a b
89 + *
90 + * the commit list will be "b" -> "a" -> NULL, so we reverse
91 + * the order of the objects if the first one is not marked
92 + * UNINTERESTING.
93 + */
94 + nr_sha1 = 0;
95 + list = opt->pending_objects;
96 + if (list) {
97 + nr_sha1++;
98 + tree1 = list->item;
99 + list = list->next;
100 + if (list) {
101 + nr_sha1++;
102 + tree2 = tree1;
103 + tree1 = list->item;
104 + if (list->next)
105 + usage(diff_tree_usage);
106 + /* Switch them around if the second one was uninteresting.. */
107 + if (tree2->flags & UNINTERESTING) {
108 + struct object *tmp = tree2;
109 + tree2 = tree1;
110 + tree1 = tmp;
111 + }
112 + }
113 + }
114
115 switch (nr_sha1) {
116 case 0:
@@ -129,10 +118,12 @@ int main(int argc, const char **argv)
118 usage(diff_tree_usage);
119 break;
120 case 1:
132 - diff_tree_commit_sha1(sha1[0]);
121 + diff_tree_commit_sha1(tree1->sha1);
122 break;
123 case 2:
135 - diff_tree_sha1(sha1[0], sha1[1], "", &opt->diffopt);
124 + diff_tree_sha1(tree1->sha1,
125 + tree2->sha1,
126 + "", &opt->diffopt);
127 log_tree_diff_flush(opt);
128 break;
129 }
git.c
+13 -70
@@ -283,82 +283,25 @@ static int cmd_log(int argc, const char **argv, char **envp)
283 struct rev_info rev;
284 struct commit *commit;
285 char *buf = xmalloc(LOGSIZE);
286 - static enum cmit_fmt commit_format = CMIT_FMT_DEFAULT;
287 - int abbrev = DEFAULT_ABBREV;
288 - int abbrev_commit = 0;
286 const char *commit_prefix = "commit ";
290 - struct log_tree_opt opt;
287 int shown = 0;
292 - int do_diff = 0;
293 - int full_diff = 0;
288
295 - init_log_tree_opt(&opt);
289 argc = setup_revisions(argc, argv, &rev, "HEAD");
297 - while (1 < argc) {
298 - const char *arg = argv[1];
299 - if (!strncmp(arg, "--pretty", 8)) {
300 - commit_format = get_commit_format(arg + 8);
301 - if (commit_format == CMIT_FMT_ONELINE)
302 - commit_prefix = "";
303 - }
304 - else if (!strcmp(arg, "--no-abbrev")) {
305 - abbrev = 0;
306 - }
307 - else if (!strcmp(arg, "--abbrev")) {
308 - abbrev = DEFAULT_ABBREV;
309 - }
310 - else if (!strcmp(arg, "--abbrev-commit")) {
311 - abbrev_commit = 1;
312 - }
313 - else if (!strncmp(arg, "--abbrev=", 9)) {
314 - abbrev = strtoul(arg + 9, NULL, 10);
315 - if (abbrev && abbrev < MINIMUM_ABBREV)
316 - abbrev = MINIMUM_ABBREV;
317 - else if (40 < abbrev)
318 - abbrev = 40;
319 - }
320 - else if (!strcmp(arg, "--full-diff")) {
321 - do_diff = 1;
322 - full_diff = 1;
323 - }
324 - else {
325 - int cnt = log_tree_opt_parse(&opt, argv+1, argc-1);
326 - if (0 < cnt) {
327 - do_diff = 1;
328 - argv += cnt;
329 - argc -= cnt;
330 - continue;
331 - }
332 - die("unrecognized argument: %s", arg);
333 - }
290 + if (argc > 1)
291 + die("unrecognized argument: %s", argv[1]);
292
335 - argc--; argv++;
336 - }
337 -
338 - if (do_diff) {
339 - opt.diffopt.abbrev = abbrev;
340 - opt.verbose_header = 0;
341 - opt.always_show_header = 0;
342 - opt.no_commit_id = 1;
343 - if (opt.combine_merges)
344 - opt.ignore_merges = 0;
345 - if (opt.dense_combined_merges)
346 - opt.diffopt.output_format = DIFF_FORMAT_PATCH;
347 - if (opt.diffopt.output_format == DIFF_FORMAT_PATCH)
348 - opt.diffopt.recursive = 1;
349 - if (!full_diff && rev.prune_data)
350 - diff_tree_setup_paths(rev.prune_data, &opt.diffopt);
351 - diff_setup_done(&opt.diffopt);
352 - }
293 + rev.no_commit_id = 1;
294 + if (rev.commit_format == CMIT_FMT_ONELINE)
295 + commit_prefix = "";
296
297 prepare_revision_walk(&rev);
298 setup_pager();
299 while ((commit = get_revision(&rev)) != NULL) {
357 - if (shown && do_diff && commit_format != CMIT_FMT_ONELINE)
300 + if (shown && rev.diff && rev.commit_format != CMIT_FMT_ONELINE)
301 putchar('\n');
302 fputs(commit_prefix, stdout);
360 - if (abbrev_commit && abbrev)
361 - fputs(find_unique_abbrev(commit->object.sha1, abbrev),
303 + if (rev.abbrev_commit && rev.abbrev)
304 + fputs(find_unique_abbrev(commit->object.sha1, rev.abbrev),
305 stdout);
306 else
307 fputs(sha1_to_hex(commit->object.sha1), stdout);
@@ -381,15 +324,15 @@ static int cmd_log(int argc, const char **argv, char **envp)
324 parents = parents->next)
325 parents->item->object.flags &= ~TMP_MARK;
326 }
384 - if (commit_format == CMIT_FMT_ONELINE)
327 + if (rev.commit_format == CMIT_FMT_ONELINE)
328 putchar(' ');
329 else
330 putchar('\n');
388 - pretty_print_commit(commit_format, commit, ~0, buf,
389 - LOGSIZE, abbrev);
331 + pretty_print_commit(rev.commit_format, commit, ~0, buf,
332 + LOGSIZE, rev.abbrev);
333 printf("%s\n", buf);
391 - if (do_diff)
392 - log_tree_commit(&opt, commit);
334 + if (rev.diff)
335 + log_tree_commit(&rev, commit);
336 shown = 1;
337 free(commit->buffer);
338 commit->buffer = NULL;
log-tree.c
+5 -55
@@ -3,57 +3,7 @@
3 #include "commit.h"
4 #include "log-tree.h"
5
6 -void init_log_tree_opt(struct log_tree_opt *opt)
7 -{
8 - memset(opt, 0, sizeof *opt);
9 - opt->ignore_merges = 1;
10 - opt->header_prefix = "";
11 - opt->commit_format = CMIT_FMT_RAW;
12 - diff_setup(&opt->diffopt);
13 -}
14 -
15 -int log_tree_opt_parse(struct log_tree_opt *opt, const char **av, int ac)
16 -{
17 - const char *arg;
18 - int cnt = diff_opt_parse(&opt->diffopt, av, ac);
19 - if (0 < cnt)
20 - return cnt;
21 - arg = *av;
22 - if (!strcmp(arg, "-r"))
23 - opt->diffopt.recursive = 1;
24 - else if (!strcmp(arg, "-t")) {
25 - opt->diffopt.recursive = 1;
26 - opt->diffopt.tree_in_recursive = 1;
27 - }
28 - else if (!strcmp(arg, "-m"))
29 - opt->ignore_merges = 0;
30 - else if (!strcmp(arg, "-c"))
31 - opt->combine_merges = 1;
32 - else if (!strcmp(arg, "--cc")) {
33 - opt->dense_combined_merges = 1;
34 - opt->combine_merges = 1;
35 - }
36 - else if (!strcmp(arg, "-v")) {
37 - opt->verbose_header = 1;
38 - opt->header_prefix = "diff-tree ";
39 - }
40 - else if (!strncmp(arg, "--pretty", 8)) {
41 - opt->verbose_header = 1;
42 - opt->header_prefix = "diff-tree ";
43 - opt->commit_format = get_commit_format(arg+8);
44 - }
45 - else if (!strcmp(arg, "--root"))
46 - opt->show_root_diff = 1;
47 - else if (!strcmp(arg, "--no-commit-id"))
48 - opt->no_commit_id = 1;
49 - else if (!strcmp(arg, "--always"))
50 - opt->always_show_header = 1;
51 - else
52 - return 0;
53 - return 1;
54 -}
55 -
56 -int log_tree_diff_flush(struct log_tree_opt *opt)
6 +int log_tree_diff_flush(struct rev_info *opt)
7 {
8 diffcore_std(&opt->diffopt);
9 if (diff_queue_is_empty()) {
@@ -73,7 +23,7 @@ int log_tree_diff_flush(struct log_tree_opt *opt)
23 return 1;
24 }
25
76 -static int diff_root_tree(struct log_tree_opt *opt,
26 +static int diff_root_tree(struct rev_info *opt,
27 const unsigned char *new, const char *base)
28 {
29 int retval;
@@ -93,7 +43,7 @@ static int diff_root_tree(struct log_tree_opt *opt,
43 return retval;
44 }
45
96 -static const char *generate_header(struct log_tree_opt *opt,
46 +static const char *generate_header(struct rev_info *opt,
47 const unsigned char *commit_sha1,
48 const unsigned char *parent_sha1,
49 const struct commit *commit)
@@ -129,7 +79,7 @@ static const char *generate_header(struct log_tree_opt *opt,
79 return this_header;
80 }
81
132 -static int do_diff_combined(struct log_tree_opt *opt, struct commit *commit)
82 +static int do_diff_combined(struct rev_info *opt, struct commit *commit)
83 {
84 unsigned const char *sha1 = commit->object.sha1;
85
@@ -142,7 +92,7 @@ static int do_diff_combined(struct log_tree_opt *opt, struct commit *commit)
92 return 0;
93 }
94
145 -int log_tree_commit(struct log_tree_opt *opt, struct commit *commit)
95 +int log_tree_commit(struct rev_info *opt, struct commit *commit)
96 {
97 struct commit_list *parents;
98 unsigned const char *sha1 = commit->object.sha1;
log-tree.h
+5 -17
@@ -1,23 +1,11 @@
1 #ifndef LOG_TREE_H
2 #define LOG_TREE_H
3
4 -struct log_tree_opt {
5 - struct diff_options diffopt;
6 - int show_root_diff;
7 - int no_commit_id;
8 - int verbose_header;
9 - int ignore_merges;
10 - int combine_merges;
11 - int dense_combined_merges;
12 - int always_show_header;
13 - const char *header_prefix;
14 - const char *header;
15 - enum cmit_fmt commit_format;
16 -};
4 +#include "revision.h"
5
18 -void init_log_tree_opt(struct log_tree_opt *);
19 -int log_tree_diff_flush(struct log_tree_opt *);
20 -int log_tree_commit(struct log_tree_opt *, struct commit *);
21 -int log_tree_opt_parse(struct log_tree_opt *, const char **, int);
6 +void init_log_tree_opt(struct rev_info *);
7 +int log_tree_diff_flush(struct rev_info *);
8 +int log_tree_commit(struct rev_info *, struct commit *);
9 +int log_tree_opt_parse(struct rev_info *, const char **, int);
10
11 #endif
revision.c
+134 -34
@@ -116,21 +116,27 @@ static void add_pending_object(struct rev_info *revs, struct object *obj, const
116 add_object(obj, &revs->pending_objects, NULL, name);
117 }
118
119 -static struct commit *get_commit_reference(struct rev_info *revs, const char *name, const unsigned char *sha1, unsigned int flags)
119 +static struct object *get_reference(struct rev_info *revs, const char *name, const unsigned char *sha1, unsigned int flags)
120 {
121 struct object *object;
122
123 object = parse_object(sha1);
124 if (!object)
125 die("bad object %s", name);
126 + object->flags |= flags;
127 + return object;
128 +}
129 +
130 +static struct commit *handle_commit(struct rev_info *revs, struct object *object, const char *name)
131 +{
132 + unsigned long flags = object->flags;
133
134 /*
135 * Tag object? Look what it points to..
136 */
137 while (object->type == tag_type) {
138 struct tag *tag = (struct tag *) object;
132 - object->flags |= flags;
133 - if (revs->tag_objects && !(object->flags & UNINTERESTING))
139 + if (revs->tag_objects && !(flags & UNINTERESTING))
140 add_pending_object(revs, object, tag->tag);
141 object = parse_object(tag->tagged->sha1);
142 if (!object)
@@ -143,7 +149,6 @@ static struct commit *get_commit_reference(struct rev_info *revs, const char *na
149 */
150 if (object->type == commit_type) {
151 struct commit *commit = (struct commit *)object;
146 - object->flags |= flags;
152 if (parse_commit(commit) < 0)
153 die("unable to parse commit %s", name);
154 if (flags & UNINTERESTING) {
@@ -241,7 +246,7 @@ int rev_compare_tree(struct rev_info *revs, struct tree *t1, struct tree *t2)
246 return REV_TREE_DIFFERENT;
247 tree_difference = REV_TREE_SAME;
248 if (diff_tree_sha1(t1->object.sha1, t2->object.sha1, "",
244 - &revs->diffopt) < 0)
249 + &revs->pruning) < 0)
250 return REV_TREE_DIFFERENT;
251 return tree_difference;
252 }
@@ -264,7 +269,7 @@ int rev_same_tree_as_empty(struct rev_info *revs, struct tree *t1)
269 empty.size = 0;
270
271 tree_difference = 0;
267 - retval = diff_tree(&empty, &real, "", &revs->diffopt);
272 + retval = diff_tree(&empty, &real, "", &revs->pruning);
273 free(tree);
274
275 return retval >= 0 && !tree_difference;
@@ -451,21 +456,13 @@ static void limit_list(struct rev_info *revs)
456 revs->commits = newlist;
457 }
458
454 -static void add_one_commit(struct commit *commit, struct rev_info *revs)
455 -{
456 - if (!commit || (commit->object.flags & SEEN))
457 - return;
458 - commit->object.flags |= SEEN;
459 - commit_list_insert(commit, &revs->commits);
460 -}
461 -
459 static int all_flags;
460 static struct rev_info *all_revs;
461
462 static int handle_one_ref(const char *path, const unsigned char *sha1)
463 {
467 - struct commit *commit = get_commit_reference(all_revs, path, sha1, all_flags);
468 - add_one_commit(commit, all_revs);
464 + struct object *object = get_reference(all_revs, path, sha1, all_flags);
465 + add_pending_object(all_revs, object, "");
466 return 0;
467 }
468
@@ -479,9 +476,9 @@ static void handle_all(struct rev_info *revs, unsigned flags)
476 void init_revisions(struct rev_info *revs)
477 {
478 memset(revs, 0, sizeof(*revs));
482 - revs->diffopt.recursive = 1;
483 - revs->diffopt.add_remove = file_add_remove;
484 - revs->diffopt.change = file_change;
479 + revs->pruning.recursive = 1;
480 + revs->pruning.add_remove = file_add_remove;
481 + revs->pruning.change = file_change;
482 revs->lifo = 1;
483 revs->dense = 1;
484 revs->prefix = setup_git_directory();
@@ -494,6 +491,11 @@ void init_revisions(struct rev_info *revs)
491
492 revs->topo_setter = topo_sort_default_setter;
493 revs->topo_getter = topo_sort_default_getter;
494 +
495 + revs->header_prefix = "";
496 + revs->commit_format = CMIT_FMT_DEFAULT;
497 +
498 + diff_setup(&revs->diffopt);
499 }
500
501 /*
@@ -526,13 +528,14 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
528
529 flags = 0;
530 for (i = 1; i < argc; i++) {
529 - struct commit *commit;
531 + struct object *object;
532 const char *arg = argv[i];
533 unsigned char sha1[20];
534 char *dotdot;
535 int local_flags;
536
537 if (*arg == '-') {
538 + int opts;
539 if (!strncmp(arg, "--max-count=", 12)) {
540 revs->max_count = atoi(arg + 12);
541 continue;
@@ -640,6 +643,78 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
643 revs->unpacked = 1;
644 continue;
645 }
646 + if (!strcmp(arg, "-r")) {
647 + revs->diff = 1;
648 + revs->diffopt.recursive = 1;
649 + continue;
650 + }
651 + if (!strcmp(arg, "-t")) {
652 + revs->diff = 1;
653 + revs->diffopt.recursive = 1;
654 + revs->diffopt.tree_in_recursive = 1;
655 + continue;
656 + }
657 + if (!strcmp(arg, "-m")) {
658 + revs->ignore_merges = 0;
659 + continue;
660 + }
661 + if (!strcmp(arg, "-c")) {
662 + revs->diff = 1;
663 + revs->combine_merges = 1;
664 + continue;
665 + }
666 + if (!strcmp(arg, "--cc")) {
667 + revs->diff = 1;
668 + revs->dense_combined_merges = 1;
669 + revs->combine_merges = 1;
670 + continue;
671 + }
672 + if (!strcmp(arg, "-v")) {
673 + revs->verbose_header = 1;
674 + revs->header_prefix = "diff-tree ";
675 + continue;
676 + }
677 + if (!strncmp(arg, "--pretty", 8)) {
678 + revs->verbose_header = 1;
679 + revs->header_prefix = "diff-tree ";
680 + revs->commit_format = get_commit_format(arg+8);
681 + continue;
682 + }
683 + if (!strcmp(arg, "--root")) {
684 + revs->show_root_diff = 1;
685 + continue;
686 + }
687 + if (!strcmp(arg, "--no-commit-id")) {
688 + revs->no_commit_id = 1;
689 + continue;
690 + }
691 + if (!strcmp(arg, "--always")) {
692 + revs->always_show_header = 1;
693 + continue;
694 + }
695 + if (!strcmp(arg, "--no-abbrev")) {
696 + revs->abbrev = 0;
697 + continue;
698 + }
699 + if (!strcmp(arg, "--abbrev")) {
700 + revs->abbrev = DEFAULT_ABBREV;
701 + continue;
702 + }
703 + if (!strcmp(arg, "--abbrev-commit")) {
704 + revs->abbrev_commit = 1;
705 + continue;
706 + }
707 + if (!strcmp(arg, "--full-diff")) {
708 + revs->diff = 1;
709 + revs->full_diff = 1;
710 + continue;
711 + }
712 + opts = diff_opt_parse(&revs->diffopt, argv+i, argc-i);
713 + if (opts > 0) {
714 + revs->diff = 1;
715 + i += opts - 1;
716 + continue;
717 + }
718 *unrecognized++ = arg;
719 left++;
720 continue;
@@ -656,15 +731,15 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
731 this = "HEAD";
732 if (!get_sha1(this, from_sha1) &&
733 !get_sha1(next, sha1)) {
659 - struct commit *exclude;
660 - struct commit *include;
734 + struct object *exclude;
735 + struct object *include;
736
662 - exclude = get_commit_reference(revs, this, from_sha1, flags ^ UNINTERESTING);
663 - include = get_commit_reference(revs, next, sha1, flags);
737 + exclude = get_reference(revs, this, from_sha1, flags ^ UNINTERESTING);
738 + include = get_reference(revs, next, sha1, flags);
739 if (!exclude || !include)
740 die("Invalid revision range %s..%s", arg, next);
666 - add_one_commit(exclude, revs);
667 - add_one_commit(include, revs);
741 + add_pending_object(revs, exclude, this);
742 + add_pending_object(revs, include, next);
743 continue;
744 }
745 *dotdot = '.';
@@ -689,32 +764,57 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
764 revs->prune_data = get_pathspec(revs->prefix, argv + i);
765 break;
766 }
692 - commit = get_commit_reference(revs, arg, sha1, flags ^ local_flags);
693 - add_one_commit(commit, revs);
767 + object = get_reference(revs, arg, sha1, flags ^ local_flags);
768 + add_pending_object(revs, object, arg);
769 }
695 - if (def && !revs->commits) {
770 + if (def && !revs->pending_objects) {
771 unsigned char sha1[20];
697 - struct commit *commit;
772 + struct object *object;
773 if (get_sha1(def, sha1) < 0)
774 die("bad default revision '%s'", def);
700 - commit = get_commit_reference(revs, def, sha1, 0);
701 - add_one_commit(commit, revs);
775 + object = get_reference(revs, def, sha1, 0);
776 + add_pending_object(revs, object, def);
777 }
778
779 if (revs->topo_order || revs->unpacked)
780 revs->limited = 1;
781
782 if (revs->prune_data) {
708 - diff_tree_setup_paths(revs->prune_data, &revs->diffopt);
783 + diff_tree_setup_paths(revs->prune_data, &revs->pruning);
784 revs->prune_fn = try_to_simplify_commit;
785 + if (!revs->full_diff)
786 + diff_tree_setup_paths(revs->prune_data, &revs->diffopt);
787 }
788 + if (revs->combine_merges) {
789 + revs->ignore_merges = 0;
790 + if (revs->dense_combined_merges)
791 + revs->diffopt.output_format = DIFF_FORMAT_PATCH;
792 + }
793 + if (revs->diffopt.output_format == DIFF_FORMAT_PATCH)
794 + revs->diffopt.recursive = 1;
795 + revs->diffopt.abbrev = revs->abbrev;
796 + diff_setup_done(&revs->diffopt);
797
798 return left;
799 }
800
801 void prepare_revision_walk(struct rev_info *revs)
802 {
717 - sort_by_date(&revs->commits);
803 + struct object_list *list;
804 +
805 + list = revs->pending_objects;
806 + revs->pending_objects = NULL;
807 + while (list) {
808 + struct commit *commit = handle_commit(revs, list->item, list->name);
809 + if (commit) {
810 + if (!(commit->object.flags & SEEN)) {
811 + commit->object.flags |= SEEN;
812 + insert_by_date(commit, &revs->commits);
813 + }
814 + }
815 + list = list->next;
816 + }
817 +
818 if (revs->limited)
819 limit_list(revs);
820 if (revs->topo_order)
revision.h
+20 -1
@@ -38,13 +38,32 @@ struct rev_info {
38 boundary:1,
39 parents:1;
40
41 + /* Diff flags */
42 + unsigned int diff:1,
43 + full_diff:1,
44 + show_root_diff:1,
45 + no_commit_id:1,
46 + verbose_header:1,
47 + ignore_merges:1,
48 + combine_merges:1,
49 + dense_combined_merges:1,
50 + always_show_header:1;
51 +
52 + /* Format info */
53 + unsigned int abbrev_commit:1;
54 + unsigned int abbrev;
55 + enum cmit_fmt commit_format;
56 + const char *header_prefix;
57 + const char *header;
58 +
59 /* special limits */
60 int max_count;
61 unsigned long max_age;
62 unsigned long min_age;
63
46 - /* paths limiting */
64 + /* diff info for patches and for paths limiting */
65 struct diff_options diffopt;
66 + struct diff_options pruning;
67
68 topo_sort_set_fn_t topo_setter;
69 topo_sort_get_fn_t topo_getter;