From: "Nguyen Thai Ngoc Duy" <pclouds@gmail.com>
To: "Deskin Miller" <deskinm@umich.edu>
Cc: "kenneth johansson" <ken@kenjo.org>, git@vger.kernel.org
Subject: Re: git archive
Date: Thu, 23 Oct 2008 22:33:31 +0700 [thread overview]
Message-ID: <fcaeb9bf0810230833i3953a5abt2d2ba6ca1b751754@mail.gmail.com> (raw)
In-Reply-To: <20081022130829.GC2015@riemann.deskinm.fdns.net>
On 10/22/08, Deskin Miller <deskinm@umich.edu> wrote:
> On Wed, Oct 22, 2008 at 08:42:01AM +0000, kenneth johansson wrote:
> > I was going to make a tar of the latest stable linux kernel.
> > Done it before but now I got a strange problem.
> >
> > >git archive --format=tar v2.6.27.2
> > fatal: Not a valid object name
>
>
> I had the same thing happen to me, while trying to make an archive of Git.
> Were you perchance working in a bare repository, as I was? I spent some time
> looking at it and I think git archive sets up the environment in the wrong
> order, though of course I never finished a patch so I'm going from memory:
>
> After looking at the code again, I think the issue is that git_config is called
> in builtin-archive.c:cmd_archive before setup_git_directory is called in
> archive.c:write_archive. The former ends up setting GIT_DIR to be '.git' even
> if you're in a bare repository. My coding skills weren't up to fixing it
> easily; moving setup_git_directory before git_config in builtin-archive caused
> last test of t5000 to fail: GIT_DIR=some/nonexistent/path git archive --list
> should still display the archive formats.
The problem affects some other commands as well. I tried the following
patch, ran "make test" and discovered "git mailinfo", "git
verify-pack", "git hash-object" and "git unpack-file". A bandage patch
is at the end of this mail. Solution is as Jeff suggested: call
setup_git_directory_gently() early.
---<---
diff --git a/environment.c b/environment.c
index 0693cd9..00ed640 100644
--- a/environment.c
+++ b/environment.c
@@ -49,14 +49,18 @@ static char *work_tree;
static const char *git_dir;
static char *git_object_dir, *git_index_file, *git_refs_dir, *git_graft_file;
+int git_dir_discovered;
static void setup_git_env(void)
{
git_dir = getenv(GIT_DIR_ENVIRONMENT);
if (!git_dir)
git_dir = read_gitfile_gently(DEFAULT_GIT_DIR_ENVIRONMENT);
- if (!git_dir)
+ if (!git_dir) {
+ if (!git_dir_discovered)
+ die("Internal error: .git must be relocated at cwd by setup_git_*");
git_dir = DEFAULT_GIT_DIR_ENVIRONMENT;
+ }
git_object_dir = getenv(DB_ENVIRONMENT);
if (!git_object_dir) {
git_object_dir = xmalloc(strlen(git_dir) + 9);
diff --git a/setup.c b/setup.c
index 78a8041..d404c21 100644
--- a/setup.c
+++ b/setup.c
@@ -368,6 +368,7 @@ const char *read_gitfile_gently(const char *path)
* We cannot decide in this function whether we are in the work tree or
* not, since the config can only be read _after_ this function was called.
*/
+extern int git_dir_discovered;
const char *setup_git_directory_gently(int *nongit_ok)
{
const char *work_tree_env = getenv(GIT_WORK_TREE_ENVIRONMENT);
@@ -472,6 +473,8 @@ const char *setup_git_directory_gently(int *nongit_ok)
}
chdir("..");
}
+ /* It is safe to call setup_git_env() now */
+ git_dir_discovered = 1;
inside_git_dir = 0;
if (!work_tree_env)
---<---
Bandage patch:
---<---
diff --git a/builtin-archive.c b/builtin-archive.c
index 432ce2a..5ea0a12 100644
--- a/builtin-archive.c
+++ b/builtin-archive.c
@@ -110,7 +110,9 @@ static const char *extract_remote_arg(int *ac,
const char **av)
int cmd_archive(int argc, const char **argv, const char *prefix)
{
const char *remote = NULL;
+ int nongit;
+ prefix = setup_git_directory_gently(&nongit);
git_config(git_default_config, NULL);
remote = extract_remote_arg(&argc, argv);
diff --git a/builtin-mailinfo.c b/builtin-mailinfo.c
index e890f7a..5d401fb 100644
--- a/builtin-mailinfo.c
+++ b/builtin-mailinfo.c
@@ -916,10 +916,9 @@ static const char mailinfo_usage[] =
int cmd_mailinfo(int argc, const char **argv, const char *prefix)
{
const char *def_charset;
+ int nongit;
- /* NEEDSWORK: might want to do the optional .git/ directory
- * discovery
- */
+ prefix = setup_git_directory_gently(&nongit);
git_config(git_default_config, NULL);
def_charset = (git_commit_encoding ? git_commit_encoding : "utf-8");
diff --git a/builtin-verify-pack.c b/builtin-verify-pack.c
index 25a29f1..35a4eb2 100644
--- a/builtin-verify-pack.c
+++ b/builtin-verify-pack.c
@@ -115,7 +115,9 @@ int cmd_verify_pack(int argc, const char **argv,
const char *prefix)
int verbose = 0;
int no_more_options = 0;
int nothing_done = 1;
+ int nongit;
+ prefix = setup_git_directory_gently(&nongit);
git_config(git_default_config, NULL);
while (1 < argc) {
if (!no_more_options && argv[1][0] == '-') {
diff --git a/hash-object.c b/hash-object.c
index 20937ff..a52b6be 100644
--- a/hash-object.c
+++ b/hash-object.c
@@ -78,19 +78,20 @@ int main(int argc, const char **argv)
const char *prefix = NULL;
int prefix_length = -1;
const char *errstr = NULL;
+ int nongit;
type = blob_type;
- git_config(git_default_config, NULL);
-
argc = parse_options(argc, argv, hash_object_options, hash_object_usage, 0);
- if (write_object) {
- prefix = setup_git_directory();
- prefix_length = prefix ? strlen(prefix) : 0;
- if (vpath && prefix)
- vpath = prefix_filename(prefix, prefix_length, vpath);
- }
+ prefix = setup_git_directory_gently(&nongit);
+ git_config(git_default_config, NULL);
+ prefix_length = prefix ? strlen(prefix) : 0;
+ if (vpath && prefix)
+ vpath = prefix_filename(prefix, prefix_length, vpath);
+
+ if (write_object && nongit)
+ die("Git repository required");
if (stdin_paths) {
if (hashstdin)
diff --git a/unpack-file.c b/unpack-file.c
index bcdc8bb..1a58d72 100644
--- a/unpack-file.c
+++ b/unpack-file.c
@@ -27,10 +27,10 @@ int main(int argc, char **argv)
if (argc != 2)
usage("git-unpack-file <sha1>");
+ setup_git_directory();
if (get_sha1(argv[1], sha1))
die("Not a valid object name %s", argv[1]);
- setup_git_directory();
git_config(git_default_config, NULL);
puts(create_temp_file(sha1));
---<---
--
Duy
next prev parent reply other threads:[~2008-10-23 15:35 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-10-22 8:42 git archive kenneth johansson
2008-10-22 13:08 ` Deskin Miller
2008-10-22 18:45 ` kenneth johansson
2008-10-22 20:37 ` [RFC PATCH] archive: fix setup to work in bare repositories Deskin Miller
2008-10-22 20:46 ` Jeff King
2008-10-22 21:09 ` Charles Bailey
2008-10-22 21:47 ` [PATCH] Fixed git archive for bare repos Charles Bailey
2008-10-23 1:37 ` Deskin Miller
2008-10-24 22:19 ` René Scharfe
2008-10-25 15:38 ` [PATCH v2] " Deskin Miller
2008-10-25 19:15 ` Junio C Hamano
2008-10-23 15:33 ` Nguyen Thai Ngoc Duy [this message]
2008-10-23 18:21 ` git archive Deskin Miller
2008-10-24 3:58 ` Nguyen Thai Ngoc Duy
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=fcaeb9bf0810230833i3953a5abt2d2ba6ca1b751754@mail.gmail.com \
--to=pclouds@gmail.com \
--cc=deskinm@umich.edu \
--cc=git@vger.kernel.org \
--cc=ken@kenjo.org \
/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).