From 14d9c578961ab834bfb0e26481d0212bc0670883 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Wed, 12 Nov 2008 03:17:52 -0500 Subject: [PATCH 1/3] define empty tree sha1 as a macro This can potentially be used in a few places, so let's make it available to all parts of the code. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- cache.h | 6 ++++++ sha1_file.c | 4 +--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/cache.h b/cache.h index eda7028992..07795d9a81 100644 --- a/cache.h +++ b/cache.h @@ -528,6 +528,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); /* diff --git a/sha1_file.c b/sha1_file.c index ab2b520f03..1489d04d03 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -1996,9 +1996,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 From c1e255b71964e45cee571819c011fbcaaf18be41 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Wed, 12 Nov 2008 03:21:39 -0500 Subject: [PATCH 2/3] wt-status: refactor initial commit printing When we showed the initial commit, we had no reference to diff against, so we went through the cache manually. Nowadays, however, we have a virtual empty tree commit, so we can simply diff against that to get the same results. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- wt-status.c | 28 +++------------------------- 1 file changed, 3 insertions(+), 25 deletions(-) diff --git a/wt-status.c b/wt-status.c index c3a9cab898..cb1fc48079 100644 --- a/wt-status.c +++ b/wt-status.c @@ -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; @@ -351,12 +332,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); From 1324fb6f161ee516eb4c597880847003a42c0c5d Mon Sep 17 00:00:00 2001 From: Jeff King Date: Wed, 12 Nov 2008 03:23:37 -0500 Subject: [PATCH 3/3] status: show "-v" diff even for initial commit Since we can use the same "diff against empty tree" trick as we do for the non-initial case, it is trivial to make this work. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- t/t7507-commit-verbose.sh | 2 +- wt-status.c | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/t/t7507-commit-verbose.sh b/t/t7507-commit-verbose.sh index 519adba80b..da5bd3b5a5 100755 --- a/t/t7507-commit-verbose.sh +++ b/t/t7507-commit-verbose.sh @@ -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 ' diff --git a/wt-status.c b/wt-status.c index cb1fc48079..ec91fba601 100644 --- a/wt-status.c +++ b/wt-status.c @@ -279,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; rev.diffopt.file = s->fp; @@ -343,7 +344,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)