Skip to content

Commit 898b188

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 introduces 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 6c5c234 commit 898b188

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
@@ -255,8 +255,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
255255
* fall-back to the usual case.
256256
*/
257257
}
258-
buf = read_object_with_reference(the_repository, &oid,
259-
exp_type_id, &size, NULL);
258+
buf = odb_read_object_peeled(the_repository->objects, &oid,
259+
exp_type_id, &size, NULL);
260260

261261
if (use_mailmap) {
262262
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
@@ -914,11 +914,11 @@ void *odb_read_object(struct object_database *odb,
914914
return data;
915915
}
916916

917-
void *read_object_with_reference(struct repository *r,
918-
const struct object_id *oid,
919-
enum object_type required_type,
920-
unsigned long *size,
921-
struct object_id *actual_oid_return)
917+
void *odb_read_object_peeled(struct object_database *odb,
918+
const struct object_id *oid,
919+
enum object_type required_type,
920+
unsigned long *size,
921+
struct object_id *actual_oid_return)
922922
{
923923
enum object_type type;
924924
void *buffer;
@@ -930,7 +930,7 @@ void *read_object_with_reference(struct repository *r,
930930
int ref_length = -1;
931931
const char *ref_type = NULL;
932932

933-
buffer = odb_read_object(r->objects, &actual_oid, &type, &isize);
933+
buffer = odb_read_object(odb, &actual_oid, &type, &isize);
934934
if (!buffer)
935935
return NULL;
936936
if (type == required_type) {
@@ -950,9 +950,10 @@ void *read_object_with_reference(struct repository *r,
950950
}
951951
ref_length = strlen(ref_type);
952952

953-
if (ref_length + r->hash_algo->hexsz > isize ||
953+
if (ref_length + odb->repo->hash_algo->hexsz > isize ||
954954
memcmp(buffer, ref_type, ref_length) ||
955-
get_oid_hex_algop((char *) buffer + ref_length, &actual_oid, r->hash_algo)) {
955+
get_oid_hex_algop((char *) buffer + ref_length, &actual_oid,
956+
odb->repo->hash_algo)) {
956957
free(buffer);
957958
return NULL;
958959
}

odb.h

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

269+
void *odb_read_object_peeled(struct object_database *odb,
270+
const struct object_id *oid,
271+
enum object_type required_type,
272+
unsigned long *size,
273+
struct object_id *oid_ret);
274+
269275
/*
270276
* Add an object file to the in-memory object store, without writing it
271277
* to disk.
@@ -377,7 +383,7 @@ void odb_assert_oid_type(struct object_database *odb,
377383
/*
378384
* Enabling the object read lock allows multiple threads to safely call the
379385
* following functions in parallel: odb_read_object(),
380-
* read_object_with_reference(), odb_read_object_info() and odb().
386+
* odb_read_object_peeled(), odb_read_object_info() and odb().
381387
*
382388
* obj_read_lock() and obj_read_unlock() may also be used to protect other
383389
* section which cannot execute in parallel with object reading. Since the used
@@ -426,13 +432,6 @@ enum for_each_object_flags {
426432
FOR_EACH_OBJECT_SKIP_ON_DISK_KEPT_PACKS = (1<<4),
427433
};
428434

429-
430-
void *read_object_with_reference(struct repository *r,
431-
const struct object_id *oid,
432-
enum object_type required_type,
433-
unsigned long *size,
434-
struct object_id *oid_ret);
435-
436435
/* Compatibility wrappers, to be removed once Git 2.50 has been released. */
437436
#include "repository.h"
438437

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)