From: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
To: git@vger.kernel.org
Cc: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
Subject: [PATCH master] expand "<branch>" in format.subjectprefix
Date: Wed, 13 Jan 2010 18:16:28 +0100 [thread overview]
Message-ID: <1263402988-925-1-git-send-email-rep.dot.nop@gmail.com> (raw)
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
next reply other threads:[~2010-01-13 17:11 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-13 17:16 Bernhard Reutner-Fischer [this message]
2010-01-13 20:29 ` [PATCH master] expand "<branch>" in format.subjectprefix Jeff King
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1263402988-925-1-git-send-email-rep.dot.nop@gmail.com \
--to=rep.dot.nop@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).