All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] format-patch: add --prefix to prepend a prefix to output file names
@ 2009-06-09 11:33 Nguyễn Thái Ngọc Duy
  2009-06-09 12:37 ` Andreas Ericsson
  2009-06-09 13:30 ` [PATCH] format-patch: add --prefix " Johannes Sixt
  0 siblings, 2 replies; 15+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2009-06-09 11:33 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

I use git to manages patches in my Gentoo development. In Gentoo,
all ebuilds (another form of RPM spec) corresponding to different
versions of the same package are grouped into one directory. So patches
for each versions usually have a prefix to separate them from the ones
for other versions. With --prefix it comes handy to produce such patches,
for example:

git format-patch --prefix dbus-1.2.3- HEAD~5

will generate patches for dbus-1.2.3 for me, all starting with "dbus-1.2.3-".

This might be handy for RPM developers as well.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 This reminds me of another handy patch: git init --import. Any chance that patch
 could get in too?

 Documentation/git-format-patch.txt                 |    6 ++-
 builtin-log.c                                      |    9 ++-
 log-tree.c                                         |   10 ++-
 log-tree.h                                         |    4 +-
 revision.h                                         |    1 +
 t/t4013-diff-various.sh                            |    1 +
 ...h_--attach_--stdout_--prefix=foo-_initial..side |   61 ++++++++++++++++++++
 7 files changed, 83 insertions(+), 9 deletions(-)
 create mode 100644 t/t4013/diff.format-patch_--attach_--stdout_--prefix=foo-_initial..side

diff --git a/Documentation/git-format-patch.txt b/Documentation/git-format-patch.txt
index 6f1fc80..7423d67 100644
--- a/Documentation/git-format-patch.txt
+++ b/Documentation/git-format-patch.txt
@@ -15,7 +15,8 @@ SYNOPSIS
 		   [-s | --signoff]
 		   [-n | --numbered | -N | --no-numbered]
 		   [--start-number <n>] [--numbered-files]
-		   [--in-reply-to=Message-Id] [--suffix=.<sfx>]
+		   [--in-reply-to=Message-Id]
+		   [--prefix=<pfx>] [--suffix=.<sfx>]
 		   [--ignore-if-in-upstream]
 		   [--subject-prefix=Subject-Prefix]
 		   [--cc=<email>]
@@ -168,6 +169,9 @@ if that is not set.
 	containing the shortlog and the overall diffstat.  You can
 	fill in a description in the file before sending it out.
 
+--prefix=.<pfx>::
+	Prepend specified prefix in front of generated filenames.
+
 --suffix=.<sfx>::
 	Instead of using `.patch` as the suffix for generated
 	filenames, use specified suffix.  A common alternative is
diff --git a/builtin-log.c b/builtin-log.c
index 0d34050..dafa628 100644
--- a/builtin-log.c
+++ b/builtin-log.c
@@ -419,6 +419,7 @@ int cmd_log(int argc, const char **argv, const char *prefix)
 
 /* format-patch */
 
+static const char *fmt_patch_prefix = "";
 static const char *fmt_patch_suffix = ".patch";
 static int numbered = 0;
 static int auto_number = 1;
@@ -524,18 +525,19 @@ static int outdir_offset;
 static int reopen_stdout(struct commit *commit, struct rev_info *rev)
 {
 	struct strbuf filename = STRBUF_INIT;
+	int prefix_len = strlen(fmt_patch_prefix);
 	int suffix_len = strlen(fmt_patch_suffix) + 1;
 
 	if (output_directory) {
 		strbuf_addstr(&filename, output_directory);
 		if (filename.len >=
-		    PATH_MAX - FORMAT_PATCH_NAME_MAX - suffix_len)
+		    PATH_MAX - FORMAT_PATCH_NAME_MAX - prefix_len - suffix_len)
 			return error("name of output directory is too long");
 		if (filename.buf[filename.len - 1] != '/')
 			strbuf_addch(&filename, '/');
 	}
 
-	get_patch_filename(commit, rev->nr, fmt_patch_suffix, &filename);
+	get_patch_filename(commit, rev->nr, fmt_patch_prefix, fmt_patch_suffix, &filename);
 
 	if (!DIFF_OPT_TST(&rev->diffopt, QUIET))
 		fprintf(realstdout, "%s\n", filename.buf + outdir_offset);
@@ -877,6 +879,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 			    "generate a cover letter"),
 		OPT_BOOLEAN(0, "numbered-files", &numbered_files,
 			    "use simple number sequence for output file names"),
+		OPT_STRING(0, "prefix", &fmt_patch_prefix, "pfx",
+			    "prepend <pfx> to output file names"),
 		OPT_STRING(0, "suffix", &fmt_patch_suffix, "sfx",
 			    "use <sfx> instead of '.patch'"),
 		OPT_INTEGER(0, "start-number", &start_number,
@@ -1093,6 +1097,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 		string_list_append(msgid, rev.ref_message_ids);
 	}
 	rev.numbered_files = numbered_files;
