{"thread":{"id":"38485","subject":"[PATCHv3 1/2] t5304-prune: demonstrate bug in pruning alternates","startedAt":"2015-02-02T18:40:08Z","lastAt":"2015-02-02T18:40:27Z","messageCount":2,"participants":["Jonathon Mah"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"255525","messageId":"FF73A39C-2678-40C2-9E2D-58855AEC4E40@jonathonmah.com","threadId":"38485","inReplyTo":null,"subject":"[PATCHv3 1/2] t5304-prune: demonstrate bug in pruning alternates","fromName":"Jonathon Mah","fromEmail":"me@jonathonmah.com","sentAt":"2015-02-02T18:40:08Z","receivedAt":"2015-02-02T18:40:08Z","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---\nMessed up the v2 patch, sorry.\n\n t/t5304-prune.sh | 13 +++++++++++++\n 1 file changed, 13 insertions(+)\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\n-- \n2.3.0.rc2.2.g184f7a0\n"},{"id":"255526","messageId":"CA2B8433-E268-49A1-8D75-FBE6B4B8F182@jonathonmah.com","threadId":"38485","inReplyTo":"FF73A39C-2678-40C2-9E2D-58855AEC4E40@jonathonmah.com","subject":"[PATCHv3 2/2] sha1_file: fix iterating loose alternate objects","fromName":"Jonathon Mah","fromEmail":"me@jonathonmah.com","sentAt":"2015-02-02T18:40:27Z","receivedAt":"2015-02-02T18:40:27Z","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"}]}