From 8f56e9d4baa836a4a3cd56767457d6122de7ce1d Mon Sep 17 00:00:00 2001 From: Nguyễn Thái Ngọc Duy Date: Sat, 6 Apr 2019 18:34:26 +0700 Subject: refs.c: remove the_repo from substitute_branch_name() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- cache.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index ac92421f3a..fcb24b5781 100644 --- a/cache.h +++ b/cache.h @@ -1468,8 +1468,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); +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 get_oid_mb(const char *str, struct object_id *oid); extern int validate_headref(const char *ref); -- cgit v1.2.3 From 8bb95572b05d70cce6ea6eef9396cdaf6b34b14f Mon Sep 17 00:00:00 2001 From: Nguyễn Thái Ngọc Duy Date: Tue, 16 Apr 2019 16:33:22 +0700 Subject: sha1-name.c: add repo_find_unique_abbrev_r() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- cache.h | 6 ++++-- sha1-name.c | 15 +++++++++------ 2 files changed, 13 insertions(+), 8 deletions(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index fcb24b5781..4f8ebb0a67 100644 --- a/cache.h +++ b/cache.h @@ -1045,8 +1045,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; diff --git a/sha1-name.c b/sha1-name.c index b9381aaba6..9b57787b76 100644 --- a/sha1-name.c +++ b/sha1-name.c @@ -626,15 +626,16 @@ static void find_abbrev_len_packed(struct min_abbrev_data *mad) find_abbrev_len_for_pack(p, mad); } -int find_unique_abbrev_r(char *hex, const struct object_id *oid, int len) +int repo_find_unique_abbrev_r(struct repository *r, char *hex, + const struct object_id *oid, int len) { struct disambiguate_state ds; struct min_abbrev_data mad; struct object_id oid_ret; - const unsigned hexsz = the_hash_algo->hexsz; + const unsigned hexsz = r->hash_algo->hexsz; if (len < 0) { - unsigned long count = approximate_object_count(); + unsigned long count = repo_approximate_object_count(r); /* * Add one because the MSB only tells us the highest bit set, * not including the value of all the _other_ bits (so "15" @@ -659,7 +660,7 @@ int find_unique_abbrev_r(char *hex, const struct object_id *oid, int len) if (len == hexsz || !len) return hexsz; - mad.repo = the_repository; + mad.repo = r; mad.init_len = len; mad.cur_len = len; mad.hex = hex; @@ -681,13 +682,15 @@ int find_unique_abbrev_r(char *hex, const struct object_id *oid, int len) return mad.cur_len; } -const char *find_unique_abbrev(const struct object_id *oid, int len) +const char *repo_find_unique_abbrev(struct repository *r, + const struct object_id *oid, + int len) { static int bufno; static char hexbuffer[4][GIT_MAX_HEXSZ + 1]; char *hex = hexbuffer[bufno]; bufno = (bufno + 1) % ARRAY_SIZE(hexbuffer); - find_unique_abbrev_r(hex, oid, len); + repo_find_unique_abbrev_r(r, hex, oid, len); return hex; } -- cgit v1.2.3 From 4e99f2dbea542bc5d7f696f7a358737eb521f040 Mon Sep 17 00:00:00 2001 From: Nguyễn Thái Ngọc Duy Date: Tue, 16 Apr 2019 16:33:24 +0700 Subject: sha1-name.c: add repo_for_each_abbrev() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- cache.h | 3 ++- sha1-name.c | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 4f8ebb0a67..0cb95c0d4f 100644 --- a/cache.h +++ b/cache.h @@ -1392,7 +1392,8 @@ extern enum get_oid_result get_oid_with_context(struct repository *repo, const c struct object_context *oc); 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); diff --git a/sha1-name.c b/sha1-name.c index a75992eb54..cdcf84b826 100644 --- a/sha1-name.c +++ b/sha1-name.c @@ -493,13 +493,14 @@ static enum get_oid_result get_short_oid(const char *name, int len, return status; } -int for_each_abbrev(const char *prefix, each_abbrev_fn fn, void *cb_data) +int repo_for_each_abbrev(struct repository *r, const char *prefix, + each_abbrev_fn fn, void *cb_data) { struct oid_array collect = OID_ARRAY_INIT; struct disambiguate_state ds; int ret; - if (init_object_disambiguation(the_repository, prefix, strlen(prefix), &ds) < 0) + if (init_object_disambiguation(r, prefix, strlen(prefix), &ds) < 0) return -1; ds.always_call_fn = 1; -- cgit v1.2.3 From 2b1790f5ab949abc86124d107ee4b7e7fef1323c Mon Sep 17 00:00:00 2001 From: Nguyễn Thái Ngọc Duy Date: Tue, 16 Apr 2019 16:33:32 +0700 Subject: sha1-name.c: remove the_repo from get_oid_1() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There is a cyclic dependency between one of these functions so they cannot be converted one by one, so all related functions are converted at once. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- cache.h | 7 +++++-- sha1-name.c | 59 +++++++++++++++++++++++++++++++---------------------------- 2 files changed, 36 insertions(+), 30 deletions(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 0cb95c0d4f..2149dc4f56 100644 --- a/cache.h +++ b/cache.h @@ -1491,8 +1491,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/sha1-name.c b/sha1-name.c index d4c135aea8..5741a9f821 100644 --- a/sha1-name.c +++ b/sha1-name.c @@ -770,7 +770,7 @@ static inline int push_mark(const char *string, int len) return at_mark(string, len, suffix, ARRAY_SIZE(suffix)); } -static enum get_oid_result get_oid_1(const char *name, int len, struct object_id *oid, unsigned lookup_flags); +static enum get_oid_result get_oid_1(struct repository *r, const char *name, int len, struct object_id *oid, unsigned lookup_flags); static int interpret_nth_prior_checkout(struct repository *r, const char *name, int namelen, struct strbuf *buf); static int get_oid_basic(struct repository *r, const char *str, int len, @@ -921,18 +921,19 @@ static int get_oid_basic(struct repository *r, const char *str, int len, return 0; } -static enum get_oid_result get_parent(const char *name, int len, +static enum get_oid_result get_parent(struct repository *r, + const char *name, int len, struct object_id *result, int idx) { struct object_id oid; - enum get_oid_result ret = get_oid_1(name, len, &oid, + enum get_oid_result ret = get_oid_1(r, name, len, &oid, GET_OID_COMMITTISH); struct commit *commit; struct commit_list *p; if (ret) return ret; - commit = lookup_commit_reference(the_repository, &oid); + commit = lookup_commit_reference(r, &oid); if (parse_commit(commit)) return MISSING_OBJECT; if (!idx) { @@ -950,7 +951,8 @@ static enum get_oid_result get_parent(const char *name, int len, return MISSING_OBJECT; } -static enum get_oid_result get_nth_ancestor(const char *name, int len, +static enum get_oid_result get_nth_ancestor(struct repository *r, + const char *name, int len, struct object_id *result, int generation) { @@ -958,10 +960,10 @@ static enum get_oid_result get_nth_ancestor(const char *name, int len, struct commit *commit; int ret; - ret = get_oid_1(name, len, &oid, GET_OID_COMMITTISH); + ret = get_oid_1(r, name, len, &oid, GET_OID_COMMITTISH); if (ret) return ret; - commit = lookup_commit_reference(the_repository, &oid); + commit = lookup_commit_reference(r, &oid); if (!commit) return MISSING_OBJECT; @@ -974,20 +976,20 @@ static enum get_oid_result get_nth_ancestor(const char *name, int len, return FOUND; } -struct object *peel_to_type(const char *name, int namelen, - struct object *o, enum object_type expected_type) +struct object *repo_peel_to_type(struct repository *r, const char *name, int namelen, + struct object *o, enum object_type expected_type) { if (name && !namelen) namelen = strlen(name); while (1) { - if (!o || (!o->parsed && !parse_object(the_repository, &o->oid))) + if (!o || (!o->parsed && !parse_object(r, &o->oid))) return NULL; if (expected_type == OBJ_ANY || o->type == expected_type) return o; if (o->type == OBJ_TAG) o = ((struct tag*) o)->tagged; else if (o->type == OBJ_COMMIT) - o = &(get_commit_tree(((struct commit *)o))->object); + o = &(repo_get_commit_tree(r, ((struct commit *)o))->object); else { if (name) error("%.*s: expected %s type, but the object " @@ -999,8 +1001,8 @@ struct object *peel_to_type(const char *name, int namelen, } } -static int peel_onion(const char *name, int len, struct object_id *oid, - unsigned lookup_flags) +static int peel_onion(struct repository *r, const char *name, int len, + struct object_id *oid, unsigned lookup_flags) { struct object_id outer; const char *sp; @@ -1050,15 +1052,15 @@ static int peel_onion(const char *name, int len, struct object_id *oid, else if (expected_type == OBJ_TREE) lookup_flags |= GET_OID_TREEISH; - if (get_oid_1(name, sp - name - 2, &outer, lookup_flags)) + if (get_oid_1(r, name, sp - name - 2, &outer, lookup_flags)) return -1; - o = parse_object(the_repository, &outer); + o = parse_object(r, &outer); if (!o) return -1; if (!expected_type) { - o = deref_tag(the_repository, o, name, sp - name - 2); - if (!o || (!o->parsed && !parse_object(the_repository, &o->oid))) + o = deref_tag(r, o, name, sp - name - 2); + if (!o || (!o->parsed && !parse_object(r, &o->oid))) return -1; oidcpy(oid, &o->oid); return 0; @@ -1069,7 +1071,7 @@ static int peel_onion(const char *name, int len, struct object_id *oid, * if we do not get the needed object, we should * barf. */ - o = peel_to_type(name, len, o, expected_type); + o = repo_peel_to_type(r, name, len, o, expected_type); if (!o) return -1; @@ -1089,7 +1091,7 @@ static int peel_onion(const char *name, int len, struct object_id *oid, prefix = xstrndup(sp + 1, name + len - 1 - (sp + 1)); commit_list_insert((struct commit *)o, &list); - ret = get_oid_oneline(the_repository, prefix, oid, list); + ret = get_oid_oneline(r, prefix, oid, list); free(prefix); return ret; } @@ -1120,7 +1122,8 @@ static int get_describe_name(struct repository *r, return -1; } -static enum get_oid_result get_oid_1(const char *name, int len, +static enum get_oid_result get_oid_1(struct repository *r, + const char *name, int len, struct object_id *oid, unsigned lookup_flags) { @@ -1149,25 +1152,25 @@ static enum get_oid_result get_oid_1(const char *name, int len, if (!num && len1 == len - 1) num = 1; if (has_suffix == '^') - return get_parent(name, len1, oid, num); + return get_parent(r, name, len1, oid, num); /* else if (has_suffix == '~') -- goes without saying */ - return get_nth_ancestor(name, len1, oid, num); + return get_nth_ancestor(r, name, len1, oid, num); } - ret = peel_onion(name, len, oid, lookup_flags); + ret = peel_onion(r, name, len, oid, lookup_flags); if (!ret) return FOUND; - ret = get_oid_basic(the_repository, name, len, oid, lookup_flags); + ret = get_oid_basic(r, name, len, oid, lookup_flags); if (!ret) return FOUND; /* It could be describe output that is "SOMETHING-gXXXX" */ - ret = get_describe_name(the_repository, name, len, oid); + ret = get_describe_name(r, name, len, oid); if (!ret) return FOUND; - return get_short_oid(the_repository, name, len, oid, lookup_flags); + return get_short_oid(r, name, len, oid, lookup_flags); } /* @@ -1741,7 +1744,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo, memset(oc, 0, sizeof(*oc)); oc->mode = S_IFINVALID; strbuf_init(&oc->symlink_path, 0); - ret = get_oid_1(name, namelen, oid, flags); + ret = get_oid_1(repo, name, namelen, oid, flags); if (!ret) return ret; /* @@ -1822,7 +1825,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo, sub_flags &= ~GET_OID_DISAMBIGUATORS; sub_flags |= GET_OID_TREEISH; - if (!get_oid_1(name, len, &tree_oid, sub_flags)) { + if (!get_oid_1(repo, name, len, &tree_oid, sub_flags)) { const char *filename = cp+1; char *new_filename = NULL; -- cgit v1.2.3 From ec580eaaa3bdc2327d049932d1ebb2ca62aae837 Mon Sep 17 00:00:00 2001 From: Nguyễn Thái Ngọc Duy Date: Tue, 16 Apr 2019 16:33:37 +0700 Subject: sha1-name.c: add repo_get_oid() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- cache.h | 3 ++- sha1-name.c | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 2149dc4f56..f6e87194d0 100644 --- a/cache.h +++ b/cache.h @@ -1380,7 +1380,8 @@ enum get_oid_result { */ }; -extern int get_oid(const char *str, struct object_id *oid); +int repo_get_oid(struct repository *r, const char *str, struct object_id *oid); +#define get_oid(str, oid) repo_get_oid(the_repository, str, oid) 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); diff --git a/sha1-name.c b/sha1-name.c index 64a50d1291..953df0d692 100644 --- a/sha1-name.c +++ b/sha1-name.c @@ -1573,10 +1573,10 @@ int strbuf_check_branch_ref(struct strbuf *sb, const char *name) * This is like "get_oid_basic()", except it allows "object ID expressions", * notably "xyz^" for "parent of xyz" */ -int get_oid(const char *name, struct object_id *oid) +int repo_get_oid(struct repository *r, const char *name, struct object_id *oid) { struct object_context unused; - return get_oid_with_context(the_repository, name, 0, oid, &unused); + return get_oid_with_context(r, name, 0, oid, &unused); } -- cgit v1.2.3 From e270f42c4d26fca591ca89ea8ee08ff17a72c1b5 Mon Sep 17 00:00:00 2001 From: Nguyễn Thái Ngọc Duy Date: Tue, 16 Apr 2019 16:33:39 +0700 Subject: sha1-name.c: remove the_repo from maybe_die_on_misspelt_object_name MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- cache.h | 4 +++- setup.c | 7 ++++--- sha1-name.c | 6 ++++-- 3 files changed, 11 insertions(+), 6 deletions(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index f6e87194d0..3718b3db8a 100644 --- a/cache.h +++ b/cache.h @@ -1387,7 +1387,9 @@ 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); +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); 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 953df0d692..b94d381bef 100644 --- a/sha1-name.c +++ b/sha1-name.c @@ -1885,11 +1885,13 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo, * exist in 'HEAD'" when given "HEAD:doc", or it may return in which case * you have a chance to diagnose the error further. */ -void maybe_die_on_misspelt_object_name(const char *name, const char *prefix) +void maybe_die_on_misspelt_object_name(struct repository *r, + const char *name, + const char *prefix) { struct object_context oc; struct object_id oid; - get_oid_with_context_1(the_repository, name, GET_OID_ONLY_TO_DIE, + get_oid_with_context_1(r, name, GET_OID_ONLY_TO_DIE, prefix, &oid, &oc); } -- cgit v1.2.3 From 65e5046400fd07e32749ff20557e11a0fc65cc67 Mon Sep 17 00:00:00 2001 From: Nguyễn Thái Ngọc Duy Date: Tue, 16 Apr 2019 16:33:40 +0700 Subject: sha1-name.c: remove the_repo from other get_oid_* MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- cache.h | 18 ++++++++++++------ sha1-name.c | 35 ++++++++++++++++++++--------------- 2 files changed, 32 insertions(+), 21 deletions(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 3718b3db8a..871a167bf8 100644 --- a/cache.h +++ b/cache.h @@ -1381,12 +1381,11 @@ enum get_oid_result { }; int repo_get_oid(struct repository *r, const char *str, struct object_id *oid); -#define get_oid(str, oid) repo_get_oid(the_repository, str, oid) -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); +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); void maybe_die_on_misspelt_object_name(struct repository *repo, const char *name, const char *prefix); @@ -1394,6 +1393,13 @@ extern enum get_oid_result get_oid_with_context(struct repository *repo, const c 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) + typedef int each_abbrev_fn(const struct object_id *oid, 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) diff --git a/sha1-name.c b/sha1-name.c index b94d381bef..d49496397d 100644 --- a/sha1-name.c +++ b/sha1-name.c @@ -1590,43 +1590,48 @@ int repo_get_oid(struct repository *r, const char *name, struct object_id *oid) * commit-ish. It is merely to give a hint to the disambiguation * machinery. */ -int get_oid_committish(const char *name, struct object_id *oid) +int repo_get_oid_committish(struct repository *r, + const char *name, + struct object_id *oid) { struct object_context unused; - return get_oid_with_context(the_repository, - name, GET_OID_COMMITTISH, + return get_oid_with_context(r, name, GET_OID_COMMITTISH, oid, &unused); } -int get_oid_treeish(const char *name, struct object_id *oid) +int repo_get_oid_treeish(struct repository *r, + const char *name, + struct object_id *oid) { struct object_context unused; - return get_oid_with_context(the_repository, - name, GET_OID_TREEISH, + return get_oid_with_context(r, name, GET_OID_TREEISH, oid, &unused); } -int get_oid_commit(const char *name, struct object_id *oid) +int repo_get_oid_commit(struct repository *r, + const char *name, + struct object_id *oid) { struct object_context unused; - return get_oid_with_context(the_repository, - name, GET_OID_COMMIT, + return get_oid_with_context(r, name, GET_OID_COMMIT, oid, &unused); } -int get_oid_tree(const char *name, struct object_id *oid) +int repo_get_oid_tree(struct repository *r, + const char *name, + struct object_id *oid) { struct object_context unused; - return get_oid_with_context(the_repository, - name, GET_OID_TREE, + return get_oid_with_context(r, name, GET_OID_TREE, oid, &unused); } -int get_oid_blob(const char *name, struct object_id *oid) +int repo_get_oid_blob(struct repository *r, + const char *name, + struct object_id *oid) { struct object_context unused; - return get_oid_with_context(the_repository, - name, GET_OID_BLOB, + return get_oid_with_context(r, name, GET_OID_BLOB, oid, &unused); } -- cgit v1.2.3 From 0daf7ff6c0f877e4b518893b51d44e024fc88fb3 Mon Sep 17 00:00:00 2001 From: Nguyễn Thái Ngọc Duy Date: Tue, 16 Apr 2019 16:33:41 +0700 Subject: sha1-name.c: remove the_repo from get_oid_mb() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- cache.h | 3 ++- sha1-name.c | 18 +++++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 871a167bf8..9a600a8b50 100644 --- a/cache.h +++ b/cache.h @@ -1386,6 +1386,7 @@ int repo_get_oid_committish(struct repository *r, const char *str, struct object 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); @@ -1399,6 +1400,7 @@ extern enum get_oid_result get_oid_with_context(struct repository *repo, const c #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 *); int repo_for_each_abbrev(struct repository *r, const char *prefix, each_abbrev_fn, void *); @@ -1486,7 +1488,6 @@ int repo_interpret_branch_name(struct repository *r, unsigned allowed); #define interpret_branch_name(str, len, buf, allowed) \ repo_interpret_branch_name(the_repository, str, len, buf, allowed) -extern int get_oid_mb(const char *str, struct object_id *oid); extern int validate_headref(const char *ref); diff --git a/sha1-name.c b/sha1-name.c index d49496397d..cf314ebb29 100644 --- a/sha1-name.c +++ b/sha1-name.c @@ -1338,7 +1338,9 @@ static int interpret_nth_prior_checkout(struct repository *r, return retval; } -int get_oid_mb(const char *name, struct object_id *oid) +int repo_get_oid_mb(struct repository *r, + const char *name, + struct object_id *oid) { struct commit *one, *two; struct commit_list *mbs; @@ -1348,27 +1350,29 @@ int get_oid_mb(const char *name, struct object_id *oid) dots = strstr(name, "..."); if (!dots) - return get_oid(name, oid); + return repo_get_oid(r, name, oid); if (dots == name) - st = get_oid("HEAD", &oid_tmp); + st = repo_get_oid(r, "HEAD", &oid_tmp); else { struct strbuf sb; strbuf_init(&sb, dots - name); strbuf_add(&sb, name, dots - name); - st = get_oid_committish(sb.buf, &oid_tmp); + st = repo_get_oid_committish(r, sb.buf, &oid_tmp); strbuf_release(&sb); } if (st) return st; - one = lookup_commit_reference_gently(the_repository, &oid_tmp, 0); + one = lookup_commit_reference_gently(r, &oid_tmp, 0); if (!one) return -1; - if (get_oid_committish(dots[3] ? (dots + 3) : "HEAD", &oid_tmp)) + if (repo_get_oid_committish(r, dots[3] ? (dots + 3) : "HEAD", &oid_tmp)) return -1; - two = lookup_commit_reference_gently(the_repository, &oid_tmp, 0); + two = lookup_commit_reference_gently(r, &oid_tmp, 0); if (!two) return -1; + if (r != the_repository) + BUG("sorry get_merge_bases() can't take struct repository yet"); mbs = get_merge_bases(one, two); if (!mbs || mbs->next) st = -1; -- cgit v1.2.3