summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2019-05-09 00:37:24 +0900
committerLibravatar Junio C Hamano <gitster@pobox.com>2019-05-09 00:37:25 +0900
commit0b179f3175d1a152b1d22ce8352efda34b258ce2 (patch)
tree9e16191a22ae5cd48da67b0197af2aa94fc45462
parentMerge branch 'cc/replace-graft-peel-tags' (diff)
parentsha1-name.c: remove the_repo from get_oid_mb() (diff)
downloadtgif-0b179f3175d1a152b1d22ce8352efda34b258ce2.tar.xz
Merge branch 'nd/sha1-name-c-wo-the-repository'
Further code clean-up to allow the lowest level of name-to-object mapping layer to work with a passed-in repository other than the default one. * nd/sha1-name-c-wo-the-repository: (34 commits) sha1-name.c: remove the_repo from get_oid_mb() sha1-name.c: remove the_repo from other get_oid_* sha1-name.c: remove the_repo from maybe_die_on_misspelt_object_name submodule-config.c: use repo_get_oid for reading .gitmodules sha1-name.c: add repo_get_oid() sha1-name.c: remove the_repo from get_oid_with_context_1() sha1-name.c: remove the_repo from resolve_relative_path() sha1-name.c: remove the_repo from diagnose_invalid_index_path() sha1-name.c: remove the_repo from handle_one_ref() sha1-name.c: remove the_repo from get_oid_1() sha1-name.c: remove the_repo from get_oid_basic() sha1-name.c: remove the_repo from get_describe_name() sha1-name.c: remove the_repo from get_oid_oneline() sha1-name.c: add repo_interpret_branch_name() sha1-name.c: remove the_repo from interpret_branch_mark() sha1-name.c: remove the_repo from interpret_nth_prior_checkout() sha1-name.c: remove the_repo from get_short_oid() sha1-name.c: add repo_for_each_abbrev() sha1-name.c: store and use repo in struct disambiguate_state sha1-name.c: add repo_find_unique_abbrev_r() ...
-rw-r--r--builtin/rebase.c5
-rw-r--r--builtin/show-branch.c6
-rw-r--r--cache.h52
-rw-r--r--commit-graph.c9
-rw-r--r--commit.c14
-rw-r--r--commit.h5
-rw-r--r--contrib/coccinelle/commit.cocci20
-rw-r--r--dir.c8
-rw-r--r--dir.h4
-rw-r--r--merge-recursive.c7
-rw-r--r--packfile.c14
-rw-r--r--packfile.h3
-rw-r--r--refs.c71
-rw-r--r--refs.h9
-rw-r--r--setup.c7
-rw-r--r--sha1-name.c388
-rw-r--r--submodule-config.c20
-rwxr-xr-xt/t7814-grep-recurse-submodules.sh6
-rw-r--r--upload-pack.c2
19 files changed, 408 insertions, 242 deletions
diff --git a/builtin/rebase.c b/builtin/rebase.c
index 2e41ad5644..966b953e86 100644
--- a/builtin/rebase.c
+++ b/builtin/rebase.c
@@ -1568,8 +1568,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
branch_name = options.head_name;
} else {
- free(options.head_name);
- options.head_name = NULL;
+ FREE_AND_NULL(options.head_name);
branch_name = "HEAD";
}
if (get_oid("HEAD", &options.orig_head))
@@ -1769,7 +1768,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
* we just fast-forwarded.
*/
strbuf_reset(&msg);
- if (!oidcmp(&merge_base, &options.orig_head)) {
+ if (oideq(&merge_base, &options.orig_head)) {
printf(_("Fast-forwarded %s to %s.\n"),
branch_name, options.onto_name);
strbuf_addf(&msg, "rebase finished: %s onto %s",
diff --git a/builtin/show-branch.c b/builtin/show-branch.c
index 934e514944..082daeac32 100644
--- a/builtin/show-branch.c
+++ b/builtin/show-branch.c
@@ -753,7 +753,8 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
/* Ah, that is a date spec... */
timestamp_t at;
at = approxidate(reflog_base);
- read_ref_at(ref, flags, at, -1, &oid, NULL,
+ read_ref_at(get_main_ref_store(the_repository),
+ ref, flags, at, -1, &oid, NULL,
NULL, NULL, &base);
}
}
@@ -765,7 +766,8 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
timestamp_t timestamp;
int tz;
- if (read_ref_at(ref, flags, 0, base + i, &oid, &logmsg,
+ if (read_ref_at(get_main_ref_store(the_repository),
+ ref, flags, 0, base + i, &oid, &logmsg,
&timestamp, &tz, NULL)) {
reflog = i;
break;
diff --git a/cache.h b/cache.h
index 9f2fb7b2ea..67cc2e1806 100644
--- a/cache.h
+++ b/cache.h
@@ -1047,8 +1047,10 @@ extern void check_repository_format(void);
* Note that while this version avoids the static buffer, it is not fully
* reentrant, as it calls into other non-reentrant git code.
*/
-extern const char *find_unique_abbrev(const struct object_id *oid, int len);
-extern int find_unique_abbrev_r(char *hex, const struct object_id *oid, int len);
+const char *repo_find_unique_abbrev(struct repository *r, const struct object_id *oid, int len);
+#define find_unique_abbrev(oid, len) repo_find_unique_abbrev(the_repository, oid, len)
+int repo_find_unique_abbrev_r(struct repository *r, char *hex, const struct object_id *oid, int len);
+#define find_unique_abbrev_r(hex, oid, len) repo_find_unique_abbrev_r(the_repository, hex, oid, len)
extern const unsigned char null_sha1[GIT_MAX_RAWSZ];
extern const struct object_id null_oid;
@@ -1380,20 +1382,32 @@ enum get_oid_result {
*/
};
-extern int get_oid(const char *str, struct object_id *oid);
-extern int get_oidf(struct object_id *oid, const char *fmt, ...);
-extern int get_oid_commit(const char *str, struct object_id *oid);
-extern int get_oid_committish(const char *str, struct object_id *oid);
-extern int get_oid_tree(const char *str, struct object_id *oid);
-extern int get_oid_treeish(const char *str, struct object_id *oid);
-extern int get_oid_blob(const char *str, struct object_id *oid);
-extern void maybe_die_on_misspelt_object_name(const char *name, const char *prefix);
+int repo_get_oid(struct repository *r, const char *str, struct object_id *oid);
+int get_oidf(struct object_id *oid, const char *fmt, ...);
+int repo_get_oid_commit(struct repository *r, const char *str, struct object_id *oid);
+int repo_get_oid_committish(struct repository *r, const char *str, struct object_id *oid);
+int repo_get_oid_tree(struct repository *r, const char *str, struct object_id *oid);
+int repo_get_oid_treeish(struct repository *r, const char *str, struct object_id *oid);
+int repo_get_oid_blob(struct repository *r, const char *str, struct object_id *oid);
+int repo_get_oid_mb(struct repository *r, const char *str, struct object_id *oid);
+void maybe_die_on_misspelt_object_name(struct repository *repo,
+ const char *name,
+ const char *prefix);
extern enum get_oid_result get_oid_with_context(struct repository *repo, const char *str,
unsigned flags, struct object_id *oid,
struct object_context *oc);
+#define get_oid(str, oid) repo_get_oid(the_repository, str, oid)
+#define get_oid_commit(str, oid) repo_get_oid_commit(the_repository, str, oid)
+#define get_oid_committish(str, oid) repo_get_oid_committish(the_repository, str, oid)
+#define get_oid_tree(str, oid) repo_get_oid_tree(the_repository, str, oid)
+#define get_oid_treeish(str, oid) repo_get_oid_treeish(the_repository, str, oid)
+#define get_oid_blob(str, oid) repo_get_oid_blob(the_repository, str, oid)
+#define get_oid_mb(str, oid) repo_get_oid_mb(the_repository, str, oid)
+
typedef int each_abbrev_fn(const struct object_id *oid, void *);
-extern int for_each_abbrev(const char *prefix, each_abbrev_fn, void *);
+int repo_for_each_abbrev(struct repository *r, const char *prefix, each_abbrev_fn, void *);
+#define for_each_abbrev(prefix, fn, data) repo_for_each_abbrev(the_repository, prefix, fn, data)
extern int set_disambiguate_hint_config(const char *var, const char *value);
@@ -1471,9 +1485,12 @@ extern int parse_oid_hex(const char *hex, struct object_id *oid, const char **en
#define INTERPRET_BRANCH_LOCAL (1<<0)
#define INTERPRET_BRANCH_REMOTE (1<<1)
#define INTERPRET_BRANCH_HEAD (1<<2)
-extern int interpret_branch_name(const char *str, int len, struct strbuf *,
- unsigned allowed);
-extern int get_oid_mb(const char *str, struct object_id *oid);
+int repo_interpret_branch_name(struct repository *r,
+ const char *str, int len,
+ struct strbuf *buf,
+ unsigned allowed);
+#define interpret_branch_name(str, len, buf, allowed) \
+ repo_interpret_branch_name(the_repository, str, len, buf, allowed)
extern int validate_headref(const char *ref);
@@ -1487,8 +1504,11 @@ extern void *read_object_with_reference(const struct object_id *oid,
unsigned long *size,
struct object_id *oid_ret);
-extern struct object *peel_to_type(const char *name, int namelen,
- struct object *o, enum object_type);
+struct object *repo_peel_to_type(struct repository *r,
+ const char *name, int namelen,
+ struct object *o, enum object_type);
+#define peel_to_type(name, namelen, obj, type) \
+ repo_peel_to_type(the_repository, name, namelen, obj, type)
enum date_mode_type {
DATE_NORMAL = 0,
diff --git a/commit-graph.c b/commit-graph.c
index 66865acbd7..7bcc9bb7e0 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -397,6 +397,11 @@ static void fill_commit_graph_info(struct commit *item, struct commit_graph *g,
item->generation = get_be32(commit_data + g->hash_len + 8) >> 2;
}
+static inline void set_commit_tree(struct commit *c, struct tree *t)
+{
+ c->maybe_tree = t;
+}
+
static int fill_commit_in_graph(struct repository *r,
struct commit *item,
struct commit_graph *g, uint32_t pos)
@@ -410,7 +415,7 @@ static int fill_commit_in_graph(struct repository *r,
item->object.parsed = 1;
item->graph_pos = pos;
- item->maybe_tree = NULL;
+ set_commit_tree(item, NULL);
date_high = get_be32(commit_data + g->hash_len + 8) & 0x3;
date_low = get_be32(commit_data + g->hash_len + 12);
@@ -496,7 +501,7 @@ static struct tree *load_tree_for_commit(struct repository *r,
GRAPH_DATA_WIDTH * (c->graph_pos);
hashcpy(oid.hash, commit_data);
- c->maybe_tree = lookup_tree(r, &oid);
+ set_commit_tree(c, lookup_tree(r, &oid));
return c->maybe_tree;
}
diff --git a/commit.c b/commit.c
index a5333c7ac6..a9e74647dc 100644
--- a/commit.c
+++ b/commit.c
@@ -340,7 +340,13 @@ void free_commit_buffer(struct parsed_object_pool *pool, struct commit *commit)
}
}
-struct tree *get_commit_tree(const struct commit *commit)
+static inline void set_commit_tree(struct commit *c, struct tree *t)
+{
+ c->maybe_tree = t;
+}
+
+struct tree *repo_get_commit_tree(struct repository *r,
+ const struct commit *commit)
{
if (commit->maybe_tree || !commit->object.parsed)
return commit->maybe_tree;
@@ -348,7 +354,7 @@ struct tree *get_commit_tree(const struct commit *commit)
if (commit->graph_pos == COMMIT_NOT_FROM_GRAPH)
BUG("commit has NULL tree, but was not loaded from commit-graph");
- return get_commit_tree_in_graph(the_repository, commit);
+ return get_commit_tree_in_graph(r, commit);
}
struct object_id *get_commit_tree_oid(const struct commit *commit)
@@ -358,7 +364,7 @@ struct object_id *get_commit_tree_oid(const struct commit *commit)
void release_commit_memory(struct parsed_object_pool *pool, struct commit *c)
{
- c->maybe_tree = NULL;
+ set_commit_tree(c, NULL);
c->index = 0;
free_commit_buffer(pool, c);
free_commit_list(c->parents);
@@ -406,7 +412,7 @@ int parse_commit_buffer(struct repository *r, struct commit *item, const void *b
if (get_oid_hex(bufptr + 5, &parent) < 0)
return error("bad tree pointer in commit %s",
oid_to_hex(&item->object.oid));
- item->maybe_tree = lookup_tree(r, &parent);
+ set_commit_tree(item, lookup_tree(r, &parent));
bufptr += tree_entry_len + 1; /* "tree " + "hex sha1" + "\n" */
pptr = &item->parents;
diff --git a/commit.h b/commit.h
index 8f1f39f4c3..cc19cb5314 100644
--- a/commit.h
+++ b/commit.h
@@ -32,7 +32,7 @@ struct commit {
/*
* If the commit is loaded from the commit-graph file, then this
- * member may be NULL. Only access it through get_commit_tree()
+ * member may be NULL. Only access it through repo_get_commit_tree()
* or get_commit_tree_oid().
*/
struct tree *maybe_tree;
@@ -149,7 +149,8 @@ void repo_unuse_commit_buffer(struct repository *r,
*/
void free_commit_buffer(struct parsed_object_pool *pool, struct commit *);
-struct tree *get_commit_tree(const struct commit *);
+struct tree *repo_get_commit_tree(struct repository *, const struct commit *);
+#define get_commit_tree(c) repo_get_commit_tree(the_repository, c)
struct object_id *get_commit_tree_oid(const struct commit *);
/*
diff --git a/contrib/coccinelle/commit.cocci b/contrib/coccinelle/commit.cocci
index c49aa558f0..d03453341e 100644
--- a/contrib/coccinelle/commit.cocci
+++ b/contrib/coccinelle/commit.cocci
@@ -10,19 +10,25 @@ expression c;
- c->maybe_tree->object.oid.hash
+ get_commit_tree_oid(c)->hash
-// These excluded functions must access c->maybe_tree direcly.
@@
-identifier f !~ "^(get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit)$";
+identifier f !~ "^set_commit_tree$";
expression c;
+expression s;
@@
f(...) {<...
-- c->maybe_tree
-+ get_commit_tree(c)
+- c->maybe_tree = s
++ set_commit_tree(c, s)
...>}
+// These excluded functions must access c->maybe_tree direcly.
+// Note that if c->maybe_tree is written somewhere outside of these
+// functions, then the recommended transformation will be bogus with
+// repo_get_commit_tree() on the LHS.
@@
+identifier f !~ "^(repo_get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit|set_commit_tree)$";
expression c;
-expression s;
@@
-- get_commit_tree(c) = s
-+ c->maybe_tree = s
+ f(...) {<...
+- c->maybe_tree
++ repo_get_commit_tree(specify_the_right_repo_here, c)
+ ...>}
diff --git a/dir.c b/dir.c
index 0a3ddcf2bc..2ccd4db664 100644
--- a/dir.c
+++ b/dir.c
@@ -2316,6 +2316,14 @@ int file_exists(const char *f)
return lstat(f, &sb) == 0;
}
+int repo_file_exists(struct repository *repo, const char *path)
+{
+ if (repo != the_repository)
+ BUG("do not know how to check file existence in arbitrary repo");
+
+ return file_exists(path);
+}
+
static int cmp_icase(char a, char b)
{
if (a == b)
diff --git a/dir.h b/dir.h
index 823bae628b..c23313b021 100644
--- a/dir.h
+++ b/dir.h
@@ -269,7 +269,9 @@ extern void add_exclude(const char *string, const char *base,
int baselen, struct exclude_list *el, int srcpos);
extern void clear_exclude_list(struct exclude_list *el);
extern void clear_directory(struct dir_struct *dir);
-extern int file_exists(const char *);
+
+int repo_file_exists(struct repository *repo, const char *path);
+int file_exists(const char *);
extern int is_inside_dir(const char *dir);
extern int dir_inside_of(const char *subdir, const char *dir);
diff --git a/merge-recursive.c b/merge-recursive.c
index 69abd6edec..a7bcfcbeb4 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -163,6 +163,11 @@ static struct tree *shift_tree_object(struct repository *repo,
return lookup_tree(repo, &shifted);
}
+static inline void set_commit_tree(struct commit *c, struct tree *t)
+{
+ c->maybe_tree = t;
+}
+
static struct commit *make_virtual_commit(struct repository *repo,
struct tree *tree,
const char *comment)
@@ -170,7 +175,7 @@ static struct commit *make_virtual_commit(struct repository *repo,
struct commit *commit = alloc_commit_node(repo);
set_merge_remote_desc(commit, comment, (struct object *)commit);
- commit->maybe_tree = tree;
+ set_commit_tree(commit, tree);
commit->object.parsed = 1;
return commit;
}
diff --git a/packfile.c b/packfile.c
index cdf6b6ec34..9f52af9281 100644
--- a/packfile.c
+++ b/packfile.c
@@ -903,25 +903,25 @@ static void prepare_packed_git(struct repository *r);
* all unreachable objects about to be pruned, in which case they're not really
* interesting as a measure of repo size in the first place.
*/
-unsigned long approximate_object_count(void)
+unsigned long repo_approximate_object_count(struct repository *r)
{
- if (!the_repository->objects->approximate_object_count_valid) {
+ if (!r->objects->approximate_object_count_valid) {
unsigned long count;
struct multi_pack_index *m;
struct packed_git *p;
- prepare_packed_git(the_repository);
+ prepare_packed_git(r);
count = 0;
- for (m = get_multi_pack_index(the_repository); m; m = m->next)
+ for (m = get_multi_pack_index(r); m; m = m->next)
count += m->num_objects;
- for (p = the_repository->objects->packed_git; p; p = p->next) {
+ for (p = r->objects->packed_git; p; p = p->next) {
if (open_pack_index(p))
continue;
count += p->num_objects;
}
- the_repository->objects->approximate_object_count = count;
+ r->objects->approximate_object_count = count;
}
- return the_repository->objects->approximate_object_count;
+ return r->objects->approximate_object_count;
}
static void *get_next_packed_git(const void *p)
diff --git a/packfile.h b/packfile.h
index 12baa6118a..b678d35c0b 100644
--- a/packfile.h
+++ b/packfile.h
@@ -63,7 +63,8 @@ struct packed_git *get_all_packs(struct repository *r);
* Give a rough count of objects in the repository. This sacrifices accuracy
* for speed.
*/
-unsigned long approximate_object_count(void);
+unsigned long repo_approximate_object_count(struct repository *r);
+#define approximate_object_count() repo_approximate_object_count(the_repository)
struct packed_git *find_sha1_pack(const unsigned char *sha1,
struct packed_git *packs);
diff --git a/refs.c b/refs.c
index 142888a40a..92d1f6dbdd 100644
--- a/refs.c
+++ b/refs.c
@@ -241,9 +241,14 @@ int read_ref(const char *refname, struct object_id *oid)
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,
@@ -534,10 +539,11 @@ void expand_ref_prefix(struct argv_array *prefixes, const char *prefix)
* 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;
@@ -549,15 +555,22 @@ static char *substitute_branch_name(const char **string, int *len)
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;
@@ -572,8 +585,9 @@ int expand_ref(const char *str, int len, struct object_id *oid, char **ref)
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);
@@ -589,9 +603,11 @@ int expand_ref(const char *str, int len, struct object_id *oid, char **ref)
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;
@@ -603,13 +619,15 @@ int dwim_log(const char *str, int len, struct object_id *oid, char **log)
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;
@@ -625,6 +643,11 @@ int dwim_log(const char *str, int len, struct object_id *oid, char **log)
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") ||
@@ -944,7 +967,8 @@ static int read_ref_at_ent_oldest(struct object_id *ooid, struct object_id *noid
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)
{
@@ -960,7 +984,7 @@ int read_ref_at(const char *refname, unsigned int flags, timestamp_t at_time, in
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)
@@ -971,7 +995,7 @@ int read_ref_at(const char *refname, unsigned int flags, timestamp_t at_time, in
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;
}
@@ -1164,7 +1188,8 @@ int update_ref(const char *msg, const char *refname,
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;
@@ -1242,7 +1267,7 @@ char *shorten_unambiguous_ref(const char *refname, int strict)
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;
}
@@ -1261,6 +1286,12 @@ char *shorten_unambiguous_ref(const char *refname, int strict)
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)
diff --git a/refs.h b/refs.h
index 308fa1f03b..8f9cbf8a93 100644
--- a/refs.h
+++ b/refs.h
@@ -148,7 +148,9 @@ int refname_match(const char *abbrev_name, const char *full_name);
struct argv_array;
void expand_ref_prefix(struct argv_array *prefixes, const char *prefix);
-int expand_ref(const char *str, int len, struct object_id *oid, char **ref);
+int expand_ref(struct repository *r, 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);
+int repo_dwim_log(struct repository *r, 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);
int dwim_log(const char *str, int len, struct object_id *oid, char **ref);
@@ -386,7 +388,8 @@ int refs_create_reflog(struct ref_store *refs, const char *refname,
int safe_create_reflog(const char *refname, int force_create, struct strbuf *err);
/** Reads log for the value of ref during at_time. **/
-int read_ref_at(const char *refname, unsigned int flags,
+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);
@@ -462,6 +465,8 @@ int check_refname_format(const char *refname, int flags);
const char *prettify_refname(const char *refname);
+char *refs_shorten_unambiguous_ref(struct ref_store *refs,
+ const char *refname, int strict);
char *shorten_unambiguous_ref(const char *refname, int strict);
/** rename ref, return 0 on success **/
diff --git a/setup.c b/setup.c
index d0c958c3b2..8dcb4631f7 100644
--- a/setup.c
+++ b/setup.c
@@ -164,7 +164,8 @@ int check_filename(const char *prefix, const char *arg)
die_errno(_("failed to stat '%s'"), arg);
}
-static void NORETURN die_verify_filename(const char *prefix,
+static void NORETURN die_verify_filename(struct repository *r,
+ const char *prefix,
const char *arg,
int diagnose_misspelt_rev)
{
@@ -179,7 +180,7 @@ static void NORETURN die_verify_filename(const char *prefix,
* let maybe_die_on_misspelt_object_name() even trigger.
*/
if (!(arg[0] == ':' && !isalnum(arg[1])))
- maybe_die_on_misspelt_object_name(arg, prefix);
+ maybe_die_on_misspelt_object_name(r, arg, prefix);
/* ... or fall back the most general message. */
die(_("ambiguous argument '%s': unknown revision or path not in the working tree.\n"
@@ -234,7 +235,7 @@ void verify_filename(const char *prefix,
die(_("option '%s' must come before non-option arguments"), arg);
if (looks_like_pathspec(arg) || check_filename(prefix, arg))
return;
- die_verify_filename(prefix, arg, diagnose_misspelt_rev);
+ die_verify_filename(the_repository, prefix, arg, diagnose_misspelt_rev);
}
/*
diff --git a/sha1-name.c b/sha1-name.c
index 7754d3a3de..775a73d8ad 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -12,18 +12,20 @@
#include "packfile.h"
#include "object-store.h"
#include "repository.h"
+#include "submodule.h"
#include "midx.h"
#include "commit-reach.h"
-static int get_oid_oneline(const char *, struct object_id *, struct commit_list *);
+static int get_oid_oneline(struct repository *r, const char *, struct object_id *, struct commit_list *);
-typedef int (*disambiguate_hint_fn)(const struct object_id *, void *);
+typedef int (*disambiguate_hint_fn)(struct repository *, const struct object_id *, void *);
struct disambiguate_state {
int len; /* length of prefix in hex chars */
char hex_pfx[GIT_MAX_HEXSZ + 1];
struct object_id bin_pfx;
+ struct repository *repo;
disambiguate_hint_fn fn;
void *cb_data;
struct object_id candidate;
@@ -38,7 +40,7 @@ struct disambiguate_state {
static void update_candidates(struct disambiguate_state *ds, const struct object_id *current)
{
if (ds->always_call_fn) {
- ds->ambiguous = ds->fn(current, ds->cb_data) ? 1 : 0;
+ ds->ambiguous = ds->fn(ds->repo, current, ds->cb_data) ? 1 : 0;
return;
}
if (!ds->candidate_exists) {
@@ -58,7 +60,7 @@ static void update_candidates(struct disambiguate_state *ds, const struct object
}
if (!ds->candidate_checked) {
- ds->candidate_ok = ds->fn(&ds->candidate, ds->cb_data);
+ ds->candidate_ok = ds->fn(ds->repo, &ds->candidate, ds->cb_data);
ds->disambiguate_fn_used = 1;
ds->candidate_checked = 1;
}
@@ -71,7 +73,7 @@ static void update_candidates(struct disambiguate_state *ds, const struct object
}
/* if we reach this point, we know ds->candidate satisfies fn */
- if (ds->fn(current, ds->cb_data)) {
+ if (ds->fn(ds->repo, current, ds->cb_data)) {
/*
* if both current and candidate satisfy fn, we cannot
* disambiguate.
@@ -89,9 +91,7 @@ static void find_short_object_filename(struct disambiguate_state *ds)
{
struct object_directory *odb;
- for (odb = the_repository->objects->odb;
- odb && !ds->ambiguous;
- odb = odb->next) {
+ for (odb = ds->repo->objects->odb; odb && !ds->ambiguous; odb = odb->next) {
int pos;
struct oid_array *loose_objects;
@@ -182,10 +182,10 @@ static void find_short_packed_object(struct disambiguate_state *ds)
struct multi_pack_index *m;
struct packed_git *p;
- for (m = get_multi_pack_index(the_repository); m && !ds->ambiguous;
+ for (m = get_multi_pack_index(ds->repo); m && !ds->ambiguous;
m = m->next)
unique_in_midx(m, ds);
- for (p = get_packed_git(the_repository); p && !ds->ambiguous;
+ for (p = get_packed_git(ds->repo); p && !ds->ambiguous;
p = p->next)
unique_in_pack(p, ds);
}
@@ -215,7 +215,7 @@ static int finish_object_disambiguation(struct disambiguate_state *ds,
* same repository!
*/
ds->candidate_ok = (!ds->disambiguate_fn_used ||
- ds->fn(&ds->candidate, ds->cb_data));
+ ds->fn(ds->repo, &ds->candidate, ds->cb_data));
if (!ds->candidate_ok)
return SHORT_NAME_AMBIGUOUS;
@@ -224,59 +224,67 @@ static int finish_object_disambiguation(struct disambiguate_state *ds,
return 0;
}
-static int disambiguate_commit_only(const struct object_id *oid, void *cb_data_unused)
+static int disambiguate_commit_only(struct repository *r,
+ const struct object_id *oid,
+ void *cb_data_unused)
{
- int kind = oid_object_info(the_repository, oid, NULL);
+ int kind = oid_object_info(r, oid, NULL);
return kind == OBJ_COMMIT;
}
-static int disambiguate_committish_only(const struct object_id *oid, void *cb_data_unused)
+static int disambiguate_committish_only(struct repository *r,
+ const struct object_id *oid,
+ void *cb_data_unused)
{
struct object *obj;
int kind;
- kind = oid_object_info(the_repository, oid, NULL);
+ kind = oid_object_info(r, oid, NULL);
if (kind == OBJ_COMMIT)
return 1;
if (kind != OBJ_TAG)
return 0;
/* We need to do this the hard way... */
- obj = deref_tag(the_repository, parse_object(the_repository, oid),
- NULL, 0);
+ obj = deref_tag(r, parse_object(r, oid), NULL, 0);
if (obj && obj->type == OBJ_COMMIT)
return 1;
return 0;
}
-static int disambiguate_tree_only(const struct object_id *oid, void *cb_data_unused)
+static int disambiguate_tree_only(struct repository *r,
+ const struct object_id *oid,
+ void *cb_data_unused)
{
- int kind = oid_object_info(the_repository, oid, NULL);
+ int kind = oid_object_info(r, oid, NULL);
return kind == OBJ_TREE;
}
-static int disambiguate_treeish_only(const struct object_id *oid, void *cb_data_unused)
+static int disambiguate_treeish_only(struct repository *r,
+ const struct object_id *oid,
+ void *cb_data_unused)
{
struct object *obj;
int kind;
- kind = oid_object_info(the_repository, oid, NULL);
+ kind = oid_object_info(r, oid, NULL);
if (kind == OBJ_TREE || kind == OBJ_COMMIT)
return 1;
if (kind != OBJ_TAG)
return 0;
/* We need to do this the hard way... */
- obj = deref_tag(the_repository, parse_object(the_repository, oid),
- NULL, 0);
+ obj = deref_tag(r, parse_object(r, oid), NULL, 0);
if (obj && (obj->type == OBJ_TREE || obj->type == OBJ_COMMIT))
return 1;
return 0;
}
-static int disambiguate_blob_only(const struct object_id *oid, void *cb_data_unused)
+static int disambiguate_blob_only(struct repository *r,
+ const struct object_id *oid,
+ void *cb_data_unused)
{
- int kind = oid_object_info(the_repository, oid, NULL);
+ int kind = oid_object_info(r, oid, NULL);
return kind == OBJ_BLOB;
}
@@ -310,7 +318,8 @@ int set_disambiguate_hint_config(const char *var, const char *value)
return error("unknown hint type for '%s':