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, but some callers should change their behaviour when the merge in
the superproject still has conflicts.

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
the $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.  Then
update the codepaths for each subcommands this way:

 - "update" should not touch the submodule repository, because we do not
   know what commit should be checked out yet.

 - "status" reports the conflicting submodules as 'U000...000' and does
   not recurse into them (we might later want to make it recurse).

 - The command called by "foreach" may want to do whatever it wants to do
   by noticing the merged status in the superproject itself, so feed the
   path to it from module_list as before, but only once per submodule.

 - "init" and "sync" are unlikely things to do while the superproject is
   still not merged, 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.

Acked-by: Jens Lehmann <Jens.Lehmann@web.de>
Thanks-to: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Nicolas Morey-Chaisemartin <nicolas@morey-chaisemartin.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 files changed
tree: 2c774c3458f022aeb1285f0686dd3ec5f26469eb
  1. block-sha1/
  2. builtin/
  3. compat/
  4. contrib/
  5. Documentation/
  6. git-gui/
  7. git_remote_helpers/
  8. gitk-git/
  9. gitweb/
  10. perl/
  11. ppc/
  12. t/
  13. templates/
  14. vcs-svn/
  15. xdiff/
  16. .gitattributes
  17. .gitignore
  18. .mailmap
  19. abspath.c
  20. aclocal.m4
  21. advice.c
  22. advice.h
  23. alias.c
  24. alloc.c
  25. archive-tar.c
  26. archive-zip.c
  27. archive.c
  28. archive.h
  29. attr.c
  30. attr.h
  31. base85.c
  32. bisect.c
  33. bisect.h
  34. blob.c
  35. blob.h
  36. branch.c
  37. branch.h
  38. builtin.h
  39. bundle.c
  40. bundle.h
  41. cache-tree.c
  42. cache-tree.h
  43. cache.h
  44. check-builtins.sh
  45. check-racy.c
  46. check_bindir
  47. color.c
  48. color.h
  49. combine-diff.c
  50. command-list.txt
  51. commit.c
  52. commit.h
  53. config.c
  54. config.mak.in
  55. configure.ac
  56. connect.c
  57. convert.c
  58. copy.c
  59. COPYING
  60. csum-file.c
  61. csum-file.h
  62. ctype.c
  63. daemon.c
  64. date.c
  65. decorate.c
  66. decorate.h
  67. delta.h
  68. diff-delta.c
  69. diff-lib.c
  70. diff-no-index.c
  71. diff.c
  72. diff.h
  73. diffcore-break.c
  74. diffcore-delta.c
  75. diffcore-order.c
  76. diffcore-pickaxe.c
  77. diffcore-rename.c
  78. diffcore.h
  79. dir.c
  80. dir.h
  81. editor.c
  82. entry.c
  83. environment.c
  84. exec_cmd.c
  85. exec_cmd.h
  86. fast-import.c
  87. fetch-pack.h
  88. fixup-builtins
  89. fsck.c
  90. fsck.h
  91. generate-cmdlist.sh
  92. git-add--interactive.perl
  93. git-am.sh
  94. git-archimport.perl
  95. git-bisect.sh
  96. git-compat-util.h
  97. git-cvsexportcommit.perl
  98. git-cvsimport.perl
  99. git-cvsserver.perl
  100. git-difftool--helper.sh
  101. git-difftool.perl
  102. git-filter-branch.sh
  103. git-instaweb.sh
  104. git-lost-found.sh
  105. git-merge-octopus.sh
  106. git-merge-one-file.sh
  107. git-merge-resolve.sh
  108. git-mergetool--lib.sh
  109. git-mergetool.sh
  110. git-parse-remote.sh
  111. git-pull.sh
  112. git-quiltimport.sh
  113. git-rebase--interactive.sh
  114. git-rebase.sh
  115. git-relink.perl
  116. git-remote-testgit.py
  117. git-repack.sh
  118. git-request-pull.sh
  119. git-send-email.perl
  120. git-sh-setup.sh
  121. git-stash.sh
  122. git-submodule.sh
  123. git-svn.perl
  124. GIT-VERSION-GEN
  125. git-web--browse.sh
  126. git.c
  127. git.spec.in
  128. graph.c
  129. graph.h
  130. grep.c
  131. grep.h
  132. hash.c
  133. hash.h
  134. help.c
  135. help.h
  136. hex.c
  137. http-backend.c
  138. http-fetch.c
  139. http-push.c
  140. http-walker.c
  141. http.c
  142. http.h
  143. ident.c
  144. imap-send.c
  145. INSTALL
  146. levenshtein.c
  147. levenshtein.h
  148. list-objects.c
  149. list-objects.h
  150. ll-merge.c
  151. ll-merge.h
  152. lockfile.c
  153. log-tree.c
  154. log-tree.h
  155. mailmap.c
  156. mailmap.h
  157. Makefile
  158. match-trees.c
  159. merge-file.c
  160. merge-recursive.c
  161. merge-recursive.h
  162. name-hash.c
  163. notes-cache.c
  164. notes-cache.h
  165. notes-merge.c
  166. notes-merge.h
  167. notes.c
  168. notes.h
  169. object.c
  170. object.h
  171. pack-check.c
  172. pack-refs.c
  173. pack-refs.h
  174. pack-revindex.c
  175. pack-revindex.h
  176. pack-write.c
  177. pack.h
  178. pager.c
  179. parse-options.c
  180. parse-options.h
  181. patch-delta.c
  182. patch-ids.c
  183. patch-ids.h
  184. path.c
  185. pkt-line.c
  186. pkt-line.h
  187. preload-index.c
  188. pretty.c
  189. progress.c
  190. progress.h
  191. quote.c
  192. quote.h
  193. reachable.c
  194. reachable.h
  195. read-cache.c
  196. README
  197. reflog-walk.c
  198. reflog-walk.h
  199. refs.c
  200. refs.h
  201. remote-curl.c
  202. remote.c
  203. remote.h
  204. replace_object.c
  205. rerere.c
  206. rerere.h
  207. resolve-undo.c
  208. resolve-undo.h
  209. revision.c
  210. revision.h
  211. run-command.c
  212. run-command.h
  213. send-pack.h
  214. server-info.c
  215. setup.c
  216. sha1-lookup.c
  217. sha1-lookup.h
  218. sha1_file.c
  219. sha1_name.c
  220. shallow.c
  221. shell.c
  222. shortlog.h
  223. show-index.c
  224. sideband.c
  225. sideband.h
  226. sigchain.c
  227. sigchain.h
  228. strbuf.c
  229. strbuf.h
  230. string-list.c
  231. string-list.h
  232. submodule.c
  233. submodule.h
  234. symlinks.c
  235. tag.c
  236. tag.h
  237. tar.h
  238. test-chmtime.c
  239. test-ctype.c
  240. test-date.c
  241. test-delta.c
  242. test-dump-cache-tree.c
  243. test-genrandom.c
  244. test-index-version.c
  245. test-line-buffer.c
  246. test-match-trees.c
  247. test-mktemp.c
  248. test-obj-pool.c
  249. test-parse-options.c
  250. test-path-utils.c
  251. test-run-command.c
  252. test-sha1.c
  253. test-sha1.sh
  254. test-sigchain.c
  255. test-string-pool.c
  256. test-subprocess.c
  257. test-svn-fe.c
  258. test-treap.c
  259. thread-utils.c
  260. thread-utils.h
  261. trace.c
  262. transport-helper.c
  263. transport.c
  264. transport.h
  265. tree-diff.c
  266. tree-walk.c
  267. tree-walk.h
  268. tree.c
  269. tree.h
  270. unimplemented.sh
  271. unpack-trees.c
  272. unpack-trees.h
  273. upload-pack.c
  274. url.c
  275. url.h
  276. usage.c
  277. userdiff.c
  278. userdiff.h
  279. utf8.c
  280. utf8.h
  281. walker.c
  282. walker.h
  283. wrap-for-bin.sh
  284. wrapper.c
  285. write_or_die.c
  286. ws.c
  287. wt-status.c
  288. wt-status.h
  289. xdiff-interface.c
  290. xdiff-interface.h
  291. zlib.c