Skip to content

Commit 841a03b

Browse files
pks-tgitster
authored andcommitted
odb: rename read_object_with_reference()
Rename `read_object_with_reference()` to `odb_read_object_peeled()` to match other functions related to the object database and our modern coding guidelines. Furthermore though, the old name didn't really describe very well what this function actually does, which is to walk down any commit and tag objects until an object of the required type has been found. This is generally referred to as "peeling", so the new name should be way more descriptive. No compatibility wrapper is introduced as the function is not used a lot throughout our codebase. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 08218b8 commit 841a03b

File tree

8 files changed

+37
-45
lines changed

8 files changed

+37
-45
lines changed

Documentation/user-manual.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4301,11 +4301,11 @@ Now, for the meat:
43014301

43024302
-----------------------------------------------------------------------------
43034303
case 0:
4304-
buf = read_object_with_reference(sha1, argv[1], &size, NULL);
4304+
buf = odb_read_object_peeled(r->objects, sha1, argv[1], &size, NULL);
43054305
-----------------------------------------------------------------------------
43064306

43074307
This is how you read a blob (actually, not only a blob, but any type of
4308-
object). To know how the function `read_object_with_reference()` actually
4308+
object). To know how the function `odb_read_object_peeled()` actually
43094309
works, find the source code for it (something like `git grep
43104310
read_object_with | grep ":[a-z]"` in the Git repository), and read
43114311
the source.

builtin/cat-file.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
246246
* fall-back to the usual case.
247247
*/
248248
}
249-
buf = read_object_with_reference(the_repository, &oid,
250-
exp_type_id, &size, NULL);
249+
buf = odb_read_object_peeled(the_repository->objects, &oid,
250+
exp_type_id, &size, NULL);
251251

