git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: git-cherry filter

From
Jeff King <peff@peff.net>
Date
Feb 14, 2012, 21:44 UTC
Message-ID
<20120214214400.GB23649@sigill.intra.peff.net>
In-Reply-To
<jhcnfc$aec$1@dough.gmane.org>
On Mon, Feb 13, 2012 at 10:20:59PM -0600, Neal Kreitzinger wrote:
> Is there a way to add a pre-git-patch-id filter to git-cherry?
Not directly, but see below.
Show 6 quoted lines
> (a) perform "keyword contraction" to the patch before generating the 
> git-patch-id.
> 
> e.g.  I want to run a git-cherry to see if two patches are identical other 
> than keyword expansion values like $User: foo$ vs. $User: bar$.  (I would 
> have to tell git-cherry which keyword formats to "contract".)

Shouldn't these be contracted already in the canonical versions in the repo?

> (b) ignore comments in the source code.

This one is tough, because you are talking about arbitrary transformation of the diff.

> (c) exclude certain files from the diff (ie., binaries, comment files, 
> etc.).

This one is perhaps easier, and git-cherry could learn to use the regular pathspec-limiting when generating patch-ids.

In any case, git-cherry is basically just comparing the set of patch ids in one set to the patch-ids in the other set. So you could do all of the above transformations by hacking together something like:

  merge_base=`git merge-base $upstream $head`
  get_patch_ids() {
    git rev-list $merge_base..$1 |
      git diff-tree --stdin -p -- $path_limiters |
      munge_your_diff_however_you_like |
      git patch-id
  }
  get_patch_ids $head >head
  get_patch_ids $upstream | cut -d' ' -f1 >upstream
  perl -l <<-\EOF
  open(my $head, '<', 'head');
  open(my $upstream, '<', 'upstream');
  my %upstream = map { $_ => 1 } <$upstream>;
  while (<$head>) {
          chomp;
          my ($patch, $commit) = split;
          print exists($upstream{$patch}) ? '+' : '-',
                ' ',
                $commit;
  }
  EOF
-Peff
Previous: Neal Kreitzinger
Message 2 of 2 in “git-cherry filter”
  1. Neal KreitzingerFeb 14, 2012
  2. Jeff KingFeb 14, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.