sha1-name.c: remove the_repo from get_oid_1()
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 <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
Apr 16, 2019 at 16:33 UTC
2b1790f5ab949abc86124d107ee4b7e7fef1323c
2 files changed
+36
-30
cache.h
+5
-2
@@ -1491,8 +1491,11 @@ extern void *read_object_with_reference(const struct object_id *oid,
1491
unsigned long *size,
1492
struct object_id *oid_ret);
1493
1494
-extern struct object *peel_to_type(const char *name, int namelen,
1495
- struct object *o, enum object_type);
1494
+struct object *repo_peel_to_type(struct repository *r,
1495
+ const char *name, int namelen,
1496
+ struct object *o, enum object_type);
1497
+#define peel_to_type(name, namelen, obj, type) \
1498
+ repo_peel_to_type(the_repository, name, namelen, obj, type)
1499
1500
enum date_mode_type {
1501
DATE_NORMAL = 0,
sha1-name.c
+31
-28
@@ -770,7 +770,7 @@ static inline int push_mark(const char *string, int len)
770
return at_mark(string, len, suffix, ARRAY_SIZE(suffix));
771
}
772
773
-static enum get_oid_result get_oid_1(const char *name, int len, struct object_id *oid, unsigned lookup_flags);
773
+static enum get_oid_result get_oid_1(struct repository *r, const char *name, int len, struct object_id *oid, unsigned lookup_flags);
774
static int interpret_nth_prior_checkout(struct repository *r, const char *name, int namelen, struct strbuf *buf);
775
776
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,
921
return 0;
922
}
923
924
-static enum get_oid_result get_parent(const char *name, int len,
924
+static enum get_oid_result get_parent(struct repository *r,
925
+ const char *name, int len,
926
struct object_id *result, int idx)
927
{
928
struct object_id oid;
928
- enum get_oid_result ret = get_oid_1(name, len, &oid,
929
+ enum get_oid_result ret = get_oid_1(r, name, len, &oid,
930
GET_OID_COMMITTISH);
931
struct commit *commit;
932
struct commit_list *p;
933
934
if (ret)
935
return ret;
935
- commit = lookup_commit_reference(the_repository, &oid);
936
+ commit = lookup_commit_reference(r, &oid);
937
if (parse_commit(commit))
938
return MISSING_OBJECT;
939
if (!idx) {
@@ -950,7 +951,8 @@ static enum get_oid_result get_parent(const char *name, int len,
951
return MISSING_OBJECT;
952
}
953
953
-static enum get_oid_result get_nth_ancestor(const char *name, int len,
954
+static enum get_oid_result get_nth_ancestor(struct repository *r,
955
+ const char *name, int len,
956
struct object_id *result,
957
int generation)
958
{
@@ -958,10 +960,10 @@ static enum get_oid_result get_nth_ancestor(const char *name, int len,
960
struct commit *commit;
961
int ret;
962
961
- ret = get_oid_1(name, len, &oid, GET_OID_COMMITTISH);
963
+ ret = get_oid_1(r, name, len, &oid, GET_OID_COMMITTISH);
964
if (ret)
965
return ret;
964
- commit = lookup_commit_reference(the_repository, &oid);
966
+ commit = lookup_commit_reference(r, &oid);
967
if (!commit)
968
return MISSING_OBJECT;
969
@@ -974,20 +976,20 @@ static enum get_oid_result get_nth_ancestor(const char *name, int len,
976
return FOUND;
977
}
978
977
-struct object *peel_to_type(const char *name, int namelen,
978
- struct object *o, enum object_type expected_type)
979
+struct object *repo_peel_to_type(struct repository *r, const char *name, int namelen,
980
+ struct object *o, enum object_type expected_type)
981
{
982
if (name && !namelen)
983
namelen = strlen(name);
984
while (1) {
983
- if (!o || (!o->parsed && !parse_object(the_repository, &o->oid)))
985
+ if (!o || (!o->parsed && !parse_object(r, &o->oid)))
986
return NULL;
987
if (expected_type == OBJ_ANY || o->type == expected_type)
988
return o;
989
if (o->type == OBJ_TAG)
990
o = ((struct tag*) o)->tagged;
991
else if (o->type == OBJ_COMMIT)
990
- o = &(get_commit_tree(((struct commit *)o))->object);
992
+ o = &(repo_get_commit_tree(r, ((struct commit *)o))->object);
993
else {
994
if (name)
995
error("%.*s: expected %s type, but the object "
@@ -999,8 +1001,8 @@ struct object *peel_to_type(const char *name, int namelen,
1001
}
1002
}
1003
1002
-static int peel_onion(const char *name, int len, struct object_id *oid,
1003
- unsigned lookup_flags)
1004
+static int peel_onion(struct repository *r, const char *name, int len,
1005
+ struct object_id *oid, unsigned lookup_flags)
1006
{
1007
struct object_id outer;
1008
const char *sp;
@@ -1050,15 +1052,15 @@ static int peel_onion(const char *name, int len, struct object_id *oid,
1052
else if (expected_type == OBJ_TREE)
1053
lookup_flags |= GET_OID_TREEISH;
1054
1053
- if (get_oid_1(name, sp - name - 2, &outer, lookup_flags))
1055
+ if (get_oid_1(r, name, sp - name - 2, &outer, lookup_flags))
1056
return -1;
1057
1056
- o = parse_object(the_repository, &outer);
1058
+ o = parse_object(r, &outer);
1059
if (!o)
1060
return -1;
1061
if (!expected_type) {
1060
- o = deref_tag(the_repository, o, name, sp - name - 2);
1061
- if (!o || (!o->parsed && !parse_object(the_repository, &o->oid)))
1062
+ o = deref_tag(r, o, name, sp - name - 2);
1063
+ if (!o || (!o->parsed && !parse_object(r, &o->oid)))
1064
return -1;
1065
oidcpy(oid, &o->oid);
1066
return 0;
@@ -1069,7 +1071,7 @@ static int peel_onion(const char *name, int len, struct object_id *oid,
1071
* if we do not get the needed object, we should
1072
* barf.
1073
*/
1072
- o = peel_to_type(name, len, o, expected_type);
1074
+ o = repo_peel_to_type(r, name, len, o, expected_type);
1075
if (!o)
1076
return -1;
1077
@@ -1089,7 +1091,7 @@ static int peel_onion(const char *name, int len, struct object_id *oid,
1091
1092
prefix = xstrndup(sp + 1, name + len - 1 - (sp + 1));
1093
commit_list_insert((struct commit *)o, &list);
1092
- ret = get_oid_oneline(the_repository, prefix, oid, list);
1094
+ ret = get_oid_oneline(r, prefix, oid, list);
1095
free(prefix);
1096
return ret;
1097
}
@@ -1120,7 +1122,8 @@ static int get_describe_name(struct repository *r,
1122
return -1;
1123
}
1124
1123
-static enum get_oid_result get_oid_1(const char *name, int len,
1125
+static enum get_oid_result get_oid_1(struct repository *r,
1126
+ const char *name, int len,
1127
struct object_id *oid,
1128
unsigned lookup_flags)
1129
{
@@ -1149,25 +1152,25 @@ static enum get_oid_result get_oid_1(const char *name, int len,
1152
if (!num && len1 == len - 1)
1153
num = 1;
1154
if (has_suffix == '^')
1152
- return get_parent(name, len1, oid, num);
1155
+ return get_parent(r, name, len1, oid, num);
1156
/* else if (has_suffix == '~') -- goes without saying */
1154
- return get_nth_ancestor(name, len1, oid, num);
1157
+ return get_nth_ancestor(r, name, len1, oid, num);
1158
}
1159
1157
- ret = peel_onion(name, len, oid, lookup_flags);
1160
+ ret = peel_onion(r, name, len, oid, lookup_flags);
1161
if (!ret)
1162
return FOUND;
1163
1161
- ret = get_oid_basic(the_repository, name, len, oid, lookup_flags);
1164
+ ret = get_oid_basic(r, name, len, oid, lookup_flags);
1165
if (!ret)
1166
return FOUND;
1167
1168
/* It could be describe output that is "SOMETHING-gXXXX" */
1166
- ret = get_describe_name(the_repository, name, len, oid);
1169
+ ret = get_describe_name(r, name, len, oid);
1170
if (!ret)
1171
return FOUND;
1172
1170
- return get_short_oid(the_repository, name, len, oid, lookup_flags);
1173
+ return get_short_oid(r, name, len, oid, lookup_flags);
1174
}
1175
1176
/*
@@ -1741,7 +1744,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,
1744
memset(oc, 0, sizeof(*oc));
1745
oc->mode = S_IFINVALID;
1746
strbuf_init(&oc->symlink_path, 0);
1744
- ret = get_oid_1(name, namelen, oid, flags);
1747
+ ret = get_oid_1(repo, name, namelen, oid, flags);
1748
if (!ret)
1749
return ret;
1750
/*
@@ -1822,7 +1825,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,
1825
sub_flags &= ~GET_OID_DISAMBIGUATORS;
1826
sub_flags |= GET_OID_TREEISH;
1827
1825
- if (!get_oid_1(name, len, &tree_oid, sub_flags)) {
1828
+ if (!get_oid_1(repo, name, len, &tree_oid, sub_flags)) {
1829
const char *filename = cp+1;
1830
char *new_filename = NULL;
1831