]> git.proxmox.com Git - libgit2.git/commitdiff
Don't try to pack symbolic refs
authorRussell Belfer <rb@github.com>
Mon, 19 Aug 2013 17:42:48 +0000 (10:42 -0700)
committerRussell Belfer <rb@github.com>
Tue, 20 Aug 2013 23:14:23 +0000 (16:14 -0700)
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.

src/refdb_fs.c
tests-clar/refs/pack.c

index acd82594b267b4b5b4ed93d3762939708581a143..658bebb618ca5656c6dfbf6b60f6d977603dd76f 100644 (file)
@@ -316,6 +316,12 @@ static int loose_lookup_to_packfile(
        if (reference_read(&ref_file, NULL, backend->path, name, NULL) < 0)
                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);
 
        name_len = strlen(name);
@@ -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)
                return -1;
 
+       if (!ref)
+               return 0;
+
        git_strmap_insert2(
                backend->refcache.packfile, ref->name, ref, old_ref, err);
        if (err < 0) {
@@ -460,7 +469,7 @@ static int loose_lookup(
        if (error < 0)
                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);
 
                if ((target = loose_parse_symbolic(&ref_file)) == NULL) {
index d8d5cc6d0cf7adab7129ded6717a96c0c3738121..6019ed75ad0ab1bf74c67f82fb22ab53e4c1a466 100644 (file)
@@ -32,7 +32,7 @@ static void packall(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;
 
        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)
 
 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_buf temp_path = GIT_BUF_INIT;
 
@@ -77,3 +77,29 @@ void test_refs_pack__loose(void)
        git_reference_free(reference);
        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();
+}