mailinfo: read local configuration
authorJunio C Hamano <gitster@pobox.com>
Tue, 22 Nov 2016 21:13:16 +0000 (13:13 -0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 22 Nov 2016 21:13:16 +0000 (13:13 -0800)
Since b9605bc4f2 ("config: only read .git/config from configured
repos", 2016-09-12), we do not read from ".git/config" unless we
know we are in a repository. "git mailinfo" however didn't do the
repository discovery and instead relied on the old behaviour. This
was mostly OK because it was merely run as a helper program by other
porcelain scripts that first chdir's up to the root of the working
tree.

Teach the command to run a "gentle" version of repository discovery
so that local configuration variables like mailinfo.scissors are
honoured.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/mailinfo.c
git.c
t/t5100-mailinfo.sh
index f6df2741112144a38d048ebfd1fe201c8576a040..e3b62f2fc744d340de5e3d9efad12b5de93cd55c 100644 (file)
 static const char mailinfo_usage[] =
        "git mailinfo [-k | -b] [-m | --message-id] [-u | --encoding=<encoding> | -n] [--scissors | --no-scissors] <msg> <patch> < mail >info";
 
+static char *prefix_copy(const char *prefix, const char *filename)
+{
+       if (!prefix || is_absolute_path(filename))
+               return xstrdup(filename);
+       return xstrdup(prefix_filename(prefix, strlen(prefix), filename));
+}
+
 int cmd_mailinfo(int argc, const char **argv, const char *prefix)
 {
        const char *def_charset;
        struct mailinfo mi;
        int status;
+       char *msgfile, *patchfile;
 
-       /* NEEDSWORK: might want to do the optional .git/ directory
-        * discovery
-        */
        setup_mailinfo(&mi);
 
        def_charset = get_commit_output_encoding();
@@ -54,8 +59,14 @@ int cmd_mailinfo(int argc, const char **argv, const char *prefix)
 
        mi.input = stdin;
        mi.output = stdout;
-       status = !!mailinfo(&mi, argv[1], argv[2]);
+
+       msgfile = prefix_copy(prefix, argv[1]);
+       patchfile = prefix_copy(prefix, argv[2]);
+
+       status = !!mailinfo(&mi, msgfile, patchfile);
        clear_mailinfo(&mi);
 
+       free(msgfile);
+       free(patchfile);
        return status;
 }
diff --git a/git.c b/git.c
index efa1059fe060e413336ed4a02ac01d9381b34323..fd3abf85d21daa3382361b415e1c66a876da8ad2 100644 (file)
--- a/git.c
+++ b/git.c
@@ -445,7 +445,7 @@ static struct cmd_struct commands[] = {
        { "ls-files", cmd_ls_files, RUN_SETUP | SUPPORT_SUPER_PREFIX },
        { "ls-remote", cmd_ls_remote, RUN_SETUP_GENTLY },
        { "ls-tree", cmd_ls_tree, RUN_SETUP },
-       { "mailinfo", cmd_mailinfo },
+       { "mailinfo", cmd_mailinfo, RUN_SETUP_GENTLY },
        { "mailsplit", cmd_mailsplit },
        { "merge", cmd_merge, RUN_SETUP | NEED_WORK_TREE },
        { "merge-base", cmd_merge_base, RUN_SETUP },
index e6b995161e0fd15493bdaf4e5a5df2a3c2990798..7171f67539bfafcb17d2d2fcb2f4ba4856c1131c 100755 (executable)
@@ -158,4 +158,17 @@ test_expect_success 'mailinfo handles rfc2822 comment' '
        test_cmp "$DATA/comment.expect" comment/info
 '
 
+test_expect_success 'mailinfo with mailinfo.scissors config' '
+       test_config mailinfo.scissors true &&
+       (
+               mkdir sub &&
+               cd sub &&
+               git mailinfo ../msg0014.sc ../patch0014.sc <../0014 >../info0014.sc
+       ) &&
+       test_cmp "$DATA/msg0014--scissors" msg0014.sc &&
+       test_cmp "$DATA/patch0014--scissors" patch0014.sc &&
+       test_cmp "$DATA/info0014--scissors" info0014.sc
+'
+
+
 test_done