aboutsummaryrefslogtreecommitdiffstats
path: root/builtin/rev-list.c
diff options
context:
space:
mode:
Diffstat (limited to 'builtin/rev-list.c')
-rw-r--r--builtin/rev-list.c211
1 files changed, 170 insertions, 41 deletions
diff --git a/builtin/rev-list.c b/builtin/rev-list.c
index f62bcbf2b1..4d0c460f18 100644
--- a/builtin/rev-list.c
+++ b/builtin/rev-list.c
@@ -1,4 +1,6 @@
#define USE_THE_REPOSITORY_VARIABLE
+#define DISABLE_SIGN_COMPARE_WARNINGS
+
#include "builtin.h"
#include "config.h"
#include "commit.h"
@@ -12,15 +14,19 @@
#include "object.h"
#include "object-name.h"
#include "object-file.h"
-#include "object-store-ll.h"
+#include "odb.h"
#include "pack-bitmap.h"
+#include "parse-options.h"
#include "log-tree.h"
#include "graph.h"
#include "bisect.h"
#include "progress.h"
#include "reflog-walk.h"
#include "oidset.h"
+#include "oidmap.h"
#include "packfile.h"
+#include "quote.h"
+#include "strbuf.h"
static const char rev_list_usage[] =
"git rev-list [<options>] <commit>... [--] [<path>...]\n"
@@ -59,6 +65,7 @@ static const char rev_list_usage[] =
" --abbrev-commit\n"
" --left-right\n"
" --count\n"
+" -z\n"
" special purpose:\n"
" --bisect\n"
" --bisect-vars\n"
@@ -71,11 +78,17 @@ static unsigned progress_counter;
static struct oidset omitted_objects;
static int arg_print_omitted; /* print objects omitted by filter */
-static struct oidset missing_objects;
+struct missing_objects_map_entry {
+ struct oidmap_entry entry;
+ const char *path;
+ unsigned type;
+};
+static struct oidmap missing_objects;
enum missing_action {
MA_ERROR = 0, /* fail if any missing objects are encountered */
MA_ALLOW_ANY, /* silently allow ALL missing objects */
MA_PRINT, /* print ALL missing objects in special section */
+ MA_PRINT_INFO, /* same as MA_PRINT but also prints missing object info */
MA_ALLOW_PROMISOR, /* silently allow all missing PROMISOR objects */
};
static enum missing_action arg_missing_action;
@@ -85,6 +98,9 @@ static int arg_show_object_names = 1;
#define DEFAULT_OIDSET_SIZE (16*1024)
+static char line_term = '\n';
+static char info_term = ' ';
+
static int show_disk_usage;
static off_t total_disk_usage;
static int human_readable;
@@ -94,12 +110,68 @@ static off_t get_object_disk_usage(struct object *obj)
off_t size;
struct object_info oi = OBJECT_INFO_INIT;
oi.disk_sizep = &size;
- if (oid_object_info_extended(the_repository, &obj->oid, &oi, 0) < 0)
+ if (odb_read_object_info_extended(the_repository->objects,
+ &obj->oid, &oi, 0) < 0)
die(_("unable to get disk usage of %s"), oid_to_hex(&obj->oid));
return size;
}
-static inline void finish_object__ma(struct object *obj)
+static void add_missing_object_entry(struct object_id *oid, const char *path,
+ unsigned type)
+{
+ struct missing_objects_map_entry *entry;
+
+ if (oidmap_get(&missing_objects, oid))
+ return;
+
+ CALLOC_ARRAY(entry, 1);
+ entry->entry.oid = *oid;
+ entry->type = type;
+ if (path)
+ entry->path = xstrdup(path);
+ oidmap_put(&missing_objects, entry);
+}
+
+static void print_missing_object(struct missing_objects_map_entry *entry,
+ int print_missing_info)
+{
+ struct strbuf sb = STRBUF_INIT;
+
+ if (line_term)
+ printf("?%s", oid_to_hex(&entry->entry.oid));
+ else
+ printf("%s%cmissing=yes", oid_to_hex(&entry->entry.oid),
+ info_term);
+
+ if (!print_missing_info) {
+ putchar(line_term);
+ return;
+ }
+
+ if (entry->path && *entry->path) {
+ strbuf_addf(&sb, "%cpath=", info_term);
+
+ if (line_term) {
+ struct strbuf path = STRBUF_INIT;
+
+ quote_path(entry->path, NULL, &path, QUOTE_PATH_QUOTE_SP);
+ strbuf_addbuf(&sb, &path);
+
+ strbuf_release(&path);
+ } else {
+ strbuf_addstr(&sb, entry->path);
+ }
+ }
+ if (entry->type)
+ strbuf_addf(&sb, "%ctype=%s", info_term, type_name(entry->type));
+
+ fwrite(sb.buf, sizeof(char), sb.len, stdout);
+ putchar(line_term);
+
+ strbuf_release(&sb);
+}
+
+static inline void finish_object__ma(struct object *obj, const char *name)
{
/*
* Whether or not we try to dynamically fetch missing objects
@@ -117,11 +189,12 @@ static inline void finish_object__ma(struct object *obj)
return;
case MA_PRINT:
- oidset_insert(&missing_objects, &obj->oid);
+ case MA_PRINT_INFO:
+ add_missing_object_entry(&obj->oid, name, obj->type);
return;
case MA_ALLOW_PROMISOR:
- if (is_promisor_object(&obj->oid))
+ if (is_promisor_object(the_repository, &obj->oid))
return;
die("unexpected missing %s object '%s'",
type_name(obj->type), oid_to_hex(&obj->oid));
@@ -150,7 +223,7 @@ static void show_commit(struct commit *commit, void *data)
if (revs->do_not_die_on_missing_objects &&
oidset_contains(&revs->missing_commits, &commit->object.oid)) {
- finish_object__ma(&commit->object);
+ finish_object__ma(&commit->object, NULL);
return;
}
@@ -181,13 +254,18 @@ static void show_commit(struct commit *commit, void *data)
fputs(info->header_prefix, stdout);
if (revs->include_header) {
- if (!revs->graph)
+ if (!revs->graph && line_term)
fputs(get_revision_mark(revs, commit), stdout);
if (revs->abbrev_commit && revs->abbrev)
fputs(repo_find_unique_abbrev(the_repository, &commit->object.oid, revs->abbrev),
stdout);
else
fputs(oid_to_hex(&commit->object.oid), stdout);
+
+ if (!line_term) {
+ if (commit->object.flags & BOUNDARY)
+ printf("%cboundary=yes", info_term);
+ }
}
if (revs->print_parents) {
struct commit_list *parents = commit->parents;
@@ -209,7 +287,7 @@ static void show_commit(struct commit *commit, void *data)
if (revs->commit_format == CMIT_FMT_ONELINE)
putchar(' ');
else if (revs->include_header)
- putchar('\n');
+ putchar(line_term);
if (revs->verbose_header) {
struct strbuf buf = STRBUF_INIT;
@@ -266,12 +344,12 @@ static void show_commit(struct commit *commit, void *data)
finish_commit(commit);
}
-static int finish_object(struct object *obj, const char *name UNUSED,
- void *cb_data)
+static int finish_object(struct object *obj, const char *name, void *cb_data)
{
struct rev_list_info *info = cb_data;
- if (oid_object_info_extended(the_repository, &obj->oid, NULL, 0) < 0) {
- finish_object__ma(obj);
+ if (odb_read_object_info_extended(the_repository->objects,
+ &obj->oid, NULL, 0) < 0) {
+ finish_object__ma(obj, name);
return 1;
}
if (info->revs->verify_objects && !obj->parsed && obj->type != OBJ_COMMIT)
@@ -304,10 +382,19 @@ static void show_object(struct object *obj, const char *name, void *cb_data)
return;
}
- if (arg_show_object_names)
- show_object_with_name(stdout, obj, name);
- else
- printf("%s\n", oid_to_hex(&obj->oid));
+ printf("%s", oid_to_hex(&obj->oid));
+
+ if (arg_show_object_names) {
+ if (line_term) {
+ putchar(info_term);
+ for (const char *p = name; *p && *p != '\n'; p++)
+ putchar(*p);
+ } else if (*name) {
+ printf("%cpath=%s", info_term, name);
+ }
+ }
+
+ putchar(line_term);
}
static void show_edge(struct commit *commit)
@@ -376,7 +463,8 @@ static int show_object_fast(
int exclude UNUSED,
uint32_t name_hash UNUSED,
struct packed_git *found_pack UNUSED,
- off_t found_offset UNUSED)
+ off_t found_offset UNUSED,
+ void *payload UNUSED)
{
fprintf(stdout, "%s\n", oid_to_hex(oid));
return 1;
@@ -412,6 +500,12 @@ static inline int parse_missing_action_value(const char *value)
return 1;
}
+ if (!strcmp(value, "print-info")) {
+ arg_missing_action = MA_PRINT_INFO;
+ fetch_if_missing = 0;
+ return 1;
+ }
+
if (!strcmp(value, "allow-promisor")) {
arg_missing_action = MA_ALLOW_PROMISOR;
fetch_if_missing = 0;
@@ -485,6 +579,13 @@ static int try_bitmap_traversal(struct rev_info *revs,
if (revs->max_count >= 0)
return -1;
+ /*
+ * We can't know which commits were left/right in a single traversal,
+ * and we don't yet know how to traverse them separately.
+ */
+ if (revs->left_right)
+ return -1;
+
bitmap_git = prepare_bitmap_walk(revs, filter_provided_objects);
if (!bitmap_git)
return -1;
@@ -533,8 +634,7 @@ int cmd_rev_list(int argc,
const char *show_progress = NULL;
int ret = 0;
- if (argc == 2 && !strcmp(argv[1], "-h"))
- usage(rev_list_usage);
+ show_usage_if_asked(argc, argv, rev_list_usage);
git_config(git_default_config, NULL);
repo_init_revisions(the_repository, &revs, prefix);
@@ -569,19 +669,18 @@ int cmd_rev_list(int argc,
if (!strcmp(arg, "--exclude-promisor-objects")) {
fetch_if_missing = 0;
revs.exclude_promisor_objects = 1;
- break;
- }
- }
- for (i = 1; i < argc; i++) {
- const char *arg = argv[i];
- if (skip_prefix(arg, "--missing=", &arg)) {
- if (revs.exclude_promisor_objects)
- die(_("options '%s' and '%s' cannot be used together"), "--exclude-promisor-objects", "--missing");
- if (parse_missing_action_value(arg))
- break;
+ } else if (skip_prefix(arg, "--missing=", &arg)) {
+ parse_missing_action_value(arg);
+ } else if (!strcmp(arg, "-z")) {
+ line_term = '\0';
+ info_term = '\0';
}
}
+ die_for_incompatible_opt2(revs.exclude_promisor_objects,
+ "--exclude_promisor_objects",
+ arg_missing_action, "--missing");
+
if (arg_missing_action)
revs.do_not_die_on_missing_objects = 1;
@@ -690,6 +789,20 @@ int cmd_rev_list(int argc,
usage(rev_list_usage);
}
+
+ /*
+ * Reject options currently incompatible with -z. For some options, this
+ * is not an inherent limitation and support may be implemented in the
+ * future.
+ */
+ if (!line_term) {
+ if (revs.graph || revs.verbose_header || show_disk_usage ||
+ info.show_timestamp || info.header_prefix || bisect_list ||
+ use_bitmap_index || revs.edge_hint || revs.left_right ||
+ revs.cherry_mark)
+ die(_("-z option used with unsupported option"));
+ }
+
if (revs.commit_format != CMIT_FMT_USERFORMAT)
revs.include_header = 1;
if (revs.commit_format != CMIT_FMT_UNSPECIFIED) {
@@ -726,7 +839,8 @@ int cmd_rev_list(int argc,
revs.limited = 1;
if (show_progress)
- progress = start_delayed_progress(show_progress, 0);
+ progress = start_delayed_progress(the_repository,
+ show_progress, 0);
if (use_bitmap_index) {
if (!try_bitmap_count(&revs, filter_provided_objects))
@@ -772,10 +886,18 @@ int cmd_rev_list(int argc,
if (arg_print_omitted)
oidset_init(&omitted_objects, DEFAULT_OIDSET_SIZE);
- if (arg_missing_action == MA_PRINT) {
- oidset_init(&missing_objects, DEFAULT_OIDSET_SIZE);
+ if (arg_missing_action == MA_PRINT ||
+ arg_missing_action == MA_PRINT_INFO) {
+ struct oidset_iter iter;
+ struct object_id *oid;
+
+ oidmap_init(&missing_objects, DEFAULT_OIDSET_SIZE);
+ oidset_iter_init(&revs.missing_commits, &iter);
+
/* Add missing tips */
- oidset_insert_from_set(&missing_objects, &revs.missing_commits);
+ while ((oid = oidset_iter_next(&iter)))
+ add_missing_object_entry(oid, NULL, 0);
+
oidset_clear(&revs.missing_commits);
}
@@ -791,13 +913,20 @@ int cmd_rev_list(int argc,
printf("~%s\n", oid_to_hex(oid));
oidset_clear(&omitted_objects);
}
- if (arg_missing_action == MA_PRINT) {
- struct oidset_iter iter;
- struct object_id *oid;
- oidset_iter_init(&missing_objects, &iter);
- while ((oid = oidset_iter_next(&iter)))
- printf("?%s\n", oid_to_hex(oid));
- oidset_clear(&missing_objects);
+ if (arg_missing_action == MA_PRINT ||
+ arg_missing_action == MA_PRINT_INFO) {
+ struct missing_objects_map_entry *entry;
+ struct oidmap_iter iter;
+
+ oidmap_iter_init(&missing_objects, &iter);
+
+ while ((entry = oidmap_iter_next(&iter))) {
+ print_missing_object(entry, arg_missing_action ==
+ MA_PRINT_INFO);
+ free((void *)entry->path);
+ }
+
+ oidmap_clear(&missing_objects, true);
}
stop_progress(&progress);