Skip to content

Commit cc243c3

Browse files
committed
show: --ignore-missing
Instead of barfing, simply ignore bad object names seen in the input. This is useful when reading from "git notes list" output that may refer to objects that have already been garbage collected. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4653801 commit cc243c3

File tree

5 files changed

+21
-3
lines changed

5 files changed

+21
-3
lines changed

Documentation/git-rev-list.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ SYNOPSIS
2929
[ \--tags[=<pattern>] ]
3030
[ \--remotes[=<pattern>] ]
3131
[ \--glob=<glob-pattern> ]
32+
[ \--ignore-missing ]
3233
[ \--stdin ]
3334
[ \--quiet ]
3435
[ \--topo-order ]

Documentation/rev-list-options.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,10 @@ parents) and `--max-parents=-1` (negative numbers denote no upper limit).
139139
is automatically prepended if missing. If pattern lacks '?', '*',
140140
or '[', '/*' at the end is implied.
141141

142+
--ignore-missing::
143+
144+
Upon seeing an invalid object name in the input, pretend as if
145+
the bad input was not given.
142146

143147
ifndef::git-rev-list[]
144148
--bisect::

builtin/rev-parse.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ static int is_rev_argument(const char *arg)
4444
"--branches=",
4545
"--branches",
4646
"--header",
47+
"--ignore-missing",
4748
"--max-age=",
4849
"--max-count=",
4950
"--min-age=",

revision.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ void mark_parents_uninteresting(struct commit *commit)
133133

134134
static void add_pending_object_with_mode(struct rev_info *revs, struct object *obj, const char *name, unsigned mode)
135135
{
136+
if (!obj)
137+
return;
136138
if (revs->no_walk && (obj->flags & UNINTERESTING))
137139
revs->no_walk = 0;
138140
if (revs->reflog_info && obj->type == OBJ_COMMIT) {
@@ -174,8 +176,11 @@ static struct object *get_reference(struct rev_info *revs, const char *name, con
174176
struct object *object;
175177

176178
object = parse_object(sha1);
177-
if (!object)
179+
if (!object) {
180+
if (revs->ignore_missing)
181+
return object;
178182
die("bad object %s", name);
183+
}
179184
object->flags |= flags;
180185
return object;
181186
}
@@ -906,6 +911,8 @@ static int add_parents_only(struct rev_info *revs, const char *arg, int flags)
906911
return 0;
907912
while (1) {
908913
it = get_reference(revs, arg, sha1, 0);
914+
if (!it && revs->ignore_missing)
915+
return 0;
909916
if (it->type != OBJ_TAG)
910917
break;
911918
if (!((struct tag*)it)->tagged)
@@ -1044,6 +1051,8 @@ int handle_revision_arg(const char *arg, struct rev_info *revs,
10441051
a = lookup_commit_reference(from_sha1);
10451052
b = lookup_commit_reference(sha1);
10461053
if (!a || !b) {
1054+
if (revs->ignore_missing)
1055+
return 0;
10471056
die(symmetric ?
10481057
"Invalid symmetric difference expression %s...%s" :
10491058
"Invalid revision range %s..%s",
@@ -1090,7 +1099,7 @@ int handle_revision_arg(const char *arg, struct rev_info *revs,
10901099
arg++;
10911100
}
10921101
if (get_sha1_with_mode(arg, sha1, &mode))
1093-
return -1;
1102+
return revs->ignore_missing ? 0 : -1;
10941103
if (!cant_be_filename)
10951104
verify_non_filename(revs->prefix, arg);
10961105
object = get_reference(revs, arg, sha1, flags ^ local_flags);
@@ -1475,6 +1484,8 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
14751484
} else if (!strcmp(arg, "--children")) {
14761485
revs->children.name = "children";
14771486
revs->limited = 1;
1487+
} else if (!strcmp(arg, "--ignore-missing")) {
1488+
revs->ignore_missing = 1;
14781489
} else {
14791490
int opts = diff_opt_parse(&revs->diffopt, argv, argc);
14801491
if (!opts)

revision.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ struct rev_info {
3636
const char *prefix;
3737
const char *def;
3838
struct pathspec prune_data;
39-
unsigned int early_output;
39+
unsigned int early_output:1,
40+
ignore_missing:1;
4041

4142
/* Traversal flags */
4243
unsigned int dense:1,

0 commit comments

Comments
 (0)