Skip to content

Commit 3a7a698

Browse files
pcloudsgitster
authored andcommitted
sha1-name.c: remove implicit dependency on the_index
This kills the_index dependency in get_oid_with_context() but for get_oid() and friends, they still assume the_repository (which also means the_index). Unfortunately the widespread use of get_oid() will make it hard to make the conversion now. We probably will add repo_get_oid() at some point and limit the use of get_oid() in builtin/ instead of forcing all get_oid() call sites to carry struct repository. Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1b0d968 commit 3a7a698

File tree

8 files changed

+50
-33
lines changed

8 files changed

+50
-33
lines changed

builtin/cat-file.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
7373
if (unknown_type)
7474
flags |= OBJECT_INFO_ALLOW_UNKNOWN_TYPE;
7575

76-
if (get_oid_with_context(obj_name, GET_OID_RECORD_PATH,
76+
if (get_oid_with_context(the_repository, obj_name,
77+
GET_OID_RECORD_PATH,
7778
&oid, &obj_context))
7879
die("Not a valid object name %s", obj_name);
7980

@@ -382,7 +383,8 @@ static void batch_one_object(const char *obj_name,
382383
int flags = opt->follow_symlinks ? GET_OID_FOLLOW_SYMLINKS : 0;
383384
enum follow_symlinks_result result;
384385

385-
result = get_oid_with_context(obj_name, flags, &data->oid, &ctx);
386+
result = get_oid_with_context(the_repository, obj_name,
387+
flags, &data->oid, &ctx);
386388
if (result != FOUND) {
387389
switch (result) {
388390
case MISSING_OBJECT:

builtin/grep.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,8 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
10211021
break;
10221022
}
10231023

1024-
if (get_oid_with_context(arg, GET_OID_RECORD_PATH,
1024+
if (get_oid_with_context(the_repository, arg,
1025+
GET_OID_RECORD_PATH,
10251026
&oid, &oc)) {
10261027
if (seen_dashdash)
10271028
die(_("unable to resolve revision: %s"), arg);

builtin/log.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,8 @@ static int show_blob_object(const struct object_id *oid, struct rev_info *rev, c
508508
!rev->diffopt.flags.allow_textconv)
509509
return stream_blob_to_fd(1, oid, NULL, 0);
510510

511-
if (get_oid_with_context(obj_name, GET_OID_RECORD_PATH,
511+
if (get_oid_with_context(the_repository, obj_name,
512+
GET_OID_RECORD_PATH,
512513
&oidc, &obj_context))
513514
die(_("Not a valid object name %s"), obj_name);
514515
if (!obj_context.path ||

builtin/rev-parse.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,8 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
933933
name++;
934934
type = REVERSED;
935935
}
936-
if (!get_oid_with_context(name, flags, &oid, &unused)) {
936+
if (!get_oid_with_context(the_repository, name,
937+
flags, &oid, &unused)) {
937938
if (verify)
938939
revs_count++;
939940
else

cache.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1328,7 +1328,9 @@ extern int get_oid_tree(const char *str, struct object_id *oid);
13281328
extern int get_oid_treeish(const char *str, struct object_id *oid);
13291329
extern int get_oid_blob(const char *str, struct object_id *oid);
13301330
extern void maybe_die_on_misspelt_object_name(const char *name, const char *prefix);
1331-
extern int get_oid_with_context(const char *str, unsigned flags, struct object_id *oid, struct object_context *oc);
1331+
extern int get_oid_with_context(struct repository *repo, const char *str,
1332+
unsigned flags, struct object_id *oid,
1333+
struct object_context *oc);
13321334

13331335

13341336
typedef int each_abbrev_fn(const struct object_id *oid, void *);

list-objects-filter-options.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ static int gently_parse_list_objects_filter(
7171
* command, but DO NOT complain if we don't have the blob or
7272
* ref locally.
7373
*/
74-
if (!get_oid_with_context(v0, GET_OID_BLOB,
74+
if (!get_oid_with_context(the_repository, v0, GET_OID_BLOB,
7575
&sparse_oid, &oc))
7676
filter_options->sparse_oid_value = oiddup(&sparse_oid);
7777
filter_options->choice = LOFC_SPARSE_OID;

revision.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1589,8 +1589,8 @@ static int handle_dotdot_1(const char *arg, char *dotdot,
15891589
if (!*b_name)
15901590
b_name = "HEAD";
15911591

1592-
if (get_oid_with_context(a_name, oc_flags, &a_oid, a_oc) ||
1593-
get_oid_with_context(b_name, oc_flags, &b_oid, b_oc))
1592+
if (get_oid_with_context(revs->repo, a_name, oc_flags, &a_oid, a_oc) ||
1593+
get_oid_with_context(revs->repo, b_name, oc_flags, &b_oid, b_oc))
15941594
return -1;
15951595

15961596
if (!cant_be_filename) {
@@ -1724,7 +1724,7 @@ int handle_revision_arg(const char *arg_, struct rev_info *revs, int flags, unsi
17241724
if (revarg_opt & REVARG_COMMITTISH)
17251725
get_sha1_flags |= GET_OID_COMMITTISH;
17261726

1727-
if (get_oid_with_context(arg, get_sha1_flags, &oid, &oc))
1727+
if (get_oid_with_context(revs->repo, arg, get_sha1_flags, &oid, &oc))
17281728
return revs->ignore_missing ? 0 : -1;
17291729
if (!cant_be_filename)
17301730
verify_non_filename(revs->prefix, arg);
@@ -2453,7 +2453,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
24532453
struct object_id oid;
24542454
struct object *object;
24552455
struct object_context oc;
2456-
if (get_oid_with_context(revs->def, 0, &oid, &oc))
2456+
if (get_oid_with_context(revs->repo, revs->def, 0, &oid, &oc))
24572457
diagnose_missing_default(revs->def);
24582458
object = get_reference(revs, revs->def, &oid, 0);
24592459
add_pending_object_with_mode(revs, object, revs->def, oc.mode);

sha1-name.c

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1513,7 +1513,7 @@ int strbuf_check_branch_ref(struct strbuf *sb, const char *name)
15131513
int get_oid(const char *name, struct object_id *oid)
15141514
{
15151515
struct object_context unused;
1516-
return get_oid_with_context(name, 0, oid, &unused);
1516+
return get_oid_with_context(the_repository, name, 0, oid, &unused);
15171517
}
15181518

15191519

@@ -1530,35 +1530,40 @@ int get_oid(const char *name, struct object_id *oid)
15301530
int get_oid_committish(const char *name, struct object_id *oid)
15311531
{
15321532
struct object_context unused;
1533-
return get_oid_with_context(name, GET_OID_COMMITTISH,
1533+
return get_oid_with_context(the_repository,
1534+
name, GET_OID_COMMITTISH,
15341535
oid, &unused);
15351536
}
15361537

15371538
int get_oid_treeish(const char *name, struct object_id *oid)
15381539
{
15391540
struct object_context unused;
1540-
return get_oid_with_context(name, GET_OID_TREEISH,
1541+
return get_oid_with_context(the_repository,
1542+
name, GET_OID_TREEISH,
15411543
oid, &unused);
15421544
}
15431545

15441546
int get_oid_commit(const char *name, struct object_id *oid)
15451547
{
15461548
struct object_context unused;
1547-
return get_oid_with_context(name, GET_OID_COMMIT,
1549+
return get_oid_with_context(the_repository,
1550+
name, GET_OID_COMMIT,
15481551
oid, &unused);
15491552
}
15501553

15511554
int get_oid_tree(const char *name, struct object_id *oid)
15521555
{
15531556
struct object_context unused;
1554-
return get_oid_with_context(name, GET_OID_TREE,
1557+
return get_oid_with_context(the_repository,
1558+
name, GET_OID_TREE,
15551559
oid, &unused);
15561560
}
15571561

15581562
int get_oid_blob(const char *name, struct object_id *oid)
15591563
{
15601564
struct object_context unused;
1561-
return get_oid_with_context(name, GET_OID_BLOB,
1565+
return get_oid_with_context(the_repository,
1566+
name, GET_OID_BLOB,
15621567
oid, &unused);
15631568
}
15641569

@@ -1597,7 +1602,8 @@ static void diagnose_invalid_oid_path(const char *prefix,
15971602
}
15981603

15991604
/* Must be called only when :stage:filename doesn't exist. */
1600-
static void diagnose_invalid_index_path(int stage,
1605+
static void diagnose_invalid_index_path(struct index_state *istate,
1606+
int stage,
16011607
const char *prefix,
16021608
const char *filename)
16031609
{
@@ -1610,11 +1616,11 @@ static void diagnose_invalid_index_path(int stage,
16101616
prefix = "";
16111617

16121618
/* Wrong stage number? */
1613-
pos = cache_name_pos(filename, namelen);
1619+
pos = index_name_pos(istate, filename, namelen);
16141620
if (pos < 0)
16151621
pos = -pos - 1;
1616-
if (pos < active_nr) {
1617-
ce = active_cache[pos];
1622+
if (pos < istate->cache_nr) {
1623+
ce = istate->cache[pos];
16181624
if (ce_namelen(ce) == namelen &&
16191625
!memcmp(ce->name, filename, namelen))
16201626
die("Path '%s' is in the index, but not at stage %d.\n"
@@ -1626,11 +1632,11 @@ static void diagnose_invalid_index_path(int stage,
16261632
/* Confusion between relative and absolute filenames? */
16271633
strbuf_addstr(&fullname, prefix);
16281634
strbuf_addstr(&fullname, filename);
1629-
pos = cache_name_pos(fullname.buf, fullname.len);
1635+
pos = index_name_pos(istate, fullname.buf, fullname.len);
16301636
if (pos < 0)
16311637
pos = -pos - 1;
1632-
if (pos < active_nr) {
1633-
ce = active_cache[pos];
1638+
if (pos < istate->cache_nr) {
1639+
ce = istate->cache[pos];
16341640
if (ce_namelen(ce) == fullname.len &&
16351641
!memcmp(ce->name, fullname.buf, fullname.len))
16361642
die("Path '%s' is in the index, but not '%s'.\n"
@@ -1664,7 +1670,8 @@ static char *resolve_relative_path(const char *rel)
16641670
rel);
16651671
}
16661672

1667-
static int get_oid_with_context_1(const char *name,
1673+
static int get_oid_with_context_1(struct repository *repo,
1674+
const char *name,
16681675
unsigned flags,
16691676
const char *prefix,
16701677
struct object_id *oid,
@@ -1723,13 +1730,13 @@ static int get_oid_with_context_1(const char *name,
17231730
if (flags & GET_OID_RECORD_PATH)
17241731
oc->path = xstrdup(cp);
17251732

1726-
if (!the_index.cache)
1733+
if (!repo->index->cache)
17271734
repo_read_index(the_repository);
1728-
pos = index_name_pos(&the_index, cp, namelen);
1735+
pos = index_name_pos(repo->index, cp, namelen);
17291736
if (pos < 0)
17301737
pos = -pos - 1;
1731-
while (pos < active_nr) {
1732-
ce = active_cache[pos];
1738+
while (pos < repo->index->cache_nr) {
1739+
ce = repo->index->cache[pos];
17331740
if (ce_namelen(ce) != namelen ||
17341741
memcmp(ce->name, cp, namelen))
17351742
break;
@@ -1742,7 +1749,7 @@ static int get_oid_with_context_1(const char *name,
17421749
pos++;
17431750
}
17441751
if (only_to_die && name[1] && name[1] != '/')
1745-
diagnose_invalid_index_path(stage, prefix, cp);
1752+
diagnose_invalid_index_path(repo->index, stage, prefix, cp);
17461753
free(new_path);
17471754
return -1;
17481755
}
@@ -1807,12 +1814,15 @@ void maybe_die_on_misspelt_object_name(const char *name, const char *prefix)
18071814
{
18081815
struct object_context oc;
18091816
struct object_id oid;
1810-
get_oid_with_context_1(name, GET_OID_ONLY_TO_DIE, prefix, &oid, &oc);
1817+
get_oid_with_context_1(the_repository, name, GET_OID_ONLY_TO_DIE,
1818+
prefix, &oid, &oc);
18111819
}
18121820

1813-
int get_oid_with_context(const char *str, unsigned flags, struct object_id *oid, struct object_context *oc)
1821+
int get_oid_with_context(struct repository *repo, const char *str,
1822+
unsigned flags, struct object_id *oid,
1823+
struct object_context *oc)
18141824
{
18151825
if (flags & GET_OID_FOLLOW_SYMLINKS && flags & GET_OID_ONLY_TO_DIE)
18161826
BUG("incompatible flags for get_sha1_with_context");
1817-
return get_oid_with_context_1(str, flags, NULL, oid, oc);
1827+
return get_oid_with_context_1(repo, str, flags, NULL, oid, oc);
18181828
}

0 commit comments

Comments
 (0)