submodule--helper: offer a consistent API

In 48308681 (2016-02-29, git submodule update: have a dedicated helper for cloning), the helper communicated errors back only via exit code, and dance with printing '#unmatched' in case of error was left to git-submodule.sh as it uses the output of the helper and pipes it into shell commands. This change makes the helper consistent by never printing '#unmatched' in the helper but always handling these piping issues in the actual shell script. Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Stefan Beller committed May 31, 2016 at 16:59 UTC b0f4b4084626ab0f87611acd89030e8bdf0b850e
2 files changed +17 -7
builtin/submodule--helper.c
+1 -3
@@ -287,10 +287,8 @@ static int module_list(int argc, const char **argv, const char *prefix)
287 argc = parse_options(argc, argv, prefix, module_list_options,
288 git_submodule_helper_usage, 0);
289
290 - if (module_list_compute(argc, argv, prefix, &pathspec, &list) < 0) {
291 - printf("#unmatched\n");
290 + if (module_list_compute(argc, argv, prefix, &pathspec, &list) < 0)
291 return 1;
293 - }
292
293 for (i = 0; i < list.nr; i++) {
294 const struct cache_entry *ce = list.entries[i];
git-submodule.sh
+16 -4
@@ -345,7 +345,10 @@ cmd_foreach()
345 # command in the subshell (and a recursive call to this function)
346 exec 3<&0
347
348 - git submodule--helper list --prefix "$wt_prefix"|
348 + {
349 + git submodule--helper list --prefix "$wt_prefix" ||
350 + echo "#unmatched"
351 + } |
352 while read mode sha1 stage sm_path
353 do
354 die_if_unmatched "$mode"
@@ -453,7 +456,10 @@ cmd_deinit()
456 die "$(eval_gettext "Use '--all' if you really want to deinitialize all submodules")"
457 fi
458
456 - git submodule--helper list --prefix "$wt_prefix" "$@" |
459 + {
460 + git submodule--helper list --prefix "$wt_prefix" "$@" ||
461 + echo "#unmatched"
462 + } |
463 while read mode sha1 stage sm_path
464 do
465 die_if_unmatched "$mode"
@@ -1013,7 +1019,10 @@ cmd_status()
1019 shift
1020 done
1021
1016 - git submodule--helper list --prefix "$wt_prefix" "$@" |
1022 + {
1023 + git submodule--helper list --prefix "$wt_prefix" "$@" ||
1024 + echo "#unmatched"
1025 + } |
1026 while read mode sha1 stage sm_path
1027 do
1028 die_if_unmatched "$mode"
@@ -1091,7 +1100,10 @@ cmd_sync()
1100 esac
1101 done
1102 cd_to_toplevel
1094 - git submodule--helper list --prefix "$wt_prefix" "$@" |
1103 + {
1104 + git submodule--helper list --prefix "$wt_prefix" "$@" ||
1105 + echo "#unmatched"
1106 + } |
1107 while read mode sha1 stage sm_path
1108 do
1109 die_if_unmatched "$mode"