diff options
author | Vicent Martà <vicent@github.com> | 2013-06-03 09:28:58 -0700 |
---|---|---|
committer | Vicent Martà <vicent@github.com> | 2013-06-03 09:28:58 -0700 |
commit | 947fad4f7f7fbbc6d624570e9186326d3beb8cce (patch) | |
tree | 6a52a0a06d219abcffa62046054d54c6114a0854 /src/remote.c | |
parent | 9d9fff3c3dbc207a8a2ee2114eab19086afecb6e (diff) | |
parent | efd5a4e16a55ff32ce0b300d3792e44aed4157f8 (diff) | |
download | libgit2-947fad4f7f7fbbc6d624570e9186326d3beb8cce.tar.gz |
Merge pull request #1624 from libgit2/vmg/full-ref-iterator
Breaking RefDB changes
Diffstat (limited to 'src/remote.c')
-rw-r--r-- | src/remote.c | 52 |
1 files changed, 13 insertions, 39 deletions
diff --git a/src/remote.c b/src/remote.c index 4c1b39818..943b72bb7 100644 --- a/src/remote.c +++ b/src/remote.c @@ -1233,31 +1233,23 @@ static int update_branch_remote_config_entry( } static int rename_one_remote_reference( - git_repository *repo, - const char *reference_name, + git_reference *reference, const char *old_remote_name, const char *new_remote_name) { int error = -1; git_buf new_name = GIT_BUF_INIT; - git_reference *reference = NULL; - git_reference *newref = NULL; if (git_buf_printf( &new_name, GIT_REFS_REMOTES_DIR "%s%s", new_remote_name, - reference_name + strlen(GIT_REFS_REMOTES_DIR) + strlen(old_remote_name)) < 0) + reference->name + strlen(GIT_REFS_REMOTES_DIR) + strlen(old_remote_name)) < 0) return -1; - if (git_reference_lookup(&reference, repo, reference_name) < 0) - goto cleanup; - - error = git_reference_rename(&newref, reference, git_buf_cstr(&new_name), 0); + error = git_reference_rename(NULL, reference, git_buf_cstr(&new_name), 0); git_reference_free(reference); -cleanup: - git_reference_free(newref); git_buf_free(&new_name); return error; } @@ -1267,46 +1259,28 @@ static int rename_remote_references( const char *old_name, const char *new_name) { - git_vector refnames; int error = -1; - unsigned int i; - char *name; - const char *refname; + git_reference *ref; git_reference_iterator *iter; - if (git_vector_init(&refnames, 8, NULL) < 0) - return -1; - if (git_reference_iterator_new(&iter, repo) < 0) - goto cleanup; + return -1; - while ((error = git_reference_next(&refname, iter)) == 0) { - if (git__prefixcmp(refname, GIT_REFS_REMOTES_DIR)) + while ((error = git_reference_next(&ref, iter)) == 0) { + if (git__prefixcmp(ref->name, GIT_REFS_REMOTES_DIR)) continue; - if ((error = git_vector_insert(&refnames, git__strdup(refname))) < 0) - break; - + if ((error = rename_one_remote_reference(ref, old_name, new_name)) < 0) { + git_reference_iterator_free(iter); + return error; + } } git_reference_iterator_free(iter); - if (error == GIT_ITEROVER) - error = 0; - else - goto cleanup; - git_vector_foreach(&refnames, i, name) { - if ((error = rename_one_remote_reference(repo, name, old_name, new_name)) < 0) - goto cleanup; - } - - error = 0; -cleanup: - git_vector_foreach(&refnames, i, name) { - git__free(name); - } + if (error == GIT_ITEROVER) + return 0; - git_vector_free(&refnames); return error; } |