+	rev.patch_prefix = fmt_patch_prefix;
 	rev.patch_suffix = fmt_patch_suffix;
 	if (cover_letter) {
 		if (thread)
diff --git a/log-tree.c b/log-tree.c
index 59d63eb..139c8b5 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -180,12 +180,13 @@ 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)
+void get_patch_filename(struct commit *commit, int nr, const char *prefix,
+			const char *suffix, struct strbuf *buf)
 {
 	int suffix_len = strlen(suffix) + 1;
-	int start_len = buf->len;
+	int start_len = buf->len + strlen(prefix);
 
+	strbuf_addstr(buf, prefix);
 	strbuf_addf(buf, commit ? "%04d-" : "%d", nr);
 	if (commit) {
 		int max_len = start_len + FORMAT_PATCH_NAME_MAX - suffix_len;
@@ -263,7 +264,8 @@ void log_write_email_headers(struct rev_info *opt, struct commit *commit,
 		extra_headers = subject_buffer;
 
 		get_patch_filename(opt->numbered_files ? NULL : commit, opt->nr,
-				    opt->patch_suffix, &filename);
+				    opt->patch_prefix, opt->patch_suffix,
+				    &filename);
 		snprintf(buffer, sizeof(buffer) - 1,
 			 "\n--%s%s\n"
 			 "Content-Type: text/x-patch;"
diff --git a/log-tree.h b/log-tree.h
index 20b5caf..566c85d 100644
--- a/log-tree.h
+++ b/log-tree.h
@@ -20,7 +20,7 @@ void log_write_email_headers(struct rev_info *opt, struct commit *commit,
 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);
+void get_patch_filename(struct commit *commit, int nr, const char *prefix,
+			const char *suffix, struct strbuf *buf);
 
 #endif
diff --git a/revision.h b/revision.h
index 227164c..b35c038 100644
--- a/revision.h
+++ b/revision.h
@@ -85,6 +85,7 @@ struct rev_info {
 	struct log_info *loginfo;
 	int		nr, total;
 	const char	*mime_boundary;
+	const char	*patch_prefix;
 	const char	*patch_suffix;
 	int		numbered_files;
 	char		*message_id;
diff --git a/t/t4013-diff-various.sh b/t/t4013-diff-various.sh
index 8b33321..771b849 100755
--- a/t/t4013-diff-various.sh
+++ b/t/t4013-diff-various.sh
@@ -246,6 +246,7 @@ format-patch --stdout initial..master
 format-patch --stdout --no-numbered initial..master
 format-patch --stdout --numbered initial..master
 format-patch --attach --stdout initial..side
+format-patch --attach --stdout --prefix=foo- initial..side
 format-patch --attach --stdout --suffix=.diff initial..side
 format-patch --attach --stdout initial..master^
 format-patch --attach --stdout initial..master
diff --git a/t/t4013/diff.format-patch_--attach_--stdout_--prefix=foo-_initial..side b/t/t4013/diff.format-patch_--attach_--stdout_--prefix=foo-_initial..side
new file mode 100644
index 0000000..a5a78d8
--- /dev/null
+++ b/t/t4013/diff.format-patch_--attach_--stdout_--prefix=foo-_initial..side
@@ -0,0 +1,61 @@
+$ git format-patch --attach --stdout --prefix=foo- initial..side
+From c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a Mon Sep 17 00:00:00 2001
+From: A U Thor <author@example.com>
+Date: Mon, 26 Jun 2006 00:03:00 +0000
+Subject: [PATCH] Side
+MIME-Version: 1.0
+Content-Type: multipart/mixed; boundary="------------g-i-t--v-e-r-s-i-o-n"
+
+This is a multi-part message in MIME format.
+--------------g-i-t--v-e-r-s-i-o-n
+Content-Type: text/plain; charset=UTF-8; format=fixed
+Content-Transfer-Encoding: 8bit
+
+---
+ dir/sub |    2 ++
+ file0   |    3 +++
+ file3   |    4 ++++
+ 3 files changed, 9 insertions(+), 0 deletions(-)
+ create mode 100644 file3
+
+
+--------------g-i-t--v-e-r-s-i-o-n
+Content-Type: text/x-patch; name="foo-0001-Side.patch"
+Content-Transfer-Encoding: 8bit
+Content-Disposition: attachment; filename="foo-0001-Side.patch"
+
+diff --git a/dir/sub b/dir/sub
+index 35d242b..7289e35 100644
+--- a/dir/sub
++++ b/dir/sub
+@@ -1,2 +1,4 @@
+ A
+ B
++1
++2
+diff --git a/file0 b/file0
+index 01e79c3..f4615da 100644
+--- a/file0
++++ b/file0
+@@ -1,3 +1,6 @@
+ 1
+ 2
+ 3
++A
++B
++C
+diff --git a/file3 b/file3
+new file mode 100644
+index 0000000..7289e35
+--- /dev/null
++++ b/file3
+@@ -0,0 +1,4 @@
++A
++B
++1
++2
+
+--------------g-i-t--v-e-r-s-i-o-n--
+
+
+$
-- 
1.6.3.2.318.g2fd57

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [PATCH] format-patch: add --prefix to prepend a prefix to output file names
  2009-06-09 11:33 [PATCH] format-patch: add --prefix to prepend a prefix to output file names Nguyễn Thái Ngọc Duy
@ 2009-06-09 12:37 ` Andreas Ericsson
  2009-06-09 23:14   ` Nguyen Thai Ngoc Duy
  2009-06-10 10:28   ` [PATCH] format-patch: add --filename-prefix " Nguyễn Thái Ngọc Duy
  2009-06-09 13:30 ` [PATCH] format-patch: add --prefix " Johannes Sixt
  1 sibling, 2 replies; 15+ messages in thread
From: Andreas Ericsson @ 2009-06-09 12:37 UTC (permalink / raw)
  To: Nguyễn Thái Ngọc Duy; +Cc: git

Nguyễn Thái Ngọc Duy wrote:
> I use git to manages patches in my Gentoo development. In Gentoo,
> all ebuilds (another form of RPM spec) corresponding to different
> versions of the same package are grouped into one directory. So patches
> for each versions usually have a prefix to separate them from the ones
> for other versions. With --prefix it comes handy to produce such patches,
> for example:
> 
> git format-patch --prefix dbus-1.2.3- HEAD~5
> 
> will generate patches for dbus-1.2.3 for me, all starting with "dbus-1.2.3-".
> 
> This might be handy for RPM developers as well.
> 

I'm thinking this could be confused with '--subject-prefix' which was
given the long option to *not* confuse it with cover-letters and filename
prefixes. Any chance you could make it --filename-prefix instead? Since
it already lacks a short option, the extra typing will probably be worth
it to avoid unnecessary confusion.

-- 
Andreas Ericsson                   andreas.ericsson@op5.se
OP5 AB                             www.op5.se
Tel: +46 8-230225                  Fax: +46 8-230231

Considering the successes of the wars on alcohol, poverty, drugs and
terror, I think we should give some serious thought to declaring war
on peace.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] format-patch: add --prefix to prepend a prefix to output file names
  2009-06-09 11:33 [PATCH] format-patch: add --prefix to prepend a prefix to output file names Nguyễn Thái Ngọc Duy
  2009-06-09 12:37 ` Andreas Ericsson
@ 2009-06-09 13:30 ` Johannes Sixt
  2009-06-09 23:18   ` Nguyen Thai Ngoc Duy
  1 sibling, 1 reply; 15+ messages in thread
From: Johannes Sixt @ 2009-06-09 13:30 UTC (permalink / raw)
  To: Nguyễn Thái Ngọc Duy; +Cc: git

Nguyễn Thái Ngọc Duy schrieb:
> I use git to manages patches in my Gentoo development. In Gentoo,
> all ebuilds (another form of RPM spec) corresponding to different
> versions of the same package are grouped into one directory. So patches
> for each versions usually have a prefix to separate them from the ones
> for other versions. With --prefix it comes handy to produce such patches,
> for example:
> 
> git format-patch --prefix dbus-1.2.3- HEAD~5
> 
> will generate patches for dbus-1.2.3 for me, all starting with "dbus-1.2.3-".

Can't you use --output-directory/-o? It is not the same, but almost.

-- Hannes

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] format-patch: add --prefix to prepend a prefix to output  file names
  2009-06-09 12:37 ` Andreas Ericsson
@ 2009-06-09 23:14   ` Nguyen Thai Ngoc Duy
  2009-06-10 10:28   ` [PATCH] format-patch: add --filename-prefix " Nguyễn Thái Ngọc Duy
  1 sibling, 0 replies; 15+ messages in thread
From: Nguyen Thai Ngoc Duy @ 2009-06-09 23:14 UTC (permalink / raw)
  To: Andreas Ericsson; +Cc: git

2009/6/9 Andreas Ericsson <ae@op5.se>:
> Nguyễn Thái Ngọc Duy wrote:
>>
>> I use git to manages patches in my Gentoo development. In Gentoo,
>> all ebuilds (another form of RPM spec) corresponding to different
>> versions of the same package are grouped into one directory. So patches
>> for each versions usually have a prefix to separate them from the ones
>> for other versions. With --prefix it comes handy to produce such patches,
>> for example:
>>
>> git format-patch --prefix dbus-1.2.3- HEAD~5
>>
>> will generate patches for dbus-1.2.3 for me, all starting with
>> "dbus-1.2.3-".
>>
>> This might be handy for RPM developers as well.
>>
>
> I'm thinking this could be confused with '--subject-prefix' which was
> given the long option to *not* confuse it with cover-letters and filename
> prefixes. Any chance you could make it --filename-prefix instead? Since
> it already lacks a short option, the extra typing will probably be worth
> it to avoid unnecessary confusion.

I made it --prefix because I see --suffix for file names already. Yes
--filename-prefix may be less confusing than plain --prefix.
-- 
Duy

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] format-patch: add --prefix to prepend a prefix to output  file names
  2009-06-09 13:30 ` [PATCH] format-patch: add --prefix " Johannes Sixt
@ 2009-06-09 23:18   ` Nguyen Thai Ngoc Duy
  0 siblings, 0 replies; 15+ messages in thread
From: Nguyen Thai Ngoc Duy @ 2009-06-09 23:18 UTC (permalink / raw)
  To: Johannes Sixt; +Cc: git

2009/6/9 Johannes Sixt <j.sixt@viscovery.net>:
> Nguyễn Thái Ngọc Duy schrieb:
>> I use git to manages patches in my Gentoo development. In Gentoo,
>> all ebuilds (another form of RPM spec) corresponding to different
>> versions of the same package are grouped into one directory. So patches
>> for each versions usually have a prefix to separate them from the ones
>> for other versions. With --prefix it comes handy to produce such patches,
>> for example:
>>
>> git format-patch --prefix dbus-1.2.3- HEAD~5
>>
>> will generate patches for dbus-1.2.3 for me, all starting with "dbus-1.2.3-".
>
> Can't you use --output-directory/-o? It is not the same, but almost.

-o seems to put slash at the end (in reopen_stdout()) but I don't want
to create another directory.
-- 
Duy

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH] format-patch: add --filename-prefix to prepend a prefix to output file names
  2009-06-09 12:37 ` Andreas Ericsson
  2009-06-09 23:14   ` Nguyen Thai Ngoc Duy
@ 2009-06-10 10:28   ` Nguyễn Thái Ngọc Duy
  2009-06-10 10:51     ` Jakub Narebski
  2009-06-10 15:58     ` Junio C Hamano
  1 sibling, 2 replies; 15+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2009-06-10 10:28 UTC (permalink / raw)
  To: Andreas Ericsson, git; +Cc: Nguyễn Thái Ngọc Duy

I use git to manage patches in my Gentoo development. In Gentoo, all
ebuilds (another form of RPM spec) corresponding to different versions
of the same package are grouped into one directory. So patches for
each version usually have a prefix to separate them from ones for
other versions. With --filename-prefix it comes handy to produce such
patches, for example:

git format-patch --filename-prefix dbus-1.2.3- HEAD~5

will generate patches for dbus-1.2.3 for me, all starting with "dbus-1.2.3-".

This might be handy for RPM developers as well.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 Renamed --prefix to --filename-prefix

 Documentation/git-format-patch.txt                 |    6 ++-
 builtin-log.c                                      |    9 ++-
 log-tree.c                                         |   10 ++-
 log-tree.h                                         |    4 +-
 revision.h                                         |    1 +
 t/t4013-diff-various.sh                            |    1 +
 ...h_--stdout_--filename-prefix=foo-_initial..side |   61 ++++++++++++++++++++
 7 files changed, 83 insertions(+), 9 deletions(-)
 create mode 100644 t/t4013/diff.format-patch_--attach_--stdout_--filename-prefix=foo-_initial..side

diff --git a/Documentation/git-format-patch.txt b/Documentation/git-format-patch.txt
index 6f1fc80..30815bc 100644
--- a/Documentation/git-format-patch.txt
+++ b/Documentation/git-format-patch.txt
@@ -15,7 +15,8 @@ SYNOPSIS
 		   [-s | --signoff]
 		   [-n | --numbered | -N | --no-numbered]
 		   [--start-number <n>] [--numbered-files]
-		   [--in-reply-to=Message-Id] [--suffix=.<sfx>]
+		   [--in-reply-to=Message-Id]
+		   [--filename-prefix=<pfx>] [--suffix=.<sfx>]
 		   [--ignore-if-in-upstream]
 		   [--subject-prefix=Subject-Prefix]
 		   [--cc=<email>]
@@ -168,6 +169,9 @@ if that is not set.
 	containing the shortlog and the overall diffstat.  You can
 	fill in a description in the file before sending it out.
 
+--filename-prefix=.<pfx>::
+	Prepend specified prefix in front of generated filenames.
+
 --suffix=.<sfx>::
 	Instead of using `.patch` as the suffix for generated
 	filenames, use specified suffix.  A common alternative is
diff --git a/builtin-log.c b/builtin-log.c
index 0d34050..d458753 100644
--- a/builtin-log.c
+++ b/builtin-log.c
@@ -419,6 +419,7 @@ int cmd_log(int argc, const char **argv, const char *prefix)
 
 /* format-patch */
 
+static const char *fmt_patch_prefix = "";
 static const char *fmt_patch_suffix = ".patch";
 static int numbered = 0;
 static int auto_number = 1;
@@ -524,18 +525,19 @@ static int outdir_offset;
 static int reopen_stdout(struct commit *commit, struct rev_info *rev)
 {
 	struct strbuf filename = STRBUF_INIT;
+	int prefix_len = strlen(fmt_patch_prefix);
 	int suffix_len = strlen(fmt_patch_suffix) + 1;
 
 	if (output_directory) {
 		strbuf_addstr(&filename, output_directory);
 		if (filename.len >=
-		    PATH_MAX - FORMAT_PATCH_NAME_MAX - suffix_len)
+		    PATH_MAX - FORMAT_PATCH_NAME_MAX - prefix_len - suffix_len)
 			return error("name of output directory is too long");
 		if (filename.buf[filename.len - 1] != '/')
 			strbuf_addch(&filename, '/');
 	}
 
-	get_patch_filename(commit, rev->nr, fmt_patch_suffix, &filename);
+	get_patch_filename(commit, rev->nr, fmt_patch_prefix, fmt_patch_suffix, &filename);
 
 	if (!DIFF_OPT_TST(&rev->diffopt, QUIET))
 		fprintf(realstdout, "%s\n", filename.buf + outdir_offset);
@@ -877,6 +879,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 			    "generate a cover letter"),
 		OPT_BOOLEAN(0, "numbered-files", &numbered_files,
 			    "use simple number sequence for output file names"),
+		OPT_STRING(0, "filename-prefix", &fmt_patch_prefix, "pfx",
+			    "prepend <pfx> to output file names"),
 		OPT_STRING(0, "suffix", &fmt_patch_suffix, "sfx",
 			    "use <sfx> instead of '.patch'"),
 		OPT_INTEGER(0, "start-number", &start_number,
@@ -1093,6 +1097,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 		string_list_append(msgid, rev.ref_message_ids);
 	}
 	rev.numbered_files = numbered_files;
+	rev.patch_prefix = fmt_patch_prefix;
 	rev.patch_suffix = fmt_patch_suffix;
 	if (cover_letter) {
 		if (thread)
diff --git a/log-tree.c b/log-tree.c
index 59d63eb..139c8b5 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -180,12 +180,13 @@ 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)
+void get_patch_filename(struct commit *commit, int nr, const char *prefix,
+			const char *suffix, struct strbuf *buf)
 {
 	int suffix_len = strlen(suffix) + 1;
-	int start_len = buf->len;
+	int start_len = buf->len + strlen(prefix);
 
+	strbuf_addstr(buf, prefix);
 	strbuf_addf(buf, commit ? "%04d-" : "%d", nr);
 	if (commit) {
 		int max_len = start_len + FORMAT_PATCH_NAME_MAX - suffix_len;
@@ -263,7 +264,8 @@ void log_write_email_headers(struct rev_info *opt, struct commit *commit,
 		extra_headers = subject_buffer;
 
 		get_patch_filename(opt->numbered_files ? NULL : commit, opt->nr,
-				    opt->patch_suffix, &filename);
+				    opt->patch_prefix, opt->patch_suffix,
+				    &filename);
 		snprintf(buffer, sizeof(buffer) - 1,
 			 "\n--%s%s\n"
 			 "Content-Type: text/x-patch;"
diff --git a/log-tree.h b/log-tree.h
index 20b5caf..566c85d 100644
--- a/log-tree.h
+++ b/log-tree.h
@@ -20,7 +20,7 @@ void log_write_email_headers(struct rev_info *opt, struct commit *commit,
 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);
+void get_patch_filename(struct commit *commit, int nr, const char *prefix,
+			const char *suffix, struct strbuf *buf);
 
 #endif
diff --git a/revision.h b/revision.h
index 227164c..b35c038 100644
--- a/revision.h
+++ b/revision.h
@@ -85,6 +85,7 @@ struct rev_info {
 	struct log_info *loginfo;
 	int		nr, total;
 	const char	*mime_boundary;
+	const char	*patch_prefix;
 	const char	*patch_suffix;
 	int		numbered_files;
 	char		*message_id;
diff --git a/t/t4013-diff-various.sh b/t/t4013-diff-various.sh
index 8b33321..cf16c0a 100755
--- a/t/t4013-diff-various.sh
+++ b/t/t4013-diff-various.sh
@@ -246,6 +246,7 @@ format-patch --stdout initial..master
 format-patch --stdout --no-numbered initial..master
 format-patch --stdout --numbered initial..master
 format-patch --attach --stdout initial..side
+format-patch --attach --stdout --filename-prefix=foo- initial..side
 format-patch --attach --stdout --suffix=.diff initial..side
 format-patch --attach --stdout initial..master^
 format-patch --attach --stdout initial..master
diff --git a/t/t4013/diff.format-patch_--attach_--stdout_--filename-prefix=foo-_initial..side b/t/t4013/diff.format-patch_--attach_--stdout_--filename-prefix=foo-_initial..side
new file mode 100644
index 0000000..72127eb
--- /dev/null
+++ b/t/t4013/diff.format-patch_--attach_--stdout_--filename-prefix=foo-_initial..side
@@ -0,0 +1,61 @@
+$ git format-patch --attach --stdout --filename-prefix=foo- initial..side
+From c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a Mon Sep 17 00:00:00 2001
+From: A U Thor <author@example.com>
+Date: Mon, 26 Jun 2006 00:03:00 +0000
+Subject: [PATCH] Side
+MIME-Version: 1.0
+Content-Type: multipart/mixed; boundary="------------g-i-t--v-e-r-s-i-o-n"
+
+This is a multi-part message in MIME format.
+--------------g-i-t--v-e-r-s-i-o-n
+Content-Type: text/plain; charset=UTF-8; format=fixed
+Content-Transfer-Encoding: 8bit
+
+---
+ dir/sub |    2 ++
+ file0   |    3 +++
+ file3   |    4 ++++
+ 3 files changed, 9 insertions(+), 0 deletions(-)
+ create mode 100644 file3
+
+
+--------------g-i-t--v-e-r-s-i-o-n
+Content-Type: text/x-patch; name="foo-0001-Side.patch"
+Content-Transfer-Encoding: 8bit
+Content-Disposition: attachment; filename="foo-0001-Side.patch"
+
+diff --git a/dir/sub b/dir/sub
+index 35d242b..7289e35 100644
+--- a/dir/sub
++++ b/dir/sub
+@@ -1,2 +1,4 @@
+ A
+ B
++1
++2
+diff --git a/file0 b/file0
+index 01e79c3..f4615da 100644
+--- a/file0
++++ b/file0
+@@ -1,3 +1,6 @@
+ 1
+ 2
+ 3
++A
++B
++C
+diff --git a/file3 b/file3
+new file mode 100644
+index 0000000..7289e35
+--- /dev/null
++++ b/file3
+@@ -0,0 +1,4 @@
++A
++B
++1
++2
+
+--------------g-i-t--v-e-r-s-i-o-n--
+
+
+$
-- 
1.6.3.2.318.g2fd57

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [PATCH] format-patch: add --filename-prefix to prepend a prefix to output file names
  2009-06-10 10:28   ` [PATCH] format-patch: add --filename-prefix " Nguyễn Thái Ngọc Duy
@ 2009-06-10 10:51     ` Jakub Narebski
  2009-06-10 10:56       ` Nguyen Thai Ngoc Duy
  2009-06-10 15:58     ` Junio C Hamano
  1 sibling, 1 reply; 15+ messages in thread
From: Jakub Narebski @ 2009-06-10 10:51 UTC (permalink / raw)
  To: git

Nguy?n Thái Ng?c Duy wrote:

> +--filename-prefix=.<pfx>::
> +       Prepend specified prefix in front of generated filenames.
> +
>  --suffix=.<sfx>::
>         Instead of using `.patch` as the suffix for generated
>         filenames, use specified suffix.  A common alternative is

I think it should be

   --filename-prefix=<pfx>::

(without the dot '.').
-- 
Jakub Narebski
Warsaw, Poland
ShadeHawk on #git

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] format-patch: add --filename-prefix to prepend a prefix  to output file names
  2009-06-10 10:51     ` Jakub Narebski
@ 2009-06-10 10:56       ` Nguyen Thai Ngoc Duy
  0 siblings, 0 replies; 15+ messages in thread
From: Nguyen Thai Ngoc Duy @ 2009-06-10 10:56 UTC (permalink / raw)
  To: Jakub Narebski; +Cc: git

2009/6/10 Jakub Narebski <jnareb@gmail.com>:
> Nguy?n Thái Ng?c Duy wrote:
>
>> +--filename-prefix=.<pfx>::
>> +       Prepend specified prefix in front of generated filenames.
>> +
>>  --suffix=.<sfx>::
>>         Instead of using `.patch` as the suffix for generated
>>         filenames, use specified suffix.  A common alternative is
>
> I think it should be
>
>   --filename-prefix=<pfx>::
>
> (without the dot '.').

Right. I remember I got rid of that dot in the synopis. Obviously I
missed another one.
-- 
Duy

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] format-patch: add --filename-prefix to prepend a prefix to output file names
  2009-06-10 10:28   ` [PATCH] format-patch: add --filename-prefix " Nguyễn Thái Ngọc Duy
  2009-06-10 10:51     ` Jakub Narebski
@ 2009-06-10 15:58     ` Junio C Hamano
  2009-06-14  7:10       ` Nguyễn Thái Ngọc Duy
  1 sibling, 1 reply; 15+ messages in thread
From: Junio C Hamano @ 2009-06-10 15:58 UTC (permalink / raw)
  To: Nguyễn Thái Ngọc Duy; +Cc: Andreas Ericsson, git

Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:

> I use git to manage patches in my Gentoo development. In Gentoo, all
> ebuilds (another form of RPM spec) corresponding to different versions
> of the same package are grouped into one directory. So patches for
> each version usually have a prefix to separate them from ones for
> other versions. With --filename-prefix it comes handy to produce such
> patches, for example:
>
> git format-patch --filename-prefix dbus-1.2.3- HEAD~5
>
> will generate patches for dbus-1.2.3 for me, all starting with "dbus-1.2.3-".
>
> This might be handy for RPM developers as well.

If this patch needs another round, I would prefer seeing the explanation
done in a different order.  When a busy person who is uninterested in
Gentoo starts reading the above paragraph, the patch will (incorrectly) be
dismissed with an "Ah, Gentoo specific feature?  Not interesting." after
reading the first two lines.  I.e. "Add X that does Y.  This is useful in
such and such situations because ...".

> +--filename-prefix=.<pfx>::
> +	Prepend specified prefix in front of generated filenames.

Hmm... ;-)

What happens when I feed a path with a slash in it with --filename-prefix?
We will fail in open/creat if the leading path does not exist?

I am not saying we must allow a slash in the prefix and create necessary
leading paths ourselves, nor we must check for a slash and fail in the
input validation phase, but I am wondering if we can have some clever way
to internally unify the handling of this new option with --outdir.

> diff --git a/t/t4013-diff-various.sh b/t/t4013-diff-various.sh
> index 8b33321..cf16c0a 100755
> --- a/t/t4013-diff-various.sh
> +++ b/t/t4013-diff-various.sh
> @@ -246,6 +246,7 @@ format-patch --stdout initial..master
>  format-patch --stdout --no-numbered initial..master
>  format-patch --stdout --numbered initial..master
>  format-patch --attach --stdout initial..side
> +format-patch --attach --stdout --filename-prefix=foo- initial..side

Heh, clever.  I wondered what the point of testing with --stdout was
for a patch that affects the generated filename.  The magic of --attach ;-)

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH] format-patch: add --filename-prefix to prepend a prefix to output file names
  2009-06-10 15:58     ` Junio C Hamano
@ 2009-06-14  7:10       ` Nguyễn Thái Ngọc Duy
  2009-06-14  8:25         ` Junio C Hamano
  2009-06-14  8:29         ` Stephen Boyd
  0 siblings, 2 replies; 15+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2009-06-14  7:10 UTC (permalink / raw)
  To: git, Junio C Hamano, Jakub Narebski, Andreas Ericsson
  Cc: Nguyễn Thái Ngọc Duy

In Linux packaging, patches are usually saved along with the "package
spec" (to suit distro specific needs or just to back port some
fixes). Those patches are usually prefixed with either the package
name, or package version for various reasons. With --filename-prefix
it comes handy to produce such patches, for example:

git format-patch --filename-prefix dbus-1.2.3- HEAD~5

will generate patches for dbus-1.2.3 for me, all starting with "dbus-1.2.3-".

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 On Wed, Jun 10, 2009 at 08:58:01AM -0700, Junio C Hamano wrote:
 > Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:
 > 
 > > I use git to manage patches in my Gentoo development. In Gentoo, all
 > > ebuilds (another form of RPM spec) corresponding to different versions
 > > of the same package are grouped into one directory. So patches for
 > > each version usually have a prefix to separate them from ones for
 > > other versions. With --filename-prefix it comes handy to produce such
 > > patches, for example:
 > >
 > > git format-patch --filename-prefix dbus-1.2.3- HEAD~5
 > >
 > > will generate patches for dbus-1.2.3 for me, all starting with "dbus-1.2.3-".
 > >
 > > This might be handy for RPM developers as well.
 > 
 > If this patch needs another round, I would prefer seeing the explanation
 > done in a different order.  When a busy person who is uninterested in
 > Gentoo starts reading the above paragraph, the patch will (incorrectly) be
 > dismissed with an "Ah, Gentoo specific feature?  Not interesting." after
 > reading the first two lines.  I.e. "Add X that does Y.  This is useful in
 > such and such situations because ...".

 Done

 > 
 > > +--filename-prefix=.<pfx>::
 > > +	Prepend specified prefix in front of generated filenames.
 > 
 > Hmm... ;-)
 > 
 > What happens when I feed a path with a slash in it with --filename-prefix?
 > We will fail in open/creat if the leading path does not exist?
 > 
 > I am not saying we must allow a slash in the prefix and create necessary
 > leading paths ourselves, nor we must check for a slash and fail in the
 > input validation phase, but I am wondering if we can have some clever way
 > to internally unify the handling of this new option with --outdir.

 Hardly, the way it is handled now (chdir()ing to --outdir, then write patches)

 Documentation/git-format-patch.txt                 |    6 ++-
 builtin-log.c                                      |    9 ++-
 log-tree.c                                         |   10 ++-
 log-tree.h                                         |    4 +-
 revision.h                                         |    1 +
 t/t4013-diff-various.sh                            |    1 +
 ...h_--stdout_--filename-prefix=foo-_initial..side |   61 ++++++++++++++++++++
 7 files changed, 83 insertions(+), 9 deletions(-)
 create mode 100644 t/t4013/diff.format-patch_--attach_--stdout_--filename-prefix=foo-_initial..side

diff --git a/Documentation/git-format-patch.txt b/Documentation/git-format-patch.txt
index 6f1fc80..052a3b8 100644
--- a/Documentation/git-format-patch.txt
+++ b/Documentation/git-format-patch.txt
@@ -15,7 +15,8 @@ SYNOPSIS
 		   [-s | --signoff]
 		   [-n | --numbered | -N | --no-numbered]
 		   [--start-number <n>] [--numbered-files]
-		   [--in-reply-to=Message-Id] [--suffix=.<sfx>]
+		   [--in-reply-to=Message-Id]
+		   [--filename-prefix=<pfx>] [--suffix=.<sfx>]
 		   [--ignore-if-in-upstream]
 		   [--subject-prefix=Subject-Prefix]
 		   [--cc=<email>]
@@ -168,6 +169,9 @@ if that is not set.
 	containing the shortlog and the overall diffstat.  You can
 	fill in a description in the file before sending it out.
 
+--filename-prefix=<pfx>::
+	Prepend specified prefix in front of generated filenames.
+
 --suffix=.<sfx>::
 	Instead of using `.patch` as the suffix for generated
 	filenames, use specified suffix.  A common alternative is
diff --git a/builtin-log.c b/builtin-log.c
index 0d34050..d458753 100644
--- a/builtin-log.c
+++ b/builtin-log.c
@@ -419,6 +419,7 @@ int cmd_log(int argc, const char **argv, const char *prefix)
 
 /* format-patch */
 
+static const char *fmt_patch_prefix = "";
 static const char *fmt_patch_suffix = ".patch";
 static int numbered = 0;
 static int auto_number = 1;
@@ -524,18 +525,19 @@ static int outdir_offset;
 static int reopen_stdout(struct commit *commit, struct rev_info *rev)
 {
 	struct strbuf filename = STRBUF_INIT;
+	int prefix_len = strlen(fmt_patch_prefix);
 	int suffix_len = strlen(fmt_patch_suffix) + 1;
 
 	if (output_directory) {
 		strbuf_addstr(&filename, output_directory);
 		if (filename.len >=
-		    PATH_MAX - FORMAT_PATCH_NAME_MAX - suffix_len)
+		    PATH_MAX - FORMAT_PATCH_NAME_MAX - prefix_len - suffix_len)
 			return error("name of output directory is too long");
 		if (filename.buf[filename.len - 1] != '/')
 			strbuf_addch(&filename, '/');
 	}
 
-	get_patch_filename(commit, rev->nr, fmt_patch_suffix, &filename);
+	get_patch_filename(commit, rev->nr, fmt_patch_prefix, fmt_patch_suffix, &filename);
 
 	if (!DIFF_OPT_TST(&rev->diffopt, QUIET))
 		fprintf(realstdout, "%s\n", filename.buf + outdir_offset);
@@ -877,6 +879,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 			    "generate a cover letter"),
 		OPT_BOOLEAN(0, "numbered-files", &numbered_files,
 			    "use simple number sequence for output file names"),
+		OPT_STRING(0, "filename-prefix", &fmt_patch_prefix, "pfx",
+			    "prepend <pfx> to output file names"),
 		OPT_STRING(0, "suffix", &fmt_patch_suffix, "sfx",
 			    "use <sfx> instead of '.patch'"),
 		OPT_INTEGER(0, "start-number", &start_number,
@@ -1093,6 +1097,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 		string_list_append(msgid, rev.ref_message_ids);
 	}
 	rev.numbered_files = numbered_files;
+	rev.patch_prefix = fmt_patch_prefix;
 	rev.patch_suffix = fmt_patch_suffix;
 	if (cover_letter) {
 		if (thread)
diff --git a/log-tree.c b/log-tree.c
index 59d63eb..139c8b5 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -180,12 +180,13 @@ 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)
+void get_patch_filename(struct commit *commit, int nr, const char *prefix,
+			const char *suffix, struct strbuf *buf)
 {
 	int suffix_len = strlen(suffix) + 1;
-	int start_len = buf->len;
+	int start_len = buf->len + strlen(prefix);
 
+	strbuf_addstr(buf, prefix);
 	strbuf_addf(buf, commit ? "%04d-" : "%d", nr);
 	if (commit) {
 		int max_len = start_len + FORMAT_PATCH_NAME_MAX - suffix_len;
@@ -263,7 +264,8 @@ void log_write_email_headers(struct rev_info *opt, struct commit *commit,
 		extra_headers = subject_buffer;
 
 		get_patch_filename(opt->numbered_files ? NULL : commit, opt->nr,
-				    opt->patch_suffix, &filename);
+				    opt->patch_prefix, opt->patch_suffix,
+				    &filename);
 		snprintf(buffer, sizeof(buffer) - 1,
 			 "\n--%s%s\n"
 			 "Content-Type: text/x-patch;"
diff --git a/log-tree.h b/log-tree.h
index 20b5caf..566c85d 100644
--- a/log-tree.h
+++ b/log-tree.h
@@ -20,7 +20,7 @@ void log_write_email_headers(struct rev_info *opt, struct commit *commit,
 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);
+void get_patch_filename(struct commit *commit, int nr, const char *prefix,
+			const char *suffix, struct strbuf *buf);
 
 #endif
diff --git a/revision.h b/revision.h
index 227164c..b35c038 100644
--- a/revision.h
+++ b/revision.h
@@ -85,6 +85,7 @@ struct rev_info {
 	struct log_info *loginfo;
 	int		nr, total;
 	const char	*mime_boundary;
+	const char	*patch_prefix;
 	const char	*patch_suffix;
 	int		numbered_files;
 	char		*message_id;
diff --git a/t/t4013-diff-various.sh b/t/t4013-diff-various.sh
index 8b33321..cf16c0a 100755
--- a/t/t4013-diff-various.sh
+++ b/t/t4013-diff-various.sh
@@ -246,6 +246,7 @@ format-patch --stdout initial..master
 format-patch --stdout --no-numbered initial..master
 format-patch --stdout --numbered initial..master
 format-patch --attach --stdout initial..side
+format-patch --attach --stdout --filename-prefix=foo- initial..side
 format-patch --attach --stdout --suffix=.diff initial..side
 format-patch --attach --stdout initial..master^
 format-patch --attach --stdout initial..master
diff --git a/t/t4013/diff.format-patch_--attach_--stdout_--filename-prefix=foo-_initial..side b/t/t4013/diff.format-patch_--attach_--stdout_--filename-prefix=foo-_initial..side
new file mode 100644
index 0000000..72127eb
--- /dev/null
+++ b/t/t4013/diff.format-patch_--attach_--stdout_--filename-prefix=foo-_initial..side
@@ -0,0 +1,61 @@
+$ git format-patch --attach --stdout --filename-prefix=foo- initial..side
+From c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a Mon Sep 17 00:00:00 2001
+From: A U Thor <author@example.com>
+Date: Mon, 26 Jun 2006 00:03:00 +0000
+Subject: [PATCH] Side
+MIME-Version: 1.0
+Content-Type: multipart/mixed; boundary="------------g-i-t--v-e-r-s-i-o-n"
+
+This is a multi-part message in MIME format.
+--------------g-i-t--v-e-r-s-i-o-n
+Content-Type: text/plain; charset=UTF-8; format=fixed
+Content-Transfer-Encoding: 8bit
+
+---
+ dir/sub |    2 ++
+ file0   |    3 +++
+ file3   |    4 ++++
+ 3 files changed, 9 insertions(+), 0 deletions(-)
+ create mode 100644 file3
+
+
+--------------g-i-t--v-e-r-s-i-o-n
+Content-Type: text/x-patch; name="foo-0001-Side.patch"
+Content-Transfer-Encoding: 8bit
+Content-Disposition: attachment; filename="foo-0001-Side.patch"
+
+diff --git a/dir/sub b/dir/sub
+index 35d242b..7289e35 100644
+--- a/dir/sub
++++ b/dir/sub
+@@ -1,2 +1,4 @@
+ A
+ B
++1
++2
+diff --git a/file0 b/file0
+index 01e79c3..f4615da 100644
+--- a/file0
++++ b/file0
+@@ -1,3 +1,6 @@
+ 1
+ 2
+ 3
++A
++B
++C
+diff --git a/file3 b/file3
+new file mode 100644
+index 0000000..7289e35
+--- /dev/null
++++ b/file3
+@@ -0,0 +1,4 @@
++A
++B
++1
++2
+
+--------------g-i-t--v-e-r-s-i-o-n--
+
+
+$
-- 
1.6.3.2.318.g2fd57

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [PATCH] format-patch: add --filename-prefix to prepend a prefix to output file names
  2009-06-14  7:10       ` Nguyễn Thái Ngọc Duy
@ 2009-06-14  8:25         ` Junio C Hamano
  2009-06-14  8:29         ` Stephen Boyd
  1 sibling, 0 replies; 15+ messages in thread
From: Junio C Hamano @ 2009-06-14  8:25 UTC (permalink / raw)
  To: Nguyễn Thái Ngọc Duy
  Cc: git, Junio C Hamano, Jakub Narebski, Andreas Ericsson

Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:

>  > I am not saying we must allow a slash in the prefix and create necessary
>  > leading paths ourselves, nor we must check for a slash and fail in the
>  > input validation phase, but I am wondering if we can have some clever way
>  > to internally unify the handling of this new option with --outdir.
>
>  Hardly, the way it is handled now (chdir()ing to --outdir, then write patches)

Ah, true enough.  Thanks.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] format-patch: add --filename-prefix to prepend a prefix to output file names
  2009-06-14  7:10       ` Nguyễn Thái Ngọc Duy
  2009-06-14  8:25         ` Junio C Hamano
