Thread (11 messages) flat view 11 messages, 4 authors, 2016-06-15

Re: [RFC PATCH 3/3] filter-branch: support --submodule-filter

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:50:19

Thomas Rast [off-list ref] writes:
Subject: TOY PATCH: filter-branch --split-submodule

Sometimes it makes sense to split out a path not as a subdirectory
(that would be merged by subtree-merge), but as a submodule.  Since
git objects are just shaped in the right way, this is actually quite
easy to do in a way that maintains the correct history relations:
The patch from a cursory look feels sane.
quoted hunk ↗ jump to hunk
@@ -349,6 +352,43 @@ while read commit parents; do
 	eval "$filter_index" < /dev/null ||
 		die "index filter failed: $filter_index"
 
+	if test -n "$split_submodule"; then
+		sub_differs=
+		sub_parents=
+		sub_commit=
Just a style, but I find

	if test -n "$split_submodule"
        then
        	sub_differs= sub_parents= sub_commit=

easier to read.  Not a biggie, as the neighbourhood in the script already
is infested in the other style, but I thought I'd mention it.
+		submodule="$(git rev-parse --verify $commit:$split_submodule 2>/dev/null)"
Do we need double quotes around it?
+		if test -z "$parents"; then
+			if test -n "$submodule"; then
+				sub_differs=t
+			fi
+		fi
	if test -z "$parents" && test -n "$submodule"
        then
        	sub_differs=t
	fi
+		for parent in $parents; do
+			if ! test "$(git rev-parse --verify $parent:$split_submodule 2>/dev/null)" = "$submodule"; then
+				sub_differs=t
+			fi
If even one of the parents is different, we say "differs"...
+		if test -n "$sub_differs"; then
+			sub_commit="$(sed -e '1,/^$/d' <../commit |
+				      git commit-tree $submodule $sub_parents)" || exit
+		else
+			for parent in $parents; do
+				sub_commit="$(git rev-parse --verify "$(map "$parent")":$split_submodule 2>/dev/null)"
+				break
... so we can just pick from the first parent and know all of them are the
same (could be empty which also is fine).  Good.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help