]> git.proxmox.com Git - libgit2.git/commitdiff
ref: free the last ref when cancelling git_branch_foreach()
authoryorah <yoram.harmelin@gmail.com>
Mon, 17 Jun 2013 16:25:30 +0000 (18:25 +0200)
committeryorah <yoram.harmelin@gmail.com>
Mon, 17 Jun 2013 16:29:05 +0000 (18:29 +0200)
Also fixed an assert typo on nulltoken's HEAD

src/branch.c
tests-clar/refs/branches/foreach.c

index de38e3355fb33f2d319c9a504cbc124489bc1966..590cdc027eb0a3014a3132003bb8de5ab0594654 100644 (file)
@@ -132,18 +132,17 @@ int git_branch_foreach(
 {
        git_reference_iterator *iter;
        git_reference *ref;
-       int error;
+       int error = 0;
 
        if (git_reference_iterator_new(&iter, repo) < 0)
                return -1;
 
-       while ((error = git_reference_next(&ref, iter)) == 0) {
+       while (!error && (error = git_reference_next(&ref, iter)) == 0) {
                if (list_flags & GIT_BRANCH_LOCAL &&
                    git__prefixcmp(ref->name, GIT_REFS_HEADS_DIR) == 0) {
                        if (callback(ref->name + strlen(GIT_REFS_HEADS_DIR),
                                        GIT_BRANCH_LOCAL, payload)) {
                                error = GIT_EUSER;
-                               break;
                        }
                }
 
@@ -152,7 +151,6 @@ int git_branch_foreach(
                        if (callback(ref->name + strlen(GIT_REFS_REMOTES_DIR),
                                        GIT_BRANCH_REMOTE, payload)) {
                                error = GIT_EUSER;
-                               break;
                        }
                }
 
index 57f9c0e3974234f7924514c9f54cfea09364bb1f..433812cb40de276ea2bbc7709c2c1770de373140 100644 (file)
@@ -122,7 +122,7 @@ void test_refs_branches_foreach__retrieve_remote_symbolic_HEAD_when_present(void
        cl_git_pass(git_branch_foreach(repo, GIT_BRANCH_REMOTE, contains_branch_list_cb, &exp));
 
        assert_branch_has_been_found(exp, "nulltoken/HEAD");
-       assert_branch_has_been_found(exp, "nulltoken/HEAD");
+       assert_branch_has_been_found(exp, "nulltoken/master");
 }
 
 static int branch_list_interrupt_cb(