Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 38ec23a

Browse files
committed
get_patch_filename(): drop "just-numbers" hack
The function chooses from three operating modes (format using the subject, the commit, or just number) based on NULL-ness of two of its parameters, which is an ugly hack for sharing only a bit of code. Separate out the "just numbers" part out to the callers. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 021f2f4 commit 38ec23a

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

builtin/log.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,10 @@ static int reopen_stdout(struct commit *commit, const char *subject,
684684
strbuf_addch(&filename, '/');
685685
}
686686

687-
get_patch_filename(&filename, commit, subject, rev);
687+
if (rev->numbered_files)
688+
strbuf_addf(&filename, "%d", rev->nr);
689+
else
690+
get_patch_filename(&filename, commit, subject, rev);
688691

689692
if (!quiet)
690693
fprintf(realstdout, "%s\n", filename.buf + outdir_offset);

log-tree.c

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -307,21 +307,18 @@ void get_patch_filename(struct strbuf *buf,
307307
int nr = info->nr;
308308
int suffix_len = strlen(suffix) + 1;
309309
int start_len = buf->len;
310+
int max_len = start_len + FORMAT_PATCH_NAME_MAX - suffix_len;
310311

311-
strbuf_addf(buf, commit || subject ? "%04d-" : "%d", nr);
312-
if (commit || subject) {
313-
int max_len = start_len + FORMAT_PATCH_NAME_MAX - suffix_len;
312+
strbuf_addf(buf, "%04d-", nr);
313+
if (subject)
314+
strbuf_addstr(buf, subject);
315+
else if (commit) {
314316
struct pretty_print_context ctx = {0};
315-
316-
if (subject)
317-
strbuf_addstr(buf, subject);
318-
else if (commit)
319-
format_commit_message(commit, "%f", buf, &ctx);
320-
321-
if (max_len < buf->len)
322-
strbuf_setlen(buf, max_len);
323-
strbuf_addstr(buf, suffix);
317+
format_commit_message(commit, "%f", buf, &ctx);
324318
}
319+
if (max_len < buf->len)
320+
strbuf_setlen(buf, max_len);
321+
strbuf_addstr(buf, suffix);
325322
}
326323

327324
void log_write_email_headers(struct rev_info *opt, struct commit *commit,
@@ -390,9 +387,11 @@ void log_write_email_headers(struct rev_info *opt, struct commit *commit,
390387
mime_boundary_leader, opt->mime_boundary);
391388
extra_headers = subject_buffer;
392389

393-
get_patch_filename(&filename,
394-
opt->numbered_files ? NULL : commit, NULL,
395-
opt);
390+
if (opt->numbered_files)
391+
strbuf_addf(&filename, "%d", opt->nr);
392+
else
393+
get_patch_filename(&filename, commit, NULL,
394+
opt);
396395
snprintf(buffer, sizeof(buffer) - 1,
397396
"\n--%s%s\n"
398397
"Content-Type: text/x-patch;"

0 commit comments

Comments
 (0)