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

Extended SHA1 -- "rev^@" syntax to mean "all parents"

A short-hand "rev^@" is understood to be "all parents of the named commit" with this patch. So you can do git show v1.0.0^@ to view the parents of a merge commit, gitk ^v1.0.0^@ v1.0.4 to view the log between two revs (including the bottom one), and git diff --cc v1.1.0 v1.0.0^@ to inspect what got changed from the merge parents of v1.0.0 to v1.1.0. This might be just my shiny new toy that is not very useful in practice. I needed it to do the multi-tree diff on Len's infamous 12-way Octopus; typing "diff --cc funmerge funmerge^1 funmerge^2 funmerge^3 ..." was too painful. [jc: taking suggestions from Linus and Johannes to match expectations from shell users who are used to see $@ or $* either of which makes sense. I tend to write "$@" more often so...] Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Apr 30, 2006 at 00:54 UTC ea4a19e172e8db52779c06723b1e99cc12f228c9
1 file changed +37
revision.c
+37
@@ -477,6 +477,36 @@ static void handle_all(struct rev_info *revs, unsigned flags)
477 for_each_ref(handle_one_ref);
478 }
479
480 +static int add_parents_only(struct rev_info *revs, const char *arg, int flags)
481 +{
482 + unsigned char sha1[20];
483 + struct object *it;
484 + struct commit *commit;
485 + struct commit_list *parents;
486 +
487 + if (*arg == '^') {
488 + flags ^= UNINTERESTING;
489 + arg++;
490 + }
491 + if (get_sha1(arg, sha1))
492 + return 0;
493 + while (1) {
494 + it = get_reference(revs, arg, sha1, 0);
495 + if (strcmp(it->type, tag_type))
496 + break;
497 + memcpy(sha1, ((struct tag*)it)->tagged->sha1, 20);
498 + }
499 + if (strcmp(it->type, commit_type))
500 + return 0;
501 + commit = (struct commit *)it;
502 + for (parents = commit->parents; parents; parents = parents->next) {
503 + it = &parents->item->object;
504 + it->flags |= flags;
505 + add_pending_object(revs, it, arg);
506 + }
507 + return 1;
508 +}
509 +
510 void init_revisions(struct rev_info *revs)
511 {
512 memset(revs, 0, sizeof(*revs));
@@ -746,6 +776,13 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
776 }
777 *dotdot = '.';
778 }
779 + dotdot = strstr(arg, "^@");
780 + if (dotdot && !dotdot[2]) {
781 + *dotdot = 0;
782 + if (add_parents_only(revs, arg, flags))
783 + continue;
784 + *dotdot = '^';
785 + }
786 local_flags = 0;
787 if (*arg == '^') {
788 local_flags = UNINTERESTING;