From: Jeff King <redacted>
On Tue, Apr 22, 2008 at 12:51:14PM -0400, Avery Pennarun wrote:
Do you think git would benefit from having a generalized version of
this script? Basically, the user provides a "munge" script on the
command line, and there's a git-filter-branch mode for auto-munging
(with a cache) every file in every checkin. Even if it's *only* ever
used for CRLF, I can imagine this being useful to a lot of people.
It was easy enough to work up the patch below, which allows
git filter-branch --blob-filter 'tr a-z A-Z'
However, it's _still_ horribly slow. Shell script is nice and flexible,
but running a tight loop like this is just painful. I suspect
filter-branch in something like perl would be a lot faster and just as
flexible (you could even do it in C, but you'd probably have to invent a
little domain-specific scripting language).
It is still much better performance than a tree filter, though:
$ cd git && time git filter-branch --tree-filter '
find . -type f | while read f; do
tr a-z A-Z <"$f" >tmp
mv tmp "$f"
done
' HEAD~10..HEAD
real 4m38.626s
user 1m32.726s
sys 2m51.163s
$ cd git && git filter-branch --blob-filter 'tr a-z A-Z' HEAD~10..HEAD
real 1m40.809s
user 0m36.822s
sys 1m14.273s
Lots of system time in both. I'm sure we spend a fair bit of time
hitting our very large map and blob-cache directories, which would be
much more nicely implemented as associative arrays in memory (if we were
using a more featureful language).
Anyway, here is the patch. I don't know if it is even worth applying,
since it is still painfully slow.
Acked-by: Johannes Schindelin <redacted>
---
git-filter-branch.sh | 30 ++++++++++++++++++++++++++++++
1 files changed, 30 insertions(+), 0 deletions(-)
@@ -54,6 +54,23 @@ EOFeval"$functions"+munge_blobs(){+whilereadmodesha1stagepath+do+if!test-r"$workdir/../blob-cache/$sha1"+then+new=`gitcat-fileblob$sha1|+eval"$filter_blob"|+githash-object-w--stdin`+printf$new>$workdir/../blob-cache/$sha1+fi+printf"%s %s\t%s\n"\+"$mode"\+$(cat"$workdir/../blob-cache/$sha1")\+"$path"+done+}+# When piped a commit, output a script to set the ident of either# "author" or "committer
@@ -143,6 +144,15 @@ definition impossible to preserve signatures at any rate.) The result will contain that directory (and only that) as its project root.+--blob-filter <command>::+ This is the filter for modifying the contents of each file (blob)+ in the tree. The contents of a file are provided on stdin, and+ the new file contents should be provided on stdout. For efficiency,+ the before/after results of a given blob are only calculated once+ and then cached, so your filter must always return the same output+ blob for any given input blob. You might use this filter for+ converting CRLF to LF in all your files, for example.+ --original <namespace>:: Use this option to set the namespace where the original commits will be stored. The default value is 'refs/original'.
@@ -185,6 +195,13 @@ git filter-branch --index-filter 'git update-index --remove filename' HEAD Now, you will get the rewritten history saved in HEAD.+To convert CRLF to LF in all your files using the "fromdos" program (be+careful: this will attempt to modify binary files too!):++----------------------------------------------+git filter-branch --blob-filter 'fromdos' HEAD+----------------------------------------------+ To set a commit (which typically is at the tip of another history) to be the parent of the current initial commit, in order to paste the other history behind the current history:
The main loop of munge_blobs() had to fork-exec "cat" every time through the
loop, even when a blob was already cached. Let's use the sh builtin 'read'
instead for a huge speedup.
cd git
time git filter-branch --blob-filter 'tr a-z A-Z' HEAD~10..HEAD
(original --blob-filter)
real 3m58.569s
user 0m22.900s
sys 3m32.030s
(with 'cat' calls removed)
real 1m11.931s
user 0m8.520s
sys 1m2.900s
(with 'cat' calls removed and blob cache already filled)
real 0m19.660s
user 0m3.930s
sys 0m15.720s
Signed-off-by: Avery Pennarun <redacted>
---
git-filter-branch.sh | 18 +++++++++++-------
1 files changed, 11 insertions(+), 7 deletions(-)
From: Johannes Schindelin <hidden> Date: 2016-06-15 22:44:31
Hi,
On Wed, 23 Apr 2008, Avery Pennarun wrote:
From: Jeff King <redacted>
On Tue, Apr 22, 2008 at 12:51:14PM -0400, Avery Pennarun wrote:
quoted
Do you think git would benefit from having a generalized version of
this script? Basically, the user provides a "munge" script on the
command line, and there's a git-filter-branch mode for auto-munging
(with a cache) every file in every checkin. Even if it's *only* ever
used for CRLF, I can imagine this being useful to a lot of people.
It was easy enough to work up the patch below, which allows
git filter-branch --blob-filter 'tr a-z A-Z'
However, it's _still_ horribly slow. Shell script is nice and flexible,
but running a tight loop like this is just painful. I suspect
filter-branch in something like perl would be a lot faster and just as
flexible (you could even do it in C, but you'd probably have to invent a
little domain-specific scripting language).
It is still much better performance than a tree filter, though:
$ cd git && time git filter-branch --tree-filter '
find . -type f | while read f; do
tr a-z A-Z <"$f" >tmp
mv tmp "$f"
done
' HEAD~10..HEAD
real 4m38.626s
user 1m32.726s
sys 2m51.163s
$ cd git && git filter-branch --blob-filter 'tr a-z A-Z' HEAD~10..HEAD
real 1m40.809s
user 0m36.822s
sys 1m14.273s
Lots of system time in both. I'm sure we spend a fair bit of time
hitting our very large map and blob-cache directories, which would be
much more nicely implemented as associative arrays in memory (if we were
using a more featureful language).
Anyway, here is the patch. I don't know if it is even worth applying,
since it is still painfully slow.
Not all of this belongs in the commit messaage.
Acked-by: Johannes Schindelin <redacted>
This does.
A good general rule is: if you think it would be funny/strange to read
this message in the output of "git log", it should be changed.
Ciao,
Dscho
On 4/23/08, Johannes Schindelin [off-list ref] wrote:
Not all of this belongs in the commit messaage.
> Acked-by: Johannes Schindelin [off-list ref]
This does.
A good general rule is: if you think it would be funny/strange to read
this message in the output of "git log", it should be changed.
I felt uncomfortable modifying the message attached to Jeff's patch
(which actually does pretty clearly explain what's going on), since
it's not mine. If he wants to send me a better commit message,
that'll be fine too.
Have fun,
Avery
From: Johannes Schindelin <hidden> Date: 2016-06-15 22:44:31
Hi,
On Wed, 23 Apr 2008, Avery Pennarun wrote:
On 4/23/08, Johannes Schindelin [off-list ref] wrote:
quoted
Not all of this belongs in the commit messaage.
> Acked-by: Johannes Schindelin [off-list ref]
This does.
A good general rule is: if you think it would be funny/strange to
read this message in the output of "git log", it should be changed.
I felt uncomfortable modifying the message attached to Jeff's patch
(which actually does pretty clearly explain what's going on), since
it's not mine. If he wants to send me a better commit message,
that'll be fine too.
Well, I think that you would do a good job rephrasing this as a proper
commit message :-)
Ciao,
Dscho
From: Jeff King <redacted>
This patch allows
git filter-branch --blob-filter 'tr a-z A-Z'
However, it's _still_ horribly slow. Shell script is nice and flexible,
but running a tight loop like this is just painful. I suspect
filter-branch in something like perl would be a lot faster and just as
flexible.
It is still much better performance than a tree filter, though:
$ cd git && time git filter-branch --tree-filter '
find . -type f | while read f; do
tr a-z A-Z <"$f" >tmp
mv tmp "$f"
done
' HEAD~10..HEAD
real 4m38.626s
user 1m32.726s
sys 2m51.163s
$ cd git && git filter-branch --blob-filter 'tr a-z A-Z' HEAD~10..HEAD
real 1m40.809s
user 0m36.822s
sys 1m14.273s
Acked-by: Johannes Schindelin <redacted>
---
git-filter-branch.sh | 30 ++++++++++++++++++++++++++++++
1 files changed, 30 insertions(+), 0 deletions(-)
@@ -54,6 +54,23 @@ EOFeval"$functions"+munge_blobs(){+whilereadmodesha1stagepath+do+if!test-r"$workdir/../blob-cache/$sha1"+then+new=`gitcat-fileblob$sha1|+eval"$filter_blob"|+githash-object-w--stdin`+printf$new>$workdir/../blob-cache/$sha1+fi+printf"%s %s\t%s\n"\+"$mode"\+$(cat"$workdir/../blob-cache/$sha1")\+"$path"+done+}+# When piped a commit, output a script to set the ident of either# "author" or "committer
From: Johannes Schindelin <hidden> Date: 2016-06-15 22:44:31
Hi,
On Wed, 23 Apr 2008, Avery Pennarun wrote:
From: Jeff King <redacted>
This patch allows
git filter-branch --blob-filter 'tr a-z A-Z'
However, it's _still_ horribly slow. Shell script is nice and flexible,
but running a tight loop like this is just painful. I suspect
filter-branch in something like perl would be a lot faster and just as
flexible.
It is still much better performance than a tree filter, though:
$ cd git && time git filter-branch --tree-filter '
find . -type f | while read f; do
tr a-z A-Z <"$f" >tmp
mv tmp "$f"
done
' HEAD~10..HEAD
real 4m38.626s
user 1m32.726s
sys 2m51.163s
$ cd git && git filter-branch --blob-filter 'tr a-z A-Z' HEAD~10..HEAD
real 1m40.809s
user 0m36.822s
sys 1m14.273s
Acked-by: Johannes Schindelin <redacted>
---
From: Jeff King <hidden> Date: 2016-06-15 22:44:31
On Wed, Apr 23, 2008 at 04:18:10PM -0400, Avery Pennarun wrote:
From: Jeff King <redacted>
This patch allows
git filter-branch --blob-filter 'tr a-z A-Z'
The commit message munging you did is fine.
However, I think Johannes Sixt's question about providing the pathname
needs to be resolved. As it is now, the blob-filter is impossible to use
in a mixed binary/text repository, short of the undocumented $path magic
that you described. And I am a little uncomfortable just adding the
$path as he suggested because of the subtle bug it introduces.
-Peff
On Wed, Apr 23, 2008 at 04:18:10PM -0400, Avery Pennarun wrote:
> From: Jeff King [off-list ref]
>
> This patch allows
>
> git filter-branch --blob-filter 'tr a-z A-Z'
The commit message munging you did is fine.
However, I think Johannes Sixt's question about providing the pathname
needs to be resolved. As it is now, the blob-filter is impossible to use
in a mixed binary/text repository, short of the undocumented $path magic
that you described. And I am a little uncomfortable just adding the
$path as he suggested because of the subtle bug it introduces.
It is indeed a very subtle bug; so subtle, in fact, that I never
expect to experience it myself :)
I think it would be fine to index into the cache using $path$sha1,
which would seem to resolve this issue. The catch is that $path isn't
a very good cachefile name. I'd suggest doing an md5sum or something
on it, but that would result in an extra fork for every file, which
brings us back to our original level of slowness (or worse).
Hmm, I gues using a cachefile like $sha1/$path would work; it requires
a "mkdir -p", but only when *filling* the cache.
Avery
From: Jeff King <hidden> Date: 2016-06-15 22:44:31
On Wed, Apr 23, 2008 at 06:07:03PM -0400, Avery Pennarun wrote:
I think it would be fine to index into the cache using $path$sha1,
which would seem to resolve this issue. The catch is that $path isn't
a very good cachefile name. I'd suggest doing an md5sum or something
on it, but that would result in an extra fork for every file, which
brings us back to our original level of slowness (or worse).
Hmm, I gues using a cachefile like $sha1/$path would work; it requires
a "mkdir -p", but only when *filling* the cache.
Keep in mind that $path can have slashes. So you actually need to:
mkdir -p `dirname $sha1/$path`
echo $new >$sha1/$path
-Peff