@ 2009-06-14  8:29         ` Stephen Boyd
  2009-06-14  8:59           ` Junio C Hamano
  2009-06-14 23:32           ` Nguyen Thai Ngoc Duy
  1 sibling, 2 replies; 15+ messages in thread
From: Stephen Boyd @ 2009-06-14  8:29 UTC (permalink / raw)
  To: Nguyễn Thái Ngọc Duy
  Cc: git, Junio C Hamano, Jakub Narebski, Andreas Ericsson

Nguyễn Thái Ngọc Duy wrote:
> diff --git a/log-tree.c b/log-tree.c
> index 59d63eb..139c8b5 100644
> --- a/log-tree.c
> +++ b/log-tree.c
> @@ -180,12 +180,13 @@ 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)
> +void get_patch_filename(struct commit *commit, int nr, const char *prefix,
> +			const char *suffix, struct strbuf *buf)
>  {
>  	int suffix_len = strlen(suffix) + 1;
> -	int start_len = buf->len;
> +	int start_len = buf->len + strlen(prefix);
>  
> +	strbuf_addstr(buf, prefix);
>  	strbuf_addf(buf, commit ? "%04d-" : "%d", nr);
>  	if (commit) {
>  		int max_len = start_len + FORMAT_PATCH_NAME_MAX - suffix_len;
>   

Why does the prefix length not count against the filename length? I
think you want to subtract a prefix_len.

Also, this doesn't replace the numbering (0001, 0002, etc.) which I
consider to be a prefix. Does anyone else feel the same way?

This is kind of a funny thought, but I'll throw it out there. Could you
just put the desired prefix in your patch subjects, and then add an
option for no-numbered-files? So in your case, you add "dbus 1.2.3" at
the start of each subject during git-commit and then format-patch with
--no-numbered-files. This way you get git to insert the dashes you want,
other people get files with no numbers, and you don't have to deal with
slashes and directory prefixes.

I'm kind of confused about this though. The patches you're generating
for Gentoo are not being read by humans; merely being applied by portage
correct? Are you going back and removing the mail headers and commit
messages from these patches? What I'm getting at is for your case
format-patch may be overkill.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] format-patch: add --filename-prefix to prepend a prefix to output file names
  2009-06-14  8:29         ` Stephen Boyd
