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() ...
This commit is contained in:
commit
0b179f3175
@ -1568,8 +1568,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
|
|||||||
branch_name = options.head_name;
|
branch_name = options.head_name;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
free(options.head_name);
|
FREE_AND_NULL(options.head_name);
|
||||||
options.head_name = NULL;
|
|
||||||
branch_name = "HEAD";
|
branch_name = "HEAD";
|
||||||
}
|
}
|
||||||
if (get_oid("HEAD", &options.orig_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.
|
* we just fast-forwarded.
|
||||||
*/
|
*/
|
||||||
strbuf_reset(&msg);
|
strbuf_reset(&msg);
|
||||||
if (!oidcmp(&merge_base, &options.orig_head)) {
|
if (oideq(&merge_base, &options.orig_head)) {
|
||||||
printf(_("Fast-forwarded %s to %s.\n"),
|
printf(_("Fast-forwarded %s to %s.\n"),
|
||||||
branch_name, options.onto_name);
|
branch_name, options.onto_name);
|
||||||
strbuf_addf(&msg, "rebase finished: %s onto %s",
|
strbuf_addf(&msg, "rebase finished: %s onto %s",
|
||||||
|
@ -753,7 +753,8 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
|
|||||||
/* Ah, that is a date spec... */
|
/* Ah, that is a date spec... */
|
||||||
timestamp_t at;
|
timestamp_t at;
|
||||||
at = approxidate(reflog_base);
|
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);
|
NULL, NULL, &base);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -765,7 +766,8 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
|
|||||||
timestamp_t timestamp;
|
timestamp_t timestamp;
|
||||||
int tz;
|
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,
|
||||||
×tamp, &tz, NULL)) {
|
×tamp, &tz, NULL)) {
|
||||||
reflog = i;
|
reflog = i;
|
||||||
break;
|
break;
|
||||||
|
52
cache.h
52
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
|
* Note that while this version avoids the static buffer, it is not fully
|
||||||
* reentrant, as it calls into other non-reentrant git code.
|
* reentrant, as it calls into other non-reentrant git code.
|
||||||
*/
|
*/
|
||||||
extern 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);
|
||||||
extern int find_unique_abbrev_r(char *hex, 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 unsigned char null_sha1[GIT_MAX_RAWSZ];
|
||||||
extern const struct object_id null_oid;
|
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);
|
int repo_get_oid(struct repository *r, const char *str, struct object_id *oid);
|
||||||
extern int get_oidf(struct object_id *oid, const char *fmt, ...);
|
int get_oidf(struct object_id *oid, const char *fmt, ...);
|
||||||
extern int get_oid_commit(const char *str, struct object_id *oid);
|
int repo_get_oid_commit(struct repository *r, const char *str, struct object_id *oid);
|
||||||
extern int get_oid_committish(const char *str, struct object_id *oid);
|
int repo_get_oid_committish(struct repository *r, const char *str, struct object_id *oid);
|
||||||
extern int get_oid_tree(const char *str, struct object_id *oid);
|
int repo_get_oid_tree(struct repository *r, const char *str, struct object_id *oid);
|
||||||
extern int get_oid_treeish(const char *str, struct object_id *oid);
|
int repo_get_oid_treeish(struct repository *r, const char *str, struct object_id *oid);
|
||||||
extern int get_oid_blob(const char *str, struct object_id *oid);
|
int repo_get_oid_blob(struct repository *r, 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_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,
|
extern enum get_oid_result get_oid_with_context(struct repository *repo, const char *str,
|
||||||
unsigned flags, struct object_id *oid,
|
unsigned flags, struct object_id *oid,
|
||||||
struct object_context *oc);
|
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 *);
|
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);
|
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_LOCAL (1<<0)
|
||||||
#define INTERPRET_BRANCH_REMOTE (1<<1)
|
#define INTERPRET_BRANCH_REMOTE (1<<1)
|
||||||
#define INTERPRET_BRANCH_HEAD (1<<2)
|
#define INTERPRET_BRANCH_HEAD (1<<2)
|
||||||
extern int interpret_branch_name(const char *str, int len, struct strbuf *,
|
int repo_interpret_branch_name(struct repository *r,
|
||||||
unsigned allowed);
|
const char *str, int len,
|
||||||
extern int get_oid_mb(const char *str, struct object_id *oid);
|
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);
|
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,
|
unsigned long *size,
|
||||||
struct object_id *oid_ret);
|
struct object_id *oid_ret);
|
||||||
|
|
||||||
extern struct object *peel_to_type(const char *name, int namelen,
|
struct object *repo_peel_to_type(struct repository *r,
|
||||||
struct object *o, enum object_type);
|
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 {
|
enum date_mode_type {
|
||||||
DATE_NORMAL = 0,
|
DATE_NORMAL = 0,
|
||||||
|
@ -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;
|
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,
|
static int fill_commit_in_graph(struct repository *r,
|
||||||
struct commit *item,
|
struct commit *item,
|
||||||
struct commit_graph *g, uint32_t pos)
|
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->object.parsed = 1;
|
||||||
item->graph_pos = pos;
|
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_high = get_be32(commit_data + g->hash_len + 8) & 0x3;
|
||||||
date_low = get_be32(commit_data + g->hash_len + 12);
|
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);
|
GRAPH_DATA_WIDTH * (c->graph_pos);
|
||||||
|
|
||||||
hashcpy(oid.hash, commit_data);
|
hashcpy(oid.hash, commit_data);
|
||||||
c->maybe_tree = lookup_tree(r, &oid);
|
set_commit_tree(c, lookup_tree(r, &oid));
|
||||||
|
|
||||||
return c->maybe_tree;
|
return c->maybe_tree;
|
||||||
}
|
}
|
||||||
|
14
commit.c
14
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)
|
if (commit->maybe_tree || !commit->object.parsed)
|
||||||
return commit->maybe_tree;
|
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)
|
if (commit->graph_pos == COMMIT_NOT_FROM_GRAPH)
|
||||||
BUG("commit has NULL tree, but was not loaded from commit-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)
|
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)
|
void release_commit_memory(struct parsed_object_pool *pool, struct commit *c)
|
||||||
{
|
{
|
||||||
c->maybe_tree = NULL;
|
set_commit_tree(c, NULL);
|
||||||
c->index = 0;
|
c->index = 0;
|
||||||
free_commit_buffer(pool, c);
|
free_commit_buffer(pool, c);
|
||||||
free_commit_list(c->parents);
|
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)
|
if (get_oid_hex(bufptr + 5, &parent) < 0)
|
||||||
return error("bad tree pointer in commit %s",
|
return error("bad tree pointer in commit %s",
|
||||||
oid_to_hex(&item->object.oid));
|
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" */
|
bufptr += tree_entry_len + 1; /* "tree " + "hex sha1" + "\n" */
|
||||||
pptr = &item->parents;
|
pptr = &item->parents;
|
||||||
|
|
||||||
|
5
commit.h
5
commit.h
@ -32,7 +32,7 @@ struct commit {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* If the commit is loaded from the commit-graph file, then this
|
* 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().
|
* or get_commit_tree_oid().
|
||||||
*/
|
*/
|
||||||
struct tree *maybe_tree;
|
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 *);
|
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 *);
|
struct object_id *get_commit_tree_oid(const struct commit *);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -10,19 +10,25 @@ expression c;
|
|||||||
- c->maybe_tree->object.oid.hash
|
- c->maybe_tree->object.oid.hash
|
||||||
+ get_commit_tree_oid(c)->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 = 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 c;
|
||||||
@@
|
@@
|
||||||
f(...) {<...
|
f(...) {<...
|
||||||
- c->maybe_tree
|
- c->maybe_tree
|
||||||
+ get_commit_tree(c)
|
+ repo_get_commit_tree(specify_the_right_repo_here, c)
|
||||||
...>}
|
...>}
|
||||||
|
|
||||||
@@
|
|
||||||
expression c;
|
|
||||||
expression s;
|
|
||||||
@@
|
|
||||||
- get_commit_tree(c) = s
|
|
||||||
+ c->maybe_tree = s
|
|
||||||
|
8
dir.c
8
dir.c
@ -2316,6 +2316,14 @@ int file_exists(const char *f)
|
|||||||
return lstat(f, &sb) == 0;
|
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)
|
static int cmp_icase(char a, char b)
|
||||||
{
|
{
|
||||||
if (a == b)
|
if (a == b)
|
||||||
|
4
dir.h
4
dir.h
@ -269,7 +269,9 @@ extern void add_exclude(const char *string, const char *base,
|
|||||||
int baselen, struct exclude_list *el, int srcpos);
|
int baselen, struct exclude_list *el, int srcpos);
|
||||||
extern void clear_exclude_list(struct exclude_list *el);
|
extern void clear_exclude_list(struct exclude_list *el);
|
||||||
extern void clear_directory(struct dir_struct *dir);
|
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 is_inside_dir(const char *dir);
|
||||||
extern int dir_inside_of(const char *subdir, const char *dir);
|
extern int dir_inside_of(const char *subdir, const char *dir);
|
||||||
|
@ -163,6 +163,11 @@ static struct tree *shift_tree_object(struct repository *repo,
|
|||||||
return lookup_tree(repo, &shifted);
|
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,
|
static struct commit *make_virtual_commit(struct repository *repo,
|
||||||
struct tree *tree,
|
struct tree *tree,
|
||||||
const char *comment)
|
const char *comment)
|
||||||
@ -170,7 +175,7 @@ static struct commit *make_virtual_commit(struct repository *repo,
|
|||||||
struct commit *commit = alloc_commit_node(repo);
|
struct commit *commit = alloc_commit_node(repo);
|
||||||
|
|
||||||
set_merge_remote_desc(commit, comment, (struct object *)commit);
|
set_merge_remote_desc(commit, comment, (struct object *)commit);
|
||||||
commit->maybe_tree = tree;
|
set_commit_tree(commit, tree);
|
||||||
commit->object.parsed = 1;
|
commit->object.parsed = 1;
|
||||||
return commit;
|
return commit;
|
||||||
}
|
}
|
||||||
|
14
packfile.c
14
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
|
* 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.
|
* 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;
|
unsigned long count;
|
||||||
struct multi_pack_index *m;
|
struct multi_pack_index *m;
|
||||||
struct packed_git *p;
|
struct packed_git *p;
|
||||||
|
|
||||||
prepare_packed_git(the_repository);
|
prepare_packed_git(r);
|
||||||
count = 0;
|
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;
|
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))
|
if (open_pack_index(p))
|
||||||
continue;
|
continue;
|
||||||
count += p->num_objects;
|
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)
|
static void *get_next_packed_git(const void *p)
|
||||||
|
@ -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
|
* Give a rough count of objects in the repository. This sacrifices accuracy
|
||||||
* for speed.
|
* 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 *find_sha1_pack(const unsigned char *sha1,
|
||||||
struct packed_git *packs);
|
struct packed_git *packs);
|
||||||
|
71
refs.c
71
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);
|
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)
|
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,
|
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
|
* later free()ing) if the string passed in is a magic short-hand form
|
||||||
* to name a branch.
|
* 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;
|
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) {
|
if (ret == *len) {
|
||||||
size_t size;
|
size_t size;
|
||||||
@ -549,15 +555,22 @@ static char *substitute_branch_name(const char **string, int *len)
|
|||||||
return NULL;
|
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);
|
char *last_branch = substitute_branch_name(r, &str, &len);
|
||||||
int refs_found = expand_ref(str, len, oid, ref);
|
int refs_found = expand_ref(r, str, len, oid, ref);
|
||||||
free(last_branch);
|
free(last_branch);
|
||||||
return refs_found;
|
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;
|
const char **p, *r;
|
||||||
int refs_found = 0;
|
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;
|
this_result = refs_found ? &oid_from_ref : oid;
|
||||||
strbuf_reset(&fullref);
|
strbuf_reset(&fullref);
|
||||||
strbuf_addf(&fullref, *p, len, str);
|
strbuf_addf(&fullref, *p, len, str);
|
||||||
r = resolve_ref_unsafe(fullref.buf, RESOLVE_REF_READING,
|
r = refs_resolve_ref_unsafe(get_main_ref_store(repo),
|
||||||
this_result, &flag);
|
fullref.buf, RESOLVE_REF_READING,
|
||||||
|
this_result, &flag);
|
||||||
if (r) {
|
if (r) {
|
||||||
if (!refs_found++)
|
if (!refs_found++)
|
||||||
*ref = xstrdup(r);
|
*ref = xstrdup(r);
|
||||||
@ -589,9 +603,11 @@ int expand_ref(const char *str, int len, struct object_id *oid, char **ref)
|
|||||||
return refs_found;
|
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;
|
const char **p;
|
||||||
int logs_found = 0;
|
int logs_found = 0;
|
||||||
struct strbuf path = STRBUF_INIT;
|
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_reset(&path);
|
||||||
strbuf_addf(&path, *p, len, str);
|
strbuf_addf(&path, *p, len, str);
|
||||||
ref = resolve_ref_unsafe(path.buf, RESOLVE_REF_READING,
|
ref = refs_resolve_ref_unsafe(refs, path.buf,
|
||||||
&hash, NULL);
|
RESOLVE_REF_READING,
|
||||||
|
&hash, NULL);
|
||||||
if (!ref)
|
if (!ref)
|
||||||
continue;
|
continue;
|
||||||
if (reflog_exists(path.buf))
|
if (refs_reflog_exists(refs, path.buf))
|
||||||
it = 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;
|
it = ref;
|
||||||
else
|
else
|
||||||
continue;
|
continue;
|
||||||
@ -625,6 +643,11 @@ int dwim_log(const char *str, int len, struct object_id *oid, char **log)
|
|||||||
return logs_found;
|
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)
|
static int is_per_worktree_ref(const char *refname)
|
||||||
{
|
{
|
||||||
return !strcmp(refname, "HEAD") ||
|
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;
|
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,
|
struct object_id *oid, char **msg,
|
||||||
timestamp_t *cutoff_time, int *cutoff_tz, int *cutoff_cnt)
|
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.cutoff_cnt = cutoff_cnt;
|
||||||
cb.oid = oid;
|
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 (!cb.reccnt) {
|
||||||
if (flags & GET_OID_QUIETLY)
|
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)
|
if (cb.found_it)
|
||||||
return 0;
|
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;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -1164,7 +1188,8 @@ int update_ref(const char *msg, const char *refname,
|
|||||||
old_oid, flags, onerr);
|
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;
|
int i;
|
||||||
static char **scanf_fmts;
|
static char **scanf_fmts;
|
||||||
@ -1242,7 +1267,7 @@ char *shorten_unambiguous_ref(const char *refname, int strict)
|
|||||||
strbuf_reset(&resolved_buf);
|
strbuf_reset(&resolved_buf);
|
||||||
strbuf_addf(&resolved_buf, rule,
|
strbuf_addf(&resolved_buf, rule,
|
||||||
short_name_len, short_name);
|
short_name_len, short_name);
|
||||||
if (ref_exists(resolved_buf.buf))
|
if (refs_ref_exists(refs, resolved_buf.buf))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1261,6 +1286,12 @@ char *shorten_unambiguous_ref(const char *refname, int strict)
|
|||||||
return xstrdup(refname);
|
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;
|
static struct string_list *hide_refs;
|
||||||
|
|
||||||
int parse_hide_refs_config(const char *var, const char *value, const char *section)
|
int parse_hide_refs_config(const char *var, const char *value, const char *section)
|
||||||
|
9
refs.h
9
refs.h
@ -148,7 +148,9 @@ int refname_match(const char *abbrev_name, const char *full_name);
|
|||||||
struct argv_array;
|
struct argv_array;
|
||||||
void expand_ref_prefix(struct argv_array *prefixes, const char *prefix);
|
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_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);
|
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);
|
int safe_create_reflog(const char *refname, int force_create, struct strbuf *err);
|
||||||
|
|
||||||
/** Reads log for the value of ref during at_time. **/
|
/** 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,
|
timestamp_t at_time, int cnt,
|
||||||
struct object_id *oid, char **msg,
|
struct object_id *oid, char **msg,
|
||||||
timestamp_t *cutoff_time, int *cutoff_tz, int *cutoff_cnt);
|
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);
|
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);
|
char *shorten_unambiguous_ref(const char *refname, int strict);
|
||||||
|
|
||||||
/** rename ref, return 0 on success **/
|
/** rename ref, return 0 on success **/
|
||||||
|
7
setup.c
7
setup.c
@ -164,7 +164,8 @@ int check_filename(const char *prefix, const char *arg)
|
|||||||
die_errno(_("failed to stat '%s'"), 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,
|
const char *arg,
|
||||||
int diagnose_misspelt_rev)
|
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.
|
* let maybe_die_on_misspelt_object_name() even trigger.
|
||||||
*/
|
*/
|
||||||
if (!(arg[0] == ':' && !isalnum(arg[1])))
|
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. */
|
/* ... or fall back the most general message. */
|
||||||
die(_("ambiguous argument '%s': unknown revision or path not in the working tree.\n"
|
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);
|
die(_("option '%s' must come before non-option arguments"), arg);
|
||||||
if (looks_like_pathspec(arg) || check_filename(prefix, arg))
|
if (looks_like_pathspec(arg) || check_filename(prefix, arg))
|
||||||
return;
|
return;
|
||||||
die_verify_filename(prefix, arg, diagnose_misspelt_rev);
|
die_verify_filename(the_repository, prefix, arg, diagnose_misspelt_rev);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
388
sha1-name.c
388
sha1-name.c
File diff suppressed because it is too large
Load Diff
@ -625,23 +625,16 @@ static void config_from_gitmodules(config_fn_t fn, struct repository *repo, void
|
|||||||
const struct config_options opts = { 0 };
|
const struct config_options opts = { 0 };
|
||||||
struct object_id oid;
|
struct object_id oid;
|
||||||
char *file;
|
char *file;
|
||||||
|
char *oidstr = NULL;
|
||||||
|
|
||||||
file = repo_worktree_path(repo, GITMODULES_FILE);
|
file = repo_worktree_path(repo, GITMODULES_FILE);
|
||||||
if (file_exists(file)) {
|
if (file_exists(file)) {
|
||||||
config_source.file = file;
|
config_source.file = file;
|
||||||
} else if (repo->submodule_prefix) {
|
} else if (repo_get_oid(repo, GITMODULES_INDEX, &oid) >= 0 ||
|
||||||
/*
|
repo_get_oid(repo, GITMODULES_HEAD, &oid) >= 0) {
|
||||||
* When get_oid and config_with_options, used below,
|
config_source.blob = oidstr = xstrdup(oid_to_hex(&oid));
|
||||||
* become able to work on a specific repository, this
|
if (repo != the_repository)
|
||||||
* warning branch can be removed.
|
add_to_alternates_memory(repo->objects->odb->path);
|
||||||
*/
|
|
||||||
warning("nested submodules without %s in the working tree are not supported yet",
|
|
||||||
GITMODULES_FILE);
|
|
||||||
goto out;
|
|
||||||
} else if (get_oid(GITMODULES_INDEX, &oid) >= 0) {
|
|
||||||
config_source.blob = GITMODULES_INDEX;
|
|
||||||
} else if (get_oid(GITMODULES_HEAD, &oid) >= 0) {
|
|
||||||
config_source.blob = GITMODULES_HEAD;
|
|
||||||
} else {
|
} else {
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
@ -649,6 +642,7 @@ static void config_from_gitmodules(config_fn_t fn, struct repository *repo, void
|
|||||||
config_with_options(fn, data, &config_source, &opts);
|
config_with_options(fn, data, &config_source, &opts);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
|
free(oidstr);
|
||||||
free(file);
|
free(file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -380,11 +380,7 @@ test_expect_success 'grep --recurse-submodules should pass the pattern type alon
|
|||||||
fi
|
fi
|
||||||
'
|
'
|
||||||
|
|
||||||
# Recursing down into nested submodules which do not have .gitmodules in their
|
test_expect_success 'grep --recurse-submodules with submodules without .gitmodules in the working tree' '
|
||||||
# working tree does not work yet. This is because config_from_gitmodules()
|
|
||||||
# uses get_oid() and the latter is still not able to get objects from an
|
|
||||||
# arbitrary repository (the nested submodule, in this case).
|
|
||||||
test_expect_failure 'grep --recurse-submodules with submodules without .gitmodules in the working tree' '
|
|
||||||
test_when_finished "git -C submodule checkout .gitmodules" &&
|
test_when_finished "git -C submodule checkout .gitmodules" &&
|
||||||
rm submodule/.gitmodules &&
|
rm submodule/.gitmodules &&
|
||||||
git grep --recurse-submodules -e "(.|.)[\d]" >actual &&
|
git grep --recurse-submodules -e "(.|.)[\d]" >actual &&
|
||||||
|
@ -839,7 +839,7 @@ static int process_deepen_not(const char *line, struct string_list *deepen_not,
|
|||||||
if (skip_prefix(line, "deepen-not ", &arg)) {
|
if (skip_prefix(line, "deepen-not ", &arg)) {
|
||||||
char *ref = NULL;
|
char *ref = NULL;
|
||||||
struct object_id oid;
|
struct object_id oid;
|
||||||
if (expand_ref(arg, strlen(arg), &oid, &ref) != 1)
|
if (expand_ref(the_repository, arg, strlen(arg), &oid, &ref) != 1)
|
||||||
die("git upload-pack: ambiguous deepen-not: %s", line);
|
die("git upload-pack: ambiguous deepen-not: %s", line);
|
||||||
string_list_append(deepen_not, ref);
|
string_list_append(deepen_not, ref);
|
||||||
free(ref);
|
free(ref);
|
||||||
|
Loading…
Reference in New Issue
Block a user