git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Rast <trast@student.ethz.ch>
To: git@vger.kernel.org
Cc: Jan Wielemaker <J.Wielemaker@uva.nl>
Subject: [TOY PATCH] filter-branch: add option --delete-unchanged
Date: Fri,  8 Aug 2008 22:10:24 +0200	[thread overview]
Message-ID: <1218226224-25273-1-git-send-email-trast@student.ethz.ch> (raw)
In-Reply-To: <1218153031-18443-1-git-send-email-trast@student.ethz.ch>

With --delete-unchanged, we nuke refs whose targets did not change
during rewriting.  It is intended to be used along with
--subdirectory-filter to clean out old refs from before the first
commit to the filtered subdirectory.  (They would otherwise keep the
old history alive.)

Obviously this is a rather dangerous mode of operation.

Note the "sort -u" is required: Without it, --all includes
'origin/master' twice (from 'origin/master' and via 'origin/HEAD'),
and the second pass concludes it is unchanged and nukes the ref.

Signed-off-by: Thomas Rast <trast@student.ethz.ch>
---

This applies on top of "filter-branch: be more helpful when an
annotated tag changes".

I'm not really sure if this should go in, but it might have solved
Jan's problem.

 git-filter-branch.sh |   33 +++++++++++++++++++++++----------
 1 files changed, 23 insertions(+), 10 deletions(-)

diff --git a/git-filter-branch.sh b/git-filter-branch.sh
index a140337..539b2e6 100755
--- a/git-filter-branch.sh
+++ b/git-filter-branch.sh
@@ -114,6 +114,7 @@ filter_tag_name=
 filter_subdir=
 orig_namespace=refs/original/
 force=
+delete_unchanged=
 while :
 do
 	case "$1" in
@@ -126,6 +127,11 @@ do
 		force=t
 		continue
 		;;
+	--delete-unchanged-refs)
+		shift
+		delete_unchanged=t
+		continue
+		;;
 	-*)
 		;;
 	*)
@@ -215,6 +221,7 @@ export GIT_DIR GIT_WORK_TREE
 
 # The refs should be updated if their heads were rewritten
 git rev-parse --no-flags --revs-only --symbolic-full-name --default HEAD "$@" |
+sort -u |
 sed -e '/^^/d' >"$tempdir"/heads
 
 test -s "$tempdir"/heads ||
@@ -344,7 +351,7 @@ do
 	sha1=$(git rev-parse "$ref"^0)
 	rewritten=$(map $sha1)
 
-	test $sha1 = "$rewritten" &&
+	test $sha1 = "$rewritten" -a -z "$delete_unchanged" &&
 		warn "WARNING: Ref '$ref' is unchanged" &&
 		continue
 
@@ -355,16 +362,22 @@ do
 			die "Could not delete $ref"
 	;;
 	$_x40)
-		echo "Ref '$ref' was rewritten"
-		if ! git update-ref -m "filter-branch: rewrite" \
-					"$ref" $rewritten $sha1 2>/dev/null; then
-			if test $(git cat-file -t "$ref") = tag; then
-				if test -z "$filter_tag_name"; then
-					warn "WARNING: You said to rewrite tagged commits, but not the corresponding tag."
-					warn "WARNING: Perhaps use '--tag-name-filter cat' to rewrite the tag."
+		if test "$delete_unchanged" -a $sha1 = "$rewritten"; then
+			echo "Ref '$ref' was deleted because it is unchanged"
+			git update-ref -m "filter-branch: delete" -d "$ref" $sha1 ||
+				die "Could not delete $ref"
+		else
+			echo "Ref '$ref' was rewritten"
+			if ! git update-ref -m "filter-branch: rewrite" \
+			   "$ref" $rewritten $sha1 2>/dev/null; then
+				if test $(git cat-file -t "$ref") = tag; then
+					if test -z "$filter_tag_name"; then
+						warn "WARNING: You said to rewrite tagged commits, but not the corresponding tag."
+						warn "WARNING: Perhaps use '--tag-name-filter cat' to rewrite the tag."
+					fi
+				else
+					die "Could not rewrite $ref"
 				fi