@ 2009-06-14  8:59           ` Junio C Hamano
  2009-06-14 19:46             ` Stephen Boyd
  2009-06-14 23:32           ` Nguyen Thai Ngoc Duy
  1 sibling, 1 reply; 15+ messages in thread
From: Junio C Hamano @ 2009-06-14  8:59 UTC (permalink / raw)
  To: Stephen Boyd
  Cc: Nguyễn Thái Ngọc Duy, git, Jakub Narebski,
	Andreas Ericsson

Stephen Boyd <bebarino@gmail.com> writes:

> Also, this doesn't replace the numbering (0001, 0002, etc.) which I
> consider to be a prefix. Does anyone else feel the same way?

Isn't the point of the exercise to come up with something like:

      frotz-0001-first-patch-in-frotz-topic.patch
      frotz-0002-second-patch-in-frotz-topic.patch
      frotz-0003-third-patch-in-frotz-topic.patch

      nitfol-0001-first-patch-in-nitfol-topic.patch
      nitfol-0002-second-patch-in-nitfol-topic.patch

with two invocations of format-patch, and when they are dropped in the
same directory, the patches from the same series clump together?

I personally do not think this is worth the additional code (you can
easily run with --outdir=frotz and then with --outdir=nitfol and obtain
frotz/000?-*.patch and nitfol/000?-*.patch to get the same clumping) but
if the convention is to use dash instead of slash, the patch will save one
step from users.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] format-patch: add --filename-prefix to prepend a prefix to output file names
  2009-06-14  8:59           ` Junio C Hamano
