@matheusbsbs / matheus-bagliano / commits / 60adf7d73e
Fork 0

revlist.c: introduce --left/right-only for unsymmetric picking

The existing "--cherry-pick" does not work with unsymmetric ranges (A..B) for obvious reasons. Introduce "--left-only" and "--right-only" which limit the output to commits on the respective sides of a symmetric range (i.e. only "<" resp. ">" commits as per "--left-right"). This is especially useful for things like git log --cherry-pick --right-only @{u}... which is much more flexible (and descriptive) than git cherry @{u} | sed -ne 's/^+ //p' and potentially more useful than git log --cherry-pick @{u}... Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Michael J Gruber committed Feb 21, 2011 at 17:09 UTC 60adf7d73e44126289a98dada60f9c335ffc84b0
2 files changed +26
revision.c
+24
@@ -733,6 +733,23 @@ static struct commit_list *collect_bottom_commits(struct commit_list *list)
733 return bottom;
734 }
735
736 +/* Assumes either left_only or right_only is set */
737 +static void limit_left_right(struct commit_list *list, struct rev_info *revs)
738 +{
739 + struct commit_list *p;
740 +
741 + for (p = list; p; p = p->next) {
742 + struct commit *commit = p->item;
743 +
744 + if (revs->right_only) {
745 + if (commit->object.flags & SYMMETRIC_LEFT)
746 + commit->object.flags |= SHOWN;
747 + } else /* revs->left_only is set */
748 + if (!(commit->object.flags & SYMMETRIC_LEFT))
749 + commit->object.flags |= SHOWN;
750 + }
751 +}
752 +
753 static int limit_list(struct rev_info *revs)
754 {
755 int slop = SLOP;
@@ -788,6 +805,9 @@ static int limit_list(struct rev_info *revs)
805 if (revs->cherry_pick)
806 cherry_pick_list(newlist, revs);
807
808 + if (revs->left_only || revs->right_only)
809 + limit_left_right(newlist, revs);
810 +
811 if (bottom) {
812 limit_to_ancestry(bottom, newlist);
813 free_commit_list(bottom);
@@ -1263,6 +1283,10 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
1283 revs->boundary = 1;
1284 } else if (!strcmp(arg, "--left-right")) {
1285 revs->left_right = 1;
1286 + } else if (!strcmp(arg, "--left-only")) {
1287 + revs->left_only = 1;
1288 + } else if (!strcmp(arg, "--right-only")) {
1289 + revs->right_only = 1;
1290 } else if (!strcmp(arg, "--count")) {
1291 revs->count = 1;
1292 } else if (!strcmp(arg, "--cherry-pick")) {
revision.h
+2
@@ -59,6 +59,8 @@ struct rev_info {
59 boundary:2,
60 count:1,
61 left_right:1,
62 + left_only:1,
63 + right_only:1,
64 rewrite_parents:1,
65 print_parents:1,
66 show_source:1,