log: refactor "rev.pending" code in cmd_show()
Refactor the juggling of "rev.pending" and our replacement for it amended in the preceding commit so that: * We use an "unsigned int" instead of an "int" for "i", this matches the types of "struct rev_info" itself. * We don't need the "count" and "objects" variables introduced in5d7eeee2ac
(git-show: grok blobs, trees and tags, too, 2006-12-14). They were originally added since we'd clobber rev.pending in the loop without restoring it. Since the preceding commit we are restoring it when we handle OBJ_COMMIT, so the main for-loop can refer to "rev.pending" didrectly. * We use the "memcpy a &blank" idiom introduced in5726a6b401
(*.c *_init(): define in terms of corresponding *_INIT macro, 2021-07-01). This is more obvious than relying on us enumerating all of the relevant members of the "struct object_array" that we need to clear. * We comment on why we don't need an object_array_clear() here, see the analysis in [1]. 1. https://lore.kernel.org/git/YuQtJ2DxNKX%2Fy70N@coredump.intra.peff.net/ Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Helped-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
055e57b7b2
commit
f89d085b3f
@ -668,10 +668,10 @@ static void show_setup_revisions_tweak(struct rev_info *rev,
|
||||
int cmd_show(int argc, const char **argv, const char *prefix)
|
||||
{
|
||||
struct rev_info rev;
|
||||
struct object_array_entry *objects;
|
||||
unsigned int i;
|
||||
struct setup_revision_opt opt;
|
||||
struct pathspec match_all;
|
||||
int i, count, ret = 0;
|
||||
int ret = 0;
|
||||
|
||||
init_log_defaults();
|
||||
git_config(git_log_config, NULL);
|
||||
@ -698,12 +698,10 @@ int cmd_show(int argc, const char **argv, const char *prefix)
|
||||
if (!rev.no_walk)
|
||||
return cmd_log_deinit(cmd_log_walk(&rev), &rev);
|
||||
|
||||
count = rev.pending.nr;
|
||||
objects = rev.pending.objects;
|
||||
rev.diffopt.no_free = 1;
|
||||
for (i = 0; i < count && !ret; i++) {
|
||||
struct object *o = objects[i].item;
|
||||
const char *name = objects[i].name;
|
||||
for (i = 0; i < rev.pending.nr && !ret; i++) {
|
||||
struct object *o = rev.pending.objects[i].item;
|
||||
const char *name = rev.pending.objects[i].name;
|
||||
switch (o->type) {
|
||||
case OBJ_BLOB:
|
||||
ret = show_blob_object(&o->oid, &rev, name);
|
||||
@ -726,7 +724,7 @@ int cmd_show(int argc, const char **argv, const char *prefix)
|
||||
if (!o)
|
||||
ret = error(_("could not read object %s"),
|
||||
oid_to_hex(oid));
|
||||
objects[i].item = o;
|
||||
rev.pending.objects[i].item = o;
|
||||
i--;
|
||||
break;
|
||||
}
|
||||
@ -745,12 +743,19 @@ int cmd_show(int argc, const char **argv, const char *prefix)
|
||||
case OBJ_COMMIT:
|
||||
{
|
||||
struct object_array old;
|
||||
struct object_array blank = OBJECT_ARRAY_INIT;
|
||||
|
||||
memcpy(&old, &rev.pending, sizeof(old));
|
||||
rev.pending.nr = rev.pending.alloc = 0;
|
||||
rev.pending.objects = NULL;
|
||||
memcpy(&rev.pending, &blank, sizeof(rev.pending));
|
||||
|
||||
add_object_array(o, name, &rev.pending);
|
||||
ret = cmd_log_walk_no_free(&rev);
|
||||
|
||||
/*
|
||||
* No need for
|
||||
* object_array_clear(&pending). It was
|
||||
* cleared already in prepare_revision_walk()
|
||||
*/
|
||||
memcpy(&rev.pending, &old, sizeof(rev.pending));
|
||||
break;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user