return read_ref_full(refname, RESOLVE_REF_READING, oid, NULL);
}
+static int refs_ref_exists(struct ref_store *refs, const char *refname)
+{
+ return !!refs_resolve_ref_unsafe(refs, refname, RESOLVE_REF_READING, NULL, NULL);
+}
+
int ref_exists(const char *refname)
{
- return !!resolve_ref_unsafe(refname, RESOLVE_REF_READING, NULL, NULL);
+ return refs_ref_exists(get_main_ref_store(the_repository), refname);
}
static int match_ref_pattern(const char *refname,
* later free()ing) if the string passed in is a magic short-hand form
* to name a branch.
*/
-static char *substitute_branch_name(const char **string, int *len)
+static char *substitute_branch_name(struct repository *r,
+ const char **string, int *len)
{
struct strbuf buf = STRBUF_INIT;
- int ret = interpret_branch_name(*string, *len, &buf, 0);
+ int ret = repo_interpret_branch_name(r, *string, *len, &buf, 0);
if (ret == *len) {
size_t size;
return NULL;
}
-int dwim_ref(const char *str, int len, struct object_id *oid, char **ref)
+int repo_dwim_ref(struct repository *r, const char *str, int len,
+ struct object_id *oid, char **ref)
{
- char *last_branch = substitute_branch_name(&str, &len);
- int refs_found = expand_ref(str, len, oid, ref);
+ char *last_branch = substitute_branch_name(r, &str, &len);
+ int refs_found = expand_ref(r, str, len, oid, ref);
free(last_branch);
return refs_found;
}
-int expand_ref(const char *str, int len, struct object_id *oid, char **ref)
+int dwim_ref(const char *str, int len, struct object_id *oid, char **ref)
+{
+ return repo_dwim_ref(the_repository, str, len, oid, ref);
+}
+
+int expand_ref(struct repository *repo, const char *str, int len,
+ struct object_id *oid, char **ref)
{
const char **p, *r;
int refs_found = 0;
this_result = refs_found ? &oid_from_ref : oid;
strbuf_reset(&fullref);
strbuf_addf(&fullref, *p, len, str);
- r = resolve_ref_unsafe(fullref.buf, RESOLVE_REF_READING,
- this_result, &flag);
+ r = refs_resolve_ref_unsafe(get_main_ref_store(repo),
+ fullref.buf, RESOLVE_REF_READING,
+ this_result, &flag);
if (r) {
if (!refs_found++)
*ref = xstrdup(r);
return refs_found;
}
-int dwim_log(const char *str, int len, struct object_id *oid, char **log)
+int repo_dwim_log(struct repository *r, const char *str, int len,
+ struct object_id *oid, char **log)
{
- char *last_branch = substitute_branch_name(&str, &len);
+ struct ref_store *refs = get_main_ref_store(r);
+ char *last_branch = substitute_branch_name(r, &str, &len);
const char **p;
int logs_found = 0;
struct strbuf path = STRBUF_INIT;
strbuf_reset(&path);
strbuf_addf(&path, *p, len, str);
- ref = resolve_ref_unsafe(path.buf, RESOLVE_REF_READING,
- &hash, NULL);
+ ref = refs_resolve_ref_unsafe(refs, path.buf,
+ RESOLVE_REF_READING,
+ &hash, NULL);
if (!ref)
continue;
- if (reflog_exists(path.buf))
+ if (refs_reflog_exists(refs, path.buf))
it = path.buf;
- else if (strcmp(ref, path.buf) && reflog_exists(ref))
+ else if (strcmp(ref, path.buf) &&
+ refs_reflog_exists(refs, ref))
it = ref;
else
continue;
return logs_found;
}
+int dwim_log(const char *str, int len, struct object_id *oid, char **log)
+{
+ return repo_dwim_log(the_repository, str, len, oid, log);
+}
+
static int is_per_worktree_ref(const char *refname)
{
return !strcmp(refname, "HEAD") ||
return 1;
}
-int read_ref_at(const char *refname, unsigned int flags, timestamp_t at_time, int cnt,
+int read_ref_at(struct ref_store *refs, const char *refname,
+ unsigned int flags, timestamp_t at_time, int cnt,
struct object_id *oid, char **msg,
timestamp_t *cutoff_time, int *cutoff_tz, int *cutoff_cnt)
{
cb.cutoff_cnt = cutoff_cnt;
cb.oid = oid;
- for_each_reflog_ent_reverse(refname, read_ref_at_ent, &cb);
+ refs_for_each_reflog_ent_reverse(refs, refname, read_ref_at_ent, &cb);
if (!cb.reccnt) {
if (flags & GET_OID_QUIETLY)
if (cb.found_it)
return 0;
- for_each_reflog_ent(refname, read_ref_at_ent_oldest, &cb);
+ refs_for_each_reflog_ent(refs, refname, read_ref_at_ent_oldest, &cb);
return 1;
}
old_oid, flags, onerr);
}
-char *shorten_unambiguous_ref(const char *refname, int strict)
+char *refs_shorten_unambiguous_ref(struct ref_store *refs,
+ const char *refname, int strict)
{
int i;
static char **scanf_fmts;
strbuf_reset(&resolved_buf);
strbuf_addf(&resolved_buf, rule,
short_name_len, short_name);
- if (ref_exists(resolved_buf.buf))
+ if (refs_ref_exists(refs, resolved_buf.buf))
break;
}
return xstrdup(refname);
}
+char *shorten_unambiguous_ref(const char *refname, int strict)
+{
+ return refs_shorten_unambiguous_ref(get_main_ref_store(the_repository),
+ refname, strict);
+}
+
static struct string_list *hide_refs;
int parse_hide_refs_config(const char *var, const char *value, const char *section)