Skip to content

Commit c6e007b

Browse files
James BottomleyLinus Torvalds
authored andcommitted
[PATCH] update-cache: add "--ignore-missing" option
This adds an --ignore-missing option to update-cache, which makes it ignore missing files. Together with the "-n" option to checkout-cache, it allows me to do checkout-cache -n -f -a && update-cache --ignore-missing --refresh which only updates and refreshes the files I already have checked out. Signed-off-by: Linus Torvalds <[email protected]>
1 parent 32718b6 commit c6e007b

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

update-cache.c

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,23 @@
1212
* like "update-cache *" and suddenly having all the object
1313
* files be revision controlled.
1414
*/
15-
static int allow_add = 0, allow_remove = 0;
15+
static int allow_add = 0, allow_remove = 0, not_new = 0;
16+
17+
/* Three functions to allow overloaded pointer return; see linux/err.h */
18+
static inline void *ERR_PTR(long error)
19+
{
20+
return (void *) error;
21+
}
22+
23+
static inline long PTR_ERR(const void *ptr)
24+
{
25+
return (long) ptr;
26+
}
27+
28+
static inline long IS_ERR(const void *ptr)
29+
{
30+
return (unsigned long)ptr > (unsigned long)-1000L;
31+
}
1632

1733
static int index_fd(unsigned char *sha1, int fd, struct stat *st)
1834
{
@@ -172,7 +188,7 @@ static struct cache_entry *refresh_entry(struct cache_entry *ce)
172188
int changed, size;
173189

174190
if (stat(ce->name, &st) < 0)
175-
return NULL;
191+
return ERR_PTR(-errno);
176192

177193
changed = cache_match_stat(ce, &st);
178194
if (!changed)
@@ -183,10 +199,10 @@ static struct cache_entry *refresh_entry(struct cache_entry *ce)
183199
* to refresh the entry - it's not going to match
184200
*/
185201
if (changed & MODE_CHANGED)
186-
return NULL;
202+
return ERR_PTR(-EINVAL);
187203

188204
if (compare_data(ce, st.st_size))
189-
return NULL;
205+
return ERR_PTR(-EINVAL);
190206

191207
size = ce_size(ce);
192208
updated = malloc(size);
@@ -212,8 +228,9 @@ static void refresh_cache(void)
212228
}
213229

214230
new = refresh_entry(ce);
215-
if (!new) {
216-
printf("%s: needs update\n", ce->name);
231+
if (IS_ERR(new)) {
232+
if (!(not_new && PTR_ERR(new) == -ENOENT))
233+
printf("%s: needs update\n", ce->name);
217234
continue;
218235
}
219236
active_cache[i] = new;
@@ -328,6 +345,10 @@ int main(int argc, char **argv)
328345
i += 3;
329346
continue;
330347
}
348+
if (!strcmp(path, "--ignore-missing")) {
349+
not_new = 1;
350+
continue;
351+
}
331352
die("unknown option %s", path);
332353
}
333354
if (!verify_path(path)) {

0 commit comments

Comments
 (0)