{"thread":{"id":"8959","subject":"Per-file, possibly even per-hunk cherry picking","startedAt":"2007-07-10T12:16:43Z","lastAt":"2007-07-11T22:00:17Z","messageCount":5,"participants":["Sam Vilain","Johannes Schindelin","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"46931","messageId":"469378AB.7030909@vilain.net","threadId":"8959","inReplyTo":null,"subject":"Per-file, possibly even per-hunk cherry picking","fromName":"Sam Vilain","fromEmail":"sam@vilain.net","sentAt":"2007-07-10T12:16:43Z","receivedAt":"2007-07-10T12:16:43Z","isPatch":false,"sender":{"key":"sam@vilain.net","avatar":"https://gravatar.com/avatar/8fc840ca854dbf6f7065b4335e3b934951c1dca3b11db688e95e471901f8f4a8?d=mp&s=160"},"body":"Hi all,\n\nI'm interested in extending the cherry analysis to allow specification\nof the diff options used when calculating diff IDs, presenting the\ncalculated diff IDs for analysis by external tools, and even calculating\nand dealing with per-hunk diff IDs.\n\nHas anyone done anything with this before, or got any good pointers or\nadvice?\n\nSam.\n"},{"id":"46932","messageId":"4693800F.4010308@vilain.net","threadId":"8959","inReplyTo":"469378AB.7030909@vilain.net","subject":"Re: Per-file, possibly even per-hunk cherry picking","fromName":"Sam Vilain","fromEmail":"sam@vilain.net","sentAt":"2007-07-10T12:48:15Z","receivedAt":"2007-07-10T12:48:15Z","isPatch":false,"sender":{"key":"sam@vilain.net","avatar":"https://gravatar.com/avatar/8fc840ca854dbf6f7065b4335e3b934951c1dca3b11db688e95e471901f8f4a8?d=mp&s=160"},"body":"Sam Vilain wrote:\n> I'm interested in extending the cherry analysis to allow specification\n> of the diff options used when calculating diff IDs, presenting the\n> calculated diff IDs for analysis by external tools, and even calculating\n> and dealing with per-hunk diff IDs.\n>   \n\nOn reflection I think so long as --cherry-pick works together with a\nfile selection, it would probably be enough.\n\nie, if I have these commits:\n\nA---B\n \\\n  \\\n   C\n\nB changes a file foo.c, adding a line of text.  C changes foo.c as well\nas bar.c, but the change in foo.c was identical to change B.\n\nI want this to show me nothing:\n\n  git-rev-list --left-right --cherry-pick B...C -- foo.c\n\nWould it be the right approach to put this information in ids->diffopts,\nor somewhere else?\n\nSam.\n"},{"id":"46943","messageId":"Pine.LNX.4.64.0707101449220.4047@racer.site","threadId":"8959","inReplyTo":"4693800F.4010308@vilain.net","subject":"[PATCH] Fix --cherry-pick with given paths","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-07-10T13:50:49Z","receivedAt":"2007-07-10T13:50:49Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"\nIf you say --cherry-pick, you do not want to see patches which are\nin the upstream.  If you specify paths with that, what you usually\nexpect is that only those parts of the patches are looked at which\nactually touch the given paths.\n\nWith this patch, that expectation is met.\n\nNoticed by Sam Vilain.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n\n\tOn Wed, 11 Jul 2007, Sam Vilain wrote:\n\n\t> Sam Vilain wrote:\n\t> > I'm interested in extending the cherry analysis to allow \n\t> > specification of the diff options used when calculating diff \n\t> > IDs, presenting the calculated diff IDs for analysis by \n\t> > external tools, and even calculating and dealing with per-hunk \n\t> > diff IDs.\n\t> \n\t> On reflection I think so long as --cherry-pick works together \n\t> with a file selection, it would probably be enough.\n\t> \n\t> ie, if I have these commits:\n\t> \n\t> A---B\n\t>  \\\n\t>   \\\n\t>    C\n\t> \n\t> B changes a file foo.c, adding a line of text.  C changes foo.c \n\t> as well as bar.c, but the change in foo.c was identical to \n\t> change B.\n\t> \n\t> I want this to show me nothing:\n\t> \n\t>   git-rev-list --left-right --cherry-pick B...C -- foo.c\n\t> \n\t> Would it be the right approach to put this information in \n\t> ids->diffopts, or somewhere else?\n\n\tThat was interesting.  And it is indeed the right place to put it.\n\n revision.c                           |    9 +++++-\n t/t6007-rev-list-cherry-pick-file.sh |   43 ++++++++++++++++++++++++++++++++++\n 2 files changed, 50 insertions(+), 2 deletions(-)\n create mode 100755 t/t6007-rev-list-cherry-pick-file.sh\n\ndiff --git a/revision.c b/revision.c\nindex 33ee9ee..27cce09 100644\n--- a/revision.c\n+++ b/revision.c\n@@ -437,7 +437,7 @@ static int add_parents_to_list(struct rev_info *revs, struct commit *commit, str\n \treturn 0;\n }\n \n-static void cherry_pick_list(struct commit_list *list)\n+static void cherry_pick_list(struct commit_list *list, struct rev_info *revs)\n {\n \tstruct commit_list *p;\n \tint left_count = 0, right_count = 0;\n@@ -458,6 +458,11 @@ static void cherry_pick_list(struct commit_list *list)\n \n \tleft_first = left_count < right_count;\n \tinit_patch_ids(&ids);\n+\tif (revs->diffopt.nr_paths) {\n+\t\tids.diffopts.nr_paths = revs->diffopt.nr_paths;\n+\t\tids.diffopts.paths = revs->diffopt.paths;\n+\t\tids.diffopts.pathlens = revs->diffopt.pathlens;\n+\t}\n \n \t/* Compute patch-ids for one side */\n \tfor (p = list; p; p = p->next) {\n@@ -546,7 +551,7 @@ static int limit_list(struct rev_info *revs)\n \t\tp = &commit_list_insert(commit, p)->next;\n \t}\n \tif (revs->cherry_pick)\n-\t\tcherry_pick_list(newlist);\n+\t\tcherry_pick_list(newlist, revs);\n \n \trevs->commits = newlist;\n \treturn 0;\ndiff --git a/t/t6007-rev-list-cherry-pick-file.sh b/t/t6007-rev-list-cherry-pick-file.sh\nnew file mode 100755\nindex 0000000..143f332\n--- /dev/null\n+++ b/t/t6007-rev-list-cherry-pick-file.sh\n@@ -0,0 +1,43 @@\n+#!/bin/sh\n+\n+test_description='test git rev-list --cherry-pick -- file'\n+\n+. ./test-lib.sh\n+\n+# A---B\n+#  \\\n+#   \\\n+#    C\n+# \n+# B changes a file foo.c, adding a line of text.  C changes foo.c as\n+# well as bar.c, but the change in foo.c was identical to change B.\n+\n+test_expect_success setup '\n+\techo Hallo > foo &&\n+\tgit add foo &&\n+\ttest_tick &&\n+\tgit commit -m \"A\" &&\n+\tgit tag A &&\n+\tgit checkout -b branch &&\n+\techo Bello > foo &&\n+\techo Cello > bar &&\n+\tgit add foo bar &&\n+\ttest_tick &&\n+\tgit commit -m \"C\" &&\n+\tgit tag C &&\n+\tgit checkout master &&\n+\tgit checkout branch foo &&\n+\ttest_tick &&\n+\tgit commit -m \"B\" &&\n+\tgit tag B\n+'\n+\n+test_expect_success '--cherry-pick foo comes up empty' '\n+\ttest -z \"$(git rev-list --left-right --cherry-pick B...C -- foo)\"\n+'\n+\n+test_expect_success '--cherry-pick bar does not come up empty' '\n+\t! test -z \"$(git rev-list --left-right --cherry-pick B...C -- bar)\"\n+'\n+\n+test_done\n-- \n1.5.3.rc0.2782.g192a9-dirty\n"},{"id":"46952","messageId":"4693960C.1010906@vilain.net","threadId":"8959","inReplyTo":"Pine.LNX.4.64.0707101449220.4047@racer.site","subject":"Re: [PATCH] Fix --cherry-pick with given paths","fromName":"Sam Vilain","fromEmail":"sam@vilain.net","sentAt":"2007-07-10T14:22:04Z","receivedAt":"2007-07-10T14:22:04Z","isPatch":true,"sender":{"key":"sam@vilain.net","avatar":"https://gravatar.com/avatar/8fc840ca854dbf6f7065b4335e3b934951c1dca3b11db688e95e471901f8f4a8?d=mp&s=160"},"body":"Johannes Schindelin wrote:\n> If you say --cherry-pick, you do not want to see patches which are\n> in the upstream.  If you specify paths with that, what you usually\n> expect is that only those parts of the patches are looked at which\n> actually touch the given paths.\n>\n> With this patch, that expectation is met.\n>\n> Noticed by Sam Vilain.\n>\n> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n>   \n\nI just tested this, and it seems to work just like I hoped, so:\n\nSigned-off-by: Sam Vilain <sam.vilain@catalyst.net.nz>\n\nSam.\n"},{"id":"47090","messageId":"7vsl7u1tzi.fsf@assigned-by-dhcp.cox.net","threadId":"8959","inReplyTo":"Pine.LNX.4.64.0707101449220.4047@racer.site","subject":"Re: [PATCH] Fix --cherry-pick with given paths","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-07-11T22:00:17Z","receivedAt":"2007-07-11T22:00:17Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n\n> \t> Sam Vilain wrote:\n> \t> > I'm interested in extending the cherry analysis to allow \n> \t> > specification of the diff options used when calculating diff \n> \t> > IDs, presenting the calculated diff IDs for analysis by \n> \t> > external tools, and even calculating and dealing with per-hunk \n> \t> > diff IDs.\n> \t> \n> \t> On reflection I think so long as --cherry-pick works together \n> \t> with a file selection, it would probably be enough.\n> \t> \n> \t> ie, if I have these commits:\n> \t> \n> \t> A---B\n> \t>  \\\n> \t>   \\\n> \t>    C\n> \t> \n> \t> B changes a file foo.c, adding a line of text.  C changes foo.c \n> \t> as well as bar.c, but the change in foo.c was identical to \n> \t> change B.\n> \t> \n> \t> I want this to show me nothing:\n> \t> \n> \t>   git-rev-list --left-right --cherry-pick B...C -- foo.c\n\nThanks, both.\n"}]}