Skip to content

Commit 47a7925

Browse files
committed
Merge branch 'jk/commit-v-strip'
* 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
2 parents 8c4021a + 1324fb6 commit 47a7925

File tree

4 files changed

+14
-31
lines changed

4 files changed

+14
-31
lines changed

cache.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,12 @@ static inline void hashclr(unsigned char *hash)
530530
}
531531
extern int is_empty_blob_sha1(const unsigned char *sha1);
532532

533+
#define EMPTY_TREE_SHA1_HEX \
534+
"4b825dc642cb6eb9a060e54bf8d69288fbee4904"
535+
#define EMPTY_TREE_SHA1_BIN \
536+
"\x4b\x82\x5d\xc6\x42\xcb\x6e\xb9\xa0\x60" \
537+
"\xe5\x4b\xf8\xd6\x92\x88\xfb\xee\x49\x04"
538+
533539
int git_mkstemp(char *path, size_t n, const char *template);
534540

535541
/*

sha1_file.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2055,9 +2055,7 @@ static struct cached_object {
20552055
static int cached_object_nr, cached_object_alloc;
20562056

20572057
static struct cached_object empty_tree = {
2058-
/* empty tree sha1: 4b825dc642cb6eb9a060e54bf8d69288fbee4904 */
2059-
"\x4b\x82\x5d\xc6\x42\xcb\x6e\xb9\xa0\x60"
2060-
"\xe5\x4b\xf8\xd6\x92\x88\xfb\xee\x49\x04",
2058+
EMPTY_TREE_SHA1_BIN,
20612059
OBJ_TREE,
20622060
"",
20632061
0

t/t7507-commit-verbose.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ test_expect_success 'setup' '
2222
git commit -F message
2323
'
2424

25-
test_expect_failure 'initial commit shows verbose diff' '
25+
test_expect_success 'initial commit shows verbose diff' '
2626
git commit --amend -v
2727
'
2828

wt-status.c

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -185,31 +185,12 @@ static void wt_status_print_changed_cb(struct diff_queue_struct *q,
185185
wt_status_print_trailer(s);
186186
}
187187

188-
static void wt_status_print_initial(struct wt_status *s)
189-
{
190-
int i;
191-
struct strbuf buf = STRBUF_INIT;
192-
193-
if (active_nr) {
194-
s->commitable = 1;
195-
wt_status_print_cached_header(s);
196-
}
197-
for (i = 0; i < active_nr; i++) {
198-
color_fprintf(s->fp, color(WT_STATUS_HEADER), "#\t");
199-
color_fprintf_ln(s->fp, color(WT_STATUS_UPDATED), "new file: %s",
200-
quote_path(active_cache[i]->name, -1,
201-
&buf, s->prefix));
202-
}
203-
if (active_nr)
204-
wt_status_print_trailer(s);
205-
strbuf_release(&buf);
206-
}
207-
208188
static void wt_status_print_updated(struct wt_status *s)
209189
{
210190
struct rev_info rev;
211191
init_revisions(&rev, NULL);
212-
setup_revisions(0, NULL, &rev, s->reference);
192+
setup_revisions(0, NULL, &rev,
193+
s->is_initial ? EMPTY_TREE_SHA1_HEX : s->reference);
213194
rev.diffopt.output_format |= DIFF_FORMAT_CALLBACK;
214195
rev.diffopt.format_callback = wt_status_print_updated_cb;
215196
rev.diffopt.format_callback_data = s;
@@ -298,7 +279,8 @@ static void wt_status_print_verbose(struct wt_status *s)
298279
struct rev_info rev;
299280

300281
init_revisions(&rev, NULL);
301-
setup_revisions(0, NULL, &rev, s->reference);
282+
setup_revisions(0, NULL, &rev,
283+
s->is_initial ? EMPTY_TREE_SHA1_HEX : s->reference);
302284
rev.diffopt.output_format |= DIFF_FORMAT_PATCH;
303285
rev.diffopt.detect_rename = 1;
304286
DIFF_OPT_SET(&rev.diffopt, ALLOW_TEXTCONV);
@@ -360,12 +342,9 @@ void wt_status_print(struct wt_status *s)
360342
color_fprintf_ln(s->fp, color(WT_STATUS_HEADER), "#");
361343
color_fprintf_ln(s->fp, color(WT_STATUS_HEADER), "# Initial commit");
362344
color_fprintf_ln(s->fp, color(WT_STATUS_HEADER), "#");
363-
wt_status_print_initial(s);
364-
}
365-
else {
366-
wt_status_print_updated(s);
367345
}
368346

347+
wt_status_print_updated(s);
369348
wt_status_print_changed(s);
370349
if (wt_status_submodule_summary)
371350
wt_status_print_submodule_summary(s);
@@ -374,7 +353,7 @@ void wt_status_print(struct wt_status *s)
374353
else if (s->commitable)
375354
fprintf(s->fp, "# Untracked files not listed (use -u option to show untracked files)\n");
376355

377-
if (s->verbose && !s->is_initial)
356+
if (s->verbose)
378357
wt_status_print_verbose(s);
379358
if (!s->commitable) {
380359
if (s->amend)

0 commit comments

Comments
 (0)