Code

Merge branch 'jk/commit-v-strip'
authorJunio C Hamano <gitster@pobox.com>
Sun, 16 Nov 2008 08:48:59 +0000 (00:48 -0800)
committerJunio C Hamano <gitster@pobox.com>
Sun, 16 Nov 2008 08:48:59 +0000 (00:48 -0800)
* jk/commit-v-strip:
  status: show "-v" diff even for initial commit
  wt-status: refactor initial commit printing
  define empty tree sha1 as a macro

cache.h
sha1_file.c
t/t7507-commit-verbose.sh
wt-status.c

diff --git a/cache.h b/cache.h
index 3b5f0c4c003a611b45e2ca9455681dc8a8347516..7efba7756d3658996f2cda4f79f1c5d2072ed51c 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -530,6 +530,12 @@ static inline void hashclr(unsigned char *hash)
 }
 extern int is_empty_blob_sha1(const unsigned char *sha1);
 
+#define EMPTY_TREE_SHA1_HEX \
+       "4b825dc642cb6eb9a060e54bf8d69288fbee4904"
+#define EMPTY_TREE_SHA1_BIN \
+        "\x4b\x82\x5d\xc6\x42\xcb\x6e\xb9\xa0\x60" \
+        "\xe5\x4b\xf8\xd6\x92\x88\xfb\xee\x49\x04"
+
 int git_mkstemp(char *path, size_t n, const char *template);
 
 /*
index 0fa65baa59de4db058ca6a41bba29ac78eab2643..75a748a644f8f11c7bcb372fe74fbfb00faf1796 100644 (file)
@@ -2055,9 +2055,7 @@ static struct cached_object {
 static int cached_object_nr, cached_object_alloc;
 
 static struct cached_object empty_tree = {
-       /* empty tree sha1: 4b825dc642cb6eb9a060e54bf8d69288fbee4904 */
-       "\x4b\x82\x5d\xc6\x42\xcb\x6e\xb9\xa0\x60"
-       "\xe5\x4b\xf8\xd6\x92\x88\xfb\xee\x49\x04",
+       EMPTY_TREE_SHA1_BIN,
        OBJ_TREE,
        "",
        0
index 519adba80b4e5bc23a68c4bdcae607cf2d403c23..da5bd3b5a585667dad97481df27049f0aa7415eb 100755 (executable)
@@ -22,7 +22,7 @@ test_expect_success 'setup' '
        git commit -F message
 '
 
-test_expect_failure 'initial commit shows verbose diff' '
+test_expect_success 'initial commit shows verbose diff' '
        git commit --amend -v
 '
 
index 6a7645ed86fd5879e959460011a8add015d392d9..3edae43ce9d99b27ed69166d90db71bc3c219404 100644 (file)
@@ -185,31 +185,12 @@ static void wt_status_print_changed_cb(struct diff_queue_struct *q,
                wt_status_print_trailer(s);
 }
 
-static void wt_status_print_initial(struct wt_status *s)
-{
-       int i;
-       struct strbuf buf = STRBUF_INIT;
-
-       if (active_nr) {
-               s->commitable = 1;
-               wt_status_print_cached_header(s);
-       }
-       for (i = 0; i < active_nr; i++) {
-               color_fprintf(s->fp, color(WT_STATUS_HEADER), "#\t");
-               color_fprintf_ln(s->fp, color(WT_STATUS_UPDATED), "new file: %s",
-                               quote_path(active_cache[i]->name, -1,
-                                          &buf, s->prefix));
-       }
-       if (active_nr)
-               wt_status_print_trailer(s);
-       strbuf_release(&buf);
-}
-
 static void wt_status_print_updated(struct wt_status *s)
 {
        struct rev_info rev;
        init_revisions(&rev, NULL);
-       setup_revisions(0, NULL, &rev, s->reference);
+       setup_revisions(0, NULL, &rev,
+               s->is_initial ? EMPTY_TREE_SHA1_HEX : s->reference);
        rev.diffopt.output_format |= DIFF_FORMAT_CALLBACK;
        rev.diffopt.format_callback = wt_status_print_updated_cb;
        rev.diffopt.format_callback_data = s;
@@ -298,7 +279,8 @@ static void wt_status_print_verbose(struct wt_status *s)
        struct rev_info rev;
 
        init_revisions(&rev, NULL);
-       setup_revisions(0, NULL, &rev, s->reference);
+       setup_revisions(0, NULL, &rev,
+               s->is_initial ? EMPTY_TREE_SHA1_HEX : s->reference);
        rev.diffopt.output_format |= DIFF_FORMAT_PATCH;
        rev.diffopt.detect_rename = 1;
        DIFF_OPT_SET(&rev.diffopt, ALLOW_TEXTCONV);
@@ -360,12 +342,9 @@ void wt_status_print(struct wt_status *s)
                color_fprintf_ln(s->fp, color(WT_STATUS_HEADER), "#");
                color_fprintf_ln(s->fp, color(WT_STATUS_HEADER), "# Initial commit");
                color_fprintf_ln(s->fp, color(WT_STATUS_HEADER), "#");
-               wt_status_print_initial(s);
-       }
-       else {
-               wt_status_print_updated(s);
        }
 
+       wt_status_print_updated(s);
        wt_status_print_changed(s);
        if (wt_status_submodule_summary)
                wt_status_print_submodule_summary(s);
@@ -374,7 +353,7 @@ void wt_status_print(struct wt_status *s)
        else if (s->commitable)
                 fprintf(s->fp, "# Untracked files not listed (use -u option to show untracked files)\n");
 
-       if (s->verbose && !s->is_initial)
+       if (s->verbose)
                wt_status_print_verbose(s);
        if (!s->commitable) {
                if (s->amend)