Skip to content

Commit 3f0ec06

Browse files
committed
mailinfo: read local configuration
Since b9605bc ("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 <[email protected]>
1 parent 1310aff commit 3f0ec06

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

builtin/mailinfo.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,20 @@
1111
static const char mailinfo_usage[] =
1212
"git mailinfo [-k | -b] [-m | --message-id] [-u | --encoding=<encoding> | -n] [--scissors | --no-scissors] <msg> <patch> < mail >info";
1313

14+
static char *prefix_copy(const char *prefix, const char *filename)
15+
{
16+
if (!prefix || is_absolute_path(filename))
17+
return xstrdup(filename);
18+
return xstrdup(prefix_filename(prefix, strlen(prefix), filename));
19+
}
20+
1421
int cmd_mailinfo(int argc, const char **argv, const char *prefix)
1522
{
1623
const char *def_charset;
1724
struct mailinfo mi;
1825
int status;
26+
char *msgfile, *patchfile;
1927

20-
/* NEEDSWORK: might want to do the optional .git/ directory
21-
* discovery
22-
*/
2328
setup_mailinfo(&mi);
2429

2530
def_charset = get_commit_output_encoding();
@@ -54,8 +59,14 @@ int cmd_mailinfo(int argc, const char **argv, const char *prefix)
5459

5560
mi.input = stdin;
5661
mi.output = stdout;
57-
status = !!mailinfo(&mi, argv[1], argv[2]);
62+
63+
msgfile = prefix_copy(prefix, argv[1]);
64+
patchfile = prefix_copy(prefix, argv[2]);
65+
66+
status = !!mailinfo(&mi, msgfile, patchfile);
5867
clear_mailinfo(&mi);
5968

69+
free(msgfile);
70+
free(patchfile);
6071
return status;
6172
}

git.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ static struct cmd_struct commands[] = {
445445
{ "ls-files", cmd_ls_files, RUN_SETUP | SUPPORT_SUPER_PREFIX },
446446
{ "ls-remote", cmd_ls_remote, RUN_SETUP_GENTLY },
447447
{ "ls-tree", cmd_ls_tree, RUN_SETUP },
448-
{ "mailinfo", cmd_mailinfo },
448+
{ "mailinfo", cmd_mailinfo, RUN_SETUP_GENTLY },
449449
{ "mailsplit", cmd_mailsplit },
450450
{ "merge", cmd_merge, RUN_SETUP | NEED_WORK_TREE },
451451
{ "merge-base", cmd_merge_base, RUN_SETUP },

t/t5100-mailinfo.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,4 +158,17 @@ test_expect_success 'mailinfo handles rfc2822 comment' '
158158
test_cmp "$DATA/comment.expect" comment/info
159159
'
160160

161+
test_expect_success 'mailinfo with mailinfo.scissors config' '
162+
test_config mailinfo.scissors true &&
163+
(
164+
mkdir sub &&
165+
cd sub &&
166+
git mailinfo ../msg0014.sc ../patch0014.sc <../0014 >../info0014.sc
167+
) &&
168+
test_cmp "$DATA/msg0014--scissors" msg0014.sc &&
169+
test_cmp "$DATA/patch0014--scissors" patch0014.sc &&
170+
test_cmp "$DATA/info0014--scissors" info0014.sc
171+
'
172+
173+
161174
test_done

0 commit comments

Comments
 (0)