252252
if (use_mailmap) {
253253
size_t s = size;

builtin/fast-import.c

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2535,10 +2535,9 @@ static void note_change_n(const char *p, struct branch *b, unsigned char *old_fa
25352535
oidcpy(&commit_oid, &commit_oe->idx.oid);
25362536
} else if (!repo_get_oid(the_repository, p, &commit_oid)) {
25372537
unsigned long size;
2538-
char *buf = read_object_with_reference(the_repository,
2539-
&commit_oid,
2540-
OBJ_COMMIT, &size,
2541-
&commit_oid);
2538+
char *buf = odb_read_object_peeled(the_repository->objects,
2539+
&commit_oid, OBJ_COMMIT, &size,
2540+
&commit_oid);
25422541
if (!buf || size < the_hash_algo->hexsz + 6)
25432542
die("Not a valid commit: %s", p);
25442543
free(buf);
@@ -2604,9 +2603,8 @@ static void parse_from_existing(struct branch *b)
26042603
unsigned long size;
26052604
char *buf;
26062605

2607-
buf = read_object_with_reference(the_repository,
2608-
&b->oid, OBJ_COMMIT, &size,
2609-
&b->oid);
2606+
buf = odb_read_object_peeled(the_repository->objects, &b->oid,
2607+
OBJ_COMMIT, &size, &b->oid);
26102608
parse_from_commit(b, buf, size);
26112609
free(buf);
26122610
}
@@ -2699,10 +2697,9 @@ static struct hash_list *parse_merge(unsigned int *count)
26992697
oidcpy(&n->oid, &oe->idx.oid);
27002698
} else if (!repo_get_oid(the_repository, from, &n->oid)) {
27012699
unsigned long size;
2702-
char *buf = read_object_with_reference(the_repository,
2703-
&n->oid,
2704-
OBJ_COMMIT,
2705-
&size, &n->oid);
2700+
char *buf = odb_read_object_peeled(the_repository->objects,
2701+
&n->oid, OBJ_COMMIT,
2702+
&size, &n->oid);
27062703
if (!buf || size < the_hash_algo->hexsz + 6)
27072704
die("Not a valid commit: %s", from);
27082705
free(buf);

builtin/grep.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -522,9 +522,7 @@ static int grep_submodule(struct grep_opt *opt,
522522
obj_read_lock();
523523
object_type = odb_read_object_info(subrepo->objects, oid, NULL);
524524
obj_read_unlock();
525-
data = read_object_with_reference(subrepo,
526-
oid, OBJ_TREE,
527-
&size, NULL);
525+
data = odb_read_object_peeled(subrepo->objects, oid, OBJ_TREE, &size, NULL);
528526
if (!data)
529527
die(_("unable to read tree (%s)"), oid_to_hex(oid));
530528

@@ -705,9 +703,8 @@ static int grep_object(struct grep_opt *opt, const struct pathspec *pathspec,
705703
struct strbuf base;
706704
int hit, len;
707705

708-
data = read_object_with_reference(opt->repo,
709-
&obj->oid, OBJ_TREE,
710-
&size, NULL);
706+
data = odb_read_object_peeled(opt->repo->objects, &obj->oid,
707+
OBJ_TREE, &size, NULL);
711708
if (!data)
712709
die(_("unable to read tree (%s)"), oid_to_hex(&obj->oid));
713710

builtin/pack-objects.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2055,8 +2055,8 @@ static void add_preferred_base(struct object_id *oid)
20552055
if (window <= num_preferred_base++)
20562056
return;
20572057

2058-
data = read_object_with_reference(the_repository, oid,
2059-
OBJ_TREE, &size, &tree_oid);
2058+
data = odb_read_object_peeled(the_repository->objects, oid,
2059+
OBJ_TREE, &size, &tree_oid);
20602060
if (!data)
20612061
return;
20622062

odb.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -905,11 +905,11 @@ void *odb_read_object(struct object_database *odb,
905905
return data;
906906
}
907907

908-
void *read_object_with_reference(struct repository *r,
909-
const struct object_id *oid,
910-
enum object_type required_type,
911-
unsigned long *size,
912-
struct object_id *actual_oid_return)
908+
void *odb_read_object_peeled(struct object_database *odb,
909+
const struct object_id *oid,
910+
enum object_type required_type,
911+
unsigned long *size,
912+
struct object_id *actual_oid_return)
913913
{
914914
enum object_type type;
915915
void *buffer;
@@ -921,7 +921,7 @@ void *read_object_with_reference(struct repository *r,
921921
int ref_length = -1;
922922
const char *ref_type = NULL;
923923

924-
buffer = odb_read_object(r->objects, &actual_oid, &type, &isize);
924+
buffer = odb_read_object(odb, &actual_oid, &type, &isize);
925925
if (!buffer)
926926
return NULL;
927927
if (type == required_type) {
@@ -941,9 +941,10 @@ void *read_object_with_reference(struct repository *r,
941941
}
942942
ref_length = strlen(ref_type);
943943

944-
if (ref_length + r->hash_algo->hexsz > isize ||
944+
if (ref_length + odb->repo->hash_algo->hexsz > isize ||
945945
memcmp(buffer, ref_type, ref_length) ||
946-
get_oid_hex_algop((char *) buffer + ref_length, &actual_oid, r->hash_algo)) {
946+
get_oid_hex_algop((char *) buffer + ref_length, &actual_oid,
947+
odb->repo->hash_algo)) {
947948
free(buffer);
948949
return NULL;
949950
}

odb.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,12 @@ void *odb_read_object(struct object_database *odb,
274274
enum object_type *type,
275275
unsigned long *size);
276276

277+
void *odb_read_object_peeled(struct object_database *odb,
278+
const struct object_id *oid,
279+
enum object_type required_type,
280+
unsigned long *size,
281+
struct object_id *oid_ret);
282+
277283
/*
278284
* Add an object file to the in-memory object store, without writing it
279285
* to disk.
@@ -382,7 +388,7 @@ void odb_assert_oid_type(struct object_database *odb,
382388
/*
383389
* Enabling the object read lock allows multiple threads to safely call the
384390
* following functions in parallel: odb_read_object(),
385-
* read_object_with_reference(), odb_read_object_info() and odb().
391+
* odb_read_object_peeled(), odb_read_object_info() and odb().
386392
*
387393
* obj_read_lock() and obj_read_unlock() may also be used to protect other
388394
* section which cannot execute in parallel with object reading. Since the used
@@ -431,13 +437,6 @@ enum for_each_object_flags {
431437
FOR_EACH_OBJECT_SKIP_ON_DISK_KEPT_PACKS = (1<<4),
432438
};
433439

434-
435-
void *read_object_with_reference(struct repository *r,
436-
const struct object_id *oid,
437-
enum object_type required_type,
438-
unsigned long *size,
439-
struct object_id *oid_ret);
440-
441440
/* Compatibility wrappers, to be removed once Git 2.51 has been released. */
442441
#include "repository.h"
443442

tree-walk.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ void *fill_tree_descriptor(struct repository *r,
9090
void *buf = NULL;
9191

9292
if (oid) {
93-
buf = read_object_with_reference(r, oid, OBJ_TREE, &size, NULL);
93+
buf = odb_read_object_peeled(r->objects, oid, OBJ_TREE, &size, NULL);
9494
if (!buf)
9595
die(_("unable to read tree (%s)"), oid_to_hex(oid));
9696
}
@@ -611,7 +611,7 @@ int get_tree_entry(struct repository *r,
611611
unsigned long size;
612612
struct object_id root;
613613

614-
tree = read_object_with_reference(r, tree_oid, OBJ_TREE, &size, &root);
614+
tree = odb_read_object_peeled(r->objects, tree_oid, OBJ_TREE, &size, &root);
615615
if (!tree)
616616
return -1;
617617

@@ -681,10 +681,8 @@ enum get_oid_result get_tree_entry_follow_symlinks(struct repository *r,
681681
void *tree;
682682
struct object_id root;
683683
unsigned long size;
684-
tree = read_object_with_reference(r,
685-
&current_tree_oid,
686-
OBJ_TREE, &size,
687-
&root);
684+
tree = odb_read_object_peeled(r->objects, &current_tree_oid,
685+
OBJ_TREE, &size, &root);
688686
if (!tree)
689687
goto done;
690688

0 commit comments

Comments
 (0)