Skip to content

Commit c34a7da

Browse files
committed
Merge branch 'jc/setup-cleanup-fix'
"git archive" and "git mailinfo" stopped reading from local configuration file with a recent update. * jc/setup-cleanup-fix: archive: read local configuration mailinfo: read local configuration
2 parents 6a2b569 + eb0224c commit c34a7da

File tree

8 files changed

+69
-20
lines changed

8 files changed

+69
-20
lines changed

archive.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -504,23 +504,19 @@ static int parse_archive_args(int argc, const char **argv,
504504
}
505505

506506
int write_archive(int argc, const char **argv, const char *prefix,
507-
int setup_prefix, const char *name_hint, int remote)
507+
const char *name_hint, int remote)
508508
{
509-
int nongit = 0;
510509
const struct archiver *ar = NULL;
511510
struct archiver_args args;
512511

513-
if (setup_prefix && prefix == NULL)
514-
prefix = setup_git_directory_gently(&nongit);
515-
516512
git_config_get_bool("uploadarchive.allowunreachable", &remote_allow_unreachable);
517513
git_config(git_default_config, NULL);
518514

519515
init_tar_archiver();
520516
init_zip_archiver();
521517

522518
argc = parse_archive_args(argc, argv, &ar, &args, name_hint, remote);
523-
if (nongit) {
519+
if (!startup_info->have_repository) {
524520
/*
525521
* We know this will die() with an error, so we could just
526522
* die ourselves; but its error message will be more specific

archive.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ typedef int (*write_archive_entry_fn_t)(struct archiver_args *args,
3636
unsigned int mode);
3737

3838
extern int write_archive_entries(struct archiver_args *args, write_archive_entry_fn_t write_entry);
39-
extern int write_archive(int argc, const char **argv, const char *prefix, int setup_prefix, const char *name_hint, int remote);
39+
extern int write_archive(int argc, const char **argv, const char *prefix, const char *name_hint, int remote);
4040

4141
const char *archive_format_from_filename(const char *filename);
4242
extern void *sha1_file_to_archive(const struct archiver_args *args,

builtin/archive.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ int cmd_archive(int argc, const char **argv, const char *prefix)
8585
const char *output = NULL;
8686
const char *remote = NULL;
8787
struct option local_opts[] = {
88-
OPT_STRING('o', "output", &output, N_("file"),
89-
N_("write the archive to this file")),
88+
OPT_FILENAME('o', "output", &output,
89+
N_("write the archive to this file")),
9090
OPT_STRING(0, "remote", &remote, N_("repo"),
9191
N_("retrieve the archive from remote repository <repo>")),
9292
OPT_STRING(0, "exec", &exec, N_("command"),
@@ -105,5 +105,5 @@ int cmd_archive(int argc, const char **argv, const char *prefix)
105105

106106
setvbuf(stderr, NULL, _IOLBF, BUFSIZ);
107107

108-
return write_archive(argc, argv, prefix, 1, output, 0);
108+
return write_archive(argc, argv, prefix, output, 0);
109109
}

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
}

builtin/upload-archive.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ int cmd_upload_archive_writer(int argc, const char **argv, const char *prefix)
4343
}
4444

4545
/* parse all options sent by the client */
46-
return write_archive(sent_argv.argc, sent_argv.argv, prefix, 0, NULL, 1);
46+
return write_archive(sent_argv.argc, sent_argv.argv, prefix, NULL, 1);
4747
}
4848

4949
__attribute__((format (printf, 1, 2)))

git.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ static struct cmd_struct commands[] = {
396396
{ "am", cmd_am, RUN_SETUP | NEED_WORK_TREE },
397397
{ "annotate", cmd_annotate, RUN_SETUP },
398398
{ "apply", cmd_apply, RUN_SETUP_GENTLY },
399-
{ "archive", cmd_archive },
399+
{ "archive", cmd_archive, RUN_SETUP_GENTLY },
400400
{ "bisect--helper", cmd_bisect__helper, RUN_SETUP },
401401
{ "blame", cmd_blame, RUN_SETUP },
402402
{ "branch", cmd_branch, RUN_SETUP },
@@ -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/t5000-tar-tree.sh

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,20 @@ check_tar() {
9494
'
9595
}
9696

97+
# run "$@" inside a non-git directory
98+
nongit () {
99+
test -d non-repo ||
100+
mkdir non-repo ||
101+
return 1
102+
103+
(
104+
GIT_CEILING_DIRECTORIES=$(pwd) &&
105+
export GIT_CEILING_DIRECTORIES &&
106+
cd non-repo &&
107+
"$@"
108+
)
109+
}
110+
97111
test_expect_success \
98112
'populate workdir' \
99113
'mkdir a &&
@@ -179,6 +193,15 @@ test_expect_success 'git archive --remote' \
179193
'git archive --remote=. HEAD >b5.tar &&
180194
test_cmp_bin b.tar b5.tar'
181195

196+
test_expect_success 'git archive --remote with configured remote' '
197+
git config remote.foo.url . &&
198+
(
199+
cd a &&
200+
git archive --remote=foo --output=../b5-nick.tar HEAD
201+
) &&
202+
test_cmp_bin b.tar b5-nick.tar
203+
'
204+
182205
test_expect_success \
183206
'validate file modification time' \
184207
'mkdir extract &&
@@ -197,9 +220,15 @@ test_expect_success 'git archive with --output, override inferred format' '
197220
test_cmp_bin b.tar d4.zip
198221
'
199222

200-
test_expect_success \
201-
'git archive --list outside of a git repo' \
202-
'GIT_DIR=some/non-existing/directory git archive --list'
223+
test_expect_success 'git archive --list outside of a git repo' '
224+
nongit git archive --list
225+
'
226+
227+
test_expect_success 'git archive --remote outside of a git repo' '
228+
git archive HEAD >expect.tar &&
229+
nongit git archive --remote="$PWD" HEAD >actual.tar &&
230+
test_cmp_bin expect.tar actual.tar
231+
'
203232

204233
test_expect_success 'clients cannot access unreachable commits' '
205234
test_commit unreachable &&

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)