[PATCH/RFC 5/7] refs: add function to repack without multiple refs
Generalize repack_without_ref as repack_without_refs to support a list of refs and implement the former in terms of the latter. Signed-off-by: Brad King brad.k...@kitware.com --- refs.c | 29 ++--- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/refs.c b/refs.c index 5908648..5a6c14e 100644 --- a/refs.c +++ b/refs.c @@ -2414,25 +2414,35 @@ static int curate_packed_ref_fn(struct ref_entry *entry, void *cb_data) return 0; } -static int repack_without_ref(const char *refname) +static int repack_without_refs(const char **refnames, int n) { struct ref_dir *packed; struct string_list refs_to_delete = STRING_LIST_INIT_DUP; struct string_list_item *ref_to_delete; + int i, removed = 0; + + /* Look for a packed ref: */ + for (i = 0; i n; ++i) + if (get_packed_ref(refnames[i])) + break; - if (!get_packed_ref(refname)) - return 0; /* refname does not exist in packed refs */ + /* Avoid locking if we have nothing to do: */ + if(i == n) + return 0; /* no refname exists in packed refs */ if (lock_packed_refs(0)) { unable_to_lock_error(git_path(packed-refs), errno); - return error(cannot delete '%s' from packed refs, refname); + return error(cannot delete '%s' from packed refs, refnames[i]); } packed = get_packed_refs(ref_cache); - /* Remove refname from the cache: */ - if (remove_entry(packed, refname) == -1) { + /* Remove refnames from the cache: */ + for (i = 0; i n; ++i) + if (remove_entry(packed, refnames[i]) != -1) + removed = 1; + if (!removed) { /* -* The packed entry disappeared while we were +* All packed entries disappeared while we were * acquiring the lock. */ rollback_packed_refs(); @@ -2450,6 +2460,11 @@ static int repack_without_ref(const char *refname) return commit_packed_refs(); } +static int repack_without_ref(const char *refname) +{ + return repack_without_refs(refname, 1); +} + static int delete_ref_loose(struct ref_lock *lock, int type) { int err, i, ret = 0; -- 1.7.10.4 -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH/RFC 5/7] refs: add function to repack without multiple refs
Brad King brad.k...@kitware.com writes: Generalize repack_without_ref as repack_without_refs to support a list of refs and implement the former in terms of the latter. Signed-off-by: Brad King brad.k...@kitware.com --- refs.c | 29 ++--- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/refs.c b/refs.c index 5908648..5a6c14e 100644 --- a/refs.c +++ b/refs.c @@ -2414,25 +2414,35 @@ static int curate_packed_ref_fn(struct ref_entry *entry, void *cb_data) return 0; } -static int repack_without_ref(const char *refname) +static int repack_without_refs(const char **refnames, int n) { struct ref_dir *packed; struct string_list refs_to_delete = STRING_LIST_INIT_DUP; struct string_list_item *ref_to_delete; + int i, removed = 0; + + /* Look for a packed ref: */ + for (i = 0; i n; ++i) + if (get_packed_ref(refnames[i])) + break; - if (!get_packed_ref(refname)) - return 0; /* refname does not exist in packed refs */ + /* Avoid locking if we have nothing to do: */ + if(i == n) Style: if (i == n) + return 0; /* no refname exists in packed refs */ if (lock_packed_refs(0)) { unable_to_lock_error(git_path(packed-refs), errno); - return error(cannot delete '%s' from packed refs, refname); + return error(cannot delete '%s' from packed refs, refnames[i]); } packed = get_packed_refs(ref_cache); - /* Remove refname from the cache: */ - if (remove_entry(packed, refname) == -1) { + /* Remove refnames from the cache: */ + for (i = 0; i n; ++i) + if (remove_entry(packed, refnames[i]) != -1) + removed = 1; + if (!removed) { /* - * The packed entry disappeared while we were + * All packed entries disappeared while we were * acquiring the lock. */ rollback_packed_refs(); ... and this is not an error; somebody else did the work we wanted to do for us, which is good ;-) @@ -2450,6 +2460,11 @@ static int repack_without_ref(const char *refname) return commit_packed_refs(); } +static int repack_without_ref(const char *refname) +{ + return repack_without_refs(refname, 1); +} + static int delete_ref_loose(struct ref_lock *lock, int type) { int err, i, ret = 0; -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH/RFC 5/7] refs: add function to repack without multiple refs
On 08/29/2013 01:34 PM, Junio C Hamano wrote: Brad King brad.k...@kitware.com writes: +if(i == n) Style: if (i == n) Fixed in next revision. -Brad -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html