{"thread":{"id":"29621","subject":"git-cherry filter","startedAt":"2012-02-14T04:20:59Z","lastAt":"2012-02-14T21:44:00Z","messageCount":2,"participants":["Neal Kreitzinger","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"184635","messageId":"jhcnfc$aec$1@dough.gmane.org","threadId":"29621","inReplyTo":null,"subject":"git-cherry filter","fromName":"Neal Kreitzinger","fromEmail":"neal@rsss.com","sentAt":"2012-02-14T04:20:59Z","receivedAt":"2012-02-14T04:20:59Z","isPatch":false,"sender":{"key":"neal@rsss.com","avatar":null},"body":"Is there a way to add a pre-git-patch-id filter to git-cherry?\n\ne.g.,\n\n(a) perform \"keyword contraction\" to the patch before generating the \ngit-patch-id.\n\ne.g.  I want to run a git-cherry to see if two patches are identical other \nthan keyword expansion values like $User: foo$ vs. $User: bar$.  (I would \nhave to tell git-cherry which keyword formats to \"contract\".)\n\n(b) ignore comments in the source code.\n\ne.g.  I want to run a git-cherry to see if the patches are identical in \nregards to executable source.  (I would have to tell git-cherry what the \ncomment rules are for the various source files.)\n\n(c) exclude certain files from the diff (ie., binaries, comment files, \netc.).\n\ne.g.  I want to run a git-cherry to see which source code fixes from the old \nsystem have already been applied to the new system regardless of whether \ncertain files differ (ie., binaries (ie, compile date), comment files (ie., \nfixed a typo), etc.).  (I would have to tell git-cherry which \npaths/filenames to disregard.)\n\nI suppose these may be git-patch-id options that are passed via git-cherry \nlike the git-fetch options passable via git-pull.\n\n\nv/r,\nneal \n"},{"id":"184699","messageId":"20120214214400.GB23649@sigill.intra.peff.net","threadId":"29621","inReplyTo":"jhcnfc$aec$1@dough.gmane.org","subject":"Re: git-cherry filter","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2012-02-14T21:44:00Z","receivedAt":"2012-02-14T21:44:00Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Feb 13, 2012 at 10:20:59PM -0600, Neal Kreitzinger wrote:\n\n> Is there a way to add a pre-git-patch-id filter to git-cherry?\n\nNot directly, but see below.\n\n> (a) perform \"keyword contraction\" to the patch before generating the \n> git-patch-id.\n> \n> e.g.  I want to run a git-cherry to see if two patches are identical other \n> than keyword expansion values like $User: foo$ vs. $User: bar$.  (I would \n> have to tell git-cherry which keyword formats to \"contract\".)\n\nShouldn't these be contracted already in the canonical versions in the\nrepo?\n\n> (b) ignore comments in the source code.\n\nThis one is tough, because you are talking about arbitrary\ntransformation of the diff.\n\n> (c) exclude certain files from the diff (ie., binaries, comment files, \n> etc.).\n\nThis one is perhaps easier, and git-cherry could learn to use the\nregular pathspec-limiting when generating patch-ids.\n\n\nIn any case, git-cherry is basically just comparing the set of patch ids\nin one set to the patch-ids in the other set. So you could do all of\nthe above transformations by hacking together something like:\n\n  merge_base=`git merge-base $upstream $head`\n  get_patch_ids() {\n    git rev-list $merge_base..$1 |\n      git diff-tree --stdin -p -- $path_limiters |\n      munge_your_diff_however_you_like |\n      git patch-id\n  }\n  get_patch_ids $head >head\n  get_patch_ids $upstream | cut -d' ' -f1 >upstream\n  perl -l <<-\\EOF\n  open(my $head, '<', 'head');\n  open(my $upstream, '<', 'upstream');\n  my %upstream = map { $_ => 1 } <$upstream>;\n  while (<$head>) {\n          chomp;\n          my ($patch, $commit) = split;\n          print exists($upstream{$patch}) ? '+' : '-',\n                ' ',\n                $commit;\n  }\n  EOF\n\n-Peff\n"}]}