git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stephen Boyd <bebarino@gmail.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>
Subject: [PATCH 1/4] commit: -F overrides -t
Date: Sat, 23 May 2009 11:53:10 -0700	[thread overview]
Message-ID: <1243104793-3254-2-git-send-email-bebarino@gmail.com> (raw)
In-Reply-To: <1243104793-3254-1-git-send-email-bebarino@gmail.com>

Commit dbd0f5c7 (Files given on the command line are relative to $cwd,
2008-08-06) introduced parse_options_fix_filename() as a quick fix for
filename arguments used in the parse options API.

git-commit was still broken. This means

    git commit -F log -t temp

in a subdirectory would make git think the log message should be taken
from temp instead of log.

This is because parse_options_fix_filename() calls prefix_filename()
which uses a single static char buffer to do its work. Making two calls
with two char pointers causes the pointers to alias. To prevent
aliasing, we duplicate the string returned by
parse_options_fix_filename().

Signed-off-by: Stephen Boyd <bebarino@gmail.com>
---
 builtin-commit.c  |    4 ++++
 t/t7500-commit.sh |   10 ++++++++++
 2 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/builtin-commit.c b/builtin-commit.c
index 81371b1..baaa75c 100644
--- a/builtin-commit.c
+++ b/builtin-commit.c
@@ -699,7 +699,11 @@ static int parse_and_validate_options(int argc, const char *argv[],
 
 	argc = parse_options(argc, argv, builtin_commit_options, usage, 0);
 	logfile = parse_options_fix_filename(prefix, logfile);
+	if (logfile)
+		logfile = xstrdup(logfile);
 	template_file = parse_options_fix_filename(prefix, template_file);
+	if (template_file)
+		template_file = xstrdup(template_file);
 
 	if (force_author && !strchr(force_author, '>'))
 		force_author = find_author_by_nickname(force_author);
diff --git a/t/t7500-commit.sh b/t/t7500-commit.sh
index 5998baf..8eec0fa 100755
--- a/t/t7500-commit.sh
+++ b/t/t7500-commit.sh
@@ -183,4 +183,14 @@ test_expect_success 'commit message from stdin' '
 	commit_msg_is "Log with foo word"
 '
 
+test_expect_success 'commit -F overrides -t' '
+	(
+		cd subdir &&
+		echo "-F log" > f.log &&
+		echo "-t template" > t.template &&
+		git commit --allow-empty -F f.log -t t.template
+	) &&
+	commit_msg_is "-F log"
+'
+
 test_done
-- 
1.6.3.1.145.gb74d77

  reply	other threads:[~2009-05-23 18:53 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-23 18:53 [PATCH 0/4] Add OPT_FILENAME to parse-opts Stephen Boyd
2009-05-23 18:53 ` Stephen Boyd [this message]
2009-05-23 18:53   ` [PATCH 2/4] apply, fmt-merge-msg: use relative filenames Stephen Boyd
2009-05-23 18:53     ` [PATCH 3/4] parse-opts: prepare for OPT_FILENAME Stephen Boyd
2009-05-23 18:53       ` [PATCH 4/4] parse-opts: add OPT_FILENAME and transition builtins Stephen Boyd

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=1243104793-3254-2-git-send-email-bebarino@gmail.com \
    --to=bebarino@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /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).