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

[PATCH 2/3] Make filter-branch --glob-filter much faster by not calling 'cat'

From
Avery Pennarun <apenwarr@gmail.com>
Date
Apr 23, 2008, 19:42 UTC
Message-ID
<1208979757-30860-2-git-send-email-apenwarr@gmail.com>
In-Reply-To
<1208979757-30860-1-git-send-email-apenwarr@gmail.com>

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 <apenwarr@gmail.com>
---
 git-filter-branch.sh |   18 +++++++++++-------
 1 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/git-filter-branch.sh b/git-filter-branch.sh
index 980c431..37ac99d 100755
--- a/git-filter-branch.sh
+++ b/git-filter-branch.sh
@@ -57,16 +57,18 @@ eval "$functions"
 munge_blobs() {
 	while read mode sha1 stage path
 	do
-		if ! test -r "$workdir/../blob-cache/$sha1"
+		if ! test -r "$cachedir/$sha1"
 		then
-			new=`git cat-file blob $sha1 |
-			     eval "$filter_blob" |
-			     git hash-object -w --stdin`
-			printf $new >$workdir/../blob-cache/$sha1
+			new=$(git cat-file blob $sha1 |
+			      eval "$filter_blob" |
+			      git hash-object -w --stdin)
+			printf $new >$cachedir/$sha1
+		else
+			read new <"$cachedir/$sha1"
 		fi
 		printf "%s %s\t%s\n" \
 			"$mode" \
-			$(cat "$workdir/../blob-cache/$sha1") \
+			"$new" \
 			"$path"
 	done
 }
@@ -108,6 +110,7 @@ USAGE="[--env-filter <command>] [--tree-filter <command>] \
 [--index-filter <command>] [--parent-filter <command>] \
 [--msg-filter <command>] [--commit-filter <command>] \
 [--tag-name-filter <command>] [--subdirectory-filter <directory>] \
+[--blob-filter <command>] \
 [--original <namespace>] [-d <directory>] [-f | --force] \
 [<rev-list options>...]"
 
@@ -249,7 +252,8 @@ ret=0
 mkdir ../map || die "Could not create map/ directory"
 
 # cache rewritten blobs for blob filter
-mkdir ../blob-cache || die "Could not create blob-cache/ directory"
+cachedir="$workdir/../blob-cache"
+mkdir "$cachedir" || die "Could not create blob-cache/ directory"
 
 case "$filter_subdir" in
 "")
-- 
1.5.4.3
Previous: Avery PennarunNext: Avery Pennarun
Message 2 of 11 in “Add --blob-filter option to filter-branch.”
  1. 1/3 Add --blob-filter option to filter-branch.Avery Pennarun, Apr 23, 2008
  2. 2/3 Make filter-branch --glob-filter much faster by not calling 'cat'Avery Pennarun, Apr 23, 2008
  3. 3/3 Update documentation to describe git filter-branch --blob-filter.Avery Pennarun, Apr 23, 2008
  4. Johannes SchindelinApr 23, 2008
  5. Avery PennarunApr 23, 2008
  6. Johannes SchindelinApr 23, 2008
  7. 1/3 Add --blob-filter option to filter-branch.Avery Pennarun, Apr 23, 2008
  8. Johannes SchindelinApr 23, 2008
  9. Jeff KingApr 23, 2008
  10. Avery PennarunApr 23, 2008
  11. Jeff KingApr 24, 2008

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.