From: Junio C Hamano Date: Wed, 8 May 2019 15:37:24 +0000 (+0900) Subject: Merge branch 'nd/sha1-name-c-wo-the-repository' X-Git-Tag: v2.22.0-rc0~25 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0b179f3175d1a152b1d22ce8352efda34b258ce2;p=thirdparty%2Fgit.git 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() ... --- 0b179f3175d1a152b1d22ce8352efda34b258ce2 diff --cc cache.h index 9f2fb7b2ea,9a600a8b50..67cc2e1806 --- a/cache.h +++ b/cache.h @@@ -1380,14 -1380,16 +1382,17 @@@ 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); diff --cc packfile.h index 12baa6118a,f04440f984..b678d35c0b --- a/packfile.h +++ b/packfile.h @@@ -63,12 -57,13 +63,13 @@@ struct packed_git *get_all_packs(struc * 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) -extern struct packed_git *find_sha1_pack(const unsigned char *sha1, - struct packed_git *packs); +struct packed_git *find_sha1_pack(const unsigned char *sha1, + struct packed_git *packs); -extern void pack_report(void); +void pack_report(void); /* * mmap the index file for the specified packfile (if it is not diff --cc sha1-name.c index 7754d3a3de,cf314ebb29..775a73d8ad --- a/sha1-name.c +++ b/sha1-name.c @@@ -1524,31 -1577,12 +1589,31 @@@ int strbuf_check_branch_ref(struct strb * 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); } +/* + * This returns a non-zero value if the string (built using printf + * format and the given arguments) is not a valid object. + */ +int get_oidf(struct object_id *oid, const char *fmt, ...) +{ + va_list ap; + int ret; + struct strbuf sb = STRBUF_INIT; + + va_start(ap, fmt); + strbuf_vaddf(&sb, fmt, ap); + va_end(ap); + + ret = get_oid(sb.buf, oid); + strbuf_release(&sb); + + return ret; +} /* * Many callers know that the user meant to name a commit-ish by