diff options
author | Vicent Marti <tanoku@gmail.com> | 2013-05-28 22:47:55 +0400 |
---|---|---|
committer | Vicent Marti <tanoku@gmail.com> | 2013-05-28 22:47:55 +0400 |
commit | 56960b8396d3aef0b39f32aa7a9749202f925ada (patch) | |
tree | 90148977efa5b5dd715ddc4e474732737320314e /src | |
parent | 2638a03affdf57c989f573d48afca3b849cb4c1f (diff) |
Liike this
Diffstat (limited to 'src')
-rw-r--r-- | src/branch.c | 17 | ||||
-rw-r--r-- | src/refdb.c | 19 | ||||
-rw-r--r-- | src/refdb.h | 2 | ||||
-rw-r--r-- | src/refdb_fs.c | 18 | ||||
-rw-r--r-- | src/refs.c | 2 | ||||
-rw-r--r-- | src/remote.c | 49 |
6 files changed, 51 insertions, 56 deletions
diff --git a/src/branch.c b/src/branch.c index dd6dc68f4..84efadae1 100644 --- a/src/branch.c +++ b/src/branch.c @@ -131,28 +131,32 @@ int git_branch_foreach( void *payload) { git_reference_iterator *iter; - const char *name; + git_reference *ref; int error; if (git_reference_iterator_new(&iter, repo) < 0) return -1; - while ((error = git_reference_next(&name, iter)) == 0) { + while ((error = git_reference_next(&ref, iter)) == 0) { if (list_flags & GIT_BRANCH_LOCAL && - git__prefixcmp(name, GIT_REFS_HEADS_DIR) == 0) { - if (callback(name + strlen(GIT_REFS_HEADS_DIR), GIT_BRANCH_LOCAL, payload)) { + 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; } } if (list_flags & GIT_BRANCH_REMOTE && - git__prefixcmp(name, GIT_REFS_REMOTES_DIR) == 0) { - if (callback(name + strlen(GIT_REFS_REMOTES_DIR), GIT_BRANCH_REMOTE, payload)) { + git__prefixcmp(ref->name, GIT_REFS_REMOTES_DIR) == 0) { + if (callback(ref->name + strlen(GIT_REFS_REMOTES_DIR), + GIT_BRANCH_REMOTE, payload)) { error = GIT_EUSER; break; } } + + git_reference_free(ref); } if (error == GIT_ITEROVER) @@ -160,7 +164,6 @@ int git_branch_foreach( git_reference_iterator_free(iter); return error; - } int git_branch_move( diff --git a/src/refdb.c b/src/refdb.c index 9f9037ce7..6cb879288 100644 --- a/src/refdb.c +++ b/src/refdb.c @@ -160,17 +160,26 @@ int git_refdb_iterator_glob(git_reference_iterator **out, git_refdb *db, const c return 0; } -int git_refdb_next(const char **out, git_reference_iterator *iter) +int git_refdb_next(git_reference **out, git_reference_iterator *iter) { int error; - if (!iter->glob) - return iter->backend->next(out, iter); + if (!iter->glob) { + if ((error = iter->backend->next(out, iter)) < 0) + return error; + + (*out)->db = iter->backend; + return 0; + } /* If the iterator has a glob, we need to filter */ while ((error = iter->backend->next(out, iter)) == 0) { - if (!p_fnmatch(iter->glob, *out, 0)) - break; + if (!p_fnmatch(iter->glob, (*out)->name, 0)) { + (*out)->db = iter->backend; + return 0; + } + + git_reference_free(*out); } return error; diff --git a/src/refdb.h b/src/refdb.h index 2edd05d18..82522e191 100644 --- a/src/refdb.h +++ b/src/refdb.h @@ -28,7 +28,7 @@ int git_refdb_lookup( int git_refdb_iterator(git_reference_iterator **out, git_refdb *db); int git_refdb_iterator_glob(git_reference_iterator **out, git_refdb *db, const char *glob); -int git_refdb_next(const char **out, git_reference_iterator *iter); +int git_refdb_next(git_reference **out, git_reference_iterator *iter); void git_refdb_iterator_free(git_reference_iterator *iter); int git_refdb_write(git_refdb *refdb, const git_reference *ref); diff --git a/src/refdb_fs.c b/src/refdb_fs.c index 97f0b07c4..457964570 100644 --- a/src/refdb_fs.c +++ b/src/refdb_fs.c @@ -645,16 +645,19 @@ static int iter_load_loose_paths(refdb_fs_iter *iter) return 0; } -static int refdb_fs_backend__next(const char **out, git_reference_iterator *_iter) +static int refdb_fs_backend__next(git_reference **out, git_reference_iterator *_iter) { refdb_fs_iter *iter = (refdb_fs_iter *)_iter; - refdb_fs_backend *backend = (refdb_fs_backend *) iter->parent.backend; + refdb_fs_backend *backend = (refdb_fs_backend *)iter->parent.backend; git_strmap *packfile = backend->refcache.packfile; - if (iter->loose_pos < iter->loose.length) { + while (iter->loose_pos < iter->loose.length) { const char *path = git_vector_get(&iter->loose, iter->loose_pos++); - *out = path; - return 0; + + if (loose_lookup(out, backend, path) == 0) + return 0; + + giterr_clear(); } if (iter->packed_pos < kh_end(packfile)) { @@ -671,7 +674,10 @@ static int refdb_fs_backend__next(const char **out, git_reference_iterator *_ite iter->packed_pos++; } while (ref->flags & PACKREF_SHADOWED); - *out = ref->name; + *out = git_reference__alloc(ref->name, &ref->oid, &ref->peel); + if (*out == NULL) + return -1; + return 0; } diff --git a/src/refs.c b/src/refs.c index 9c6c5c623..43231b0cf 100644 --- a/src/refs.c +++ b/src/refs.c @@ -664,7 +664,7 @@ int git_reference_iterator_glob_new(git_reference_iterator **out, git_repository return git_refdb_iterator_glob(out, refdb, glob); } -int git_reference_next(const char **out, git_reference_iterator *iter) +int git_reference_next(git_reference **out, git_reference_iterator *iter) { return git_refdb_next(out, iter); } diff --git a/src/remote.c b/src/remote.c index 7a64622a5..266a3d914 100644 --- a/src/remote.c +++ b/src/remote.c @@ -1239,30 +1239,25 @@ 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; - + /* TODO: can we make this NULL? */ error = git_reference_rename(&newref, reference, git_buf_cstr(&new_name), 0); git_reference_free(reference); -cleanup: git_reference_free(newref); git_buf_free(&new_name); return error; @@ -1273,46 +1268,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; } |