From: Junio C Hamano Date: Fri, 11 Aug 2017 20:27:07 +0000 (-0700) Subject: Merge branch 'jk/rev-list-empty-input' X-Git-Tag: v2.15.0-rc0~184 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/8fbaf0b13bc54819445f613e917c44ea52eef804?ds=inline;hp=-c Merge branch 'jk/rev-list-empty-input' "git log --tag=no-such-tag" showed log starting from HEAD, which has been fixed---it now shows nothing. * jk/rev-list-empty-input: revision: do not fallback to default when rev_input_given is set rev-list: don't show usage when we see empty ref patterns revision: add rev_input_given flag t6018: flesh out empty input/output rev-list tests --- 8fbaf0b13bc54819445f613e917c44ea52eef804 diff --combined builtin/rev-list.c index e8f5048903,1e9cc59488..95b4128250 --- a/builtin/rev-list.c +++ b/builtin/rev-list.c @@@ -11,7 -11,6 +11,7 @@@ #include "graph.h" #include "bisect.h" #include "progress.h" +#include "reflog-walk.h" static const char rev_list_usage[] = "git rev-list [OPTION] ... [ -- paths... ]\n" @@@ -123,7 -122,6 +123,7 @@@ static void show_commit(struct commit * ctx.date_mode_explicit = revs->date_mode_explicit; ctx.fmt = revs->commit_format; ctx.output_encoding = get_log_output_encoding(); + ctx.color = revs->diffopt.use_color; pretty_print_commit(&ctx, commit, &buf); if (buf.len) { if (revs->commit_format != CMIT_FMT_ONELINE) @@@ -350,9 -348,10 +350,10 @@@ int cmd_rev_list(int argc, const char * /* Only --header was specified */ revs.commit_format = CMIT_FMT_RAW; - if ((!revs.commits && + if ((!revs.commits && reflog_walk_empty(revs.reflog_info) && (!(revs.tag_objects || revs.tree_objects || revs.blob_objects) && - !revs.pending.nr)) || + !revs.pending.nr) && + !revs.rev_input_given) || revs.diff) usage(rev_list_usage); diff --combined revision.c index ab4af0c352,ba2b166cd6..aa3b946a8d --- a/revision.c +++ b/revision.c @@@ -148,14 -148,16 +148,14 @@@ static void add_pending_object_with_pat if (revs->reflog_info && obj->type == OBJ_COMMIT) { struct strbuf buf = STRBUF_INIT; int len = interpret_branch_name(name, 0, &buf, 0); - int st; if (0 < len && name[len] && buf.len) strbuf_addstr(&buf, name + len); - st = add_reflog_for_walk(revs->reflog_info, - (struct commit *)obj, - buf.buf[0] ? buf.buf: name); + add_reflog_for_walk(revs->reflog_info, + (struct commit *)obj, + buf.buf[0] ? buf.buf: name); strbuf_release(&buf); - if (st) - return; + return; /* do not add the commit itself */ } add_object_array_with_path(obj, name, &revs->pending, mode, path); } @@@ -1166,6 -1168,7 +1166,7 @@@ static void init_all_refs_cb(struct all { cb->all_revs = revs; cb->all_flags = flags; + revs->rev_input_given = 1; } void clear_ref_exclusion(struct string_list **ref_excludes_p) @@@ -1301,7 -1304,7 +1302,7 @@@ static int add_parents_only(struct rev_ flags ^= UNINTERESTING | BOTTOM; arg++; } - if (get_sha1_committish(arg, oid.hash)) + if (get_oid_committish(arg, &oid)) return 0; while (1) { it = get_reference(revs, arg, &oid, 0); @@@ -1450,7 -1453,7 +1451,7 @@@ static int handle_dotdot_1(const char * unsigned int a_flags, b_flags; int symmetric = 0; unsigned int flags_exclude = flags ^ (UNINTERESTING | BOTTOM); - unsigned int oc_flags = GET_SHA1_COMMITTISH | GET_SHA1_RECORD_PATH; + unsigned int oc_flags = GET_OID_COMMITTISH | GET_OID_RECORD_PATH; a_name = arg; if (!*a_name) @@@ -1464,8 -1467,8 +1465,8 @@@ if (!*b_name) b_name = "HEAD"; - if (get_sha1_with_context(a_name, oc_flags, a_oid.hash, a_oc) || - get_sha1_with_context(b_name, oc_flags, b_oid.hash, b_oc)) + if (get_oid_with_context(a_name, oc_flags, &a_oid, a_oc) || + get_oid_with_context(b_name, oc_flags, &b_oid, b_oc)) return -1; if (!cant_be_filename) { @@@ -1546,7 -1549,7 +1547,7 @@@ int handle_revision_arg(const char *arg int local_flags; const char *arg = arg_; int cant_be_filename = revarg_opt & REVARG_CANNOT_BE_FILENAME; - unsigned get_sha1_flags = GET_SHA1_RECORD_PATH; + unsigned get_sha1_flags = GET_OID_RECORD_PATH; flags = flags & UNINTERESTING ? flags | BOTTOM : flags & ~BOTTOM; @@@ -1597,9 -1600,9 +1598,9 @@@ } if (revarg_opt & REVARG_COMMITTISH) - get_sha1_flags |= GET_SHA1_COMMITTISH; + get_sha1_flags |= GET_OID_COMMITTISH; - if (get_sha1_with_context(arg, get_sha1_flags, oid.hash, &oc)) + if (get_oid_with_context(arg, get_sha1_flags, &oid, &oc)) return revs->ignore_missing ? 0 : -1; if (!cant_be_filename) verify_non_filename(revs->prefix, arg); @@@ -2313,11 -2316,11 +2314,11 @@@ int setup_revisions(int argc, const cha opt->tweak(revs, opt); if (revs->show_merge) prepare_show_merge(revs); - if (revs->def && !revs->pending.nr && !got_rev_arg) { + if (revs->def && !revs->pending.nr && !revs->rev_input_given && !got_rev_arg) { struct object_id oid; struct object *object; struct object_context oc; - if (get_sha1_with_context(revs->def, 0, oid.hash, &oc)) + if (get_oid_with_context(revs->def, 0, &oid, &oc)) diagnose_missing_default(revs->def); object = get_reference(revs, revs->def, &oid, 0); add_pending_object_with_mode(revs, object, revs->def, oc.mode); @@@ -2362,8 -2365,6 +2363,8 @@@ if (revs->reverse && revs->reflog_info) die("cannot combine --reverse with --walk-reflogs"); + if (revs->reflog_info && revs->limited) + die("cannot combine --walk-reflogs with history-limiting options"); if (revs->rewrite_parents && revs->children.name) die("cannot combine --parents and --children"); @@@ -2963,18 -2964,6 +2964,18 @@@ static inline int want_ancestry(const s return (revs->rewrite_parents || revs->children.name); } +/* + * Return a timestamp to be used for --since/--until comparisons for this + * commit, based on the revision options. + */ +static timestamp_t comparison_date(const struct rev_info *revs, + struct commit *commit) +{ + return revs->reflog_info ? + get_reflog_timestamp(revs->reflog_info) : + commit->date; +} + enum commit_action get_commit_action(struct rev_info *revs, struct commit *commit) { if (commit->object.flags & SHOWN) @@@ -2985,9 -2974,8 +2986,9 @@@ return commit_show; if (commit->object.flags & UNINTERESTING) return commit_ignore; - if (revs->min_age != -1 && (commit->date > revs->min_age)) - return commit_ignore; + if (revs->min_age != -1 && + comparison_date(revs, commit) > revs->min_age) + return commit_ignore; if (revs->min_parents || (revs->max_parents >= 0)) { int n = commit_list_count(commit->parents); if ((n < revs->min_parents) || @@@ -3120,19 -3108,17 +3121,19 @@@ static void track_linear(struct rev_inf static struct commit *get_revision_1(struct rev_info *revs) { - if (!revs->commits) - return NULL; + while (1) { + struct commit *commit; - do { - struct commit *commit = pop_commit(&revs->commits); + if (revs->reflog_info) + commit = next_reflog_entry(revs->reflog_info); + else + commit = pop_commit(&revs->commits); - if (revs->reflog_info) { - save_parents(revs, commit); - fake_reflog_parent(revs->reflog_info, commit); + if (!commit) + return NULL; + + if (revs->reflog_info) commit->object.flags &= ~(ADDED | SEEN | SHOWN); - } /* * If we haven't done the list limiting, we need to look at @@@ -3141,12 -3127,9 +3142,12 @@@ */ if (!revs->limited) { if (revs->max_age != -1 && - (commit->date < revs->max_age)) + comparison_date(revs, commit) < revs->max_age) continue; - if (add_parents_to_list(revs, commit, &revs->commits, NULL) < 0) { + + if (revs->reflog_info) + try_to_simplify_commit(revs, commit); + else if (add_parents_to_list(revs, commit, &revs->commits, NULL) < 0) { if (!revs->ignore_missing_links) die("Failed to traverse parents of commit %s", oid_to_hex(&commit->object.oid)); @@@ -3164,7 -3147,8 +3165,7 @@@ track_linear(revs, commit); return commit; } - } while (revs->commits); - return NULL; + } } /*