Skip to contentSkip to conversation

contrib/subtree: unwrap tag refs

PATCH Superseded Rob Mayoff 4 participants 5 messages Jun 15, 2016

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Rob Mayoff

author
#0 lore raw

PATCH 1/1 contrib/subtree: unwrap tag refs

From: Rob Mayoff <[email protected]>

If a subtree was added using a tag ref, the tag ref is stored in the subtree commit message instead of the underlying commit's ref. To split or push subsequent changes to the subtree, the subtree command needs to unwrap the tag ref. This patch makes it do so.

The problem was described in a message to the mailing list from Junio C Hamano dated 29 Apr 2014, with the subject "Re: git subtree issue in more recent versions". The archived message can be found at <http://comments.gmane.org/gmane.comp.version-control.git/247503>.

---
 contrib/subtree/git-subtree.sh | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
contrib/subtree/git-subtree.sh +8 -2
index 9f06571..b051600 100755
@@ -245,7 +245,10 @@ find_latest_squash()
 		case "$a" in
 			START) sq="$b" ;;
 			git-subtree-mainline:) main="$b" ;;
-			git-subtree-split:) sub="$b" ;;
+			git-subtree-split:)
+				sub="$b"
+				sub="$(git rev-parse "$b^0")" || die "could not rev-parse split hash $b from commit $sq"
+				;;
 			END)
 				if [ -n "$sub" ]; then
 					if [ -n "$main" ]; then
@@ -278,7 +281,10 @@ find_existing_splits()
 		case "$a" in
 			START) sq="$b" ;;
 			git-subtree-mainline:) main="$b" ;;
-			git-subtree-split:) sub="$b" ;;
+			git-subtree-split:)
+				sub="$b"
+				sub="$(git rev-parse "$b^0")" || die "could not rev-parse split hash $b from commit $sq"
+				;;
 			END)
 				debug "  Main is: '$main'"
 				if [ -z "$main" -a -n "$sub" ]; then
Signature · 1 line
2.4.3
#1 lore raw

contrib/subtree/git-subtree.sh find_latest_squash() · line 249

Quoted 11 lines · Rob Mayoff
contrib/subtree/git-subtree.sh +2 -1
index 9f06571..b051600 100755
@@ -245,7 +245,10 @@ find_latest_squash()
 		case "$a" in
 			START) sq="$b" ;;
 			git-subtree-mainline:) main="$b" ;;
-			git-subtree-split:) sub="$b" ;;
+			git-subtree-split:)
+				sub="$b"

Why include the above line?

contrib/subtree/git-subtree.sh find_latest_squash() · line 250

Quoted 1 line
contrib/subtree/git-subtree.sh +1 -0
+				sub="$(git rev-parse "$b^0")" || die "could not rev-parse split hash $b from commit $sq"

This seems like odd quoting. Would not this do the same?

				sub="$(git rev-parse $b^0)" || die "could not rev-parse split hash $b from commit $sq"

Perhaps I am missing something.

contrib/subtree/git-subtree.sh find_existing_splits() · line 285

Quoted 11 lines
contrib/subtree/git-subtree.sh +3 -1
+				;;
 			END)
 				if [ -n "$sub" ]; then
 					if [ -n "$main" ]; then
@@ -278,7 +281,10 @@ find_existing_splits()
 		case "$a" in
 			START) sq="$b" ;;
 			git-subtree-mainline:) main="$b" ;;
-			git-subtree-split:) sub="$b" ;;
+			git-subtree-split:)
+				sub="$b"

And here too.

contrib/subtree/git-subtree.sh find_existing_splits() · line 286

Quoted 1 line
contrib/subtree/git-subtree.sh +1 -0
+				sub="$(git rev-parse "$b^0")" || die "could not rev-parse split hash $b from commit $sq"

Same as above.

-David

#2 lore raw
Quoted 7 lines · David A. Greene

Review

Quoted 1 line
(quoted diff) +1 -0
+				sub="$(git rev-parse "$b^0")" || die "could not rev-parse split hash $b from commit $sq"

This seems like odd quoting. Would not this do the same?

				sub="$(git rev-parse $b^0)" || die "could not rev-parse split hash $b from commit $sq"

Perhaps I am missing something.

The former is quoting "$b" against whitespace splitting in the sub-command. Given that the value just came from a "read" call, I think by definition it cannot contains IFS. Still, quoting here is a good habit.

It is actually the _outer_ quotes that are unnecessary, as variable assignment does not do extra splitting. So:

  foo=$(echo one two)

will put the full "one two" into $foo. But the quotes do not hurt anything, and it is a reasonable style to use them to avoid this discussion. :)

It also matches style-wise with nearby assignments, like:

main="$b"

-Peff

#3 lore raw
In reply to David A. Greene

I am sorry I neglected to follow-up on this.

Quoted 15 lines · [email protected] (David A. Greene) writes:

contrib/subtree/git-subtree.sh find_latest_squash() · line 249

Quoted 11 lines · Rob Mayoff
contrib/subtree/git-subtree.sh +2 -1
index 9f06571..b051600 100755
@@ -245,7 +245,10 @@ find_latest_squash()
 		case "$a" in
 			START) sq="$b" ;;
 			git-subtree-mainline:) main="$b" ;;
-			git-subtree-split:) sub="$b" ;;
+			git-subtree-split:)
+				sub="$b"

Why include the above line?

My bad. Missed the diff markers. This is fine.

Quoted 7 lines

contrib/subtree/git-subtree.sh find_latest_squash() · line 250

Quoted 1 line
contrib/subtree/git-subtree.sh +1 -0
+				sub="$(git rev-parse "$b^0")" || die "could not rev-parse split hash $b from commit $sq"

This seems like odd quoting. Would not this do the same?

				sub="$(git rev-parse $b^0)" || die "could not rev-parse split hash $b from commit $sq"

Perhaps I am missing something.

Jeff explained it, so this is ok.

This all looks good to me. Junio, please apply.

-David

#4 lore raw
Quoted 28 lines · [email protected] (David A. Greene) writes:

I am sorry I neglected to follow-up on this.

Quoted 15 lines · [email protected] (David A. Greene) writes:

contrib/subtree/git-subtree.sh find_latest_squash() · line 249

Quoted 11 lines · Rob Mayoff
contrib/subtree/git-subtree.sh +2 -1
index 9f06571..b051600 100755
@@ -245,7 +245,10 @@ find_latest_squash()
 		case "$a" in
 			START) sq="$b" ;;
 			git-subtree-mainline:) main="$b" ;;
-			git-subtree-split:) sub="$b" ;;
+			git-subtree-split:)
+				sub="$b"

Why include the above line?

My bad. Missed the diff markers. This is fine.

Quoted 6 lines

contrib/subtree/git-subtree.sh find_latest_squash() · line 250

Quoted 1 line
contrib/subtree/git-subtree.sh +1 -0
+				sub="$(git rev-parse "$b^0")" || die "could not rev-parse split hash $b from commit $sq"

This seems like odd quoting. Would not this do the same?

				sub="$(git rev-parse $b^0)" || die "could not rev-parse split hash $b from commit $sq"
Quoted 7 lines
Quoted 1 line

Perhaps I am missing something.

Jeff explained it, so this is ok.

This all looks good to me. Junio, please apply.

-David

Thanks, all. Let's mark rm/subtree-unwrap-tags topic to be merged to 'next', then.