Skip to content

Commit 6fa8e62

Browse files
bebarinogitster
authored andcommitted
format-patch: move get_patch_filename() into log-tree
Signed-off-by: Stephen Boyd <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cd2ef59 commit 6fa8e62

File tree

3 files changed

+26
-24
lines changed

3 files changed

+26
-24
lines changed

builtin-log.c

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,6 @@ int cmd_log(int argc, const char **argv, const char *prefix)
417417
}
418418

419419
/* format-patch */
420-
#define FORMAT_PATCH_NAME_MAX 64
421420

422421
static const char *fmt_patch_suffix = ".patch";
423422
static int numbered = 0;
@@ -512,29 +511,6 @@ static int git_format_config(const char *var, const char *value, void *cb)
512511
return git_log_config(var, value, cb);
513512
}
514513

515-
516-
static void get_patch_filename(struct commit *commit, int nr,
517-
const char *suffix, struct strbuf *buf)
518-
{
519-
int suffix_len = strlen(suffix) + 1;
520-
int start_len = buf->len;
521-
522-
strbuf_addf(buf, commit ? "%04d-" : "%d", nr);
523-
if (commit) {
524-
format_commit_message(commit, "%f", buf, DATE_NORMAL);
525-
/*
526-
* Replace characters at the end with the suffix if the
527-
* filename is too long
528-
*/
529-
if (buf->len + suffix_len > FORMAT_PATCH_NAME_MAX + start_len)
530-
strbuf_splice(buf,
531-
start_len + FORMAT_PATCH_NAME_MAX - suffix_len,
532-
suffix_len, suffix, suffix_len);
533-
else
534-
strbuf_addstr(buf, suffix);
535-
}
536-
}
537-
538514
static FILE *realstdout = NULL;
539515
static const char *output_directory = NULL;
540516
static int outdir_offset;

log-tree.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,28 @@ static int has_non_ascii(const char *s)
179179
return 0;
180180
}
181181

182+
void get_patch_filename(struct commit *commit, int nr, const char *suffix,
183+
struct strbuf *buf)
184+
{
185+
int suffix_len = strlen(suffix) + 1;
186+
int start_len = buf->len;
187+
188+
strbuf_addf(buf, commit ? "%04d-" : "%d", nr);
189+
if (commit) {
190+
format_commit_message(commit, "%f", buf, DATE_NORMAL);
191+
/*
192+
* Replace characters at the end with the suffix if the
193+
* filename is too long
194+
*/
195+
if (buf->len + suffix_len > FORMAT_PATCH_NAME_MAX + start_len)
196+
strbuf_splice(buf,
197+
start_len + FORMAT_PATCH_NAME_MAX - suffix_len,
198+
suffix_len, suffix, suffix_len);
199+
else
200+
strbuf_addstr(buf, suffix);
201+
}
202+
}
203+
182204
void log_write_email_headers(struct rev_info *opt, const char *name,
183205
const char **subject_p,
184206
const char **extra_headers_p,

log-tree.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,8 @@ void log_write_email_headers(struct rev_info *opt, const char *name,
1919
int *need_8bit_cte_p);
2020
void load_ref_decorations(void);
2121

22+
#define FORMAT_PATCH_NAME_MAX 64
23+
void get_patch_filename(struct commit *commit, int nr, const char *suffix,
24+
struct strbuf *buf);
25+
2226
#endif

0 commit comments

Comments
 (0)