Skip to contentSkip to conversation

submodule: process conflicting submodules only once

PATCH New Nicolas Morey-Chaisemartin 1 participant 1 message Jun 15, 2016 Documentation

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 submodule: process conflicting submodules only once

During a merge module_list returns conflicting submodules several times (stage 1,2,3) which caused the submodules to be used multiple times in git submodule init, sync, update and status command.

There are 5 callers of module_list; they all read (mode, sha1, stage, path) tuple, and most of them care only about path. As a first level approximation, it should be Ok (in the sense that it does not make things worse than it currently is) to filter the duplicate paths from module_list output.

"update" should not touch the submodule repository in such a case. "status" might want to recurse into the submodule repository, but there is no information at the superproject level to compare the submodule status against, so we should at least skip that part for submodule entries that are unmerged in the superproject.

The idea is to notice the higher-stage entries, and emit only one record from module_list, but while doing so, mark the entry with "U" (not [0-3]) in $stage field and null out the SHA-1 part, as the object name for the lowest stage does not give any useful information to the caller, and this way any caller that uses the object name would hopefully barf.

After this patch:
- The command called by foreach may want to do whatever it wants to do by noticing the merged status in the superproject itself, so I made no change to the function;

- Init and Sync are an unlikely thing to do, but as long as a submodule is there in $path, there is no point skipping it. It might however want to take the merged status of .gitmodules into account, but that is outside of the scope of this topic;

- Update skip the conflicting submodules and do not recurse into them.

- Status report the conflicting submodules as 'U000...000' and do not recurse into them.

Thanks-to: Junio C Hamano <[email protected]>

---
 Documentation/git-submodule.txt |    5 ++-
 git-submodule.sh                |   29 +++++++++++++++++++-
 t/t7405-submodule-merge.sh      |   58 +++++++++++++++++++++++++++++++++++----
 3 files changed, 83 insertions(+), 9 deletions(-)
Documentation/git-submodule.txt +3 -2
index 3a5aa01..1a16ff6 100644
@@ -101,9 +101,10 @@ status::
 	currently checked out commit for each submodule, along with the
 	submodule path and the output of 'git describe' for the
 	SHA-1. Each SHA-1 will be prefixed with `-` if the submodule is not
-	initialized and `+` if the currently checked out submodule commit
+	initialized, `+` if the currently checked out submodule commit
 	does not match the SHA-1 found in the index of the containing
-	repository. This command is the default command for 'git submodule'.
+	repository and `U` if the submodule has merge conflicts.
+	This command is the default command for 'git submodule'.
 +
 If '--recursive' is specified, this command will recurse into nested
 submodules, and show their status as well.
git-submodule.sh +28 -1
index 3a13397..7f6b3cf 100755
@@ -72,7 +72,24 @@ resolve_relative_url ()
 #
 module_list()
 {
-	git ls-files --error-unmatch --stage -- "$@" | sane_grep '^160000 '
+	git ls-files --error-unmatch --stage -- "$@" |
+	perl -e '
+	my %unmerged = ();
+	my ($null_sha1) = ("0" x 40);
+	while (<STDIN>) {
+		chomp;
+		my ($mode, $sha1, $stage, $path) =
+			/^([0-7]+) ([0-9a-f]{40}) ([0-3])\t(.*)$/;
+		next unless $mode eq "160000";
+		if ($stage ne "0") {
+			if (!$unmerged{$path}++) {
+				print "$mode $null_sha1 U\t$path\n";
+			}
+			next;
+		}
+		print "$_\n";
+	}
+	'
 }
 
 #
@@ -427,6 +444,11 @@ cmd_update()
 	module_list "$@" |
 	while read mode sha1 stage path
 	do
+		if test "$stage" = U
+		then
+			echo >&2 "Skipping unmerged submodule $path"
+			continue
+		fi
 		name=$(module_name "$path") || exit
 		url=$(git config submodule."$name".url)
 		update_module=$(git config submodule."$name".update)
@@ -770,6 +792,11 @@ cmd_status()
 		name=$(module_name "$path") || exit
 		url=$(git config submodule."$name".url)
 		displaypath="$prefix$path"
+		if test "$stage" = U
+		then
+			say "U$sha1 $displaypath"
+			continue
+		fi
 		if test -z "$url" || ! test -d "$path"/.git -o -f "$path"/.git
 		then
 			say "-$sha1 $displaypath"
t/t7405-submodule-merge.sh +52 -6

82 lines not on this page · raw message

Signature · 1 line
1.7.4.2.407.gd18fa.dirty