summaryrefslogtreecommitdiff
path: root/archive.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2011-06-15 18:31:28 -0400
committerJunio C Hamano <gitster@pobox.com>2011-06-15 15:56:28 -0700
commit2321286298bf956a3fa8e91dd361b8cf4e81e6a0 (patch)
tree8879ff6c7d193e9ea5760bff2f32bdd2444890f5 /archive.c
parent2c162b56f370f5c33e6a945e6922d598006c5ec4 (diff)
downloadgit-2321286298bf956a3fa8e91dd361b8cf4e81e6a0.tar.gz
archive: reorder option parsing and config reading
The archive command does three things during its initialization phase: 1. parse command-line options 2. setup the git directory 3. read config During phase (1), if we see any options that do not require a git directory (like "--list"), we handle them immediately and exit, making it safe to abort step (2) if we are not in a git directory. Step (3) must come after step (2), since the git directory may influence configuration. However, this leaves no possibility of configuration from step (3) impacting the command-line options in step (1) (which is useful, for example, for supporting user-configurable output formats). Instead, let's reorder this to: 1. setup the git directory, if it exists 2. read config 3. parse command-line options 4. if we are not in a git repository, die This should have the same external behavior, but puts configuration before command-line parsing. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'archive.c')
-rw-r--r--archive.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/archive.c b/archive.c
index 42f2d2fdc8..2616676fc7 100644
--- a/archive.c
+++ b/archive.c
@@ -387,17 +387,27 @@ static int parse_archive_args(int argc, const char **argv,
int write_archive(int argc, const char **argv, const char *prefix,
int setup_prefix)
{
+ int nongit = 0;
const struct archiver *ar = NULL;
struct archiver_args args;
- argc = parse_archive_args(argc, argv, &ar, &args);
if (setup_prefix && prefix == NULL)
- prefix = setup_git_directory();
+ prefix = setup_git_directory_gently(&nongit);
+
+ git_config(git_default_config, NULL);
+
+ argc = parse_archive_args(argc, argv, &ar, &args);
+ if (nongit) {
+ /*
+ * We know this will die() with an error, so we could just
+ * die ourselves; but its error message will be more specific
+ * than what we could write here.
+ */
+ setup_git_directory();
+ }
parse_treeish_arg(argv, &args, prefix);
parse_pathspec_arg(argv + 1, &args);
- git_config(git_default_config, NULL);
-
return ar->write_archive(&args);
}