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

[PATCH v2] filter-branch: also don't fail in map() if a commit cannot be mapped

From
Johannes Sixt <johannes.sixt@telecom.at>
Date
Jun 6, 2007, 18:38 UTC
Message-ID
<200706062038.36093.johannes.sixt@telecom.at>
In-Reply-To
<Pine.LNX.4.64.0706061850220.4046@racer.site>

The map() function can be used by filters to map a commit id to its rewritten id. Such a mapping may not exist, in which case the identity mapping is used (the commit is returned unchanged).

In the rewrite loop, this mapping is also needed, but was done explicitly in the same way. Use the map() function instead.

Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
---
On Wednesday 06 June 2007 19:50, Johannes Schindelin wrote:
Show 6 quoted lines
> On Wed, 6 Jun 2007, Johannes Sixt wrote:
> > -	[ -r "$workdir/../map/$1" ] || return 1
> > +	# if it was not rewritten, take the original
> > +	[ -r "$workdir/../map/$1" ] || echo "$1"
>
> Maybe "test" instead of "["? Otherwise, ACK from me.
Right!
 git-filter-branch.sh |   14 +++++---------
 1 files changed, 5 insertions(+), 9 deletions(-)
diff --git a/git-filter-branch.sh b/git-filter-branch.sh
index fbbb044..15e9b46 100644
--- a/git-filter-branch.sh
+++ b/git-filter-branch.sh
@@ -189,7 +189,8 @@ USAGE="git-filter-branch [-d TEMPDIR] [-r STARTREV]... [-k KEEPREV]... [-s SRCBR
 
 map()
 {
-	[ -r "$workdir/../map/$1" ] || return 1
+	# if it was not rewritten, take the original
+	test -r "$workdir/../map/$1" || echo "$1"
 	cat "$workdir/../map/$1"
 }
 
@@ -362,14 +363,9 @@ while read commit; do
 
 	parentstr=
 	for parent in $(get_parents $commit); do
-		if [ -r "../map/$parent" ]; then
-			for reparent in $(cat "../map/$parent"); do
-				parentstr="$parentstr -p $reparent"
-			done
-		else
-			# if it was not rewritten, take the original
-			parentstr="$parentstr -p $parent"
-		fi
+		for reparent in $(map "$parent"); do
+			parentstr="$parentstr -p $reparent"
+		done
 	done
 	if [ "$filter_parent" ]; then
 		parentstr="$(echo "$parentstr" | eval "$filter_parent")"
-- 
1.5.2
Previous: Johannes Schindelin
Message 27 of 27 in “Add git-filter-branch”
  1. Add git-filter-branchJohannes Schindelin, Jun 3, 2007
  2. Jakub NarebskiJun 3, 2007
  3. Johannes SchindelinJun 3, 2007
  4. Jakub NarebskiJun 3, 2007
  5. Steven GrimmJun 3, 2007
  6. Johannes SchindelinJun 3, 2007
  7. Jonas FonsecaJun 5, 2007
  8. David KastrupJun 5, 2007
  9. Junio C HamanoJun 5, 2007
  10. Jonas FonsecaJun 5, 2007
  11. Johannes SchindelinJun 5, 2007
  12. filter-branch: use $(($i+1)) instead of $((i+1))Johannes Schindelin, Jun 6, 2007
  13. Johannes SixtJun 4, 2007
  14. Johannes SixtJun 4, 2007
  15. Johannes SchindelinJun 4, 2007
  16. Johannes SixtJun 4, 2007
  17. Johannes SchindelinJun 4, 2007
  18. Johannes SixtJun 5, 2007
  19. Johannes SchindelinJun 5, 2007
  20. Johannes SixtJun 6, 2007
  21. Junio C HamanoJun 6, 2007
  22. Johannes SchindelinJun 6, 2007
  23. Johannes SixtJun 6, 2007
  24. Johannes SchindelinJun 6, 2007
  25. filter-branch: also don't fail in map() if a commit cannot be mappedJohannes Sixt, Jun 6, 2007
  26. Johannes SchindelinJun 6, 2007
  27. filter-branch: also don't fail in map() if a commit cannot be mappedJohannes Sixt, Jun 6, 2007

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.