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 <gitster@pobox.com>
Junio C Hamano committed
May 18, 2011 at 18:08 UTC
cc243c3cebd58d06bc4e064b08fa9c3fdd565250
5 files changed
+21
-3
Documentation/git-rev-list.txt
+1
@@ -29,6 +29,7 @@ SYNOPSIS
29
[ \--tags[=<pattern>] ]
30
[ \--remotes[=<pattern>] ]
31
[ \--glob=<glob-pattern> ]
32
+ [ \--ignore-missing ]
33
[ \--stdin ]
34
[ \--quiet ]
35
[ \--topo-order ]
Documentation/rev-list-options.txt
+4
@@ -139,6 +139,10 @@ parents) and `--max-parents=-1` (negative numbers denote no upper limit).
139
is automatically prepended if missing. If pattern lacks '?', '*',
140
or '[', '/*' at the end is implied.
141
142
+--ignore-missing::
143
+
144
+ Upon seeing an invalid object name in the input, pretend as if
145
+ the bad input was not given.
146
147
ifndef::git-rev-list[]
148
--bisect::
builtin/rev-parse.c
+1
@@ -44,6 +44,7 @@ static int is_rev_argument(const char *arg)
44
"--branches=",
45
"--branches",
46
"--header",
47
+ "--ignore-missing",
48
"--max-age=",
49
"--max-count=",
50
"--min-age=",
revision.c
+13
-2
@@ -133,6 +133,8 @@ void mark_parents_uninteresting(struct commit *commit)
133
134
static void add_pending_object_with_mode(struct rev_info *revs, struct object *obj, const char *name, unsigned mode)
135
{
136
+ if (!obj)
137
+ return;
138
if (revs->no_walk && (obj->flags & UNINTERESTING))
139
revs->no_walk = 0;
140
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
176
struct object *object;
177
178
object = parse_object(sha1);
177
- if (!object)
179
+ if (!object) {
180
+ if (revs->ignore_missing)
181
+ return object;
182
die("bad object %s", name);
183
+ }
184
object->flags |= flags;
185
return object;
186
}
@@ -906,6 +911,8 @@ static int add_parents_only(struct rev_info *revs, const char *arg, int flags)
911
return 0;
912
while (1) {
913
it = get_reference(revs, arg, sha1, 0);
914
+ if (!it && revs->ignore_missing)
915
+ return 0;
916
if (it->type != OBJ_TAG)
917
break;
918
if (!((struct tag*)it)->tagged)
@@ -1044,6 +1051,8 @@ int handle_revision_arg(const char *arg, struct rev_info *revs,
1051
a = lookup_commit_reference(from_sha1);
1052
b = lookup_commit_reference(sha1);
1053
if (!a || !b) {
1054
+ if (revs->ignore_missing)
1055
+ return 0;
1056
die(symmetric ?
1057
"Invalid symmetric difference expression %s...%s" :
1058
"Invalid revision range %s..%s",
@@ -1090,7 +1099,7 @@ int handle_revision_arg(const char *arg, struct rev_info *revs,
1099
arg++;
1100
}
1101
if (get_sha1_with_mode(arg, sha1, &mode))
1093
- return -1;
1102
+ return revs->ignore_missing ? 0 : -1;
1103
if (!cant_be_filename)
1104
verify_non_filename(revs->prefix, arg);
1105
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
1484
} else if (!strcmp(arg, "--children")) {
1485
revs->children.name = "children";
1486
revs->limited = 1;
1487
+ } else if (!strcmp(arg, "--ignore-missing")) {
1488
+ revs->ignore_missing = 1;
1489
} else {
1490
int opts = diff_opt_parse(&revs->diffopt, argv, argc);
1491
if (!opts)
revision.h
+2
-1
@@ -36,7 +36,8 @@ struct rev_info {
36
const char *prefix;
37
const char *def;
38
struct pathspec prune_data;
39
- unsigned int early_output;
39
+ unsigned int early_output:1,
40
+ ignore_missing:1;
41
42
/* Traversal flags */
43
unsigned int dense:1,