[PATCH v5 01/27] refs: Move head_ref{,_submodule} to the common code
- From
David Turner <dturner@twopensource.com>
- Date
- Feb 18, 2016, 05:17 UTC
- Message-ID
- <1455772670-21142-2-git-send-email-dturner@twopensource.com>
- In-Reply-To
- <1455772670-21142-1-git-send-email-dturner@twopensource.com>
These don't use any backend-specific functions. These were previously defined in terms of the do_head_ref helper function, but since they are otherwise identical, we don't need that function.
Signed-off-by: David Turner <dturner@twopensource.com> --- refs.c | 23 +++++++++++++++++++++++ refs/files-backend.c | 28 ---------------------------- 2 files changed, 23 insertions(+), 28 deletions(-)
diff --git a/refs.c b/refs.c index e2d34b2..4367c14 100644 --- a/refs.c +++ b/refs.c @@ -1082,3 +1082,26 @@ int rename_ref_available(const char *oldname, const char *newname) strbuf_release(&err); return ret; } + +int head_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data) +{ + struct object_id oid; + int flag; + + if (submodule) { + if (resolve_gitlink_ref(submodule, "HEAD", oid.hash) == 0) + return fn("HEAD", &oid, 0, cb_data); + + return 0; + } + + if (!read_ref_full("HEAD", RESOLVE_REF_READING, oid.hash, &flag)) + return fn("HEAD", &oid, flag, cb_data); + + return 0; +} + +int head_ref(each_ref_fn fn, void *cb_data) +{ + return head_ref_submodule(NULL, fn, cb_data); +} diff --git a/refs/files-backend.c b/refs/files-backend.c index b569762..2e2a6d9 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -1753,34 +1753,6 @@ static int do_for_each_ref(struct ref_cache *refs, const char *base, return do_for_each_entry(refs, base, do_one_ref, &data); } -static int do_head_ref(const char *submodule, each_ref_fn fn, void *cb_data) -{ - struct object_id oid; - int flag; - - if (submodule) { - if (resolve_gitlink_ref(submodule, "HEAD", oid.hash) == 0) - return fn("HEAD", &oid, 0, cb_data); - - return 0; - } - - if (!read_ref_full("HEAD", RESOLVE_REF_READING, oid.hash, &flag)) - return fn("HEAD", &oid, flag, cb_data); - - return 0; -} - -int head_ref(each_ref_fn fn, void *cb_data) -{ - return do_head_ref(NULL, fn, cb_data); -} - -int head_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data) -{ - return do_head_ref(submodule, fn, cb_data); -} - int for_each_ref(each_ref_fn fn, void *cb_data) { return do_for_each_ref(&ref_cache, "", fn, 0, 0, cb_data);
-- 2.4.2.767.g62658d5-twtrsrc