@ 2009-06-14 19:46             ` Stephen Boyd
  0 siblings, 0 replies; 15+ messages in thread
From: Stephen Boyd @ 2009-06-14 19:46 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Nguyễn Thái Ngọc Duy, git, Jakub Narebski,
	Andreas Ericsson

Junio C Hamano wrote:
> Isn't the point of the exercise to come up with something like:
>
>       frotz-0001-first-patch-in-frotz-topic.patch
>       frotz-0002-second-patch-in-frotz-topic.patch
>       frotz-0003-third-patch-in-frotz-topic.patch
>
>       nitfol-0001-first-patch-in-nitfol-topic.patch
>       nitfol-0002-second-patch-in-nitfol-topic.patch
>
> with two invocations of format-patch, and when they are dropped in the
> same directory, the patches from the same series clump together?

Ok. Maybe spelling out the full example in the commit message would be
clearer.

>
> I personally do not think this is worth the additional code (you can
> easily run with --outdir=frotz and then with --outdir=nitfol and obtain
> frotz/000?-*.patch and nitfol/000?-*.patch to get the same clumping) but
> if the convention is to use dash instead of slash, the patch will save one
> step from users.

I agree. How is it any harder to do 'git send-email frotz' instead of
'git send-email frotz-*.patch'? The only advantage I see is you get
attachment filenames with a prefix.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] format-patch: add --filename-prefix to prepend a prefix  to output file names
  2009-06-14  8:29         ` Stephen Boyd
  2009-06-14  8:59           ` Junio C Hamano
@ 2009-06-14 23:32           ` Nguyen Thai Ngoc Duy
  1 sibling, 0 replies; 15+ messages in thread
