@matheusbsbs / matheus-bagliano / commits / 6fa8e6278b
Fork 0

format-patch: move get_patch_filename() into log-tree

Signed-off-by: Stephen Boyd <bebarino@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Stephen Boyd committed Mar 22, 2009 at 19:14 UTC 6fa8e6278b210bfa56fcb54ed38d2b485350e7c6
3 files changed +26 -24
builtin-log.c
-24
@@ -417,7 +417,6 @@ int cmd_log(int argc, const char **argv, const char *prefix)
417 }
418
419 /* format-patch */
420 -#define FORMAT_PATCH_NAME_MAX 64
420
421 static const char *fmt_patch_suffix = ".patch";
422 static int numbered = 0;
@@ -512,29 +511,6 @@ static int git_format_config(const char *var, const char *value, void *cb)
511 return git_log_config(var, value, cb);
512 }
513
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 -
514 static FILE *realstdout = NULL;
515 static const char *output_directory = NULL;
516 static int outdir_offset;
log-tree.c
+22
@@ -179,6 +179,28 @@ static int has_non_ascii(const char *s)
179 return 0;
180 }
181
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 +
204 void log_write_email_headers(struct rev_info *opt, const char *name,
205 const char **subject_p,
206 const char **extra_headers_p,
log-tree.h
+4
@@ -19,4 +19,8 @@ void log_write_email_headers(struct rev_info *opt, const char *name,
19 int *need_8bit_cte_p);
20 void load_ref_decorations(void);
21
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 +
26 #endif