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

[REVISED PATCH] filter-branch: rewrite only unexcluded refs

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Jul 24, 2007, 13:42 UTC
Message-ID
<Pine.LNX.4.64.0707241442040.14781@racer.site>
In-Reply-To
<46A5FF69.F5D75C9E@eudaptics.com>
The rev-list options can exclude some -- or all -- refs:
	git filter-branch <some-filter> master ^master

Without this patch, these refs are assumed to be deleted, or worse, they are rewritten to some bogus merge bases.

So really exclude excluded refs from being rewritten. This also allows you to safely call

	git filter-branch <some-filter> --all <rev-list options>
to rewrite _all_ branches and tags.
Thanks go to Johannes Sixt for help on the implementation and for testing.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 git-filter-branch.sh     |   16 +++++++++++++++-
 t/t7003-filter-branch.sh |    9 +++++++++
 2 files changed, 24 insertions(+), 1 deletions(-)
diff --git a/git-filter-branch.sh b/git-filter-branch.sh
index 4fb3abe..3fa2f63 100755
--- a/git-filter-branch.sh
+++ b/git-filter-branch.sh
@@ -181,6 +181,14 @@ export GIT_DIR GIT_WORK_TREE=.
 
 # These refs should be updated if their heads were rewritten
 
+negatives="`git rev-parse "$@" | while read line
+	do
+		case "$line" in
+		$_x40) ;;
+		*) echo "$line";;
+		esac
+	done`"
+
 git rev-parse --revs-only --symbolic "$@" |
 while read ref
 do
@@ -196,7 +204,13 @@ do
 			grep -e "^refs/heads/$ref$" -e "^refs/tags/$ref$")"
 	esac
 
-	git check-ref-format "$ref" && echo "$ref"
+	# make sure we have a valid ref
+	git check-ref-format "$ref" || continue
+
+	# if the ref has been excluded by the other options, skip it
+	test -z "$(git rev-list -1 "$ref" $negatives --topo-order)" && continue
+
+	echo "$ref"
 done > "$tempdir"/heads
 
 test -s "$tempdir"/heads ||
diff --git a/t/t7003-filter-branch.sh b/t/t7003-filter-branch.sh
index c9a820d..667eda7 100755
--- a/t/t7003-filter-branch.sh
+++ b/t/t7003-filter-branch.sh
@@ -164,4 +164,13 @@ test_expect_success 'only dwim refs/heads/$ref or refs/tags/$ref' '
 	git filter-branch -f master
 '
 
+test_expect_success 'do not update uninteresting refs' '
+	branch=$(git rev-parse branch) &&
+	master=$(git rev-parse master) &&
+	git filter-branch -f --env-filter "GIT_AUTHOR_EMAIL=xy@probl.em" \
+		master ^removed-author branch &&
+	test $branch = $(git rev-parse branch) &&
+	test $master != $(git rev-parse master)
+'
+
 test_done
-- 
1.5.3.rc2.32.g35c5b-dirty
Previous: Johannes SchindelinNext: Johannes Sixt
Message 18 of 20 in “filter-branch: Big syntax change; support rewriting multiple refs”
  1. filter-branch: Big syntax change; support rewriting multiple refsJohannes Schindelin, Jul 23, 2007
  2. Junio C HamanoJul 24, 2007
  3. Johannes SchindelinJul 24, 2007
  4. Johannes SixtJul 24, 2007
  5. filter-branch: when dwim'ing a ref, only allow heads and tagsJohannes Schindelin, Jul 24, 2007
  6. Johannes SixtJul 24, 2007
  7. Johannes SchindelinJul 24, 2007
  8. filter-branch: when dwim'ing a ref, only allow heads and tagsJohannes Schindelin, Jul 24, 2007
  9. filter-branch: rewrite only refs which were not excluded by the optionsJohannes Schindelin, Jul 24, 2007
  10. Johannes SixtJul 24, 2007
  11. Johannes SchindelinJul 24, 2007
  12. Johannes SixtJul 24, 2007
  13. Johannes SchindelinJul 24, 2007
  14. Johannes SixtJul 24, 2007
  15. Johannes SchindelinJul 24, 2007
  16. Johannes SixtJul 24, 2007
  17. Johannes SchindelinJul 24, 2007
  18. filter-branch: rewrite only unexcluded refsJohannes Schindelin, Jul 24, 2007
  19. Johannes SixtJul 24, 2007
  20. Johannes SchindelinJul 24, 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.