From: Nguyen Thai Ngoc Duy @ 2009-06-14 23:32 UTC (permalink / raw)
  To: Stephen Boyd; +Cc: git, Junio C Hamano, Jakub Narebski, Andreas Ericsson

2009/6/14 Stephen Boyd <bebarino@gmail.com>:
> Nguyễn Thái Ngọc Duy wrote:
>> diff --git a/log-tree.c b/log-tree.c
>> index 59d63eb..139c8b5 100644
>> --- a/log-tree.c
>> +++ b/log-tree.c
>> @@ -180,12 +180,13 @@ 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)
>> +void get_patch_filename(struct commit *commit, int nr, const char *prefix,
>> +                     const char *suffix, struct strbuf *buf)
>>  {
>>       int suffix_len = strlen(suffix) + 1;
>> -     int start_len = buf->len;
>> +     int start_len = buf->len + strlen(prefix);
>>
>> +     strbuf_addstr(buf, prefix);
>>       strbuf_addf(buf, commit ? "%04d-" : "%d", nr);
>>       if (commit) {
>>               int max_len = start_len + FORMAT_PATCH_NAME_MAX - suffix_len;
>>
>
> Why does the prefix length not count against the filename length? I
> think you want to subtract a prefix_len.
>
> Also, this doesn't replace the numbering (0001, 0002, etc.) which I
> consider to be a prefix. Does anyone else feel the same way?
>
> This is kind of a funny thought, but I'll throw it out there. Could you
> just put the desired prefix in your patch subjects, and then add an
> option for no-numbered-files? So in your case, you add "dbus 1.2.3" at
> the start of each subject during git-commit and then format-patch with
> --no-numbered-files. This way you get git to insert the dashes you want,
> other people get files with no numbers, and you don't have to deal with
> slashes and directory prefixes.

Well, for true flexibility, I would implement something like printf
format. But that would be overkill.

> I'm kind of confused about this though. The patches you're generating
> for Gentoo are not being read by humans; merely being applied by portage
> correct? Are you going back and removing the mail headers and commit
> messages from these patches? What I'm getting at is for your case
> format-patch may be overkill.

They are read by human, i.e. ebuild developers, and uptream developers
too when they are submitted upstream (which is great because if
upstream uses Git, you don't have to do anything else). Plain patches
are enough for portage, other information is for human ;-)
-- 
Duy

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2009-06-14 23:33 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-06-09 11:33 [PATCH] format-patch: add --prefix to prepend a prefix to output file names Nguyễn Thái Ngọc Duy
2009-06-09 12:37 ` Andreas Ericsson
2009-06-09 23:14   ` Nguyen Thai Ngoc Duy
2009-06-10 10:28   ` [PATCH] format-patch: add --filename-prefix " Nguyễn Thái Ngọc Duy
2009-06-10 10:51     ` Jakub Narebski
2009-06-10 10:56       ` Nguyen Thai Ngoc Duy
2009-06-10 15:58     ` Junio C Hamano
2009-06-14  7:10       ` Nguyễn Thái Ngọc Duy
2009-06-14  8:25         ` Junio C Hamano
2009-06-14  8:29         ` Stephen Boyd
2009-06-14  8:59           ` Junio C Hamano
2009-06-14 19:46             ` Stephen Boyd
2009-06-14 23:32           ` Nguyen Thai Ngoc Duy
2009-06-09 13:30 ` [PATCH] format-patch: add --prefix " Johannes Sixt
2009-06-09 23:18   ` Nguyen Thai Ngoc Duy

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.