Skip to content

Commit f4f7e75

Browse files
committed
Merge branch 'es/rev-list-no-object-names'
"git rev-list --objects" learned with "--no-object-names" option to squelch the path to the object that is used as a grouping hint for pack-objects. * es/rev-list-no-object-names: rev-list: teach --no-object-names to enable piping
2 parents 9331bdb + 42357b4 commit f4f7e75

File tree

4 files changed

+49
-1
lines changed

4 files changed

+49
-1
lines changed

Documentation/git-rev-list.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ SYNOPSIS
4848
[ --date=<format>]
4949
[ [ --objects | --objects-edge | --objects-edge-aggressive ]
5050
[ --unpacked ]
51+
[ --object-names | --no-object-names ]
5152
[ --filter=<filter-spec> [ --filter-print-omitted ] ] ]
5253
[ --missing=<missing-action> ]
5354
[ --pretty | --header ]

Documentation/rev-list-options.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,16 @@ ifdef::git-rev-list[]
708708
Only useful with `--objects`; print the object IDs that are not
709709
in packs.
710710

711+
--object-names::
712+
Only useful with `--objects`; print the names of the object IDs
713+
that are found. This is the default behavior.
714+
715+
--no-object-names::
716+
Only useful with `--objects`; does not print the names of the object
717+
IDs that are found. This inverts `--object-names`. This flag allows
718+
the output to be more easily parsed by commands such as
719+
linkgit:git-cat-file[1].
720+
711721
--filter=<filter-spec>::
712722
Only useful with one of the `--objects*`; omits objects (usually
713723
blobs) from the list of printed objects. The '<filter-spec>'

builtin/rev-list.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ static const char rev_list_usage[] =
4949
" --objects | --objects-edge\n"
5050
" --unpacked\n"
5151
" --header | --pretty\n"
52+
" --[no-]object-names\n"
5253
" --abbrev=<n> | --no-abbrev\n"
5354
" --abbrev-commit\n"
5455
" --left-right\n"
@@ -75,6 +76,9 @@ enum missing_action {
7576
};
7677
static enum missing_action arg_missing_action;
7778

79+
/* display only the oid of each object encountered */
80+
static int arg_show_object_names = 1;
81+
7882
#define DEFAULT_OIDSET_SIZE (16*1024)
7983

8084
static void finish_commit(struct commit *commit);
@@ -255,7 +259,10 @@ static void show_object(struct object *obj, const char *name, void *cb_data)
255259
display_progress(progress, ++progress_counter);
256260
if (info->flags & REV_LIST_QUIET)
257261
return;
258-
show_object_with_name(stdout, obj, name);
262+
if (arg_show_object_names)
263+
show_object_with_name(stdout, obj, name);
264+
else
265+
printf("%s\n", oid_to_hex(&obj->oid));
259266
}
260267

261268
static void show_edge(struct commit *commit)
@@ -484,6 +491,16 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
484491
if (skip_prefix(arg, "--missing=", &arg))
485492
continue; /* already handled above */
486493

494+
if (!strcmp(arg, ("--no-object-names"))) {
495+
arg_show_object_names = 0;
496+
continue;
497+
}
498+
499+
if (!strcmp(arg, ("--object-names"))) {
500+
arg_show_object_names = 1;
501+
continue;
502+
}
503+
487504
usage(rev_list_usage);
488505

489506
}

t/t6000-rev-list-misc.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,26 @@ test_expect_success 'rev-list --objects with pathspecs and copied files' '
4848
! grep one output
4949
'
5050

51+
test_expect_success 'rev-list --objects --no-object-names has no space/names' '
52+
git rev-list --objects --no-object-names HEAD >output &&
53+
! grep wanted_file output &&
54+
! grep unwanted_file output &&
55+
! grep " " output
56+
'
57+
58+
test_expect_success 'rev-list --objects --no-object-names works with cat-file' '
59+
git rev-list --objects --no-object-names --all >list-output &&
60+
git cat-file --batch-check <list-output >cat-output &&
61+
! grep missing cat-output
62+
'
63+
64+
test_expect_success '--no-object-names and --object-names are last-one-wins' '
65+
git rev-list --objects --no-object-names --object-names --all >output &&
66+
grep wanted_file output &&
67+
git rev-list --objects --object-names --no-object-names --all >output &&
68+
! grep wanted_file output
69+
'
70+
5171
test_expect_success 'rev-list A..B and rev-list ^A B are the same' '
5272
git commit --allow-empty -m another &&
5373
git tag -a -m "annotated" v1.0 &&

0 commit comments

Comments
 (0)