Commit 0f0f5655 by Russell Belfer

Don't try to pack symbolic refs

If there were symbolic refs among the loose refs then the code
to create packed-refs would fail trying to parse the OID out of
them (where Git just skips trying to pack them).  This fixes it.
parent 5e1fb282
...@@ -316,6 +316,12 @@ static int loose_lookup_to_packfile( ...@@ -316,6 +316,12 @@ static int loose_lookup_to_packfile(
if (reference_read(&ref_file, NULL, backend->path, name, NULL) < 0) if (reference_read(&ref_file, NULL, backend->path, name, NULL) < 0)
return -1; return -1;
/* skip symbolic refs */
if (!git__prefixcmp(git_buf_cstr(&ref_file), GIT_SYMREF)) {
git_buf_free(&ref_file);
return 0;
}
git_buf_rtrim(&ref_file); git_buf_rtrim(&ref_file);
name_len = strlen(name); name_len = strlen(name);
...@@ -355,6 +361,9 @@ static int _dirent_loose_load(void *data, git_buf *full_path) ...@@ -355,6 +361,9 @@ static int _dirent_loose_load(void *data, git_buf *full_path)
if (loose_lookup_to_packfile(&ref, backend, file_path) < 0) if (loose_lookup_to_packfile(&ref, backend, file_path) < 0)
return -1; return -1;
if (!ref)
return 0;
git_strmap_insert2( git_strmap_insert2(
backend->refcache.packfile, ref->name, ref, old_ref, err); backend->refcache.packfile, ref->name, ref, old_ref, err);
if (err < 0) { if (err < 0) {
...@@ -460,7 +469,7 @@ static int loose_lookup( ...@@ -460,7 +469,7 @@ static int loose_lookup(
if (error < 0) if (error < 0)
goto done; goto done;
if (git__prefixcmp((const char *)(ref_file.ptr), GIT_SYMREF) == 0) { if (git__prefixcmp(git_buf_cstr(&ref_file), GIT_SYMREF) == 0) {
git_buf_rtrim(&ref_file); git_buf_rtrim(&ref_file);
if ((target = loose_parse_symbolic(&ref_file)) == NULL) { if ((target = loose_parse_symbolic(&ref_file)) == NULL) {
......
...@@ -32,7 +32,7 @@ static void packall(void) ...@@ -32,7 +32,7 @@ static void packall(void)
void test_refs_pack__empty(void) void test_refs_pack__empty(void)
{ {
// create a packfile for an empty folder /* create a packfile for an empty folder */
git_buf temp_path = GIT_BUF_INIT; git_buf temp_path = GIT_BUF_INIT;
cl_git_pass(git_buf_join_n(&temp_path, '/', 3, git_repository_path(g_repo), GIT_REFS_HEADS_DIR, "empty_dir")); cl_git_pass(git_buf_join_n(&temp_path, '/', 3, git_repository_path(g_repo), GIT_REFS_HEADS_DIR, "empty_dir"));
...@@ -44,7 +44,7 @@ void test_refs_pack__empty(void) ...@@ -44,7 +44,7 @@ void test_refs_pack__empty(void)
void test_refs_pack__loose(void) void test_refs_pack__loose(void)
{ {
// create a packfile from all the loose rn a repo /* create a packfile from all the loose rn a repo */
git_reference *reference; git_reference *reference;
git_buf temp_path = GIT_BUF_INIT; git_buf temp_path = GIT_BUF_INIT;
...@@ -77,3 +77,29 @@ void test_refs_pack__loose(void) ...@@ -77,3 +77,29 @@ void test_refs_pack__loose(void)
git_reference_free(reference); git_reference_free(reference);
git_buf_free(&temp_path); git_buf_free(&temp_path);
} }
void test_refs_pack__symbolic(void)
{
/* create a packfile from loose refs skipping symbolic refs */
int i;
git_oid head;
git_reference *ref;
char name[128];
cl_git_pass(git_reference_name_to_id(&head, g_repo, "HEAD"));
/* make a bunch of references */
for (i = 0; i < 100; ++i) {
snprintf(name, sizeof(name), "refs/heads/symbolic-%03d", i);
cl_git_pass(git_reference_symbolic_create(
&ref, g_repo, name, "refs/heads/master", 0));
git_reference_free(ref);
snprintf(name, sizeof(name), "refs/heads/direct-%03d", i);
cl_git_pass(git_reference_create(&ref, g_repo, name, &head, 0));
git_reference_free(ref);
}
packall();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment