From: Jeff King <peff@peff.net>
To: Christian Couder <christian.couder@gmail.com>
Cc: git@vger.kernel.org, "Junio C Hamano" <gitster@pobox.com>,
"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
"Jonathan Tan" <jonathantanmy@google.com>,
"SZEDER Gábor" <szeder.dev@gmail.com>,
"Christian Couder" <chriscool@tuxfamily.org>
Subject: [PATCH 07/17] object: convert lookup_object() to use object_id
Date: Thu, 20 Jun 2019 03:41:14 -0400 [thread overview]
Message-ID: <20190620074114.GG3713@sigill.intra.peff.net> (raw)
In-Reply-To: <20190620073952.GA1539@sigill.intra.peff.net>
There are no callers left of lookup_object() that aren't just passing us
the "hash" member of a "struct object_id". Let's take the whole struct,
which gets us closer to removing all raw sha1 variables. It also
matches the existing conversions of lookup_blob(), etc.
The conversions of callers were done by hand, but they're all mechanical
one-liners.
Signed-off-by: Jeff King <peff@peff.net>
---
blob.c | 2 +-
builtin/fast-export.c | 4 ++--
builtin/fsck.c | 6 +++---
builtin/name-rev.c | 3 +--
builtin/prune.c | 2 +-
builtin/unpack-objects.c | 2 +-
commit.c | 2 +-
delta-islands.c | 2 +-
fetch-pack.c | 12 ++++++------
http-push.c | 2 +-
object.c | 12 ++++++------
object.h | 2 +-
reachable.c | 4 ++--
tag.c | 2 +-
tree.c | 2 +-
upload-pack.c | 2 +-
16 files changed, 30 insertions(+), 31 deletions(-)
diff --git a/blob.c b/blob.c
index 342bdbb1bb..b9c7180b7c 100644
--- a/blob.c
+++ b/blob.c
@@ -7,7 +7,7 @@ const char *blob_type = "blob";
struct blob *lookup_blob(struct repository *r, const struct object_id *oid)
{
- struct object *obj = lookup_object(r, oid->hash);
+ struct object *obj = lookup_object(r, oid);
if (!obj)
return create_object(r, oid->hash,
alloc_blob_node(r));
diff --git a/builtin/fast-export.c b/builtin/fast-export.c
index c22cef3b2f..f541f55d33 100644
--- a/builtin/fast-export.c
+++ b/builtin/fast-export.c
@@ -275,7 +275,7 @@ static void export_blob(const struct object_id *oid)
if (is_null_oid(oid))
return;
- object = lookup_object(the_repository, oid->hash);
+ object = lookup_object(the_repository, oid);
if (object && object->flags & SHOWN)
return;
@@ -453,7 +453,7 @@ static void show_filemodify(struct diff_queue_struct *q,
&spec->oid));
else {
struct object *object = lookup_object(the_repository,
- spec->oid.hash);
+ &spec->oid);
printf("M %06o :%d ", spec->mode,
get_object_mark(object));
}
diff --git a/builtin/fsck.c b/builtin/fsck.c
index e422c82465..18403a94fa 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -238,7 +238,7 @@ static int mark_used(struct object *obj, int type, void *data, struct fsck_optio
static void mark_unreachable_referents(const struct object_id *oid)
{
struct fsck_options options = FSCK_OPTIONS_DEFAULT;
- struct object *obj = lookup_object(the_repository, oid->hash);
+ struct object *obj = lookup_object(the_repository, oid);
if (!obj || !(obj->flags & HAS_OBJ))
return; /* not part of our original set */
@@ -497,7 +497,7 @@ static void fsck_handle_reflog_oid(const char *refname, struct object_id *oid,
struct object *obj;
if (!is_null_oid(oid)) {
- obj = lookup_object(the_repository, oid->hash);
+ obj = lookup_object(the_repository, oid);
if (obj && (obj->flags & HAS_OBJ)) {
if (timestamp && name_objects)
add_decoration(fsck_walk_options.object_names,
@@ -879,7 +879,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
struct object_id oid;
if (!get_oid(arg, &oid)) {
struct object *obj = lookup_object(the_repository,
- oid.hash);
+ &oid);
if (!obj || !(obj->flags & HAS_OBJ)) {
if (is_promisor_object(&oid))
diff --git a/builtin/name-rev.c b/builtin/name-rev.c
index 16df43473a..c785fe16ba 100644
--- a/builtin/name-rev.c
+++ b/builtin/name-rev.c
@@ -378,8 +378,7 @@ static void name_rev_line(char *p, struct name_ref_data *data)
*(p+1) = 0;
if (!get_oid(p - (hexsz - 1), &oid)) {
struct object *o =
- lookup_object(the_repository,
- oid.hash);
+ lookup_object(the_repository, &oid);
if (o)
name = get_rev_name(o, &buf);
}
diff --git a/builtin/prune.c b/builtin/prune.c
index 97613eccb5..2b76872ad2 100644
--- a/builtin/prune.c
+++ b/builtin/prune.c
@@ -53,7 +53,7 @@ static int is_object_reachable(const struct object_id *oid,
perform_reachability_traversal(revs);
- obj = lookup_object(the_repository, oid->hash);
+ obj = lookup_object(the_repository, oid);
return obj && (obj->flags & SEEN);
}
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index 80478808b3..a87a4bfd2c 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -332,7 +332,7 @@ static int resolve_against_held(unsigned nr, const struct object_id *base,
{
struct object *obj;
struct obj_buffer *obj_buffer;
- obj = lookup_object(the_repository, base->hash);
+ obj = lookup_object(the_repository, base);
if (!obj)
return 0;
obj_buffer = lookup_object_buffer(obj);
diff --git a/commit.c b/commit.c
index 8fa1883c61..f47c75afae 100644
--- a/commit.c
+++ b/commit.c
@@ -57,7 +57,7 @@ struct commit *lookup_commit_or_die(const struct object_id *oid, const char *ref
struct commit *lookup_commit(struct repository *r, const struct object_id *oid)
{
- struct object *obj = lookup_object(r, oid->hash);
+ struct object *obj = lookup_object(r, oid);
if (!obj)
return create_object(r, oid->hash,
alloc_commit_node(r));
diff --git a/delta-islands.c b/delta-islands.c
index 2186bd0738..5f3ab914f5 100644
--- a/delta-islands.c
+++ b/delta-islands.c
@@ -296,7 +296,7 @@ void resolve_tree_islands(struct repository *r,
if (S_ISGITLINK(entry.mode))
continue;
- obj = lookup_object(r, entry.oid.hash);
+ obj = lookup_object(r, &entry.oid);
if (!obj)
continue;
diff --git a/fetch-pack.c b/fetch-pack.c
index 1c10f54e78..07bc48a1a5 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -286,7 +286,7 @@ static int find_common(struct fetch_negotiator *negotiator,
* we cannot trust the object flags).
*/
if (!args->no_dependents &&
- ((o = lookup_object(the_repository, remote->hash)) != NULL) &&
+ ((o = lookup_object(the_repository, remote)) != NULL) &&
(o->flags & COMPLETE)) {
continue;
}
@@ -364,7 +364,7 @@ static int find_common(struct fetch_negotiator *negotiator,
if (skip_prefix(reader.line, "unshallow ", &arg)) {
if (get_oid_hex(arg, &oid))
die(_("invalid unshallow line: %s"), reader.line);
- if (!lookup_object(the_repository, oid.hash))
+ if (!lookup_object(the_repository, &oid))
die(_("object not found: %s"), reader.line);
/* make sure that it is parsed as shallow */
if (!parse_object(the_repository, &oid))
@@ -707,7 +707,7 @@ static void mark_complete_and_common_ref(struct fetch_negotiator *negotiator,
for (ref = *refs; ref; ref = ref->next) {
struct object *o = deref_tag(the_repository,
lookup_object(the_repository,
- ref->old_oid.hash),
+ &ref->old_oid),
NULL, 0);
if (!o || o->type != OBJ_COMMIT || !(o->flags & COMPLETE))
@@ -734,7 +734,7 @@ static int everything_local(struct fetch_pack_args *args,
const struct object_id *remote = &ref->old_oid;
struct object *o;
- o = lookup_object(the_repository, remote->hash);
+ o = lookup_object(the_repository, remote);
if (!o || !(o->flags & COMPLETE)) {
retval = 0;
print_verbose(args, "want %s (%s)", oid_to_hex(remote),
@@ -1048,7 +1048,7 @@ static void add_wants(int no_dependents, const struct ref *wants, struct strbuf
* we cannot trust the object flags).
*/
if (!no_dependents &&
- ((o = lookup_object(the_repository, remote->hash)) != NULL) &&
+ ((o = lookup_object(the_repository, remote)) != NULL) &&
(o->flags & COMPLETE)) {
continue;
}
@@ -1275,7 +1275,7 @@ static void receive_shallow_info(struct fetch_pack_args *args,
if (skip_prefix(reader->line, "unshallow ", &arg)) {
if (get_oid_hex(arg, &oid))
die(_("invalid unshallow line: %s"), reader->line);
- if (!lookup_object(the_repository, oid.hash))
+ if (!lookup_object(the_repository, &oid))
die(_("object not found: %s"), reader->line);
/* make sure that it is parsed as shallow */
if (!parse_object(the_repository, &oid))
diff --git a/http-push.c b/http-push.c
index 96a98e1e61..0353f9f514 100644
--- a/http-push.c
+++ b/http-push.c
@@ -723,7 +723,7 @@ static void one_remote_object(const struct object_id *oid)
{
struct object *obj;
- obj = lookup_object(the_repository, oid->hash);
+ obj = lookup_object(the_repository, oid);
if (!obj)
obj = parse_object(the_repository, oid);
diff --git a/object.c b/object.c
index d5b1d8daaf..34c1d0dc8f 100644
--- a/object.c
+++ b/object.c
@@ -85,7 +85,7 @@ static void insert_obj_hash(struct object *obj, struct object **hash, unsigned i
* Look up the record for the given sha1 in the hash map stored in
* obj_hash. Return NULL if it was not found.
*/
-struct object *lookup_object(struct repository *r, const unsigned char *sha1)
+struct object *lookup_object(struct repository *r, const struct object_id *oid)
{
unsigned int i, first;
struct object *obj;
@@ -93,9 +93,9 @@ struct object *lookup_object(struct repository *r, const unsigned char *sha1)
if (!r->parsed_objects->obj_hash)
return NULL;
- first = i = hash_obj(sha1, r->parsed_objects->obj_hash_size);
+ first = i = hash_obj(oid->hash, r->parsed_objects->obj_hash_size);
while ((obj = r->parsed_objects->obj_hash[i]) != NULL) {
- if (hasheq(sha1, obj->oid.hash))
+ if (oideq(oid, &obj->oid))
break;
i++;
if (i == r->parsed_objects->obj_hash_size)
@@ -180,7 +180,7 @@ void *object_as_type(struct repository *r, struct object *obj, enum object_type
struct object *lookup_unknown_object(const struct object_id *oid)
{
- struct object *obj = lookup_object(the_repository, oid->hash);
+ struct object *obj = lookup_object(the_repository, oid);
if (!obj)
obj = create_object(the_repository, oid->hash,
alloc_object_node(the_repository));
@@ -256,7 +256,7 @@ struct object *parse_object(struct repository *r, const struct object_id *oid)
void *buffer;
struct object *obj;
- obj = lookup_object(r, oid->hash);
+ obj = lookup_object(r, oid);
if (obj && obj->parsed)
return obj;
@@ -268,7 +268,7 @@ struct object *parse_object(struct repository *r, const struct object_id *oid)
return NULL;
}
parse_blob_buffer(lookup_blob(r, oid), NULL, 0);
- return lookup_object(r, oid->hash);
+ return lookup_object(r, oid);
}
buffer = repo_read_object_file(r, oid, &type, &size);
diff --git a/object.h b/object.h
index 5e0ccfe0e4..47301186a4 100644
--- a/object.h
+++ b/object.h
@@ -116,7 +116,7 @@ struct object *get_indexed_object(unsigned int);
* half-initialised objects, the caller is expected to initialize them
* by calling parse_object() on them.
*/
-struct object *lookup_object(struct repository *r, const unsigned char *sha1);
+struct object *lookup_object(struct repository *r, const struct object_id *oid);
void *create_object(struct repository *r, const unsigned char *sha1, void *obj);
diff --git a/reachable.c b/reachable.c
index 0d00a91de4..8f50235b28 100644
--- a/reachable.c
+++ b/reachable.c
@@ -109,7 +109,7 @@ static int add_recent_loose(const struct object_id *oid,
const char *path, void *data)
{
struct stat st;
- struct object *obj = lookup_object(the_repository, oid->hash);
+ struct object *obj = lookup_object(the_repository, oid);
if (obj && obj->flags & SEEN)
return 0;
@@ -134,7 +134,7 @@ static int add_recent_packed(const struct object_id *oid,
struct packed_git *p, uint32_t pos,
void *data)
{
- struct object *obj = lookup_object(the_repository, oid->hash);
+ struct object *obj = lookup_object(the_repository, oid);
if (obj && obj->flags & SEEN)
return 0;
diff --git a/tag.c b/tag.c
index 7445b8f6ea..3ae00ba1ab 100644
--- a/tag.c
+++ b/tag.c
@@ -100,7 +100,7 @@ struct object *deref_tag_noverify(struct object *o)
struct tag *lookup_tag(struct repository *r, const struct object_id *oid)
{
- struct object *obj = lookup_object(r, oid->hash);
+ struct object *obj = lookup_object(r, oid);
if (!obj)
return create_object(r, oid->hash,
alloc_tag_node(r));
diff --git a/tree.c b/tree.c
index f416afc57d..0ebb8c5b02 100644
--- a/tree.c
+++ b/tree.c
@@ -197,7 +197,7 @@ int read_tree(struct repository *r, struct tree *tree, int stage,
struct tree *lookup_tree(struct repository *r, const struct object_id *oid)
{
- struct object *obj = lookup_object(r, oid->hash);
+ struct object *obj = lookup_object(r, oid);
if (!obj)
return create_object(r, oid->hash,
alloc_tree_node(r));
diff --git a/upload-pack.c b/upload-pack.c
index ecc19641fe..a0f170b5b5 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -534,7 +534,7 @@ static int get_reachable_list(struct object_array *src,
if (parse_oid_hex(namebuf, &oid, &p) || *p != '\n')
break;
- o = lookup_object(the_repository, oid.hash);
+ o = lookup_object(the_repository, &oid);
if (o && o->type == OBJ_COMMIT) {
o->flags &= ~TMP_MARK;
}
--
2.22.0.732.g5402924b4b
next prev parent reply other threads:[~2019-06-20 7:41 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-15 10:06 [PATCH v4 0/4] Test oidmap Christian Couder
2019-06-15 10:06 ` [PATCH v4 1/4] t/helper: add test-oidmap.c Christian Couder
2019-06-15 10:07 ` [PATCH v4 2/4] t: add t0016-oidmap.sh Christian Couder
2019-06-15 10:07 ` [PATCH v4 3/4] oidmap: use sha1hash() instead of static hash() function Christian Couder
2019-06-15 10:07 ` [PATCH v4 4/4] test-hashmap: remove 'hash' command Christian Couder
2019-06-19 21:42 ` [PATCH v4 0/4] Test oidmap Jeff King
2019-06-19 22:09 ` Jeff King
2019-06-19 22:25 ` Christian Couder
2019-06-20 7:39 ` [PATCH 0/17] drop non-object_id hashing Jeff King
2019-06-20 7:40 ` [PATCH 01/17] describe: fix accidental oid/hash type-punning Jeff King
2019-06-20 16:32 ` Junio C Hamano
2019-06-20 18:25 ` Jeff King
2019-06-20 7:40 ` [PATCH 02/17] upload-pack: rename a "sha1" variable to "oid" Jeff King
2019-06-20 7:40 ` [PATCH 03/17] pack-bitmap-write: convert some helpers to use object_id Jeff King
2019-06-20 7:41 ` [PATCH 04/17] pack-objects: convert packlist_find() " Jeff King
2019-06-20 7:41 ` [PATCH 05/17] pack-objects: convert locate_object_entry_hash() to object_id Jeff King
2019-06-20 7:41 ` [PATCH 06/17] object: convert lookup_unknown_object() to use object_id Jeff King
2019-06-20 7:41 ` Jeff King [this message]
2019-06-20 7:41 ` [PATCH 08/17] object: convert internal hash_obj() to object_id Jeff King
2019-06-20 7:41 ` [PATCH 09/17] object: convert create_object() to use object_id Jeff King
2019-06-20 14:21 ` Ramsay Jones
2019-06-20 18:23 ` Jeff King
2019-06-20 7:41 ` [PATCH 10/17] khash: drop broken oid_map typedef Jeff King
2019-06-20 7:41 ` [PATCH 11/17] khash: rename kh_oid_t to kh_oid_set Jeff King
2019-06-20 7:41 ` [PATCH 12/17] delta-islands: convert island_marks khash to use oids Jeff King
2019-06-20 17:38 ` Jonathan Tan
2019-06-20 18:29 ` Jeff King
2019-06-20 7:41 ` [PATCH 13/17] pack-bitmap: convert khash_sha1 maps into kh_oid_map Jeff King
2019-06-20 7:41 ` [PATCH 14/17] khash: drop sha1-specific map types Jeff King
2019-06-20 7:41 ` [PATCH 15/17] khash: rename oid helper functions Jeff King
2019-06-20 17:44 ` Junio C Hamano
2019-06-20 18:27 ` Jeff King
2019-06-23 16:00 ` René Scharfe
2019-06-23 22:46 ` Jeff King
2019-06-20 7:41 ` [PATCH 16/17] hash.h: move object_id definition from cache.h Jeff King
2019-06-20 17:41 ` Junio C Hamano
2019-06-20 7:41 ` [PATCH 17/17] hashmap: convert sha1hash() to oidhash() Jeff King
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190620074114.GG3713@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=avarab@gmail.com \
--cc=chriscool@tuxfamily.org \
--cc=christian.couder@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jonathantanmy@google.com \
--cc=szeder.dev@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).