@matheusbsbs / matheus-bagliano / commits / 84dbe7b867
Fork 0

builtin-commit: refactor short-status code into wt-status.c

Currently, builtin-commit.c contains most code producing the short-status output, whereas wt-status.c contains most of the code for the long format. Refactor so that most of the long and short format producing code resides in wt-status.c and is named analogously. Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Michael J Gruber committed Dec 5, 2009 at 16:04 UTC 84dbe7b867cfaaa929ed1941f930d564514ae714
3 files changed +95 -97
builtin-commit.c
+4 -97
@@ -79,8 +79,6 @@ static enum {
79 STATUS_FORMAT_PORCELAIN,
80 } status_format = STATUS_FORMAT_LONG;
81
82 -static void short_print(struct wt_status *s, int null_termination);
83 -
82 static int opt_parse_m(const struct option *opt, const char *arg, int unset)
83 {
84 struct strbuf *buf = opt->value;
@@ -381,10 +379,10 @@ static int run_status(FILE *fp, const char *index_file, const char *prefix, int
379
380 switch (status_format) {
381 case STATUS_FORMAT_SHORT:
384 - short_print(s, null_termination);
382 + wt_shortstatus_print(s, null_termination);
383 break;
384 case STATUS_FORMAT_PORCELAIN:
387 - short_print(s, null_termination);
385 + wt_shortstatus_print(s, null_termination);
386 break;
387 case STATUS_FORMAT_LONG:
388 wt_status_print(s);
@@ -928,97 +926,6 @@ static int git_status_config(const char *k, const char *v, void *cb)
926 return git_diff_ui_config(k, v, NULL);
927 }
928
931 -#define quote_path quote_path_relative
932 -
933 -static void short_unmerged(int null_termination, struct string_list_item *it,
934 - struct wt_status *s)
935 -{
936 - struct wt_status_change_data *d = it->util;
937 - const char *how = "??";
938 -
939 - switch (d->stagemask) {
940 - case 1: how = "DD"; break; /* both deleted */
941 - case 2: how = "AU"; break; /* added by us */
942 - case 3: how = "UD"; break; /* deleted by them */
943 - case 4: how = "UA"; break; /* added by them */
944 - case 5: how = "DU"; break; /* deleted by us */
945 - case 6: how = "AA"; break; /* both added */
946 - case 7: how = "UU"; break; /* both modified */
947 - }
948 - printf("%s ", how);
949 - if (null_termination) {
950 - fprintf(stdout, "%s%c", it->string, 0);
951 - } else {
952 - struct strbuf onebuf = STRBUF_INIT;
953 - const char *one;
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_status(int null_termination, struct string_list_item *it,
961 - struct wt_status *s)
962 -{
963 - struct wt_status_change_data *d = it->util;
964 -
965 - printf("%c%c ",
966 - !d->index_status ? ' ' : d->index_status,
967 - !d->worktree_status ? ' ' : d->worktree_status);
968 - if (null_termination) {
969 - fprintf(stdout, "%s%c", it->string, 0);
970 - if (d->head_path)
971 - fprintf(stdout, "%s%c", d->head_path, 0);
972 - } else {
973 - struct strbuf onebuf = STRBUF_INIT;
974 - const char *one;
975 - if (d->head_path) {
976 - one = quote_path(d->head_path, -1, &onebuf, s->prefix);
977 - printf("%s -> ", one);
978 - strbuf_release(&onebuf);
979 - }
980 - one = quote_path(it->string, -1, &onebuf, s->prefix);
981 - printf("%s\n", one);
982 - strbuf_release(&onebuf);
983 - }
984 -}
985 -
986 -static void short_untracked(int null_termination, struct string_list_item *it,
987 - struct wt_status *s)
988 -{
989 - if (null_termination) {
990 - fprintf(stdout, "?? %s%c", it->string, 0);
991 - } else {
992 - struct strbuf onebuf = STRBUF_INIT;
993 - const char *one;
994 - one = quote_path(it->string, -1, &onebuf, s->prefix);
995 - printf("?? %s\n", one);
996 - strbuf_release(&onebuf);
997 - }
998 -}
999 -
1000 -static void short_print(struct wt_status *s, int null_termination)
1001 -{
1002 - int i;
1003 - for (i = 0; i < s->change.nr; i++) {
1004 - struct wt_status_change_data *d;
1005 - struct string_list_item *it;
1006 -
1007 - it = &(s->change.items[i]);
1008 - d = it->util;
1009 - if (d->stagemask)
1010 - short_unmerged(null_termination, it, s);
1011 - else
1012 - short_status(null_termination, it, s);
1013 - }
1014 - for (i = 0; i < s->untracked.nr; i++) {
1015 - struct string_list_item *it;
1016 -
1017 - it = &(s->untracked.items[i]);
1018 - short_untracked(null_termination, it, s);
1019 - }
1020 -}
1021 -
929 int cmd_status(int argc, const char **argv, const char *prefix)
930 {
931 struct wt_status s;
@@ -1061,10 +968,10 @@ int cmd_status(int argc, const char **argv, const char *prefix)
968 case STATUS_FORMAT_SHORT:
969 if (s.relative_paths)
970 s.prefix = prefix;
1064 - short_print(&s, null_termination);
971 + wt_shortstatus_print(&s, null_termination);
972 break;
973 case STATUS_FORMAT_PORCELAIN:
1067 - short_print(&s, null_termination);
974 + wt_shortstatus_print(&s, null_termination);
975 break;
976 case STATUS_FORMAT_LONG:
977 s.verbose = verbose;
wt-status.c
+89
@@ -592,3 +592,92 @@ void wt_status_print(struct wt_status *s)
592 printf("nothing to commit (working directory clean)\n");
593 }
594 }
595 +
596 +static void wt_shortstatus_unmerged(int null_termination, struct string_list_item *it,
597 + struct wt_status *s)
598 +{
599 + struct wt_status_change_data *d = it->util;
600 + const char *how = "??";
601 +
602 + switch (d->stagemask) {
603 + case 1: how = "DD"; break; /* both deleted */
604 + case 2: how = "AU"; break; /* added by us */
605 + case 3: how = "UD"; break; /* deleted by them */
606 + case 4: how = "UA"; break; /* added by them */
607 + case 5: how = "DU"; break; /* deleted by us */
608 + case 6: how = "AA"; break; /* both added */
609 + case 7: how = "UU"; break; /* both modified */
610 + }
611 + printf("%s ", how);
612 + if (null_termination) {
613 + fprintf(stdout, "%s%c", it->string, 0);
614 + } else {
615 + struct strbuf onebuf = STRBUF_INIT;
616 + const char *one;
617 + one = quote_path(it->string, -1, &onebuf, s->prefix);
618 + printf("%s\n", one);
619 + strbuf_release(&onebuf);
620 + }
621 +}
622 +
623 +static void wt_shortstatus_status(int null_termination, struct string_list_item *it,
624 + struct wt_status *s)
625 +{
626 + struct wt_status_change_data *d = it->util;
627 +
628 + printf("%c%c ",
629 + !d->index_status ? ' ' : d->index_status,
630 + !d->worktree_status ? ' ' : d->worktree_status);
631 + if (null_termination) {
632 + fprintf(stdout, "%s%c", it->string, 0);
633 + if (d->head_path)
634 + fprintf(stdout, "%s%c", d->head_path, 0);
635 + } else {
636 + struct strbuf onebuf = STRBUF_INIT;
637 + const char *one;
638 + if (d->head_path) {
639 + one = quote_path(d->head_path, -1, &onebuf, s->prefix);
640 + printf("%s -> ", one);
641 + strbuf_release(&onebuf);
642 + }
643 + one = quote_path(it->string, -1, &onebuf, s->prefix);
644 + printf("%s\n", one);
645 + strbuf_release(&onebuf);
646 + }
647 +}
648 +
649 +static void wt_shortstatus_untracked(int null_termination, struct string_list_item *it,
650 + struct wt_status *s)
651 +{
652 + if (null_termination) {
653 + fprintf(stdout, "?? %s%c", it->string, 0);
654 + } else {
655 + struct strbuf onebuf = STRBUF_INIT;
656 + const char *one;
657 + one = quote_path(it->string, -1, &onebuf, s->prefix);
658 + printf("?? %s\n", one);
659 + strbuf_release(&onebuf);
660 + }
661 +}
662 +
663 +void wt_shortstatus_print(struct wt_status *s, int null_termination)
664 +{
665 + int i;
666 + for (i = 0; i < s->change.nr; i++) {
667 + struct wt_status_change_data *d;
668 + struct string_list_item *it;
669 +
670 + it = &(s->change.items[i]);
671 + d = it->util;
672 + if (d->stagemask)
673 + wt_shortstatus_unmerged(null_termination, it, s);
674 + else
675 + wt_shortstatus_status(null_termination, it, s);
676 + }
677 + for (i = 0; i < s->untracked.nr; i++) {
678 + struct string_list_item *it;
679 +
680 + it = &(s->untracked.items[i]);
681 + wt_shortstatus_untracked(null_termination, it, s);
682 + }
683 +}
wt-status.h
+2
@@ -56,4 +56,6 @@ void wt_status_prepare(struct wt_status *s);
56 void wt_status_print(struct wt_status *s);
57 void wt_status_collect(struct wt_status *s);
58
59 +void wt_shortstatus_print(struct wt_status *s, int null_termination);
60 +
61 #endif /* STATUS_H */