From: Matheus Tavares <matheus.bernardino@usp.br>
To: git@vger.kernel.org
Cc: Jonathan Nieder <jrnieder@gmail.com>,
Brandon Williams <bwilliams.eng@gmail.com>,
Junio C Hamano <gitster@pobox.com>, Jeff King <peff@peff.net>,
"brian m. carlson" <sandals@crustytoothpaste.net>
Subject: [RFC PATCH 2/3] object: allow parse_object_or_die() to handle any repo
Date: Tue, 17 Sep 2019 22:56:04 -0300 [thread overview]
Message-ID: <e819ba8a81b11db597bb33e94da869c9ca10febb.1568771073.git.matheus.bernardino@usp.br> (raw)
In-Reply-To: <cover.1568771073.git.matheus.bernardino@usp.br>
parse_object_or_die() was added before parse_object() learned to handle
arbitrary repositories. Now that it did, let's also bring this behavior
improvement to the former, adding a struct repository argument. Also
adjust the callers and, while we are here, avoid using `oid_to_hex(oid)`
for the third parameter as it's the default when NULL is given.
This will be used in the following patch, to allow git-grep to parse
submodule's objects.
Signed-off-by: Matheus Tavares <matheus.bernardino@usp.br>
---
builtin/grep.c | 4 ++--
builtin/prune.c | 4 ++--
bundle.c | 13 ++++++++-----
object.c | 5 +++--
object.h | 4 +++-
pack-bitmap.c | 5 +++--
reachable.c | 4 ++--
upload-pack.c | 2 +-
8 files changed, 24 insertions(+), 17 deletions(-)
diff --git a/builtin/grep.c b/builtin/grep.c
index 2699001fbd..73ef00c426 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -455,7 +455,7 @@ static int grep_submodule(struct grep_opt *opt,
unsigned long size;
struct strbuf base = STRBUF_INIT;
- object = parse_object_or_die(oid, oid_to_hex(oid));
+ object = parse_object_or_die(the_repository, oid, NULL);
grep_read_lock();
data = read_object_with_reference(&subrepo,
@@ -1037,7 +1037,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
break;
}
- object = parse_object_or_die(&oid, arg);
+ object = parse_object_or_die(the_repository, &oid, arg);
if (!seen_dashdash)
verify_non_filename(prefix, arg);
add_object_array_with_path(object, arg, &list, oc.mode, oc.path);
diff --git a/builtin/prune.c b/builtin/prune.c
index 2b76872ad2..996defe284 100644
--- a/builtin/prune.c
+++ b/builtin/prune.c
@@ -154,8 +154,8 @@ int cmd_prune(int argc, const char **argv, const char *prefix)
const char *name = *argv++;
if (!get_oid(name, &oid)) {
- struct object *object = parse_object_or_die(&oid,
- name);
+ struct object *object =
+ parse_object_or_die(the_repository, &oid, name);
add_pending_object(&revs, object, "");
}
else
diff --git a/bundle.c b/bundle.c
index b5d21cd80f..67552786a5 100644
--- a/bundle.c
+++ b/bundle.c
@@ -315,14 +315,16 @@ static int compute_and_write_prerequisites(int bundle_fd,
if (buf.len > 0 && buf.buf[0] == '-') {
write_or_die(bundle_fd, buf.buf, buf.len);
if (!get_oid_hex(buf.buf + 1, &oid)) {
- struct object *object = parse_object_or_die(&oid,
- buf.buf);
+ struct object *object =
+ parse_object_or_die(the_repository,
+ &oid, buf.buf);
object->flags |= UNINTERESTING;
add_pending_object(revs, object, buf.buf);
}
} else if (!get_oid_hex(buf.buf, &oid)) {
- struct object *object = parse_object_or_die(&oid,
- buf.buf);
+ struct object *object =
+ parse_object_or_die(the_repository,
+ &oid, buf.buf);
object->flags |= SHOWN;
}
}
@@ -406,7 +408,8 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs)
* end up triggering "empty bundle"
* error.
*/
- obj = parse_object_or_die(&oid, e->name);
+ obj = parse_object_or_die(the_repository, &oid,
+ e->name);
obj->flags |= SHOWN;
add_pending_object(revs, obj, e->name);
}
diff --git a/object.c b/object.c
index 07bdd5b26e..54c4861f4c 100644
--- a/object.c
+++ b/object.c
@@ -237,10 +237,11 @@ struct object *parse_object_buffer(struct repository *r, const struct object_id
return obj;
}
-struct object *parse_object_or_die(const struct object_id *oid,
+struct object *parse_object_or_die(struct repository *r,
+ const struct object_id *oid,
const char *name)
{
- struct object *o = parse_object(the_repository, oid);
+ struct object *o = parse_object(r, oid);
if (o)
return o;
diff --git a/object.h b/object.h
index 0120892bbd..d8f02f53cd 100644
--- a/object.h
+++ b/object.h
@@ -134,7 +134,9 @@ struct object *parse_object(struct repository *r, const struct object_id *oid);
* "name" parameter is not NULL, it is included in the error message
* (otherwise, the hex object ID is given).
*/
-struct object *parse_object_or_die(const struct object_id *oid, const char *name);
+struct object *parse_object_or_die(struct repository *r,
+ const struct object_id *oid,
+ const char *name);
/* Given the result of read_sha1_file(), returns the object after
* parsing it. eaten_p indicates if the object has a borrowed copy
diff --git a/pack-bitmap.c b/pack-bitmap.c
index ed2befaac6..383b2351db 100644
--- a/pack-bitmap.c
+++ b/pack-bitmap.c
@@ -699,7 +699,7 @@ struct bitmap_index *prepare_bitmap_walk(struct rev_info *revs)
struct object *object = revs->pending.objects[i].item;
if (object->type == OBJ_NONE)
- parse_object_or_die(&object->oid, NULL);
+ parse_object_or_die(the_repository, &object->oid, NULL);
while (object->type == OBJ_TAG) {
struct tag *tag = (struct tag *) object;
@@ -711,7 +711,8 @@ struct bitmap_index *prepare_bitmap_walk(struct rev_info *revs)
if (!tag->tagged)
die("bad tag");
- object = parse_object_or_die(&tag->tagged->oid, NULL);
+ object = parse_object_or_die(the_repository,
+ &tag->tagged->oid, NULL);
}
if (object->flags & UNINTERESTING)
diff --git a/reachable.c b/reachable.c
index 8f50235b28..7c5f7a0ba0 100644
--- a/reachable.c
+++ b/reachable.c
@@ -37,7 +37,7 @@ static int add_one_ref(const char *path, const struct object_id *oid,
return 0;
}
- object = parse_object_or_die(oid, path);
+ object = parse_object_or_die(the_repository, oid, path);
add_pending_object(revs, object, "");
return 0;
@@ -86,7 +86,7 @@ static void add_recent_object(const struct object_id *oid,
switch (type) {
case OBJ_TAG:
case OBJ_COMMIT:
- obj = parse_object_or_die(oid, NULL);
+ obj = parse_object_or_die(the_repository, oid, NULL);
break;
case OBJ_TREE:
obj = (struct object *)lookup_tree(the_repository, oid);
diff --git a/upload-pack.c b/upload-pack.c
index 222cd3ad89..648ff3355b 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -1220,7 +1220,7 @@ static int parse_want_ref(struct packet_writer *writer, const char *line,
item = string_list_append(wanted_refs, arg);
item->util = oiddup(&oid);
- o = parse_object_or_die(&oid, arg);
+ o = parse_object_or_die(the_repository, &oid, arg);
if (!(o->flags & WANTED)) {
o->flags |= WANTED;
add_object_array(o, NULL, want_obj);
--
2.23.0
next prev parent reply other threads:[~2019-09-18 1:56 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-18 1:56 [RFC PATCH 0/3] grep: don't add subrepos to in-memory alternates Matheus Tavares
2019-09-18 1:56 ` [RFC PATCH 1/3] diff: use the given repo at diff_populate_filespec() Matheus Tavares
2019-09-18 1:56 ` Matheus Tavares [this message]
2019-09-18 1:56 ` [RFC PATCH 3/3] grep: don't add submodules to the alternates list Matheus Tavares
2019-09-21 21:58 ` Brandon Williams
2019-09-18 19:55 ` [RFC PATCH 0/3] grep: don't add subrepos to in-memory alternates Junio C Hamano
2019-09-19 5:18 ` Matheus Tavares Bernardino
2019-09-20 16:26 ` Junio C Hamano
2019-09-21 20:34 ` Matheus Tavares Bernardino
2019-09-28 3:24 ` Junio C Hamano
2019-09-28 4:20 ` Matheus Tavares Bernardino
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=e819ba8a81b11db597bb33e94da869c9ca10febb.1568771073.git.matheus.bernardino@usp.br \
--to=matheus.bernardino@usp.br \
--cc=bwilliams.eng@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jrnieder@gmail.com \
--cc=peff@peff.net \
--cc=sandals@crustytoothpaste.net \
/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).