* checkout/update boiler plate for --filter-index?
@ 2009-03-23 21:33 Marcel Cary
2009-03-24 7:21 ` Johannes Sixt
0 siblings, 1 reply; 3+ messages in thread
From: Marcel Cary @ 2009-03-23 21:33 UTC (permalink / raw)
To: Git Mailing List
I'm trying to do a historical find-and-replace on my code:
git grep -F foo > files
git filter-branch --index-filter "
cat `pwd`/files | xargs git checkout --
cat `pwd`/files | xargs sed -i 's/foo/bar/g; '
cat `pwd`/files | xargs git update-index --
" ancestor..HEAD
When I instead use --tree-filter and skip the checkout/update-index,
it works how I want (but it takes a while...). But when I use --index-
filter, the resulting history shows the "foo" to "bar" change
happening *after* new code is added, rather than originally adding
"bar".
How can I checkout just a few files and update them to take advantage
of the speed of index operations?
Marcel
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: checkout/update boiler plate for --filter-index?
2009-03-23 21:33 checkout/update boiler plate for --filter-index? Marcel Cary
@ 2009-03-24 7:21 ` Johannes Sixt
2009-03-24 7:43 ` Jeff King
0 siblings, 1 reply; 3+ messages in thread
From: Johannes Sixt @ 2009-03-24 7:21 UTC (permalink / raw)
To: Marcel Cary; +Cc: Git Mailing List
Marcel Cary schrieb:
> I'm trying to do a historical find-and-replace on my code:
>
> git grep -F foo > files
> git filter-branch --index-filter "
> cat `pwd`/files | xargs git checkout --
> cat `pwd`/files | xargs sed -i 's/foo/bar/g; '
> cat `pwd`/files | xargs git update-index --
> " ancestor..HEAD
>
> When I instead use --tree-filter and skip the checkout/update-index, it
> works how I want (but it takes a while...). But when I use
> --index-filter, the resulting history shows the "foo" to "bar" change
> happening *after* new code is added, rather than originally adding "bar".
>
> How can I checkout just a few files and update them to take advantage of
> the speed of index operations?
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.)
-- Hannes
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: checkout/update boiler plate for --filter-index?
2009-03-24 7:21 ` Johannes Sixt
@ 2009-03-24 7:43 ` Jeff King
0 siblings, 0 replies; 3+ messages in thread
From: Jeff King @ 2009-03-24 7:43 UTC (permalink / raw)
To: Johannes Sixt; +Cc: Marcel Cary, Git Mailing List
On Tue, Mar 24, 2009 at 08:21:06AM +0100, Johannes Sixt wrote:
> 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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2009-03-24 7:44 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-03-23 21:33 checkout/update boiler plate for --filter-index? Marcel Cary
2009-03-24 7:21 ` Johannes Sixt
2009-03-24 7:43 ` Jeff King
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).