* [PATCH master] expand "<branch>" in format.subjectprefix
@ 2010-01-13 17:16 Bernhard Reutner-Fischer
2010-01-13 20:29 ` Jeff King
0 siblings, 1 reply; 2+ messages in thread
From: Bernhard Reutner-Fischer @ 2010-01-13 17:16 UTC (permalink / raw)
To: git; +Cc: Bernhard Reutner-Fischer
Replace "<branch>" with the current branch name for
[format]
subjectprefix = PATCH <branch>
A subject-prefix given on the command-line overrides the one given in
the config.
Previously this didn't work for me:
$ git config --replace-all format.subjectprefix 'PATCH <branch>'
# edit something, commit it
$ git format-patch -o ~/foo/ HEAD^..HEAD
and that patch still has "<branch>" in the subject, even when
send-email'ed.
A manual
$ git-format-patch -o ~/foo/ HEAD^..HEAD --subject-prefix="PATCH something"
works, but is not convenient since i usually want to denote which branch
the patch is against.
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
---
builtin-log.c | 43 ++++++++++++++++++++++++++++++++++++++++---
log-tree.c | 6 +++---
revision.h | 2 +-
3 files changed, 44 insertions(+), 7 deletions(-)
diff --git a/builtin-log.c b/builtin-log.c
index 41b6df4..d7624bf 100644
--- a/builtin-log.c
+++ b/builtin-log.c
@@ -31,6 +31,43 @@ static const char * const builtin_log_usage =
"git log [<options>] [<since>..<until>] [[--] <path>...]\n"
" or: git show [options] <object>...";
+static const char* subst_subject_prefix(void)
+{
+ char *ch;
+
+ /* now expand <branch> */
+ if ((ch = strstr(fmt_patch_subject_prefix, "<branch>")) != NULL)
+ {
+ /* get_or_ask_branch_name(): */
+ struct branch *current_branch;
+ size_t len;
+ int a, b = ch - fmt_patch_subject_prefix;
+ char *branch_name, *new_subject;
+
+ current_branch = branch_get(NULL);
+ if (!current_branch || !current_branch->merge
+ || !current_branch->merge[0]
+ || !current_branch->merge[0]->dst) {
+ branch_name = "(no branch)";
+ } else {
+ branch_name = current_branch->merge[0]->dst;
+ ch = strrchr(branch_name, '/');
+ if (ch)
+ branch_name = ++ch;
+ }
+ len = strlen(branch_name);
+ a = strlen(fmt_patch_subject_prefix) - b - strlen("<branch>");
+ new_subject = xcalloc(1, 1 + b + len + a);
+ memcpy(new_subject, fmt_patch_subject_prefix, b);
+ memcpy(new_subject + b, branch_name, len);
+ memcpy(new_subject + b + len,
+ fmt_patch_subject_prefix + b + strlen("<branch>"),
+ a);
+ *&fmt_patch_subject_prefix = new_subject;
+ }
+ return fmt_patch_subject_prefix;
+}
+
static void cmd_log_init(int argc, const char **argv, const char *prefix,
struct rev_info *rev)
{
@@ -44,7 +81,7 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,
rev->verbose_header = 1;
DIFF_OPT_SET(&rev->diffopt, RECURSIVE);
rev->show_root_diff = default_show_root;
- rev->subject_prefix = fmt_patch_subject_prefix;
+ rev->subject_prefix = &subst_subject_prefix;
DIFF_OPT_SET(&rev->diffopt, ALLOW_TEXTCONV);
if (default_date_mode)
@@ -795,7 +832,7 @@ static int subject_prefix_callback(const struct option *opt, const char *arg,
int unset)
{
subject_prefix = 1;
- ((struct rev_info *)opt->value)->subject_prefix = arg;
+ *&fmt_patch_subject_prefix = arg;
return 0;
}
@@ -962,7 +999,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
rev.ignore_merges = 1;
DIFF_OPT_SET(&rev.diffopt, RECURSIVE);
- rev.subject_prefix = fmt_patch_subject_prefix;
+ rev.subject_prefix = &subst_subject_prefix;
if (default_attach) {
rev.mime_boundary = default_attach;
diff --git a/log-tree.c b/log-tree.c
index 0fdf159..e29f009 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -203,15 +203,15 @@ void log_write_email_headers(struct rev_info *opt, struct commit *commit,
static char buffer[64];
snprintf(buffer, sizeof(buffer),
"Subject: [%s %0*d/%d] ",
- opt->subject_prefix,
+ opt->subject_prefix(),
digits_in_number(opt->total),
opt->nr, opt->total);
subject = buffer;
- } else if (opt->total == 0 && opt->subject_prefix && *opt->subject_prefix) {
+ } else if (opt->total == 0 && opt->subject_prefix()) {
static char buffer[256];
snprintf(buffer, sizeof(buffer),
"Subject: [%s] ",
- opt->subject_prefix);
+ opt->subject_prefix());
subject = buffer;
} else {
subject = "Subject: ";
diff --git a/revision.h b/revision.h
index d368003..ca45c57 100644
--- a/revision.h
+++ b/revision.h
@@ -100,7 +100,7 @@ struct rev_info {
const char *add_signoff;
const char *extra_headers;
const char *log_reencode;
- const char *subject_prefix;
+ const char *(*subject_prefix)(void);
int no_inline;
int show_log_size;
--
1.6.6.103.gbcea0.dirty
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH master] expand "<branch>" in format.subjectprefix
2010-01-13 17:16 [PATCH master] expand "<branch>" in format.subjectprefix Bernhard Reutner-Fischer
@ 2010-01-13 20:29 ` Jeff King
0 siblings, 0 replies; 2+ messages in thread
From: Jeff King @ 2010-01-13 20:29 UTC (permalink / raw)
To: Bernhard Reutner-Fischer; +Cc: git
On Wed, Jan 13, 2010 at 06:16:28PM +0100, Bernhard Reutner-Fischer wrote:
> Replace "<branch>" with the current branch name for
> [format]
> subjectprefix = PATCH <branch>
>
> A subject-prefix given on the command-line overrides the one given in
> the config.
I don't have a big opinion on whether this feature is useful (it
wouldn't be to me, but I can see workflows where it could be).
I'm not sure that "current branch" makes sense, though. format-patch is
about showing commits, and the current branch is not a property of that
commit. It is about where you happen to be currently. So doing:
git checkout X
git format-patch Y..Z --subject-prefix "PATCH <branch>"
shows "X" which is not really useful information. Something like git
log's "--source" would be more useful; it shows the command-line ref
that was used to reach a given commit.
Also, please don't introduce a new substitution syntax. We already have
code to do %-expansion. In fact, if you are going to do something like
this, maybe it would be best as two patches:
1. Support '%B' as a user-format expansion for the --source branch.
2. Support user-format expansions in the subject prefix.
But I don't know if people would find any of the other substitutions
useful in the subject line.
-Peff
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2010-01-13 20:29 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-01-13 17:16 [PATCH master] expand "<branch>" in format.subjectprefix Bernhard Reutner-Fischer
2010-01-13 20:29 ` Jeff King
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).