git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Marcus Brinkmann <m.brinkmann@semantics.de>
To: "David A. Greene" <greened@obbligato.org>,
	Junio C Hamano <gitster@pobox.com>
Cc: Dave Ware <davidw@realtimegenomics.com>, <git@vger.kernel.org>
Subject: [PATCH] contrib/subtree: Split history with empty trees correctly (was: Re: BUG: git subtree split gets confused on removed and readded directory)
Date: Wed, 20 Jan 2016 02:17:58 +0100	[thread overview]
Message-ID: <569EE046.9040506@semantics.de> (raw)
In-Reply-To: <87twmbaizo.fsf@waller.obbligato.org>

'git subtree split' will fail if the history of the subtree has empty
tree commits (or trees that are considered empty, such as submodules).
This fix keeps track of this condition and correctly follows the history
over such commits.

Signed-off-by: Marcus Brinkmann <m.brinkmann@semantics.de>
---
 contrib/subtree/git-subtree.sh | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index edf36f8..b68828b 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -36,6 +36,8 @@ PATH=$PATH:$(git --exec-path)

 require_work_tree

+EMPTY_TREE=`git hash-object -t tree /dev/null`
+
 quiet=
 branch=
 debug=
@@ -449,7 +451,8 @@ copy_or_skip()
 	rev="$1"
 	tree="$2"
 	newparents="$3"
-	assert [ -n "$tree" ]
+
+	[ -z "$tree" ] && tree=$EMPTY_TREE

 	identical=
 	nonidentical=
@@ -603,6 +606,7 @@ cmd_split()
 	revmax=$(eval "$grl" | wc -l)
 	revcount=0
 	createcount=0
+	found_first_commit=
 	eval "$grl" |
 	while read rev parents; do
 		revcount=$(($revcount + 1))
@@ -625,12 +629,16 @@ cmd_split()
 		
 		# ugly.  is there no better way to tell if this is a subtree
 		# vs. a mainline commit?  Does it matter?
-		if [ -z $tree ]; then
-			set_notree $rev
-			if [ -n "$newparents" ]; then
-				cache_set $rev $rev
+		if [ -z $found_first_commit ]; then
+			if [ -z $tree ]; then
+				set_notree $rev
+				if [ -n "$newparents" ]; then
+					cache_set $rev $rev
+				fi
+				continue
+			else
+				found_first_commit=yes
 			fi
-			continue
 		fi

 		newrev=$(copy_or_skip "$rev" "$tree" "$newparents") || exit $?
-- 
2.5.0

  reply	other threads:[~2016-01-20  1:35 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-15 16:23 BUG: git subtree split gets confused on removed and readded directory Marcus Brinkmann
2016-01-15 23:44 ` Junio C Hamano
2016-01-17 19:34   ` David Ware
2016-01-17 23:23   ` David A. Greene
2016-01-20  1:17     ` Marcus Brinkmann [this message]
2016-01-20  4:05       ` [PATCH] contrib/subtree: Split history with empty trees correctly David A. Greene
2016-01-20 11:22         ` Marcus Brinkmann
2016-01-28  2:55           ` David A. Greene
2016-01-24 13:07         ` Marcus Brinkmann
2016-01-28  2:56           ` David A. Greene
2016-01-28  4:06             ` Marcus Brinkmann
2016-02-03  2:34               ` David A. Greene

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=569EE046.9040506@semantics.de \
    --to=m.brinkmann@semantics.de \
    --cc=davidw@realtimegenomics.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=greened@obbligato.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).