@matheusbsbs / matheus-bagliano / commits / 577ed5c20b
Fork 0

rev-list --left-right

The output from "symmetric diff", i.e. A...B, does not distinguish between commits that are reachable from A and the ones that are reachable from B. In this picture, such a symmetric diff includes commits marked with a and b. x---b---b branch B / \ / / . / / \ o---x---a---a branch A However, you cannot tell which ones are 'a' and which ones are 'b' from the output. Sometimes this is frustrating. This adds an output option, --left-right, to rev-list. rev-list --left-right A...B would show ones reachable from A prefixed with '<' and the ones reachable from B prefixed with '>'. When combined with --boundary, boundary commits (the ones marked with 'x' in the above picture) are shown with prefix '-', so you would see list that looks like this: git rev-list --left-right --boundary --pretty=oneline A...B >bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb 3rd on b >bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb 2nd on b <aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 3rd on a <aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 2nd on a -xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 1st on b -xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 1st on a Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Oct 22, 2006 at 17:32 UTC 577ed5c20b4ca374626c104f90c88550cf415067
4 files changed +21 -6
builtin-rev-list.c
+11
@@ -45,6 +45,7 @@ static int bisect_list;
45 static int show_timestamp;
46 static int hdr_termination;
47 static const char *header_prefix;
48 +static int show_left_right;
49
50 static void show_commit(struct commit *commit)
51 {
@@ -54,6 +55,12 @@ static void show_commit(struct commit *commit)
55 fputs(header_prefix, stdout);
56 if (commit->object.flags & BOUNDARY)
57 putchar('-');
58 + else if (show_left_right) {
59 + if (commit->object.flags & SYMMETRIC_LEFT)
60 + putchar('<');
61 + else
62 + putchar('>');
63 + }
64 if (revs.abbrev_commit && revs.abbrev)
65 fputs(find_unique_abbrev(commit->object.sha1, revs.abbrev),
66 stdout);
@@ -240,6 +247,10 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
247 bisect_list = 1;
248 continue;
249 }
250 + if (!strcmp(arg, "--left-right")) {
251 + show_left_right = 1;
252 + continue;
253 + }
254 if (!strcmp(arg, "--stdin")) {
255 if (read_from_stdin++)
256 die("--stdin given twice?");
commit.c
+5 -5
@@ -868,11 +868,11 @@ void sort_in_topological_order_fn(struct commit_list ** list, int lifo,
868
869 /* merge-rebase stuff */
870
871 -/* bits #0..7 in revision.h */
872 -#define PARENT1 (1u<< 8)
873 -#define PARENT2 (1u<< 9)
874 -#define STALE (1u<<10)
875 -#define RESULT (1u<<11)
871 +/* bits #0..15 in revision.h */
872 +#define PARENT1 (1u<<16)
873 +#define PARENT2 (1u<<17)
874 +#define STALE (1u<<18)
875 +#define RESULT (1u<<19)
876
877 static struct commit *interesting(struct commit_list *list)
878 {
revision.c
+4 -1
@@ -344,6 +344,7 @@ static void try_to_simplify_commit(struct rev_info *revs, struct commit *commit)
344 static void add_parents_to_list(struct rev_info *revs, struct commit *commit, struct commit_list **list)
345 {
346 struct commit_list *parent = commit->parents;
347 + unsigned left_flag;
348
349 if (commit->object.flags & ADDED)
350 return;
@@ -388,6 +389,7 @@ static void add_parents_to_list(struct rev_info *revs, struct commit *commit, st
389 if (revs->no_walk)
390 return;
391
392 + left_flag = (commit->object.flags & SYMMETRIC_LEFT);
393 parent = commit->parents;
394 while (parent) {
395 struct commit *p = parent->item;
@@ -395,6 +397,7 @@ static void add_parents_to_list(struct rev_info *revs, struct commit *commit, st
397 parent = parent->next;
398
399 parse_commit(p);
400 + p->object.flags |= left_flag;
401 if (p->object.flags & SEEN)
402 continue;
403 p->object.flags |= SEEN;
@@ -640,7 +643,7 @@ int handle_revision_arg(const char *arg, struct rev_info *revs,
643 add_pending_commit_list(revs, exclude,
644 flags_exclude);
645 free_commit_list(exclude);
643 - a->object.flags |= flags;
646 + a->object.flags |= flags | SYMMETRIC_LEFT;
647 } else
648 a->object.flags |= flags_exclude;
649 b->object.flags |= flags;
revision.h
+1
@@ -9,6 +9,7 @@
9 #define BOUNDARY (1u<<5)
10 #define BOUNDARY_SHOW (1u<<6)
11 #define ADDED (1u<<7) /* Parents already parsed and added? */
12 +#define SYMMETRIC_LEFT (1u<<8)
13
14 struct rev_info;
15 struct log_info;