git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCHv3 4/6] format-patch: move get_patch_filename() into log-tree

From
Stephen Boyd <bebarino@gmail.com>
Date
Mar 23, 2009, 02:14 UTC
Message-ID
<e8e0dcc738decb5f70dbc8e835263d7dc2834407.1237773604.git.bebarino@gmail.com>
In-Reply-To
<00c4e51c2ff7786be6aedb4a451b8d1ff269d7b3.1237773604.git.bebarino@gmail.com>
Signed-off-by: Stephen Boyd <bebarino@gmail.com>
---
 builtin-log.c |   25 -------------------------
 log-tree.c    |   23 +++++++++++++++++++++++
 log-tree.h    |    4 ++++
 3 files changed, 27 insertions(+), 25 deletions(-)
diff --git a/builtin-log.c b/builtin-log.c
index 392b16a..a8d6037 100644
--- a/builtin-log.c
+++ b/builtin-log.c
@@ -417,7 +417,6 @@ int cmd_log(int argc, const char **argv, const char *prefix)
 }
 
 /* format-patch */
-#define FORMAT_PATCH_NAME_MAX 64
 
 static const char *fmt_patch_suffix = ".patch";
 static int numbered = 0;
@@ -512,30 +511,6 @@ static int git_format_config(const char *var, const char *value, void *cb)
 	return git_log_config(var, value, cb);
 }
 
-
-static void get_patch_filename(struct commit *commit, int nr,
-			       const char *suffix, struct strbuf *buf)
-{
-	int suffix_len = strlen(suffix) + 1;
-	int start_len = buf->len;
-
-	strbuf_addf(buf, commit ? "%04d-" : "%d", nr);
-	if (commit)
-	{
-		format_commit_message(commit, "%f", buf, DATE_NORMAL);
-		/*
-		 * Replace characters at the end with the suffix if the the
-		 * filename is too long
-		 */
-		if (buf->len + suffix_len > FORMAT_PATCH_NAME_MAX + start_len)
-			strbuf_splice(buf,
-				start_len + FORMAT_PATCH_NAME_MAX - suffix_len,
-				suffix_len, suffix, suffix_len);
-		else
-			strbuf_addstr(buf, suffix);
-	}
-}
-
 static FILE *realstdout = NULL;
 static const char *output_directory = NULL;
 static int outdir_offset;
diff --git a/log-tree.c b/log-tree.c
index 9565c18..9a790ab 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -179,6 +179,29 @@ static int has_non_ascii(const char *s)
 	return 0;
 }
 
+void get_patch_filename(struct commit *commit, int nr, const char *suffix,
+			struct strbuf *buf)
+{
+	int suffix_len = strlen(suffix) + 1;
+	int start_len = buf->len;
+
+	strbuf_addf(buf, commit ? "%04d-" : "%d", nr);
+	if (commit)
+	{
+		format_commit_message(commit, "%f", buf, DATE_NORMAL);
+		/*
+		 * Replace characters at the end with the suffix if the the
+		 * filename is too long
+		 */
+		if (buf->len + suffix_len > FORMAT_PATCH_NAME_MAX + start_len)
+			strbuf_splice(buf,
+				start_len + FORMAT_PATCH_NAME_MAX - suffix_len,
+				suffix_len, suffix, suffix_len);
+		else
+			strbuf_addstr(buf, suffix);
+	}
+}
+
 void log_write_email_headers(struct rev_info *opt, const char *name,
 			     const char **subject_p,
 			     const char **extra_headers_p,
diff --git a/log-tree.h b/log-tree.h
index f2a9008..78dc5be 100644
--- a/log-tree.h
+++ b/log-tree.h
@@ -19,4 +19,8 @@ void log_write_email_headers(struct rev_info *opt, const char *name,
 			     int *need_8bit_cte_p);
 void load_ref_decorations(void);
 
+#define FORMAT_PATCH_NAME_MAX 64
+void get_patch_filename(struct commit *commit, int nr, const char *suffix,
+			struct strbuf *buf);
+
 #endif
-- 
1.6.2
Previous: Stephen BoydNext: Stephen Boyd
Message 16 of 20 in “[PATCHv2 0/3] format-patch --attach/--inline use filename instead of SHA1”
  1. Stephen BoydMar 22, 2009
  2. 1/3 format-patch: create patch filename in one functionStephen Boyd, Mar 22, 2009
  3. 2/3 format-patch: --attach/inline uses filename instead of SHA1Stephen Boyd, Mar 22, 2009
  4. 3/3 format-patch: --numbered-files and --stdout aren't mutually exclusiveStephen Boyd, Mar 22, 2009
  5. Junio C HamanoMar 22, 2009
  6. Junio C HamanoMar 22, 2009
  7. Junio C HamanoMar 22, 2009
  8. Stephen BoydMar 22, 2009
  9. Junio C HamanoMar 22, 2009
  10. Stephen BoydMar 22, 2009
  11. Junio C HamanoMar 22, 2009
  12. 0/6 format-patch --attach/--inline uses filename not SHA1Stephen Boyd, Mar 23, 2009
  13. 1/6 pretty.c: add %f format specifier to format_commit_message()Stephen Boyd, Mar 23, 2009
  14. 2/6 format-patch: construct patch filename in one functionStephen Boyd, Mar 23, 2009
  15. 3/6 format-patch: pass a commit to reopen_stdout()Stephen Boyd, Mar 23, 2009
  16. 4/6 format-patch: move get_patch_filename() into log-treeStephen Boyd, Mar 23, 2009
  17. 5/6 format-patch: --attach/inline uses filename instead of SHA1Stephen Boyd, Mar 23, 2009
  18. 6/6 format-patch: --numbered-files and --stdout aren't mutually exclusiveStephen Boyd, Mar 23, 2009
  19. René ScharfeMar 31, 2009
  20. format_sanitized_subject: Don't trim past initial length of strbufStephen Boyd, Mar 31, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.