status: reduce duplicated setup code
We have three output formats: short, porcelain, and long. The short and long formats respect user-config, and the porcelain one does not. This led to us repeating config-related setup code for the short and long formats. Since the last commit, color config is explicitly cleared when showing the porcelain format. Let's do the same with relative-path configuration, which enables us to hoist the duplicated code from the switch statement in cmd_status. As a bonus, this fixes "commit --dry-run --porcelain", which was unconditionally setting up that configuration, anyway. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Dec 7, 2009 at 00:26 UTC
8661768fc9cfdeeaae76693501b82940cfcbedc2
2 files changed
+9
-12
builtin-commit.c
+7
-12
@@ -964,14 +964,15 @@ int cmd_status(int argc, const char **argv, const char *prefix)
964
s.is_initial = get_sha1(s.reference, sha1) ? 1 : 0;
965
wt_status_collect(&s);
966
967
+ if (s.relative_paths)
968
+ s.prefix = prefix;
969
+ if (s.use_color == -1)
970
+ s.use_color = git_use_color_default;
971
+ if (diff_use_color_default == -1)
972
+ diff_use_color_default = git_use_color_default;
973
+
974
switch (status_format) {
975
case STATUS_FORMAT_SHORT:
969
- if (s.relative_paths)
970
- s.prefix = prefix;
971
- if (s.use_color == -1)
972
- s.use_color = git_use_color_default;
973
- if (diff_use_color_default == -1)
974
- diff_use_color_default = git_use_color_default;
976
wt_shortstatus_print(&s, null_termination);
977
break;
978
case STATUS_FORMAT_PORCELAIN:
@@ -979,12 +980,6 @@ int cmd_status(int argc, const char **argv, const char *prefix)
980
break;
981
case STATUS_FORMAT_LONG:
982
s.verbose = verbose;
982
- if (s.relative_paths)
983
- s.prefix = prefix;
984
- if (s.use_color == -1)
985
- s.use_color = git_use_color_default;
986
- if (diff_use_color_default == -1)
987
- diff_use_color_default = git_use_color_default;
983
wt_status_print(&s);
984
break;
985
}
wt-status.c
+2
@@ -692,5 +692,7 @@ void wt_shortstatus_print(struct wt_status *s, int null_termination)
692
void wt_porcelain_print(struct wt_status *s, int null_termination)
693
{
694
s->use_color = 0;
695
+ s->relative_paths = 0;
696
+ s->prefix = NULL;
697
wt_shortstatus_print(s, null_termination);
698
}