902
return git_diff_ui_config(k, v, NULL);
903
}
904
905
+#define quote_path quote_path_relative
906
+
907
+static void short_unmerged(int null_termination, struct string_list_item *it,
908
+ struct wt_status *s)
909
+{
910
+ struct wt_status_change_data *d = it->util;
911
+ const char *how = "??";
912
+
913
+ switch (d->stagemask) {
914
+ case 1: how = "DD"; break; /* both deleted */
915
+ case 2: how = "AU"; break; /* added by us */
916
+ case 3: how = "UD"; break; /* deleted by them */
917
+ case 4: how = "UA"; break; /* added by them */
918
+ case 5: how = "DU"; break; /* deleted by us */
919
+ case 6: how = "AA"; break; /* both added */
920
+ case 7: how = "UU"; break; /* both modified */
921
+ }
922
+ printf("%s ", how);
923
+ if (null_termination) {
924
+ fprintf(stdout, "%s%c", it->string, 0);
925
+ } else {
926
+ struct strbuf onebuf = STRBUF_INIT;
927
+ const char *one;
928
+ one = quote_path(it->string, -1, &onebuf, s->prefix);
929
+ printf("%s\n", one);
930
+ strbuf_release(&onebuf);
931
+ }
932
+}
933
+
934
+static void short_status(int null_termination, struct string_list_item *it,
935
+ struct wt_status *s)
936
+{
937
+ struct wt_status_change_data *d = it->util;
938
+
939
+ printf("%c%c ",
940
+ !d->index_status ? ' ' : d->index_status,
941
+ !d->worktree_status ? ' ' : d->worktree_status);
942
+ if (null_termination) {
943
+ fprintf(stdout, "%s%c", it->string, 0);
944
+ if (d->head_path)
945
+ fprintf(stdout, "%s%c", d->head_path, 0);
946
+ } else {
947
+ struct strbuf onebuf = STRBUF_INIT;
948
+ const char *one;
949
+ if (d->head_path) {
950
+ one = quote_path(d->head_path, -1, &onebuf, s->prefix);
951
+ printf("%s -> ", one);
952
+ strbuf_release(&onebuf);
953
+ }
954
+ one = quote_path(it->string, -1, &onebuf, s->prefix);
955
+ printf("%s\n", one);
956
+ strbuf_release(&onebuf);
957
+ }
958
+}
959
+
960
+static void short_untracked(int null_termination, struct string_list_item *it,
961
+ struct wt_status *s)
962
+{
963
+ if (null_termination) {
964
+ fprintf(stdout, "?? %s%c", it->string, 0);
965
+ } else {
966
+ struct strbuf onebuf = STRBUF_INIT;
967
+ const char *one;
968
+ one = quote_path(it->string, -1, &onebuf, s->prefix);
969
+ printf("?? %s\n", one);
970
+ strbuf_release(&onebuf);
971
+ }
972
+}
973
+
974
int cmd_stat(int argc, const char **argv, const char *prefix)
975
{
976
struct wt_status s;
977
+ static int null_termination, shortstatus;
978
+ int i;
979
unsigned char sha1[20];
980
static struct option builtin_stat_options[] = {
981
OPT__VERBOSE(&verbose),
982
+ OPT_BOOLEAN('s', "short", &shortstatus,
983
+ "show status concicely"),
984
+ OPT_BOOLEAN('z', "null", &null_termination,
985
+ "terminate entries with NUL"),
986
{ OPTION_STRING, 'u', "untracked-files", &untracked_files_arg,
987
"mode",
988
"show untracked files, optional modes: all, normal, no. (Default: all)",
990
OPT_END(),
991
};
992
993
+ if (null_termination)
994
+ shortstatus = 1;
995
+
996
wt_status_prepare(&s);
997
git_config(git_status_config, &s);
998
argc = parse_options(argc, argv, prefix,
1008
s.is_initial = get_sha1(s.reference, sha1) ? 1 : 0;
1009
wt_status_collect(&s);
1010
933
- s.verbose = verbose;
934
- if (s.relative_paths)
935
- s.prefix = prefix;
936
- if (s.use_color == -1)
937
- s.use_color = git_use_color_default;
938
- if (diff_use_color_default == -1)
939
- diff_use_color_default = git_use_color_default;
940
- wt_status_print(&s);
1011
+ if (shortstatus) {
1012
+ for (i = 0; i < s.change.nr; i++) {
1013
+ struct wt_status_change_data *d;
1014
+ struct string_list_item *it;
1015
+
1016
+ it = &(s.change.items[i]);
1017
+ d = it->util;
1018
+ if (d->stagemask)
1019
+ short_unmerged(null_termination, it, &s);
1020
+ else
1021
+ short_status(null_termination, it, &s);
1022
+ }
1023
+ for (i = 0; i < s.untracked.nr; i++) {
1024
+ struct string_list_item *it;
1025
+
1026
+ it = &(s.untracked.items[i]);
1027
+ short_untracked(null_termination, it, &s);
1028
+ }
1029
+ } else {
1030
+ s.verbose = verbose;
1031
+ if (s.relative_paths)
1032
+ s.prefix = prefix;
1033
+ if (s.use_color == -1)
1034
+ s.use_color = git_use_color_default;
1035
+ if (diff_use_color_default == -1)
1036
+ diff_use_color_default = git_use_color_default;
1037
+ wt_status_print(&s);
1038
+ }
1039
return 0;
1040
}
1041