{"thread":{"id":"38484","subject":"[PATCHv2 1/2] t5304-prune: demonstrate bug in pruning alternates","startedAt":"2015-02-02T18:33:02Z","lastAt":"2015-02-02T18:41:16Z","messageCount":3,"participants":["Jonathon Mah","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"255521","messageId":"0BD44E44-686B-44B2-A4C0-9E14A99BA96B@jonathonmah.com","threadId":"38484","inReplyTo":null,"subject":"[PATCHv2 1/2] t5304-prune: demonstrate bug in pruning alternates","fromName":"Jonathon Mah","fromEmail":"me@jonathonmah.com","sentAt":"2015-02-02T18:33:02Z","receivedAt":"2015-02-02T18:33:02Z","isPatch":false,"sender":{"key":"me@jonathonmah.com","avatar":"https://avatars.githubusercontent.com/u/2748?v=4"},"body":"Signed-off-by: Jonathon Mah <me@JonathonMah.com>\n---\nAdjust prune test directly, much nicer.\n\n t/t5304-prune.sh          | 13 +++++++++++++\n t/t5710-info-alternate.sh |  4 ++--\n 2 files changed, 15 insertions(+), 2 deletions(-)\n\ndiff --git a/t/t5304-prune.sh b/t/t5304-prune.sh\nindex e32e46d..e825be7 100755\n--- a/t/t5304-prune.sh\n+++ b/t/t5304-prune.sh\n@@ -253,4 +253,17 @@ test_expect_success 'prune .git/shallow' '\n \ttest_path_is_missing .git/shallow\n '\n \n+test_expect_success 'prune: handle alternate object database' '\n+\ttest_create_repo A && cd A &&\n+\techo \"Hello World\" > file1 &&\n+\tgit add file1 &&\n+\tgit commit -m \"Initial commit\" file1 &&\n+\tcd .. &&\n+\tgit clone -l -s A B && cd B &&\n+\techo \"foo bar\" > file2 &&\n+\tgit add file2 &&\n+\tgit commit -m \"next commit\" file2 &&\n+\tgit prune\n+'\n+\n test_done\ndiff --git a/t/t5710-info-alternate.sh b/t/t5710-info-alternate.sh\nindex 5a6e49d..d82844a 100755\n--- a/t/t5710-info-alternate.sh\n+++ b/t/t5710-info-alternate.sh\n@@ -18,6 +18,7 @@ reachable_via() {\n \n test_valid_repo() {\n \tgit fsck --full > fsck.log &&\n+\tgit prune &&\n \ttest_line_count = 0 fsck.log\n }\n \n@@ -47,8 +48,7 @@ test_expect_success 'preparing third repository' \\\n 'git clone -l -s B C && cd C &&\n echo \"Goodbye, cruel world\" > file3 &&\n git add file3 &&\n-git commit -m \"one more\" file3 &&\n-git repack -a -d -l &&\n+git commit -m \"one more without packing\" file3 &&\n git prune'\n \n cd \"$base_dir\"\n-- \n2.3.0.rc2.2.g184f7a0\n"},{"id":"255522","messageId":"D37068A8-F7D3-4BF6-986C-09528EF443C6@jonathonmah.com","threadId":"38484","inReplyTo":"0BD44E44-686B-44B2-A4C0-9E14A99BA96B@jonathonmah.com","subject":"[PATCHv2 2/2] sha1_file: fix iterating loose alternate objects","fromName":"Jonathon Mah","fromEmail":"me@jonathonmah.com","sentAt":"2015-02-02T18:34:07Z","receivedAt":"2015-02-02T18:34:07Z","isPatch":false,"sender":{"key":"me@jonathonmah.com","avatar":"https://avatars.githubusercontent.com/u/2748?v=4"},"body":"The string in 'base' contains a path suffix to a specific object; when\nits value is used, the suffix must either be filled (as in\nstat_sha1_file, open_sha1_file, check_and_freshen_nonlocal) or cleared\n(as in prepare_packed_git) to avoid junk at the end.  loose_from_alt_odb\n(introduced in 660c889e46d185dc98ba78963528826728b0a55d) did neither and\ntreated 'base' as a complete path to the \"base\" object directory,\ninstead of a pointer to the \"base\" of the full path string.\n\nThe trailing path after 'base' is still initialized to NUL, hiding the\nbug in some common cases.  Additionally the descendent\nfor_each_file_in_obj_subdir function swallows ENOENT, so an error only\nshows if the alternate's path was last filled with a valid object\n(where statting /path/to/existing/00/0bjectfile/00 fails).\n\nSigned-off-by: Jonathon Mah <me@JonathonMah.com>\n---\n sha1_file.c | 10 +++++++---\n 1 file changed, 7 insertions(+), 3 deletions(-)\n\ndiff --git a/sha1_file.c b/sha1_file.c\nindex 30995e6..fcb1c4b 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -3396,9 +3396,13 @@ static int loose_from_alt_odb(struct alternate_object_database *alt,\n \t\t\t      void *vdata)\n {\n \tstruct loose_alt_odb_data *data = vdata;\n-\treturn for_each_loose_file_in_objdir(alt->base,\n-\t\t\t\t\t     data->cb, NULL, NULL,\n-\t\t\t\t\t     data->data);\n+\tint r;\n+\talt->name[-1] = 0;\n+\tr = for_each_loose_file_in_objdir(alt->base,\n+\t\t\t\t\t  data->cb, NULL, NULL,\n+\t\t\t\t\t  data->data);\n+\talt->name[-1] = '/';\n+\treturn r;\n }\n \n int for_each_loose_object(each_loose_object_fn cb, void *data)\n-- \n2.3.0.rc2.2.g184f7a0\n"},{"id":"255527","messageId":"20150202184115.GA25421@peff.net","threadId":"38484","inReplyTo":"0BD44E44-686B-44B2-A4C0-9E14A99BA96B@jonathonmah.com","subject":"Re: [PATCHv2 1/2] t5304-prune: demonstrate bug in pruning alternates","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2015-02-02T18:41:16Z","receivedAt":"2015-02-02T18:41:16Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Feb 02, 2015 at 10:33:02AM -0800, Jonathon Mah wrote:\n\n> Signed-off-by: Jonathon Mah <me@JonathonMah.com>\n> ---\n> Adjust prune test directly, much nicer.\n\nAgreed, this is much nicer. A few comments:\n\n> +test_expect_success 'prune: handle alternate object database' '\n\nThis test fails, so we either need expect_failure here, or it just needs\nto be squashed in with the fix (I generally prefer the latter).\n\n> +\ttest_create_repo A && cd A &&\n\nWe generally prefer to chdir in a subshell, so that a failure in the\ntest does not leave further tests in a confusing spot. Like:\n\n  test_create_repo A &&\n  (\n\tcd A &&\n\t... do stuff in repo ...\n\t# no need to cd ..\n  ) &&\n  .. do stuff outside repo ...\n\n> +\techo \"Hello World\" > file1 &&\n\nStyle nit: we prefer \">file1\" with no space.\n\n> +\tgit add file1 &&\n> +\tgit commit -m \"Initial commit\" file1 &&\n> +\tcd .. &&\n> +\tgit clone -l -s A B && cd B &&\n\n\"-l\" is a noop these days. I don't think it is hurting, but I'd prefer\nnot to propagate bad habits in our tests.\n\n> diff --git a/t/t5710-info-alternate.sh b/t/t5710-info-alternate.sh\n> index 5a6e49d..d82844a 100755\n> --- a/t/t5710-info-alternate.sh\n> +++ b/t/t5710-info-alternate.sh\n\nWe can drop this change, then, right?\n\n-Peff\n"}]}