git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Yuki Kokubun <orga.chem.job@gmail.com>
To: git@vger.kernel.org
Cc: Yuki Kokubun <orga.chem.job@gmail.com>
Subject: [PATCH] filter-branch: consider refs can refer to an object other than commit or tag
Date: Wed, 21 Mar 2018 15:31:39 +0000	[thread overview]
Message-ID: <1521646299-16193-1-git-send-email-orga.chem.job@gmail.com> (raw)
In-Reply-To: <20180321103504.9483-1-orga.chem.job@gmail.com>
In-Reply-To: <20180321103504.9483-1-orga.chem.job@gmail.com>

"git filter-branch -- --all" can be confused when refs that refer to objects
other than commits or tags exists.
Because "git rev-parse --all" that is internally used can return refs that
refer to an object other than commit or tag. But it is not considered in the
phase of updating refs. Such refs can be created by "git replace" with
objects other than commits or trees.

Signed-off-by: Yuki Kokubun <orga.chem.job@gmail.com>
---
This patch fix the bug of the first patch.
The first patch did not consider tags.

 git-filter-branch.sh     | 11 ++++++++++-
 t/t7003-filter-branch.sh | 13 +++++++++++++
 2 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/git-filter-branch.sh b/git-filter-branch.sh
index 1b7e4b2cd..f7cd97b86 100755
--- a/git-filter-branch.sh
+++ b/git-filter-branch.sh
@@ -251,7 +251,16 @@ done < "$tempdir"/backup-refs
 
 # The refs should be updated if their heads were rewritten
 git rev-parse --no-flags --revs-only --symbolic-full-name \
-	--default HEAD "$@" > "$tempdir"/raw-heads || exit
+	--default HEAD "$@" > "$tempdir"/raw-objects || exit
+# refs/replace can refer to an object other than commit or tag
+while read ref
+do
+	type=$(git cat-file -t "$ref")
+	if test $type = commit || test $type = tag
+	then
+		echo "$ref"
+	fi
+done >"$tempdir"/raw-heads <"$tempdir"/raw-objects
 sed -e '/^^/d' "$tempdir"/raw-heads >"$tempdir"/heads
 
 test -s "$tempdir"/heads ||
diff --git a/t/t7003-filter-branch.sh b/t/t7003-filter-branch.sh
index 7cb60799b..efeaf5887 100755
--- a/t/t7003-filter-branch.sh
+++ b/t/t7003-filter-branch.sh
@@ -470,4 +470,17 @@ test_expect_success 'tree-filter deals with object name vs pathname ambiguity' '
 	git show HEAD:$ambiguous
 '
 
+test_expect_success 'rewrite repository including refs/replace that point to non commit object' '
+	test_when_finished "git reset --hard original" &&
+	tree=$(git rev-parse HEAD^{tree}) &&
+	test_when_finished "git replace -d $tree" &&
+	echo A >new &&
+	git add new &&
+	new_tree=$(git write-tree) &&
+	git replace $tree $new_tree &&
+	git reset --hard HEAD &&
+	git filter-branch -f -- --all >filter-output 2>&1 &&
+	! fgrep fatal filter-output
+'
+
 test_done
-- 
2.16.2.18.g09cb46d


  reply	other threads:[~2018-03-21 15:31 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-21 10:35 [PATCH] filter-branch: consider refs/replace can refer to an object other than commit Yuki Kokubun
2018-03-21 15:31 ` Yuki Kokubun [this message]
2018-03-21 17:21   ` [PATCH] filter-branch: consider refs can refer to an object other than commit or tag Junio C Hamano
2018-03-21 20:00   ` Yuki Kokubun
2018-03-21 20:00     ` Junio C Hamano
2018-03-22 14:26     ` Yuki Kokubun
2018-03-22 17:01       ` Junio C Hamano
2018-03-23  2:15       ` Yuki Kokubun
2018-03-23  5:09         ` [PATCH v2] filter-branch: fix errors caused by refs that cannot be used with ^0 Yuki Kokubun
2018-03-23 20:20           ` Junio C Hamano
2018-03-24 19:41             ` [PATCH v3] filter-branch: fix errors caused by refs that point at non-committish Yuki Kokubun
2018-03-25 16:25               ` Junio C Hamano
2018-03-25 16:39                 ` Yuki Kokubun
2018-03-25 20:24                   ` Junio C Hamano
2018-03-25 16:54                 ` [PATCH v4] " Yuki Kokubun
2018-03-25 16:45                   ` Yuki Kokubun
2018-04-08 23:10                     ` Junio C Hamano
2018-03-25 17:01                   ` [PATCH v5] " Yuki Kokubun
2018-03-25 17:13                   ` [PATCH v4] " Junio C Hamano
2018-03-24 19:29           ` [PATCH] filter-branch: consider refs can refer to an object other than commit or tag Yuki Kokubun

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1521646299-16193-1-git-send-email-orga.chem.job@gmail.com \
    --to=orga.chem.job@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).