Linus Torvalds | 8bc9a0c | 2005-04-07 15:16:10 -0700 | [diff] [blame] | 1 | /* |
| 2 | * GIT - The information manager from hell |
| 3 | * |
| 4 | * Copyright (C) Linus Torvalds, 2005 |
| 5 | */ |
Linus Torvalds | f2a1934 | 2005-04-26 11:55:42 -0700 | [diff] [blame] | 6 | #include <signal.h> |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 7 | #include "cache.h" |
| 8 | |
Linus Torvalds | 121481a | 2005-04-10 11:32:54 -0700 | [diff] [blame] | 9 | /* |
| 10 | * Default to not allowing changes to the list of files. The |
| 11 | * tool doesn't actually care, but this makes it harder to add |
| 12 | * files to the revision control by mistake by doing something |
| 13 | * like "update-cache *" and suddenly having all the object |
| 14 | * files be revision controlled. |
| 15 | */ |
James Bottomley | c6e007b | 2005-04-24 15:14:16 -0700 | [diff] [blame] | 16 | static int allow_add = 0, allow_remove = 0, not_new = 0; |
| 17 | |
| 18 | /* Three functions to allow overloaded pointer return; see linux/err.h */ |
| 19 | static inline void *ERR_PTR(long error) |
| 20 | { |
| 21 | return (void *) error; |
| 22 | } |
| 23 | |
| 24 | static inline long PTR_ERR(const void *ptr) |
| 25 | { |
| 26 | return (long) ptr; |
| 27 | } |
| 28 | |
| 29 | static inline long IS_ERR(const void *ptr) |
| 30 | { |
| 31 | return (unsigned long)ptr > (unsigned long)-1000L; |
| 32 | } |
Linus Torvalds | 121481a | 2005-04-10 11:32:54 -0700 | [diff] [blame] | 33 | |
Junio C Hamano | c747fc6 | 2005-04-17 10:02:22 -0700 | [diff] [blame] | 34 | static int index_fd(unsigned char *sha1, int fd, struct stat *st) |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 35 | { |
| 36 | z_stream stream; |
Linus Torvalds | 3607c27 | 2005-04-11 18:02:00 -0700 | [diff] [blame] | 37 | unsigned long size = st->st_size; |
Junio C Hamano | c747fc6 | 2005-04-17 10:02:22 -0700 | [diff] [blame] | 38 | int max_out_bytes = size + 200; |
Christopher Li | 812666c | 2005-04-26 12:00:58 -0700 | [diff] [blame^] | 39 | void *out = xmalloc(max_out_bytes); |
| 40 | void *metadata = xmalloc(200); |
Linus Torvalds | f18ca73 | 2005-04-20 01:34:54 -0700 | [diff] [blame] | 41 | int metadata_size; |
Linus Torvalds | 3607c27 | 2005-04-11 18:02:00 -0700 | [diff] [blame] | 42 | void *in; |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 43 | SHA_CTX c; |
| 44 | |
Linus Torvalds | 3607c27 | 2005-04-11 18:02:00 -0700 | [diff] [blame] | 45 | in = ""; |
| 46 | if (size) |
| 47 | in = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0); |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 48 | close(fd); |
| 49 | if (!out || (int)(long)in == -1) |
| 50 | return -1; |
| 51 | |
Linus Torvalds | f18ca73 | 2005-04-20 01:34:54 -0700 | [diff] [blame] | 52 | metadata_size = 1+sprintf(metadata, "blob %lu", size); |
| 53 | |
| 54 | SHA1_Init(&c); |
| 55 | SHA1_Update(&c, metadata, metadata_size); |
| 56 | SHA1_Update(&c, in, size); |
| 57 | SHA1_Final(sha1, &c); |
| 58 | |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 59 | memset(&stream, 0, sizeof(stream)); |
| 60 | deflateInit(&stream, Z_BEST_COMPRESSION); |
| 61 | |
| 62 | /* |
| 63 | * ASCII size + nul byte |
| 64 | */ |
| 65 | stream.next_in = metadata; |
Linus Torvalds | f18ca73 | 2005-04-20 01:34:54 -0700 | [diff] [blame] | 66 | stream.avail_in = metadata_size; |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 67 | stream.next_out = out; |
| 68 | stream.avail_out = max_out_bytes; |
| 69 | while (deflate(&stream, 0) == Z_OK) |
| 70 | /* nothing */; |
| 71 | |
| 72 | /* |
| 73 | * File content |
| 74 | */ |
| 75 | stream.next_in = in; |
Linus Torvalds | 3607c27 | 2005-04-11 18:02:00 -0700 | [diff] [blame] | 76 | stream.avail_in = size; |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 77 | while (deflate(&stream, Z_FINISH) == Z_OK) |
| 78 | /*nothing */; |
| 79 | |
| 80 | deflateEnd(&stream); |
| 81 | |
Junio C Hamano | c747fc6 | 2005-04-17 10:02:22 -0700 | [diff] [blame] | 82 | return write_sha1_buffer(sha1, out, stream.total_out); |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 83 | } |
| 84 | |
Linus Torvalds | 711cf3a | 2005-04-11 09:39:21 -0700 | [diff] [blame] | 85 | /* |
| 86 | * This only updates the "non-critical" parts of the directory |
| 87 | * cache, ie the parts that aren't tracked by GIT, and only used |
| 88 | * to validate the cache. |
| 89 | */ |
| 90 | static void fill_stat_cache_info(struct cache_entry *ce, struct stat *st) |
| 91 | { |
Linus Torvalds | ccc4feb | 2005-04-15 10:44:27 -0700 | [diff] [blame] | 92 | ce->ce_ctime.sec = htonl(st->st_ctime); |
| 93 | ce->ce_mtime.sec = htonl(st->st_mtime); |
Petr Baudis | 5ade862 | 2005-04-13 02:38:44 -0700 | [diff] [blame] | 94 | #ifdef NSEC |
Linus Torvalds | ccc4feb | 2005-04-15 10:44:27 -0700 | [diff] [blame] | 95 | ce->ce_ctime.nsec = htonl(st->st_ctim.tv_nsec); |
| 96 | ce->ce_mtime.nsec = htonl(st->st_mtim.tv_nsec); |
Petr Baudis | 5ade862 | 2005-04-13 02:38:44 -0700 | [diff] [blame] | 97 | #endif |
Linus Torvalds | ccc4feb | 2005-04-15 10:44:27 -0700 | [diff] [blame] | 98 | ce->ce_dev = htonl(st->st_dev); |
| 99 | ce->ce_ino = htonl(st->st_ino); |
| 100 | ce->ce_uid = htonl(st->st_uid); |
| 101 | ce->ce_gid = htonl(st->st_gid); |
| 102 | ce->ce_size = htonl(st->st_size); |
Linus Torvalds | 711cf3a | 2005-04-11 09:39:21 -0700 | [diff] [blame] | 103 | } |
| 104 | |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 105 | static int add_file_to_cache(char *path) |
| 106 | { |
| 107 | int size, namelen; |
| 108 | struct cache_entry *ce; |
| 109 | struct stat st; |
| 110 | int fd; |
| 111 | |
| 112 | fd = open(path, O_RDONLY); |
| 113 | if (fd < 0) { |
Linus Torvalds | 121481a | 2005-04-10 11:32:54 -0700 | [diff] [blame] | 114 | if (errno == ENOENT) { |
| 115 | if (allow_remove) |
| 116 | return remove_file_from_cache(path); |
| 117 | } |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 118 | return -1; |
| 119 | } |
| 120 | if (fstat(fd, &st) < 0) { |
| 121 | close(fd); |
| 122 | return -1; |
| 123 | } |
| 124 | namelen = strlen(path); |
| 125 | size = cache_entry_size(namelen); |
Christopher Li | 812666c | 2005-04-26 12:00:58 -0700 | [diff] [blame^] | 126 | ce = xmalloc(size); |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 127 | memset(ce, 0, size); |
| 128 | memcpy(ce->name, path, namelen); |
Linus Torvalds | 711cf3a | 2005-04-11 09:39:21 -0700 | [diff] [blame] | 129 | fill_stat_cache_info(ce, &st); |
Linus Torvalds | e447947 | 2005-04-16 22:26:31 -0700 | [diff] [blame] | 130 | ce->ce_mode = create_ce_mode(st.st_mode); |
Linus Torvalds | f5cabd1 | 2005-04-15 21:45:38 -0700 | [diff] [blame] | 131 | ce->ce_flags = htons(namelen); |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 132 | |
Junio C Hamano | c747fc6 | 2005-04-17 10:02:22 -0700 | [diff] [blame] | 133 | if (index_fd(ce->sha1, fd, &st) < 0) |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 134 | return -1; |
| 135 | |
Linus Torvalds | 121481a | 2005-04-10 11:32:54 -0700 | [diff] [blame] | 136 | return add_cache_entry(ce, allow_add); |
| 137 | } |
| 138 | |
Linus Torvalds | 711cf3a | 2005-04-11 09:39:21 -0700 | [diff] [blame] | 139 | static int match_data(int fd, void *buffer, unsigned long size) |
Linus Torvalds | 121481a | 2005-04-10 11:32:54 -0700 | [diff] [blame] | 140 | { |
Linus Torvalds | 711cf3a | 2005-04-11 09:39:21 -0700 | [diff] [blame] | 141 | while (size) { |
| 142 | char compare[1024]; |
| 143 | int ret = read(fd, compare, sizeof(compare)); |
| 144 | |
| 145 | if (ret <= 0 || ret > size || memcmp(buffer, compare, ret)) |
| 146 | return -1; |
| 147 | size -= ret; |
| 148 | buffer += ret; |
| 149 | } |
| 150 | return 0; |
| 151 | } |
| 152 | |
Linus Torvalds | 32d197f | 2005-04-11 11:33:58 -0700 | [diff] [blame] | 153 | static int compare_data(struct cache_entry *ce, unsigned long expected_size) |
Linus Torvalds | 711cf3a | 2005-04-11 09:39:21 -0700 | [diff] [blame] | 154 | { |
| 155 | int match = -1; |
| 156 | int fd = open(ce->name, O_RDONLY); |
| 157 | |
| 158 | if (fd >= 0) { |
| 159 | void *buffer; |
| 160 | unsigned long size; |
| 161 | char type[10]; |
| 162 | |
| 163 | buffer = read_sha1_file(ce->sha1, type, &size); |
| 164 | if (buffer) { |
Linus Torvalds | 32d197f | 2005-04-11 11:33:58 -0700 | [diff] [blame] | 165 | if (size == expected_size && !strcmp(type, "blob")) |
Linus Torvalds | 711cf3a | 2005-04-11 09:39:21 -0700 | [diff] [blame] | 166 | match = match_data(fd, buffer, size); |
| 167 | free(buffer); |
| 168 | } |
| 169 | close(fd); |
| 170 | } |
| 171 | return match; |
| 172 | } |
| 173 | |
| 174 | /* |
| 175 | * "refresh" does not calculate a new sha1 file or bring the |
| 176 | * cache up-to-date for mode/content changes. But what it |
| 177 | * _does_ do is to "re-match" the stat information of a file |
| 178 | * with the cache, so that you can refresh the cache for a |
| 179 | * file that hasn't been changed but where the stat entry is |
| 180 | * out of date. |
| 181 | * |
| 182 | * For example, you'd want to do this after doing a "read-tree", |
| 183 | * to link up the stat cache details with the proper files. |
| 184 | */ |
| 185 | static struct cache_entry *refresh_entry(struct cache_entry *ce) |
| 186 | { |
| 187 | struct stat st; |
| 188 | struct cache_entry *updated; |
| 189 | int changed, size; |
| 190 | |
| 191 | if (stat(ce->name, &st) < 0) |
James Bottomley | c6e007b | 2005-04-24 15:14:16 -0700 | [diff] [blame] | 192 | return ERR_PTR(-errno); |
Linus Torvalds | 711cf3a | 2005-04-11 09:39:21 -0700 | [diff] [blame] | 193 | |
| 194 | changed = cache_match_stat(ce, &st); |
| 195 | if (!changed) |
| 196 | return ce; |
| 197 | |
Linus Torvalds | 121481a | 2005-04-10 11:32:54 -0700 | [diff] [blame] | 198 | /* |
Linus Torvalds | 32d197f | 2005-04-11 11:33:58 -0700 | [diff] [blame] | 199 | * If the mode has changed, there's no point in trying |
Linus Torvalds | 711cf3a | 2005-04-11 09:39:21 -0700 | [diff] [blame] | 200 | * to refresh the entry - it's not going to match |
Linus Torvalds | 121481a | 2005-04-10 11:32:54 -0700 | [diff] [blame] | 201 | */ |
Linus Torvalds | 32d197f | 2005-04-11 11:33:58 -0700 | [diff] [blame] | 202 | if (changed & MODE_CHANGED) |
James Bottomley | c6e007b | 2005-04-24 15:14:16 -0700 | [diff] [blame] | 203 | return ERR_PTR(-EINVAL); |
Linus Torvalds | 711cf3a | 2005-04-11 09:39:21 -0700 | [diff] [blame] | 204 | |
Linus Torvalds | 32d197f | 2005-04-11 11:33:58 -0700 | [diff] [blame] | 205 | if (compare_data(ce, st.st_size)) |
James Bottomley | c6e007b | 2005-04-24 15:14:16 -0700 | [diff] [blame] | 206 | return ERR_PTR(-EINVAL); |
Linus Torvalds | 711cf3a | 2005-04-11 09:39:21 -0700 | [diff] [blame] | 207 | |
| 208 | size = ce_size(ce); |
Christopher Li | 812666c | 2005-04-26 12:00:58 -0700 | [diff] [blame^] | 209 | updated = xmalloc(size); |
Linus Torvalds | 711cf3a | 2005-04-11 09:39:21 -0700 | [diff] [blame] | 210 | memcpy(updated, ce, size); |
| 211 | fill_stat_cache_info(updated, &st); |
| 212 | return updated; |
Linus Torvalds | 121481a | 2005-04-10 11:32:54 -0700 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | static void refresh_cache(void) |
| 216 | { |
| 217 | int i; |
| 218 | |
Linus Torvalds | 711cf3a | 2005-04-11 09:39:21 -0700 | [diff] [blame] | 219 | for (i = 0; i < active_nr; i++) { |
Junio C Hamano | 1bc992a | 2005-04-18 10:42:48 -0700 | [diff] [blame] | 220 | struct cache_entry *ce, *new; |
| 221 | ce = active_cache[i]; |
| 222 | if (ce_stage(ce)) { |
| 223 | printf("%s: needs merge\n", ce->name); |
| 224 | while ((i < active_nr) && |
| 225 | ! strcmp(active_cache[i]->name, ce->name)) |
| 226 | i++; |
| 227 | i--; |
| 228 | continue; |
| 229 | } |
Linus Torvalds | 711cf3a | 2005-04-11 09:39:21 -0700 | [diff] [blame] | 230 | |
Junio C Hamano | 1bc992a | 2005-04-18 10:42:48 -0700 | [diff] [blame] | 231 | new = refresh_entry(ce); |
James Bottomley | c6e007b | 2005-04-24 15:14:16 -0700 | [diff] [blame] | 232 | if (IS_ERR(new)) { |
| 233 | if (!(not_new && PTR_ERR(new) == -ENOENT)) |
| 234 | printf("%s: needs update\n", ce->name); |
Linus Torvalds | 711cf3a | 2005-04-11 09:39:21 -0700 | [diff] [blame] | 235 | continue; |
| 236 | } |
| 237 | active_cache[i] = new; |
| 238 | } |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 239 | } |
| 240 | |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 241 | /* |
| 242 | * We fundamentally don't like some paths: we don't want |
| 243 | * dot or dot-dot anywhere, and in fact, we don't even want |
Linus Torvalds | 4bb04f2 | 2005-04-11 15:47:57 -0700 | [diff] [blame] | 244 | * any other dot-files (.git or anything else). They |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 245 | * are hidden, for chist sake. |
| 246 | * |
| 247 | * Also, we don't want double slashes or slashes at the |
Ingo Molnar | aebb267 | 2005-04-12 11:36:26 -0700 | [diff] [blame] | 248 | * end that can make pathnames ambiguous. |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 249 | */ |
| 250 | static int verify_path(char *path) |
| 251 | { |
| 252 | char c; |
| 253 | |
| 254 | goto inside; |
| 255 | for (;;) { |
| 256 | if (!c) |
| 257 | return 1; |
| 258 | if (c == '/') { |
| 259 | inside: |
| 260 | c = *path++; |
| 261 | if (c != '/' && c != '.' && c != '\0') |
| 262 | continue; |
| 263 | return 0; |
| 264 | } |
| 265 | c = *path++; |
| 266 | } |
| 267 | } |
| 268 | |
Linus Torvalds | 9945d98 | 2005-04-15 11:08:33 -0700 | [diff] [blame] | 269 | static int add_cacheinfo(char *arg1, char *arg2, char *arg3) |
| 270 | { |
| 271 | int size, len; |
| 272 | unsigned int mode; |
| 273 | unsigned char sha1[20]; |
| 274 | struct cache_entry *ce; |
| 275 | |
| 276 | if (sscanf(arg1, "%o", &mode) != 1) |
| 277 | return -1; |
Linus Torvalds | 9945d98 | 2005-04-15 11:08:33 -0700 | [diff] [blame] | 278 | if (get_sha1_hex(arg2, sha1)) |
| 279 | return -1; |
Linus Torvalds | 9945d98 | 2005-04-15 11:08:33 -0700 | [diff] [blame] | 280 | if (!verify_path(arg3)) |
| 281 | return -1; |
Linus Torvalds | 9945d98 | 2005-04-15 11:08:33 -0700 | [diff] [blame] | 282 | |
| 283 | len = strlen(arg3); |
| 284 | size = cache_entry_size(len); |
Christopher Li | 812666c | 2005-04-26 12:00:58 -0700 | [diff] [blame^] | 285 | ce = xmalloc(size); |
Linus Torvalds | 9945d98 | 2005-04-15 11:08:33 -0700 | [diff] [blame] | 286 | memset(ce, 0, size); |
| 287 | |
| 288 | memcpy(ce->sha1, sha1, 20); |
| 289 | memcpy(ce->name, arg3, len); |
Linus Torvalds | f5cabd1 | 2005-04-15 21:45:38 -0700 | [diff] [blame] | 290 | ce->ce_flags = htons(len); |
Linus Torvalds | e447947 | 2005-04-16 22:26:31 -0700 | [diff] [blame] | 291 | ce->ce_mode = create_ce_mode(mode); |
Linus Torvalds | 9945d98 | 2005-04-15 11:08:33 -0700 | [diff] [blame] | 292 | return add_cache_entry(ce, allow_add); |
| 293 | } |
| 294 | |
Linus Torvalds | bb233d6 | 2005-04-21 10:55:18 -0700 | [diff] [blame] | 295 | static const char *lockfile_name = NULL; |
Linus Torvalds | 9614b8d | 2005-04-11 15:39:26 -0700 | [diff] [blame] | 296 | |
| 297 | static void remove_lock_file(void) |
| 298 | { |
Linus Torvalds | bb233d6 | 2005-04-21 10:55:18 -0700 | [diff] [blame] | 299 | if (lockfile_name) |
| 300 | unlink(lockfile_name); |
Linus Torvalds | 9614b8d | 2005-04-11 15:39:26 -0700 | [diff] [blame] | 301 | } |
| 302 | |
Linus Torvalds | f2a1934 | 2005-04-26 11:55:42 -0700 | [diff] [blame] | 303 | static void remove_lock_file_on_signal(int signo) |
| 304 | { |
| 305 | remove_lock_file(); |
| 306 | } |
| 307 | |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 308 | int main(int argc, char **argv) |
| 309 | { |
| 310 | int i, newfd, entries; |
Linus Torvalds | 121481a | 2005-04-10 11:32:54 -0700 | [diff] [blame] | 311 | int allow_options = 1; |
Linus Torvalds | bb233d6 | 2005-04-21 10:55:18 -0700 | [diff] [blame] | 312 | static char lockfile[MAXPATHLEN+1]; |
| 313 | const char *indexfile = get_index_file(); |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 314 | |
Linus Torvalds | bb233d6 | 2005-04-21 10:55:18 -0700 | [diff] [blame] | 315 | snprintf(lockfile, sizeof(lockfile), "%s.lock", indexfile); |
| 316 | |
| 317 | newfd = open(lockfile, O_RDWR | O_CREAT | O_EXCL, 0600); |
Linus Torvalds | 9614b8d | 2005-04-11 15:39:26 -0700 | [diff] [blame] | 318 | if (newfd < 0) |
Petr Baudis | 2de381f | 2005-04-13 02:28:48 -0700 | [diff] [blame] | 319 | die("unable to create new cachefile"); |
Linus Torvalds | 9614b8d | 2005-04-11 15:39:26 -0700 | [diff] [blame] | 320 | |
Linus Torvalds | f2a1934 | 2005-04-26 11:55:42 -0700 | [diff] [blame] | 321 | signal(SIGINT, remove_lock_file_on_signal); |
Linus Torvalds | 9614b8d | 2005-04-11 15:39:26 -0700 | [diff] [blame] | 322 | atexit(remove_lock_file); |
Linus Torvalds | bb233d6 | 2005-04-21 10:55:18 -0700 | [diff] [blame] | 323 | lockfile_name = lockfile; |
Linus Torvalds | 9614b8d | 2005-04-11 15:39:26 -0700 | [diff] [blame] | 324 | |
| 325 | entries = read_cache(); |
| 326 | if (entries < 0) |
Petr Baudis | 2de381f | 2005-04-13 02:28:48 -0700 | [diff] [blame] | 327 | die("cache corrupted"); |
Linus Torvalds | 9614b8d | 2005-04-11 15:39:26 -0700 | [diff] [blame] | 328 | |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 329 | for (i = 1 ; i < argc; i++) { |
| 330 | char *path = argv[i]; |
Linus Torvalds | 121481a | 2005-04-10 11:32:54 -0700 | [diff] [blame] | 331 | |
| 332 | if (allow_options && *path == '-') { |
| 333 | if (!strcmp(path, "--")) { |
| 334 | allow_options = 0; |
| 335 | continue; |
| 336 | } |
| 337 | if (!strcmp(path, "--add")) { |
| 338 | allow_add = 1; |
| 339 | continue; |
| 340 | } |
| 341 | if (!strcmp(path, "--remove")) { |
| 342 | allow_remove = 1; |
| 343 | continue; |
| 344 | } |
| 345 | if (!strcmp(path, "--refresh")) { |
| 346 | refresh_cache(); |
| 347 | continue; |
| 348 | } |
Linus Torvalds | 9945d98 | 2005-04-15 11:08:33 -0700 | [diff] [blame] | 349 | if (!strcmp(path, "--cacheinfo")) { |
| 350 | if (i+3 >= argc || add_cacheinfo(argv[i+1], argv[i+2], argv[i+3])) |
| 351 | die("update-cache: --cacheinfo <mode> <sha1> <path>"); |
| 352 | i += 3; |
| 353 | continue; |
| 354 | } |
James Bottomley | c6e007b | 2005-04-24 15:14:16 -0700 | [diff] [blame] | 355 | if (!strcmp(path, "--ignore-missing")) { |
| 356 | not_new = 1; |
| 357 | continue; |
| 358 | } |
Petr Baudis | 2de381f | 2005-04-13 02:28:48 -0700 | [diff] [blame] | 359 | die("unknown option %s", path); |
Linus Torvalds | 121481a | 2005-04-10 11:32:54 -0700 | [diff] [blame] | 360 | } |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 361 | if (!verify_path(path)) { |
| 362 | fprintf(stderr, "Ignoring path %s\n", argv[i]); |
| 363 | continue; |
| 364 | } |
Linus Torvalds | 9614b8d | 2005-04-11 15:39:26 -0700 | [diff] [blame] | 365 | if (add_file_to_cache(path)) |
Petr Baudis | 2de381f | 2005-04-13 02:28:48 -0700 | [diff] [blame] | 366 | die("Unable to add %s to database", path); |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 367 | } |
Linus Torvalds | bb233d6 | 2005-04-21 10:55:18 -0700 | [diff] [blame] | 368 | if (write_cache(newfd, active_cache, active_nr) || rename(lockfile, indexfile)) |
Petr Baudis | 2de381f | 2005-04-13 02:28:48 -0700 | [diff] [blame] | 369 | die("Unable to write new cachefile"); |
Linus Torvalds | 9614b8d | 2005-04-11 15:39:26 -0700 | [diff] [blame] | 370 | |
Linus Torvalds | bb233d6 | 2005-04-21 10:55:18 -0700 | [diff] [blame] | 371 | lockfile_name = NULL; |
Linus Torvalds | 19b2860 | 2005-04-08 09:59:28 -0700 | [diff] [blame] | 372 | return 0; |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 373 | } |