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

Re: checkout/update boiler plate for --filter-index?

From
Jeff King <peff@peff.net>
Date
Mar 24, 2009, 07:43 UTC
Message-ID
<20090324074301.GB32400@coredump.intra.peff.net>
In-Reply-To
<49C889E2.2080208@viscovery.net>
On Tue, Mar 24, 2009 at 08:21:06AM +0100, Johannes Sixt wrote:
Show 6 quoted lines
> You cannot do that with the index filter because you need actual blob
> contents to operate on, but the index filter doesn't give you an
> opportunity to do that. The tree filter is the right filter to use. But
> you neither need 'git checkout' nor 'git update-index' in the filter -
> filter-branch calls them for you. (Oh, and get rid of that useless use of
> cat.)

Well, you _could_ do it as an index-filter, which has the potential to be much faster if you are only operating only on a small subset of the files. But it's much less readable. Something like (totally untested):

  git filter-branch --index-filter '
    for i in `cat /path/to/files`; do
      hash=$(git cat-file :$i |
             sed 's/foo/bar/' |
             git hash-object -w --stdin)
      git update-index --add --cacheinfo 100644 $hash $i
    done
  '

I'm sure you could do even do it with a constant number of processes per commit by using update-index --index-info, hash-object --stdin-paths, and cat-file --batch. But it would probably be even less readable. ;)

Personally, I would probably just do a tree-filter for simplicity unless the repo size made it prohibitively slow.

-Peff
Previous: Johannes Sixt
Message 3 of 3 in “checkout/update boiler plate for --filter-index?”
  1. Marcel CaryMar 23, 2009
  2. Johannes SixtMar 24, 2009
  3. Jeff KingMar 24, 2009

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.