diff options
| author | Edward Thomson <ethomson@microsoft.com> | 2013-04-19 18:19:53 -0500 |
|---|---|---|
| committer | Edward Thomson <ethomson@microsoft.com> | 2013-04-19 18:43:17 -0500 |
| commit | 4e4eab52f7c5062ea21ea278a38e48700e753883 (patch) | |
| tree | 4c8133d7595b355e3150b4525e25ad25103d10ff /src/refs.c | |
| parent | 4a38143c93dc705bc40109e3f79d7fac722d44d7 (diff) | |
| download | libgit2-4e4eab52f7c5062ea21ea278a38e48700e753883.tar.gz | |
alloc doesn't take a refdb; git_refdb_free nicely in the tests
Diffstat (limited to 'src/refs.c')
| -rw-r--r-- | src/refs.c | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/src/refs.c b/src/refs.c index 29d1c4fa9..5b5812aae 100644 --- a/src/refs.c +++ b/src/refs.c @@ -31,7 +31,7 @@ enum { GIT_PACKREF_WAS_LOOSE = 2 }; -static git_reference *alloc_ref(git_refdb *refdb, const char *name) +static git_reference *alloc_ref(const char *name) { git_reference *ref; size_t namelen = strlen(name); @@ -39,22 +39,20 @@ static git_reference *alloc_ref(git_refdb *refdb, const char *name) if ((ref = git__calloc(1, sizeof(git_reference) + namelen + 1)) == NULL) return NULL; - ref->db = refdb; memcpy(ref->name, name, namelen + 1); return ref; } git_reference *git_reference__alloc_symbolic( - git_refdb *refdb, const char *name, const char *target) { git_reference *ref; - assert(refdb && name && target); + assert(name && target); - ref = alloc_ref(refdb, name); + ref = alloc_ref(name); if (!ref) return NULL; @@ -69,16 +67,15 @@ git_reference *git_reference__alloc_symbolic( } git_reference *git_reference__alloc( - git_refdb *refdb, const char *name, const git_oid *oid, const git_oid *peel) { git_reference *ref; - assert(refdb && name && oid); + assert(name && oid); - ref = alloc_ref(refdb, name); + ref = alloc_ref(name); if (!ref) return NULL; @@ -368,12 +365,13 @@ static int reference__create( if (oid != NULL) { assert(symbolic == NULL); - ref = git_reference__alloc(refdb, name, oid, NULL); + ref = git_reference__alloc(name, oid, NULL); } else { - ref = git_reference__alloc_symbolic(refdb, name, symbolic); + ref = git_reference__alloc_symbolic(name, symbolic); } GITERR_CHECK_ALLOC(ref); + ref->db = refdb; if ((error = git_refdb_write(refdb, ref)) < 0) { git_reference_free(ref); @@ -490,10 +488,9 @@ int git_reference_rename( * Create the new reference. */ if (ref->type == GIT_REF_OID) { - result = git_reference__alloc(ref->db, new_name, - &ref->target.oid, &ref->peel); + result = git_reference__alloc(new_name, &ref->target.oid, &ref->peel); } else if (ref->type == GIT_REF_SYMBOLIC) { - result = git_reference__alloc_symbolic(ref->db, new_name, ref->target.symbolic); + result = git_reference__alloc_symbolic(new_name, ref->target.symbolic); } else { assert(0); } @@ -501,6 +498,8 @@ int git_reference_rename( if (result == NULL) return -1; + result->db = ref->db; + /* Check if we have to update HEAD. */ if ((error = git_branch_is_head(ref)) < 0) goto on_error; |
