rev-list: teach --no-object-names to enable piping
Allow easier parsing by cat-file by giving rev-list an option to print only the OID of a non-commit object without any additional information. This is a short-term shim; later on, rev-list should be taught how to print the types of objects it finds in a format similar to cat-file's. Before this commit, the output from rev-list needed to be massaged before being piped to cat-file, like so: git rev-list --objects HEAD | cut -f 1 -d ' ' | git cat-file --batch-check This was especially unexpected when dealing with root trees, as an invisible whitespace exists at the end of the OID: git rev-list --objects --filter=tree:1 --max-count=1 HEAD | xargs -I% echo "AA%AA" Now, it can be piped directly, as in the added test case: git rev-list --objects --no-object-names HEAD | git cat-file --batch-check Signed-off-by: Emily Shaffer <emilyshaffer@google.com> Change-Id: I489bdf0a8215532e540175188883ff7541d70e1b Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
0aae918dd9
commit
42357b4e8b
@ -49,6 +49,7 @@ static const char rev_list_usage[] =
|
||||
" --objects | --objects-edge\n"
|
||||
" --unpacked\n"
|
||||
" --header | --pretty\n"
|
||||
" --[no-]object-names\n"
|
||||
" --abbrev=<n> | --no-abbrev\n"
|
||||
" --abbrev-commit\n"
|
||||
" --left-right\n"
|
||||
@ -75,6 +76,9 @@ enum missing_action {
|
||||
};
|
||||
static enum missing_action arg_missing_action;
|
||||
|
||||
/* display only the oid of each object encountered */
|
||||
static int arg_show_object_names = 1;
|
||||
|
||||
#define DEFAULT_OIDSET_SIZE (16*1024)
|
||||
|
||||
static void finish_commit(struct commit *commit);
|
||||
@ -255,7 +259,10 @@ static void show_object(struct object *obj, const char *name, void *cb_data)
|
||||
display_progress(progress, ++progress_counter);
|
||||
if (info->flags & REV_LIST_QUIET)
|
||||
return;
|
||||
show_object_with_name(stdout, obj, name);
|
||||
if (arg_show_object_names)
|
||||
show_object_with_name(stdout, obj, name);
|
||||
else
|
||||
printf("%s\n", oid_to_hex(&obj->oid));
|
||||
}
|
||||
|
||||
static void show_edge(struct commit *commit)
|
||||
@ -484,6 +491,16 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
|
||||
if (skip_prefix(arg, "--missing=", &arg))
|
||||
continue; /* already handled above */
|
||||
|
||||
if (!strcmp(arg, ("--no-object-names"))) {
|
||||
arg_show_object_names = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!strcmp(arg, ("--object-names"))) {
|
||||
arg_show_object_names = 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
usage(rev_list_usage);
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user