Skip to content

Commit 9b6b40d

Browse files
dturner-twgitster
authored andcommitted
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>
1 parent 6fb5acf commit 9b6b40d

3 files changed

Lines changed: 17 additions & 18 deletions

File tree

refs.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,3 +1547,10 @@ int delete_refs(struct string_list *refnames, unsigned int flags)
15471547

15481548
return refs->be->delete_refs(refs, refnames, flags);
15491549
}
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

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -997,22 +997,6 @@ static struct files_ref_store *files_downcast(
997997
return (struct files_ref_store *)ref_store;
998998
}
999999

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-
10161000
/* The length of a peeled reference line in packed-refs, including EOL: */
10171001
#define PEELED_LINE_LENGTH 42
10181002

@@ -2580,9 +2564,12 @@ static int commit_ref_update(struct files_ref_store *refs,
25802564
const unsigned char *sha1, const char *logmsg,
25812565
struct strbuf *err);
25822566

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)
25842570
{
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");
25862573
unsigned char sha1[20], orig_sha1[20];
25872574
int flag = 0, logmoved = 0;
25882575
struct ref_lock *lock;
@@ -4087,6 +4074,7 @@ struct ref_storage_be refs_be_files = {
40874074
files_peel_ref,
40884075
files_create_symref,
40894076
files_delete_refs,
4077+
files_rename_ref,
40904078

40914079
files_ref_iterator_begin,
40924080
files_read_raw_ref,

refs/refs-internal.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,9 @@ typedef int create_symref_fn(struct ref_store *ref_store,
494494
const char *logmsg);
495495
typedef int delete_refs_fn(struct ref_store *ref_store,
496496
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);
497500

498501
/*
499502
* Iterate over the references in the specified ref_store that are
@@ -593,6 +596,7 @@ struct ref_storage_be {
593596
peel_ref_fn *peel_ref;
594597
create_symref_fn *create_symref;
595598
delete_refs_fn *delete_refs;
599+
rename_ref_fn *rename_ref;
596600

597601
ref_iterator_begin_fn *iterator_begin;
598602
read_raw_ref_fn *read_raw_ref;

0 commit comments

Comments
 (0)