-			else
-				die "Could not rewrite $ref"
 			fi
 		fi
 	;;
-- 
1.6.0.rc2.24.gf1dd.dirty

  reply	other threads:[~2008-08-08 20:11 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-06 13:39 git filter-branch --subdirectory-filter, still a mistery Jan Wielemaker
2008-08-07  7:13 ` Jan Wielemaker
2008-08-07  7:50 ` Thomas Rast
2008-08-07 10:14   ` Jan Wielemaker
2008-08-07 23:48     ` Thomas Rast
2008-08-07 23:50       ` [PATCH] filter-branch: be more helpful when an annotated tag changes Thomas Rast
2008-08-08 20:10         ` Thomas Rast [this message]
2008-08-09  0:35           ` [TOY PATCH] filter-branch: add option --delete-unchanged Johannes Schindelin
2008-08-11 10:43           ` Jan Wielemaker
2008-09-14 16:29           ` Felipe Contreras
2008-08-07 23:54       ` [RFH] filter-branch: ancestor detection weirdness Thomas Rast
2008-08-08 11:42         ` Johannes Schindelin
2008-08-08 14:14           ` Thomas Rast
2008-08-08 14:16             ` [PATCH] filter-branch: fix ancestor discovery for --subdirectory-filter Thomas Rast
2008-08-08 14:39             ` [RFH] filter-branch: ancestor detection weirdness Johannes Schindelin
2008-08-08 18:37               ` Thomas Rast
2008-08-08 18:39                 ` [PATCH v2] filter-branch: fix ref rewriting with --subdirectory-filter Thomas Rast
2008-08-09  0:16                 ` [RFH] filter-branch: ancestor detection weirdness Johannes Schindelin
2008-08-09  1:25                   ` Junio C Hamano
2008-08-09  9:25                     ` Thomas Rast
2008-08-09  9:35                       ` Thomas Rast
2008-08-10 14:02                     ` [PATCH] filter-branch: use --simplify-merges Thomas Rast
2008-08-12  1:54                       ` Junio C Hamano
2008-08-12  2:13                         ` Junio C Hamano
2008-08-12  5:47                           ` Thomas Rast
2008-08-12  6:59                             ` Junio C Hamano
2008-08-12  8:45                               ` [PATCH 0/3] filter-branch --subdirectory-filter improvements Thomas Rast
2008-08-12 12:11                                 ` Jan Wielemaker
2008-08-12  8:45                               ` [PATCH 1/3] filter-branch: Extend test to show rewriting bug Thomas Rast
2008-08-12  8:45                               ` [PATCH 2/3] filter-branch: fix ref rewriting with --subdirectory-filter Thomas Rast
2008-08-12  8:45                               ` [PATCH 3/3] filter-branch: use --simplify-merges Thomas Rast
2008-08-12  8:18                     ` [RFH] filter-branch: ancestor detection weirdness Petr Baudis
2008-08-12 18:33                       ` Junio C Hamano
2008-08-09 10:00                   ` Thomas Rast
2008-08-12 21:33                     ` Junio C Hamano
2008-08-12 22:15                       ` Thomas Rast
2008-08-08  7:44       ` git filter-branch --subdirectory-filter, still a mistery Jan Wielemaker
2008-08-08 11:25       ` Jan Wielemaker
2008-08-07 14:04   ` [PATCH] Documentation: filter-branch: document how to filter all refs Thomas Rast
2008-08-07 14:16     ` [PATCH v2] " Thomas Rast

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

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

  git send-email \
    --in-reply-to=1218226224-25273-1-git-send-email-trast@student.ethz.ch \
    --to=trast@student.ethz.ch \
    --cc=J.Wielemaker@uva.nl \
    --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.
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 NNTP newsgroup(s).