{"thread":{"id":"18068","subject":"[PATCH] Ensure proper setup of git_dir for git-hash-object","startedAt":"2009-02-28T19:56:49Z","lastAt":"2009-02-28T21:39:51Z","messageCount":4,"participants":["newren@gmail.com","Junio C Hamano","Elijah Newren"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"106551","messageId":"1235851009-16739-1-git-send-email-newren@gmail.com","threadId":"18068","inReplyTo":null,"subject":"[PATCH] Ensure proper setup of git_dir for git-hash-object","fromName":"","fromEmail":"newren@gmail.com","sentAt":"2009-02-28T19:56:49Z","receivedAt":"2009-02-28T19:56:49Z","isPatch":true,"sender":{"key":"newren@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5455730?v=4"},"body":"From: Elijah Newren <newren@gmail.com>\n\nCall setup_git_directory() before git_config() to make sure git_dir is set\nto the proper value.\n\nSigned-off-by: Elijah Newren <newren@gmail.com>\n---\nWithout this patch:\n$ mkdir tmp\n$ cd tmp/\n$ git init --bare\nInitialized empty Git repository in /home/newren/floss-development/git/tmp/\n$ echo hi | git hash-object -w --stdin\nerror: unable to create temporary sha1 filename .git/objects/45: No such file or directory\n\nfatal: Unable to add stdin to database\n$ echo hi | git --git-dir=. hash-object -w --stdin\n45b983be36b73c0788dc9cbcb76cbb80fc7bb057\n\n hash-object.c |    4 ++--\n 1 files changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/hash-object.c b/hash-object.c\nindex 37e6677..ebb3bed 100644\n--- a/hash-object.c\n+++ b/hash-object.c\n@@ -84,8 +84,6 @@ int main(int argc, const char **argv)\n \n \tgit_extract_argv0_path(argv[0]);\n \n-\tgit_config(git_default_config, NULL);\n-\n \targc = parse_options(argc, argv, hash_object_options, hash_object_usage, 0);\n \n \tif (write_object) {\n@@ -95,6 +93,8 @@ int main(int argc, const char **argv)\n \t\t\tvpath = prefix_filename(prefix, prefix_length, vpath);\n \t}\n \n+\tgit_config(git_default_config, NULL);\n+\n \tif (stdin_paths) {\n \t\tif (hashstdin)\n \t\t\terrstr = \"Can't use --stdin-paths with --stdin\";\n-- \n1.6.0.6\n"},{"id":"106553","messageId":"7v3adyffax.fsf@gitster.siamese.dyndns.org","threadId":"18068","inReplyTo":"1235851009-16739-1-git-send-email-newren@gmail.com","subject":"Re: [PATCH] Ensure proper setup of git_dir for git-hash-object","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-02-28T20:59:50Z","receivedAt":"2009-02-28T20:59:50Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"newren@gmail.com writes:\n\n> Without this patch:\n> $ mkdir tmp\n> $ cd tmp/\n> $ git init --bare\n> Initialized empty Git repository in /home/newren/floss-development/git/tmp/\n> $ echo hi | git hash-object -w --stdin\n> error: unable to create temporary sha1 filename .git/objects/45: No such file or directory\n>\n> fatal: Unable to add stdin to database\n> $ echo hi | git --git-dir=. hash-object -w --stdin\n> 45b983be36b73c0788dc9cbcb76cbb80fc7bb057\n\nDoes the patched version work without -w option?  Should it?\n"},{"id":"106557","messageId":"51419b2c0902281320neec7960vfbe7b806c8db56ca@mail.gmail.com","threadId":"18068","inReplyTo":"7v3adyffax.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH] Ensure proper setup of git_dir for git-hash-object","fromName":"Elijah Newren","fromEmail":"newren@gmail.com","sentAt":"2009-02-28T21:20:32Z","receivedAt":"2009-02-28T21:20:32Z","isPatch":true,"sender":{"key":"newren@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5455730?v=4"},"body":"On Sat, Feb 28, 2009 at 1:59 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> newren@gmail.com writes:\n>\n>> Without this patch:\n>> $ mkdir tmp\n>> $ cd tmp/\n>> $ git init --bare\n>> Initialized empty Git repository in /home/newren/floss-development/git/tmp/\n>> $ echo hi | git hash-object -w --stdin\n>> error: unable to create temporary sha1 filename .git/objects/45: No such file or directory\n>>\n>> fatal: Unable to add stdin to database\n>> $ echo hi | git --git-dir=. hash-object -w --stdin\n>> 45b983be36b73c0788dc9cbcb76cbb80fc7bb057\n>\n> Does the patched version work without -w option?  Should it?\n\nYes, the patched version works with or without the -w option (at least\nin my testing -- maybe you know of a case I'm missing?)  I would\ncertainly expect it to work in both cases.\n\nI basically arrived at the patch by realizing that git_config was\nsetting git_dir incorrectly as a side-effect, causing\nsetup_git_directory to notice it was already set and not try any of\nit's more detailed logic to figure out the correct value.  Then I did\nsome grepping and noticed that other source files (archive.c,\nbuiltin-apply.c, builtin-diff, etc., etc.) call\nsetup_git_directory[_gently] before git_config, and that hash-object.c\nseemed to be the only one that didn't follow that trend.\n"},{"id":"106558","messageId":"51419b2c0902281339k35f21b72v83310000b60a1416@mail.gmail.com","threadId":"18068","inReplyTo":"7v3adyffax.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH] Ensure proper setup of git_dir for git-hash-object","fromName":"Elijah Newren","fromEmail":"newren@gmail.com","sentAt":"2009-02-28T21:39:51Z","receivedAt":"2009-02-28T21:39:51Z","isPatch":true,"sender":{"key":"newren@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5455730?v=4"},"body":"On Sat, Feb 28, 2009 at 1:59 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> newren@gmail.com writes:\n>\n>> Without this patch:\n>> $ mkdir tmp\n>> $ cd tmp/\n>> $ git init --bare\n>> Initialized empty Git repository in /home/newren/floss-development/git/tmp/\n>> $ echo hi | git hash-object -w --stdin\n>> error: unable to create temporary sha1 filename .git/objects/45: No such file or directory\n>>\n>> fatal: Unable to add stdin to database\n>> $ echo hi | git --git-dir=. hash-object -w --stdin\n>> 45b983be36b73c0788dc9cbcb76cbb80fc7bb057\n>\n> Does the patched version work without -w option?  Should it?\n\nSorry, I think I partially missed what you were asking earlier.  When\n-w is not passed there is no dependence on git_dir, so it does not\nmatter if it is set up or not.  Some evidence that this is true (in\naddition to my basic testing): The call to git_config was added to\nhash-object.c in revision ff350ccf49a800c4c90f817d346fb1bcb96e02e7;\nprior to that revision, when -w was not passed, there would be no\nsetup of git_dir by either git_config or git_setup_directory.\n"}]}