refs: add method to rename refs

This removes the last caller of function get_files_ref_store(), so remove it. Signed-off-by: David Turner <dturner@twopensource.com> Signed-off-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>

David Turner committed Sep 4, 2016 at 18:08 UTC 9b6b40d93a4c93d36225533ddc6717841b07d09d
3 files changed +17 -18
refs.c
+7
@@ -1547,3 +1547,10 @@ int delete_refs(struct string_list *refnames, unsigned int flags)
1547
1548 return refs->be->delete_refs(refs, refnames, flags);
1549 }
1550 +
1551 +int rename_ref(const char *oldref, const char *newref, const char *logmsg)
1552 +{
1553 + struct ref_store *refs = get_ref_store(NULL);
1554 +
1555 + return refs->be->rename_ref(refs, oldref, newref, logmsg);
1556 +}
refs/files-backend.c
+6 -18
@@ -997,22 +997,6 @@ static struct files_ref_store *files_downcast(
997 return (struct files_ref_store *)ref_store;
998 }
999
1000 -/*
1001 - * Return a pointer to the reference store for the specified
1002 - * submodule. For the main repository, use submodule==NULL; such a
1003 - * call cannot fail. For a submodule, the submodule must exist and be
1004 - * a nonbare repository, otherwise return NULL. Verify that the
1005 - * reference store is a files_ref_store, and cast it to that type
1006 - * before returning it.
1007 - */
1008 -static struct files_ref_store *get_files_ref_store(const char *submodule,
1009 - const char *caller)
1010 -{
1011 - struct ref_store *refs = get_ref_store(submodule);
1012 -
1013 - return refs ? files_downcast(refs, 1, caller) : NULL;
1014 -}
1015 -
1000 /* The length of a peeled reference line in packed-refs, including EOL: */
1001 #define PEELED_LINE_LENGTH 42
1002
@@ -2580,9 +2564,12 @@ static int commit_ref_update(struct files_ref_store *refs,
2564 const unsigned char *sha1, const char *logmsg,
2565 struct strbuf *err);
2566
2583 -int rename_ref(const char *oldrefname, const char *newrefname, const char *logmsg)
2567 +static int files_rename_ref(struct ref_store *ref_store,
2568 + const char *oldrefname, const char *newrefname,
2569 + const char *logmsg)
2570 {
2585 - struct files_ref_store *refs = get_files_ref_store(NULL, "rename_ref");
2571 + struct files_ref_store *refs =
2572 + files_downcast(ref_store, 0, "rename_ref");
2573 unsigned char sha1[20], orig_sha1[20];
2574 int flag = 0, logmoved = 0;
2575 struct ref_lock *lock;
@@ -4087,6 +4074,7 @@ struct ref_storage_be refs_be_files = {
4074 files_peel_ref,
4075 files_create_symref,
4076 files_delete_refs,
4077 + files_rename_ref,
4078
4079 files_ref_iterator_begin,
4080 files_read_raw_ref,
refs/refs-internal.h
+4
@@ -494,6 +494,9 @@ typedef int create_symref_fn(struct ref_store *ref_store,
494 const char *logmsg);
495 typedef int delete_refs_fn(struct ref_store *ref_store,
496 struct string_list *refnames, unsigned int flags);
497 +typedef int rename_ref_fn(struct ref_store *ref_store,
498 + const char *oldref, const char *newref,
499 + const char *logmsg);
500
501 /*
502 * Iterate over the references in the specified ref_store that are
@@ -593,6 +596,7 @@ struct ref_storage_be {
596 peel_ref_fn *peel_ref;
597 create_symref_fn *create_symref;
598 delete_refs_fn *delete_refs;
599 + rename_ref_fn *rename_ref;
600
601 ref_iterator_begin_fn *iterator_begin;
602 read_raw_ref_fn *read_raw_ref;