{"thread":{"id":"28285","subject":"rev-list --cherry-pick and context lines","startedAt":"2011-09-02T10:35:20Z","lastAt":"2011-09-02T19:13:40Z","messageCount":6,"participants":["Stefan Haller","Michael J Gruber","Vijay Lakshminarayanan","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"174741","messageId":"1k6yux4.x1kexb19bkrqpM%lists@haller-berlin.de","threadId":"28285","inReplyTo":null,"subject":"rev-list --cherry-pick and context lines","fromName":"Stefan Haller","fromEmail":"lists@haller-berlin.de","sentAt":"2011-09-02T10:35:20Z","receivedAt":"2011-09-02T10:35:20Z","isPatch":false,"sender":{"key":"lists@haller-berlin.de","avatar":null},"body":"Consider two commits on different branches, one with this patch:\n\n    diff --git a/file.txt b/file.txt\n    index 704fa27..2f7e74c 100644\n    --- a/file.txt\n    +++ b/file.txt\n    @@ -1,3 +1,3 @@\n     old_context\n     \n    -foo\n    +bar\n\nand the other with this patch:\n\n    diff --git a/file.txt b/file.txt\n    index f35051b..8c7de32 100644\n    --- a/file.txt\n    +++ b/file.txt\n    @@ -1,3 +1,3 @@\n     new_context\n     \n    -foo\n    +bar\n\nIf I run \"git rev-list --cherry-pick --left-right branch1...branch2\", it\nreports both commits as being genuine commits on their respective\nbranch, even though I consider their patches to be the same.\n\nI guess for my purpose I would like to have patch-ids that ignore\ncontext (or that use only one line of context, I'm not sure which).\n\nIn fact, if I do \"git show <commit> -U1 | git patch-id\", both commits\nshow the same id.\n\nSo, would it make sense to have a parameter for git-rev-list (and\ngit-cherry) that lets you specify how much context to be used for the\npatch ids?\n\n\n-- \nStefan Haller\nBerlin, Germany\nhttp://www.haller-berlin.de/\n"},{"id":"174750","messageId":"4E60F707.40708@drmicha.warpmail.net","threadId":"28285","inReplyTo":"1k6yux4.x1kexb19bkrqpM%lists@haller-berlin.de","subject":"Re: rev-list --cherry-pick and context lines","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2011-09-02T15:32:23Z","receivedAt":"2011-09-02T15:32:23Z","isPatch":false,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"Stefan Haller venit, vidit, dixit 02.09.2011 12:35:\n> Consider two commits on different branches, one with this patch:\n> \n>     diff --git a/file.txt b/file.txt\n>     index 704fa27..2f7e74c 100644\n>     --- a/file.txt\n>     +++ b/file.txt\n>     @@ -1,3 +1,3 @@\n>      old_context\n>      \n>     -foo\n>     +bar\n> \n> and the other with this patch:\n> \n>     diff --git a/file.txt b/file.txt\n>     index f35051b..8c7de32 100644\n>     --- a/file.txt\n>     +++ b/file.txt\n>     @@ -1,3 +1,3 @@\n>      new_context\n>      \n>     -foo\n>     +bar\n> \n> If I run \"git rev-list --cherry-pick --left-right branch1...branch2\", it\n> reports both commits as being genuine commits on their respective\n> branch, even though I consider their patches to be the same.\n> \n> I guess for my purpose I would like to have patch-ids that ignore\n> context (or that use only one line of context, I'm not sure which).\n> \n> In fact, if I do \"git show <commit> -U1 | git patch-id\", both commits\n> show the same id.\n> \n> So, would it make sense to have a parameter for git-rev-list (and\n> git-cherry) that lets you specify how much context to be used for the\n> patch ids?\n\nIt would be a bit like the patch below. \"git log\" accepts diff options already.\nBut:\n\n- Do we want the patch id generation and the patch display (-p) to use the\n  same options?\n\n- -U1 implies -p/--patch and there is no --no-patch.\n\n- Which other diff options do we want to pass to the patch id\n  generation: --histogram, --patience, ...?\n\nCheers,\nMichael\n\n----\n\ndiff --git i/diff.c w/diff.c\nindex fcc0078..4e82912 100644\n--- i/diff.c\n+++ w/diff.c\n@@ -4103,7 +4103,7 @@ static int diff_get_patch_id(struct diff_options *options, unsigned char *sha1)\n \t\t}\n \n \t\txpp.flags = 0;\n-\t\txecfg.ctxlen = 3;\n+\t\txecfg.ctxlen = options->context;\n \t\txecfg.flags = 0;\n \t\txdi_diff_outf(&mf1, &mf2, patch_id_consume, &data,\n \t\t\t      &xpp, &xecfg);\ndiff --git i/revision.c w/revision.c\nindex 072ddac..5a98ed9 100644\n--- i/revision.c\n+++ w/revision.c\n@@ -601,6 +601,7 @@ static void cherry_pick_list(struct commit_list *list, struct rev_info *revs)\n \tleft_first = left_count < right_count;\n \tinit_patch_ids(&ids);\n \tids.diffopts.pathspec = revs->diffopt.pathspec;\n+\tids.diffopts.context = revs->diffopt.context;\n \n \t/* Compute patch-ids for one side */\n \tfor (p = list; p; p = p->next) {\n"},{"id":"174756","messageId":"1k6zcbk.ov5qevxc1a91M%lists@haller-berlin.de","threadId":"28285","inReplyTo":"4E60F707.40708@drmicha.warpmail.net","subject":"Re: rev-list --cherry-pick and context lines","fromName":"Stefan Haller","fromEmail":"lists@haller-berlin.de","sentAt":"2011-09-02T16:33:06Z","receivedAt":"2011-09-02T16:33:06Z","isPatch":false,"sender":{"key":"lists@haller-berlin.de","avatar":null},"body":"Michael J Gruber <git@drmicha.warpmail.net> wrote:\n\n> Stefan Haller venit, vidit, dixit 02.09.2011 12:35:\n> > Consider two commits on different branches, one with this patch:\n> > \n> >     diff --git a/file.txt b/file.txt\n> >     index 704fa27..2f7e74c 100644\n> >     --- a/file.txt\n> >     +++ b/file.txt\n> >     @@ -1,3 +1,3 @@\n> >      old_context\n> >      \n> >     -foo\n> >     +bar\n> > \n> > and the other with this patch:\n> > \n> >     diff --git a/file.txt b/file.txt\n> >     index f35051b..8c7de32 100644\n> >     --- a/file.txt\n> >     +++ b/file.txt\n> >     @@ -1,3 +1,3 @@\n> >      new_context\n> >      \n> >     -foo\n> >     +bar\n> > \n> > If I run \"git rev-list --cherry-pick --left-right branch1...branch2\", it\n> > reports both commits as being genuine commits on their respective\n> > branch, even though I consider their patches to be the same.\n> > \n> > I guess for my purpose I would like to have patch-ids that ignore\n> > context (or that use only one line of context, I'm not sure which).\n> > \n> > In fact, if I do \"git show <commit> -U1 | git patch-id\", both commits\n> > show the same id.\n> > \n> > So, would it make sense to have a parameter for git-rev-list (and\n> > git-cherry) that lets you specify how much context to be used for the\n> > patch ids?\n> \n> It would be a bit like the patch below. \"git log\" accepts diff options already.\n> But:\n> [...]\n\nThanks a lot.  I can't contribute much to answering your \"But:\"\nquestions; I can only add more questions myself. :-)\n\nIs there a reason why the hard-coded default is 3 in the current code?\nIt seems to me that 1 would be a better choice; it would mean \"patches\nare equal if their added/removed lines are the same, and they could be\ncherry-picked without conflicts.\"\n\nNow, I'm in a situation where I'll be stuck with git 1.7.1 for quite a\nwhile, so no patch is going to help me.  It looks like the only way to\nget the behaviour I want is to reimplement git-rev-list --cherry-pick\nmyself, feeding each patch to git-patch-id, right? (Horribly\ninefficient, but might be good enough for my purpose. Just wondering if\nI'm missing a smarter way to solve it.)\n\nThanks,\n   Stefan\n\n\n-- \nStefan Haller\nBerlin, Germany\nhttp://www.haller-berlin.de/\n"},{"id":"174762","messageId":"87ty8udd68.fsf@gmail.com","threadId":"28285","inReplyTo":"1k6zcbk.ov5qevxc1a91M%lists@haller-berlin.de","subject":"Re: rev-list --cherry-pick and context lines","fromName":"Vijay Lakshminarayanan","fromEmail":"laksvij@gmail.com","sentAt":"2011-09-02T18:14:39Z","receivedAt":"2011-09-02T18:14:39Z","isPatch":false,"sender":{"key":"laksvij@gmail.com","avatar":null},"body":"lists@haller-berlin.de (Stefan Haller) writes:\n\n> Is there a reason why the hard-coded default is 3 in the current code?\n\n3 is the default context for GNU diff (and possibly other diff\nimplementations also).\n\n> Thanks,\n>    Stefan\n\n-- \nCheers\n~vijay\n"},{"id":"174765","messageId":"1k6zins.7n7tsq12p4bczM%lists@haller-berlin.de","threadId":"28285","inReplyTo":"87ty8udd68.fsf@gmail.com","subject":"Re: rev-list --cherry-pick and context lines","fromName":"Stefan Haller","fromEmail":"lists@haller-berlin.de","sentAt":"2011-09-02T18:45:34Z","receivedAt":"2011-09-02T18:45:34Z","isPatch":false,"sender":{"key":"lists@haller-berlin.de","avatar":null},"body":"Vijay Lakshminarayanan <laksvij@gmail.com> wrote:\n\n> lists@haller-berlin.de (Stefan Haller) writes:\n> \n> > Is there a reason why the hard-coded default is 3 in the current code?\n> \n> 3 is the default context for GNU diff (and possibly other diff\n> implementations also).\n\nI think you misunderstood my question; I realize that 3 is a useful\ndefault for \"git show\" or \"git log -p\" et al, for the reason you give.\n\nMy question was why 3 is the hard-coded value for calculating patch-ids.\nFor that case, 1 seems to make more sense to me.\n\n\n-- \nStefan Haller\nBerlin, Germany\nhttp://www.haller-berlin.de/\n"},{"id":"174768","messageId":"7vippalpuj.fsf@alter.siamese.dyndns.org","threadId":"28285","inReplyTo":"1k6zcbk.ov5qevxc1a91M%lists@haller-berlin.de","subject":"Re: rev-list --cherry-pick and context lines","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-09-02T19:13:40Z","receivedAt":"2011-09-02T19:13:40Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"lists@haller-berlin.de (Stefan Haller) writes:\n\n> Is there a reason why the hard-coded default is 3 in the current code?\n> It seems to me that 1 would be a better choice; it would mean \"patches\n> are equal if their added/removed lines are the same, and they could be\n> cherry-picked without conflicts.\"\n\nEven if two patches have the same added/deleted lines, depending on where\nin the preimage they are applied (which is given by the context lines),\nthe meaning of the patches can be and are very different. So if the\ndefault for showing uses 3-line contect (hence applying, as e-mailed\npatches are usually generated with 3-line context), it makes sense for the\ndefault to generate patch id to match it.\n\nAs Michael hinted, I think it would make sense to reduce the number of\ncontext lines to generate patch-id the same way if/when you reduce the\ncontext to smaller number of lines for the purpose of patch application,\nbut it does not make sense to use zero-line context as default.\n"}]}