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 | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 6 | #include "cache.h" |
Junio C Hamano | ee1bec3 | 2005-09-26 18:13:08 -0700 | [diff] [blame] | 7 | #include "strbuf.h" |
Junio C Hamano | 973d6a2 | 2005-10-16 00:39:07 -0700 | [diff] [blame] | 8 | #include "quote.h" |
Junio C Hamano | a6e5642 | 2006-04-24 00:23:54 -0700 | [diff] [blame] | 9 | #include "cache-tree.h" |
Junio C Hamano | 2bd452d | 2006-04-19 23:52:05 -0700 | [diff] [blame] | 10 | #include "tree-walk.h" |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 11 | |
Linus Torvalds | 121481a | 2005-04-10 11:32:54 -0700 | [diff] [blame] | 12 | /* |
| 13 | * Default to not allowing changes to the list of files. The |
| 14 | * tool doesn't actually care, but this makes it harder to add |
| 15 | * files to the revision control by mistake by doing something |
Junio C Hamano | 215a7ad | 2005-09-07 17:26:23 -0700 | [diff] [blame] | 16 | * like "git-update-index *" and suddenly having all the object |
Linus Torvalds | 121481a | 2005-04-10 11:32:54 -0700 | [diff] [blame] | 17 | * files be revision controlled. |
| 18 | */ |
Junio C Hamano | caf4f58 | 2005-10-14 21:56:46 -0700 | [diff] [blame] | 19 | static int allow_add; |
| 20 | static int allow_remove; |
| 21 | static int allow_replace; |
Junio C Hamano | caf4f58 | 2005-10-14 21:56:46 -0700 | [diff] [blame] | 22 | static int info_only; |
Petr Baudis | 9b63f50 | 2005-05-31 18:52:43 +0200 | [diff] [blame] | 23 | static int force_remove; |
Junio C Hamano | caf4f58 | 2005-10-14 21:56:46 -0700 | [diff] [blame] | 24 | static int verbose; |
Junio C Hamano | 5f73076 | 2006-02-08 21:15:24 -0800 | [diff] [blame] | 25 | static int mark_valid_only = 0; |
| 26 | #define MARK_VALID 1 |
| 27 | #define UNMARK_VALID 2 |
| 28 | |
Junio C Hamano | caf4f58 | 2005-10-14 21:56:46 -0700 | [diff] [blame] | 29 | static void report(const char *fmt, ...) |
| 30 | { |
| 31 | va_list vp; |
| 32 | |
| 33 | if (!verbose) |
| 34 | return; |
| 35 | |
| 36 | va_start(vp, fmt); |
| 37 | vprintf(fmt, vp); |
| 38 | putchar('\n'); |
| 39 | va_end(vp); |
| 40 | } |
| 41 | |
Junio C Hamano | 5f73076 | 2006-02-08 21:15:24 -0800 | [diff] [blame] | 42 | static int mark_valid(const char *path) |
| 43 | { |
| 44 | int namelen = strlen(path); |
| 45 | int pos = cache_name_pos(path, namelen); |
| 46 | if (0 <= pos) { |
| 47 | switch (mark_valid_only) { |
| 48 | case MARK_VALID: |
| 49 | active_cache[pos]->ce_flags |= htons(CE_VALID); |
| 50 | break; |
| 51 | case UNMARK_VALID: |
| 52 | active_cache[pos]->ce_flags &= ~htons(CE_VALID); |
| 53 | break; |
| 54 | } |
Junio C Hamano | a6e5642 | 2006-04-24 00:23:54 -0700 | [diff] [blame] | 55 | cache_tree_invalidate_path(active_cache_tree, path); |
Junio C Hamano | 5f73076 | 2006-02-08 21:15:24 -0800 | [diff] [blame] | 56 | active_cache_changed = 1; |
| 57 | return 0; |
| 58 | } |
| 59 | return -1; |
| 60 | } |
| 61 | |
Junio C Hamano | 6b5ee13 | 2005-09-21 00:00:47 -0700 | [diff] [blame] | 62 | static int add_file_to_cache(const char *path) |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 63 | { |
Junio C Hamano | 4c5abf4 | 2005-05-08 00:05:18 -0700 | [diff] [blame] | 64 | int size, namelen, option, status; |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 65 | struct cache_entry *ce; |
| 66 | struct stat st; |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 67 | |
Junio C Hamano | 4c5abf4 | 2005-05-08 00:05:18 -0700 | [diff] [blame] | 68 | status = lstat(path, &st); |
Junio C Hamano | a6e5642 | 2006-04-24 00:23:54 -0700 | [diff] [blame] | 69 | |
| 70 | /* We probably want to do this in remove_file_from_cache() and |
| 71 | * add_cache_entry() instead... |
| 72 | */ |
| 73 | cache_tree_invalidate_path(active_cache_tree, path); |
| 74 | |
Junio C Hamano | 4c5abf4 | 2005-05-08 00:05:18 -0700 | [diff] [blame] | 75 | if (status < 0 || S_ISDIR(st.st_mode)) { |
| 76 | /* When we used to have "path" and now we want to add |
| 77 | * "path/file", we need a way to remove "path" before |
| 78 | * being able to add "path/file". However, |
Junio C Hamano | 215a7ad | 2005-09-07 17:26:23 -0700 | [diff] [blame] | 79 | * "git-update-index --remove path" would not work. |
Junio C Hamano | 4c5abf4 | 2005-05-08 00:05:18 -0700 | [diff] [blame] | 80 | * --force-remove can be used but this is more user |
| 81 | * friendly, especially since we can do the opposite |
| 82 | * case just fine without --force-remove. |
| 83 | */ |
| 84 | if (status == 0 || (errno == ENOENT || errno == ENOTDIR)) { |
Petr Baudis | 34143b2 | 2005-09-18 21:09:22 +0200 | [diff] [blame] | 85 | if (allow_remove) { |
| 86 | if (remove_file_from_cache(path)) |
| 87 | return error("%s: cannot remove from the index", |
| 88 | path); |
| 89 | else |
| 90 | return 0; |
| 91 | } else if (status < 0) { |
| 92 | return error("%s: does not exist and --remove not passed", |
| 93 | path); |
| 94 | } |
Linus Torvalds | 121481a | 2005-04-10 11:32:54 -0700 | [diff] [blame] | 95 | } |
Amos Waterland | 89bc8c7 | 2005-09-01 09:13:50 -0500 | [diff] [blame] | 96 | if (0 == status) |
Petr Baudis | 34143b2 | 2005-09-18 21:09:22 +0200 | [diff] [blame] | 97 | return error("%s: is a directory - add files inside instead", |
| 98 | path); |
Amos Waterland | 89bc8c7 | 2005-09-01 09:13:50 -0500 | [diff] [blame] | 99 | else |
| 100 | return error("lstat(\"%s\"): %s", path, |
| 101 | strerror(errno)); |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 102 | } |
Junio C Hamano | 3e09cdf | 2005-10-11 18:45:33 -0700 | [diff] [blame] | 103 | |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 104 | namelen = strlen(path); |
| 105 | size = cache_entry_size(namelen); |
Peter Eriksen | 90321c1 | 2006-04-03 19:30:46 +0100 | [diff] [blame] | 106 | ce = xcalloc(1, size); |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 107 | memcpy(ce->name, path, namelen); |
Junio C Hamano | 5f73076 | 2006-02-08 21:15:24 -0800 | [diff] [blame] | 108 | ce->ce_flags = htons(namelen); |
Linus Torvalds | 711cf3a | 2005-04-11 09:39:21 -0700 | [diff] [blame] | 109 | fill_stat_cache_info(ce, &st); |
Junio C Hamano | 3e09cdf | 2005-10-11 18:45:33 -0700 | [diff] [blame] | 110 | |
Linus Torvalds | e447947 | 2005-04-16 22:26:31 -0700 | [diff] [blame] | 111 | ce->ce_mode = create_ce_mode(st.st_mode); |
Junio C Hamano | 3e09cdf | 2005-10-11 18:45:33 -0700 | [diff] [blame] | 112 | if (!trust_executable_bit) { |
| 113 | /* If there is an existing entry, pick the mode bits |
| 114 | * from it. |
| 115 | */ |
| 116 | int pos = cache_name_pos(path, namelen); |
| 117 | if (0 <= pos) |
| 118 | ce->ce_mode = active_cache[pos]->ce_mode; |
| 119 | } |
Junio C Hamano | ec1fcc1 | 2005-10-07 03:42:00 -0700 | [diff] [blame] | 120 | |
| 121 | if (index_path(ce->sha1, path, &st, !info_only)) |
| 122 | return -1; |
Junio C Hamano | 192268c | 2005-05-07 21:55:21 -0700 | [diff] [blame] | 123 | option = allow_add ? ADD_CACHE_OK_TO_ADD : 0; |
| 124 | option |= allow_replace ? ADD_CACHE_OK_TO_REPLACE : 0; |
Petr Baudis | 34143b2 | 2005-09-18 21:09:22 +0200 | [diff] [blame] | 125 | if (add_cache_entry(ce, option)) |
| 126 | return error("%s: cannot add to the index - missing --add option?", |
| 127 | path); |
| 128 | return 0; |
Linus Torvalds | 121481a | 2005-04-10 11:32:54 -0700 | [diff] [blame] | 129 | } |
| 130 | |
Junio C Hamano | d23748a | 2005-12-07 01:45:38 -0800 | [diff] [blame] | 131 | static int add_cacheinfo(unsigned int mode, const unsigned char *sha1, |
| 132 | const char *path, int stage) |
Linus Torvalds | 9945d98 | 2005-04-15 11:08:33 -0700 | [diff] [blame] | 133 | { |
Junio C Hamano | 192268c | 2005-05-07 21:55:21 -0700 | [diff] [blame] | 134 | int size, len, option; |
Linus Torvalds | 9945d98 | 2005-04-15 11:08:33 -0700 | [diff] [blame] | 135 | struct cache_entry *ce; |
| 136 | |
Junio C Hamano | d23748a | 2005-12-07 01:45:38 -0800 | [diff] [blame] | 137 | if (!verify_path(path)) |
Linus Torvalds | 9945d98 | 2005-04-15 11:08:33 -0700 | [diff] [blame] | 138 | return -1; |
Linus Torvalds | 9945d98 | 2005-04-15 11:08:33 -0700 | [diff] [blame] | 139 | |
Junio C Hamano | d23748a | 2005-12-07 01:45:38 -0800 | [diff] [blame] | 140 | len = strlen(path); |
Linus Torvalds | 9945d98 | 2005-04-15 11:08:33 -0700 | [diff] [blame] | 141 | size = cache_entry_size(len); |
Peter Eriksen | 90321c1 | 2006-04-03 19:30:46 +0100 | [diff] [blame] | 142 | ce = xcalloc(1, size); |
Linus Torvalds | 9945d98 | 2005-04-15 11:08:33 -0700 | [diff] [blame] | 143 | |
| 144 | memcpy(ce->sha1, sha1, 20); |
Junio C Hamano | d23748a | 2005-12-07 01:45:38 -0800 | [diff] [blame] | 145 | memcpy(ce->name, path, len); |
| 146 | ce->ce_flags = create_ce_flags(len, stage); |
Linus Torvalds | e447947 | 2005-04-16 22:26:31 -0700 | [diff] [blame] | 147 | ce->ce_mode = create_ce_mode(mode); |
Junio C Hamano | 5f73076 | 2006-02-08 21:15:24 -0800 | [diff] [blame] | 148 | if (assume_unchanged) |
| 149 | ce->ce_flags |= htons(CE_VALID); |
Junio C Hamano | 192268c | 2005-05-07 21:55:21 -0700 | [diff] [blame] | 150 | option = allow_add ? ADD_CACHE_OK_TO_ADD : 0; |
| 151 | option |= allow_replace ? ADD_CACHE_OK_TO_REPLACE : 0; |
Junio C Hamano | caf4f58 | 2005-10-14 21:56:46 -0700 | [diff] [blame] | 152 | if (add_cache_entry(ce, option)) |
| 153 | return error("%s: cannot add to the index - missing --add option?", |
Junio C Hamano | d23748a | 2005-12-07 01:45:38 -0800 | [diff] [blame] | 154 | path); |
| 155 | report("add '%s'", path); |
Junio C Hamano | a6e5642 | 2006-04-24 00:23:54 -0700 | [diff] [blame] | 156 | cache_tree_invalidate_path(active_cache_tree, path); |
Junio C Hamano | caf4f58 | 2005-10-14 21:56:46 -0700 | [diff] [blame] | 157 | return 0; |
Linus Torvalds | 9945d98 | 2005-04-15 11:08:33 -0700 | [diff] [blame] | 158 | } |
| 159 | |
Alex Riesen | 227bdb1 | 2006-04-23 09:01:29 +0200 | [diff] [blame] | 160 | static void chmod_path(int flip, const char *path) |
Junio C Hamano | 3e09cdf | 2005-10-11 18:45:33 -0700 | [diff] [blame] | 161 | { |
| 162 | int pos; |
| 163 | struct cache_entry *ce; |
| 164 | unsigned int mode; |
Linus Torvalds | f2a1934 | 2005-04-26 11:55:42 -0700 | [diff] [blame] | 165 | |
Junio C Hamano | 3e09cdf | 2005-10-11 18:45:33 -0700 | [diff] [blame] | 166 | pos = cache_name_pos(path, strlen(path)); |
| 167 | if (pos < 0) |
Alex Riesen | 227bdb1 | 2006-04-23 09:01:29 +0200 | [diff] [blame] | 168 | goto fail; |
Junio C Hamano | 3e09cdf | 2005-10-11 18:45:33 -0700 | [diff] [blame] | 169 | ce = active_cache[pos]; |
| 170 | mode = ntohl(ce->ce_mode); |
| 171 | if (!S_ISREG(mode)) |
Alex Riesen | 227bdb1 | 2006-04-23 09:01:29 +0200 | [diff] [blame] | 172 | goto fail; |
Junio C Hamano | 3e09cdf | 2005-10-11 18:45:33 -0700 | [diff] [blame] | 173 | switch (flip) { |
| 174 | case '+': |
| 175 | ce->ce_mode |= htonl(0111); break; |
| 176 | case '-': |
| 177 | ce->ce_mode &= htonl(~0111); break; |
| 178 | default: |
Alex Riesen | 227bdb1 | 2006-04-23 09:01:29 +0200 | [diff] [blame] | 179 | goto fail; |
Junio C Hamano | 3e09cdf | 2005-10-11 18:45:33 -0700 | [diff] [blame] | 180 | } |
Junio C Hamano | a6e5642 | 2006-04-24 00:23:54 -0700 | [diff] [blame] | 181 | cache_tree_invalidate_path(active_cache_tree, path); |
Junio C Hamano | 3e09cdf | 2005-10-11 18:45:33 -0700 | [diff] [blame] | 182 | active_cache_changed = 1; |
Alex Riesen | 227bdb1 | 2006-04-23 09:01:29 +0200 | [diff] [blame] | 183 | report("chmod %cx '%s'", flip, path); |
| 184 | return; |
| 185 | fail: |
| 186 | die("git-update-index: cannot chmod %cx '%s'", flip, path); |
Junio C Hamano | 3e09cdf | 2005-10-11 18:45:33 -0700 | [diff] [blame] | 187 | } |
| 188 | |
Junio C Hamano | 021b6e4 | 2006-06-06 12:51:49 -0700 | [diff] [blame] | 189 | static struct lock_file lock_file; |
Junio C Hamano | ee1bec3 | 2005-09-26 18:13:08 -0700 | [diff] [blame] | 190 | |
| 191 | static void update_one(const char *path, const char *prefix, int prefix_length) |
| 192 | { |
| 193 | const char *p = prefix_path(prefix, prefix_length, path); |
| 194 | if (!verify_path(p)) { |
| 195 | fprintf(stderr, "Ignoring path %s\n", path); |
Junio C Hamano | fb69a76 | 2006-05-05 22:53:56 -0700 | [diff] [blame] | 196 | goto free_return; |
Junio C Hamano | ee1bec3 | 2005-09-26 18:13:08 -0700 | [diff] [blame] | 197 | } |
Junio C Hamano | 5f73076 | 2006-02-08 21:15:24 -0800 | [diff] [blame] | 198 | if (mark_valid_only) { |
| 199 | if (mark_valid(p)) |
| 200 | die("Unable to mark file %s", path); |
Junio C Hamano | fb69a76 | 2006-05-05 22:53:56 -0700 | [diff] [blame] | 201 | goto free_return; |
Junio C Hamano | 5f73076 | 2006-02-08 21:15:24 -0800 | [diff] [blame] | 202 | } |
Junio C Hamano | a6e5642 | 2006-04-24 00:23:54 -0700 | [diff] [blame] | 203 | cache_tree_invalidate_path(active_cache_tree, path); |
Junio C Hamano | 5f73076 | 2006-02-08 21:15:24 -0800 | [diff] [blame] | 204 | |
Junio C Hamano | ee1bec3 | 2005-09-26 18:13:08 -0700 | [diff] [blame] | 205 | if (force_remove) { |
| 206 | if (remove_file_from_cache(p)) |
| 207 | die("git-update-index: unable to remove %s", path); |
Junio C Hamano | caf4f58 | 2005-10-14 21:56:46 -0700 | [diff] [blame] | 208 | report("remove '%s'", path); |
Junio C Hamano | fb69a76 | 2006-05-05 22:53:56 -0700 | [diff] [blame] | 209 | goto free_return; |
Junio C Hamano | ee1bec3 | 2005-09-26 18:13:08 -0700 | [diff] [blame] | 210 | } |
| 211 | if (add_file_to_cache(p)) |
| 212 | die("Unable to process file %s", path); |
Junio C Hamano | caf4f58 | 2005-10-14 21:56:46 -0700 | [diff] [blame] | 213 | report("add '%s'", path); |
Junio C Hamano | fb69a76 | 2006-05-05 22:53:56 -0700 | [diff] [blame] | 214 | free_return: |
Johannes Schindelin | 0cc9e70 | 2006-05-07 00:02:53 +0200 | [diff] [blame] | 215 | if (p < path || p > path + strlen(path)) |
Junio C Hamano | fb69a76 | 2006-05-05 22:53:56 -0700 | [diff] [blame] | 216 | free((char*)p); |
Junio C Hamano | ee1bec3 | 2005-09-26 18:13:08 -0700 | [diff] [blame] | 217 | } |
| 218 | |
Junio C Hamano | d4dbf36d | 2005-10-07 03:42:00 -0700 | [diff] [blame] | 219 | static void read_index_info(int line_termination) |
| 220 | { |
| 221 | struct strbuf buf; |
| 222 | strbuf_init(&buf); |
| 223 | while (1) { |
Junio C Hamano | 9c20a47 | 2005-11-21 21:46:57 -0800 | [diff] [blame] | 224 | char *ptr, *tab; |
Junio C Hamano | 973d6a2 | 2005-10-16 00:39:07 -0700 | [diff] [blame] | 225 | char *path_name; |
Junio C Hamano | d4dbf36d | 2005-10-07 03:42:00 -0700 | [diff] [blame] | 226 | unsigned char sha1[20]; |
| 227 | unsigned int mode; |
Junio C Hamano | d23748a | 2005-12-07 01:45:38 -0800 | [diff] [blame] | 228 | int stage; |
Junio C Hamano | d4dbf36d | 2005-10-07 03:42:00 -0700 | [diff] [blame] | 229 | |
Junio C Hamano | d23748a | 2005-12-07 01:45:38 -0800 | [diff] [blame] | 230 | /* This reads lines formatted in one of three formats: |
| 231 | * |
| 232 | * (1) mode SP sha1 TAB path |
| 233 | * The first format is what "git-apply --index-info" |
| 234 | * reports, and used to reconstruct a partial tree |
| 235 | * that is used for phony merge base tree when falling |
| 236 | * back on 3-way merge. |
| 237 | * |
| 238 | * (2) mode SP type SP sha1 TAB path |
| 239 | * The second format is to stuff git-ls-tree output |
| 240 | * into the index file. |
| 241 | * |
| 242 | * (3) mode SP sha1 SP stage TAB path |
| 243 | * This format is to put higher order stages into the |
| 244 | * index file and matches git-ls-files --stage output. |
| 245 | */ |
Junio C Hamano | d4dbf36d | 2005-10-07 03:42:00 -0700 | [diff] [blame] | 246 | read_line(&buf, stdin, line_termination); |
| 247 | if (buf.eof) |
| 248 | break; |
| 249 | |
| 250 | mode = strtoul(buf.buf, &ptr, 8); |
Junio C Hamano | 9c20a47 | 2005-11-21 21:46:57 -0800 | [diff] [blame] | 251 | if (ptr == buf.buf || *ptr != ' ') |
Junio C Hamano | d4dbf36d | 2005-10-07 03:42:00 -0700 | [diff] [blame] | 252 | goto bad_line; |
| 253 | |
Junio C Hamano | 9c20a47 | 2005-11-21 21:46:57 -0800 | [diff] [blame] | 254 | tab = strchr(ptr, '\t'); |
| 255 | if (!tab || tab - ptr < 41) |
| 256 | goto bad_line; |
Junio C Hamano | d23748a | 2005-12-07 01:45:38 -0800 | [diff] [blame] | 257 | |
Junio C Hamano | 2d49711 | 2006-01-31 18:03:37 -0800 | [diff] [blame] | 258 | if (tab[-2] == ' ' && '0' <= tab[-1] && tab[-1] <= '3') { |
Junio C Hamano | d23748a | 2005-12-07 01:45:38 -0800 | [diff] [blame] | 259 | stage = tab[-1] - '0'; |
| 260 | ptr = tab + 1; /* point at the head of path */ |
| 261 | tab = tab - 2; /* point at tail of sha1 */ |
| 262 | } |
| 263 | else { |
| 264 | stage = 0; |
| 265 | ptr = tab + 1; /* point at the head of path */ |
| 266 | } |
| 267 | |
Junio C Hamano | 9c20a47 | 2005-11-21 21:46:57 -0800 | [diff] [blame] | 268 | if (get_sha1_hex(tab - 40, sha1) || tab[-41] != ' ') |
| 269 | goto bad_line; |
Junio C Hamano | 973d6a2 | 2005-10-16 00:39:07 -0700 | [diff] [blame] | 270 | |
| 271 | if (line_termination && ptr[0] == '"') |
| 272 | path_name = unquote_c_style(ptr, NULL); |
| 273 | else |
| 274 | path_name = ptr; |
| 275 | |
| 276 | if (!verify_path(path_name)) { |
| 277 | fprintf(stderr, "Ignoring path %s\n", path_name); |
| 278 | if (path_name != ptr) |
| 279 | free(path_name); |
Junio C Hamano | d4dbf36d | 2005-10-07 03:42:00 -0700 | [diff] [blame] | 280 | continue; |
| 281 | } |
Junio C Hamano | a6e5642 | 2006-04-24 00:23:54 -0700 | [diff] [blame] | 282 | cache_tree_invalidate_path(active_cache_tree, path_name); |
Junio C Hamano | d4dbf36d | 2005-10-07 03:42:00 -0700 | [diff] [blame] | 283 | |
| 284 | if (!mode) { |
| 285 | /* mode == 0 means there is no such path -- remove */ |
Junio C Hamano | 973d6a2 | 2005-10-16 00:39:07 -0700 | [diff] [blame] | 286 | if (remove_file_from_cache(path_name)) |
Junio C Hamano | d4dbf36d | 2005-10-07 03:42:00 -0700 | [diff] [blame] | 287 | die("git-update-index: unable to remove %s", |
| 288 | ptr); |
| 289 | } |
| 290 | else { |
| 291 | /* mode ' ' sha1 '\t' name |
| 292 | * ptr[-1] points at tab, |
| 293 | * ptr[-41] is at the beginning of sha1 |
| 294 | */ |
| 295 | ptr[-42] = ptr[-1] = 0; |
Junio C Hamano | d23748a | 2005-12-07 01:45:38 -0800 | [diff] [blame] | 296 | if (add_cacheinfo(mode, sha1, path_name, stage)) |
Junio C Hamano | d4dbf36d | 2005-10-07 03:42:00 -0700 | [diff] [blame] | 297 | die("git-update-index: unable to update %s", |
Junio C Hamano | 973d6a2 | 2005-10-16 00:39:07 -0700 | [diff] [blame] | 298 | path_name); |
Junio C Hamano | d4dbf36d | 2005-10-07 03:42:00 -0700 | [diff] [blame] | 299 | } |
Junio C Hamano | 973d6a2 | 2005-10-16 00:39:07 -0700 | [diff] [blame] | 300 | if (path_name != ptr) |
| 301 | free(path_name); |
Junio C Hamano | d4dbf36d | 2005-10-07 03:42:00 -0700 | [diff] [blame] | 302 | continue; |
| 303 | |
| 304 | bad_line: |
| 305 | die("malformed index info %s", buf.buf); |
| 306 | } |
| 307 | } |
| 308 | |
Petr Baudis | f6ab5bb | 2005-10-25 17:26:25 +0200 | [diff] [blame] | 309 | static const char update_index_usage[] = |
Junio C Hamano | 83e77a2 | 2006-05-05 17:40:47 -0700 | [diff] [blame] | 310 | "git-update-index [-q] [--add] [--replace] [--remove] [--unmerged] [--refresh] [--really-refresh] [--cacheinfo] [--chmod=(+|-)x] [--assume-unchanged] [--info-only] [--force-remove] [--stdin] [--index-info] [--unresolve] [--again] [--ignore-missing] [-z] [--verbose] [--] <file>..."; |
Petr Baudis | f6ab5bb | 2005-10-25 17:26:25 +0200 | [diff] [blame] | 311 | |
Junio C Hamano | 2bd452d | 2006-04-19 23:52:05 -0700 | [diff] [blame] | 312 | static unsigned char head_sha1[20]; |
| 313 | static unsigned char merge_head_sha1[20]; |
| 314 | |
| 315 | static struct cache_entry *read_one_ent(const char *which, |
| 316 | unsigned char *ent, const char *path, |
| 317 | int namelen, int stage) |
| 318 | { |
| 319 | unsigned mode; |
| 320 | unsigned char sha1[20]; |
| 321 | int size; |
| 322 | struct cache_entry *ce; |
| 323 | |
| 324 | if (get_tree_entry(ent, path, sha1, &mode)) { |
Junio C Hamano | 83e77a2 | 2006-05-05 17:40:47 -0700 | [diff] [blame] | 325 | if (which) |
| 326 | error("%s: not in %s branch.", path, which); |
Junio C Hamano | 2bd452d | 2006-04-19 23:52:05 -0700 | [diff] [blame] | 327 | return NULL; |
| 328 | } |
| 329 | if (mode == S_IFDIR) { |
Junio C Hamano | 83e77a2 | 2006-05-05 17:40:47 -0700 | [diff] [blame] | 330 | if (which) |
| 331 | error("%s: not a blob in %s branch.", path, which); |
Junio C Hamano | 2bd452d | 2006-04-19 23:52:05 -0700 | [diff] [blame] | 332 | return NULL; |
| 333 | } |
| 334 | size = cache_entry_size(namelen); |
| 335 | ce = xcalloc(1, size); |
| 336 | |
| 337 | memcpy(ce->sha1, sha1, 20); |
| 338 | memcpy(ce->name, path, namelen); |
| 339 | ce->ce_flags = create_ce_flags(namelen, stage); |
| 340 | ce->ce_mode = create_ce_mode(mode); |
| 341 | return ce; |
| 342 | } |
| 343 | |
| 344 | static int unresolve_one(const char *path) |
| 345 | { |
| 346 | int namelen = strlen(path); |
| 347 | int pos; |
| 348 | int ret = 0; |
| 349 | struct cache_entry *ce_2 = NULL, *ce_3 = NULL; |
| 350 | |
| 351 | /* See if there is such entry in the index. */ |
| 352 | pos = cache_name_pos(path, namelen); |
| 353 | if (pos < 0) { |
| 354 | /* If there isn't, either it is unmerged, or |
| 355 | * resolved as "removed" by mistake. We do not |
| 356 | * want to do anything in the former case. |
| 357 | */ |
| 358 | pos = -pos-1; |
| 359 | if (pos < active_nr) { |
| 360 | struct cache_entry *ce = active_cache[pos]; |
| 361 | if (ce_namelen(ce) == namelen && |
| 362 | !memcmp(ce->name, path, namelen)) { |
| 363 | fprintf(stderr, |
| 364 | "%s: skipping still unmerged path.\n", |
| 365 | path); |
| 366 | goto free_return; |
| 367 | } |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | /* Grab blobs from given path from HEAD and MERGE_HEAD, |
| 372 | * stuff HEAD version in stage #2, |
| 373 | * stuff MERGE_HEAD version in stage #3. |
| 374 | */ |
| 375 | ce_2 = read_one_ent("our", head_sha1, path, namelen, 2); |
| 376 | ce_3 = read_one_ent("their", merge_head_sha1, path, namelen, 3); |
| 377 | |
| 378 | if (!ce_2 || !ce_3) { |
| 379 | ret = -1; |
| 380 | goto free_return; |
| 381 | } |
| 382 | if (!memcmp(ce_2->sha1, ce_3->sha1, 20) && |
| 383 | ce_2->ce_mode == ce_3->ce_mode) { |
| 384 | fprintf(stderr, "%s: identical in both, skipping.\n", |
| 385 | path); |
| 386 | goto free_return; |
| 387 | } |
| 388 | |
Junio C Hamano | 497c321 | 2006-04-26 22:05:05 -0700 | [diff] [blame] | 389 | cache_tree_invalidate_path(active_cache_tree, path); |
Junio C Hamano | 2bd452d | 2006-04-19 23:52:05 -0700 | [diff] [blame] | 390 | remove_file_from_cache(path); |
| 391 | if (add_cache_entry(ce_2, ADD_CACHE_OK_TO_ADD)) { |
| 392 | error("%s: cannot add our version to the index.", path); |
| 393 | ret = -1; |
| 394 | goto free_return; |
| 395 | } |
| 396 | if (!add_cache_entry(ce_3, ADD_CACHE_OK_TO_ADD)) |
| 397 | return 0; |
| 398 | error("%s: cannot add their version to the index.", path); |
| 399 | ret = -1; |
| 400 | free_return: |
| 401 | free(ce_2); |
| 402 | free(ce_3); |
| 403 | return ret; |
| 404 | } |
| 405 | |
| 406 | static void read_head_pointers(void) |
| 407 | { |
| 408 | if (read_ref(git_path("HEAD"), head_sha1)) |
| 409 | die("No HEAD -- no initial commit yet?\n"); |
| 410 | if (read_ref(git_path("MERGE_HEAD"), merge_head_sha1)) { |
| 411 | fprintf(stderr, "Not in the middle of a merge.\n"); |
| 412 | exit(0); |
| 413 | } |
| 414 | } |
| 415 | |
Junio C Hamano | 09895c1 | 2006-05-05 17:50:06 -0700 | [diff] [blame] | 416 | static int do_unresolve(int ac, const char **av, |
| 417 | const char *prefix, int prefix_length) |
Junio C Hamano | 2bd452d | 2006-04-19 23:52:05 -0700 | [diff] [blame] | 418 | { |
| 419 | int i; |
| 420 | int err = 0; |
| 421 | |
| 422 | /* Read HEAD and MERGE_HEAD; if MERGE_HEAD does not exist, we |
| 423 | * are not doing a merge, so exit with success status. |
| 424 | */ |
| 425 | read_head_pointers(); |
| 426 | |
| 427 | for (i = 1; i < ac; i++) { |
| 428 | const char *arg = av[i]; |
Junio C Hamano | 09895c1 | 2006-05-05 17:50:06 -0700 | [diff] [blame] | 429 | const char *p = prefix_path(prefix, prefix_length, arg); |
| 430 | err |= unresolve_one(p); |
Johannes Schindelin | 0cc9e70 | 2006-05-07 00:02:53 +0200 | [diff] [blame] | 431 | if (p < arg || p > arg + strlen(arg)) |
Junio C Hamano | 09895c1 | 2006-05-05 17:50:06 -0700 | [diff] [blame] | 432 | free((char*)p); |
Junio C Hamano | 2bd452d | 2006-04-19 23:52:05 -0700 | [diff] [blame] | 433 | } |
| 434 | return err; |
| 435 | } |
| 436 | |
Junio C Hamano | 83e77a2 | 2006-05-05 17:40:47 -0700 | [diff] [blame] | 437 | static int do_reupdate(int ac, const char **av, |
| 438 | const char *prefix, int prefix_length) |
| 439 | { |
| 440 | /* Read HEAD and run update-index on paths that are |
| 441 | * merged and already different between index and HEAD. |
| 442 | */ |
| 443 | int pos; |
| 444 | int has_head = 1; |
Johannes Schindelin | 0cc9e70 | 2006-05-07 00:02:53 +0200 | [diff] [blame] | 445 | const char **pathspec = get_pathspec(prefix, av + 1); |
Junio C Hamano | 83e77a2 | 2006-05-05 17:40:47 -0700 | [diff] [blame] | 446 | |
| 447 | if (read_ref(git_path("HEAD"), head_sha1)) |
| 448 | /* If there is no HEAD, that means it is an initial |
| 449 | * commit. Update everything in the index. |
| 450 | */ |
| 451 | has_head = 0; |
| 452 | redo: |
| 453 | for (pos = 0; pos < active_nr; pos++) { |
| 454 | struct cache_entry *ce = active_cache[pos]; |
| 455 | struct cache_entry *old = NULL; |
| 456 | int save_nr; |
Junio C Hamano | 22293b9 | 2006-05-05 23:09:05 -0700 | [diff] [blame] | 457 | |
| 458 | if (ce_stage(ce) || !ce_path_match(ce, pathspec)) |
Junio C Hamano | 83e77a2 | 2006-05-05 17:40:47 -0700 | [diff] [blame] | 459 | continue; |
| 460 | if (has_head) |
| 461 | old = read_one_ent(NULL, head_sha1, |
| 462 | ce->name, ce_namelen(ce), 0); |
| 463 | if (old && ce->ce_mode == old->ce_mode && |
| 464 | !memcmp(ce->sha1, old->sha1, 20)) { |
| 465 | free(old); |
| 466 | continue; /* unchanged */ |
| 467 | } |
| 468 | /* Be careful. The working tree may not have the |
| 469 | * path anymore, in which case, under 'allow_remove', |
| 470 | * or worse yet 'allow_replace', active_nr may decrease. |
| 471 | */ |
| 472 | save_nr = active_nr; |
| 473 | update_one(ce->name + prefix_length, prefix, prefix_length); |
| 474 | if (save_nr != active_nr) |
| 475 | goto redo; |
| 476 | } |
| 477 | return 0; |
| 478 | } |
| 479 | |
Junio C Hamano | 6b5ee13 | 2005-09-21 00:00:47 -0700 | [diff] [blame] | 480 | int main(int argc, const char **argv) |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 481 | { |
Junio C Hamano | ee1bec3 | 2005-09-26 18:13:08 -0700 | [diff] [blame] | 482 | int i, newfd, entries, has_errors = 0, line_termination = '\n'; |
Linus Torvalds | 121481a | 2005-04-10 11:32:54 -0700 | [diff] [blame] | 483 | int allow_options = 1; |
Junio C Hamano | ee1bec3 | 2005-09-26 18:13:08 -0700 | [diff] [blame] | 484 | int read_from_stdin = 0; |
Linus Torvalds | cfb0af1 | 2005-08-17 13:32:22 -0700 | [diff] [blame] | 485 | const char *prefix = setup_git_directory(); |
Junio C Hamano | ee1bec3 | 2005-09-26 18:13:08 -0700 | [diff] [blame] | 486 | int prefix_length = prefix ? strlen(prefix) : 0; |
Alex Riesen | 227bdb1 | 2006-04-23 09:01:29 +0200 | [diff] [blame] | 487 | char set_executable_bit = 0; |
Linus Torvalds | 405e5b2 | 2006-05-19 09:56:35 -0700 | [diff] [blame] | 488 | unsigned int refresh_flags = 0; |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 489 | |
Junio C Hamano | 3e09cdf | 2005-10-11 18:45:33 -0700 | [diff] [blame] | 490 | git_config(git_default_config); |
| 491 | |
Junio C Hamano | 021b6e4 | 2006-06-06 12:51:49 -0700 | [diff] [blame] | 492 | newfd = hold_lock_file_for_update(&lock_file, get_index_file()); |
Linus Torvalds | 9614b8d | 2005-04-11 15:39:26 -0700 | [diff] [blame] | 493 | if (newfd < 0) |
Junio C Hamano | 021b6e4 | 2006-06-06 12:51:49 -0700 | [diff] [blame] | 494 | die("unable to create new index file"); |
Linus Torvalds | 9614b8d | 2005-04-11 15:39:26 -0700 | [diff] [blame] | 495 | |
Linus Torvalds | 9614b8d | 2005-04-11 15:39:26 -0700 | [diff] [blame] | 496 | entries = read_cache(); |
| 497 | if (entries < 0) |
Petr Baudis | 2de381f | 2005-04-13 02:28:48 -0700 | [diff] [blame] | 498 | die("cache corrupted"); |
Linus Torvalds | 9614b8d | 2005-04-11 15:39:26 -0700 | [diff] [blame] | 499 | |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 500 | for (i = 1 ; i < argc; i++) { |
Junio C Hamano | 6b5ee13 | 2005-09-21 00:00:47 -0700 | [diff] [blame] | 501 | const char *path = argv[i]; |
Linus Torvalds | 121481a | 2005-04-10 11:32:54 -0700 | [diff] [blame] | 502 | |
| 503 | if (allow_options && *path == '-') { |
| 504 | if (!strcmp(path, "--")) { |
| 505 | allow_options = 0; |
| 506 | continue; |
| 507 | } |
Linus Torvalds | 0ed3715 | 2005-06-20 21:18:54 -0700 | [diff] [blame] | 508 | if (!strcmp(path, "-q")) { |
Linus Torvalds | 405e5b2 | 2006-05-19 09:56:35 -0700 | [diff] [blame] | 509 | refresh_flags |= REFRESH_QUIET; |
Linus Torvalds | 0ed3715 | 2005-06-20 21:18:54 -0700 | [diff] [blame] | 510 | continue; |
| 511 | } |
Linus Torvalds | 121481a | 2005-04-10 11:32:54 -0700 | [diff] [blame] | 512 | if (!strcmp(path, "--add")) { |
| 513 | allow_add = 1; |
| 514 | continue; |
| 515 | } |
Junio C Hamano | 192268c | 2005-05-07 21:55:21 -0700 | [diff] [blame] | 516 | if (!strcmp(path, "--replace")) { |
| 517 | allow_replace = 1; |
| 518 | continue; |
| 519 | } |
Linus Torvalds | 121481a | 2005-04-10 11:32:54 -0700 | [diff] [blame] | 520 | if (!strcmp(path, "--remove")) { |
| 521 | allow_remove = 1; |
| 522 | continue; |
| 523 | } |
Linus Torvalds | 5d1a5c0 | 2005-10-01 13:24:27 -0700 | [diff] [blame] | 524 | if (!strcmp(path, "--unmerged")) { |
Linus Torvalds | 405e5b2 | 2006-05-19 09:56:35 -0700 | [diff] [blame] | 525 | refresh_flags |= REFRESH_UNMERGED; |
Linus Torvalds | 5d1a5c0 | 2005-10-01 13:24:27 -0700 | [diff] [blame] | 526 | continue; |
| 527 | } |
Linus Torvalds | 121481a | 2005-04-10 11:32:54 -0700 | [diff] [blame] | 528 | if (!strcmp(path, "--refresh")) { |
Linus Torvalds | 405e5b2 | 2006-05-19 09:56:35 -0700 | [diff] [blame] | 529 | has_errors |= refresh_cache(refresh_flags); |
Junio C Hamano | 5f73076 | 2006-02-08 21:15:24 -0800 | [diff] [blame] | 530 | continue; |
| 531 | } |
| 532 | if (!strcmp(path, "--really-refresh")) { |
Linus Torvalds | 405e5b2 | 2006-05-19 09:56:35 -0700 | [diff] [blame] | 533 | has_errors |= refresh_cache(REFRESH_REALLY | refresh_flags); |
Linus Torvalds | 121481a | 2005-04-10 11:32:54 -0700 | [diff] [blame] | 534 | continue; |
| 535 | } |
Linus Torvalds | 9945d98 | 2005-04-15 11:08:33 -0700 | [diff] [blame] | 536 | if (!strcmp(path, "--cacheinfo")) { |
Junio C Hamano | d23748a | 2005-12-07 01:45:38 -0800 | [diff] [blame] | 537 | unsigned char sha1[20]; |
| 538 | unsigned int mode; |
| 539 | |
Junio C Hamano | b3f94c4 | 2005-05-08 15:31:33 -0700 | [diff] [blame] | 540 | if (i+3 >= argc) |
Junio C Hamano | 215a7ad | 2005-09-07 17:26:23 -0700 | [diff] [blame] | 541 | die("git-update-index: --cacheinfo <mode> <sha1> <path>"); |
Junio C Hamano | d23748a | 2005-12-07 01:45:38 -0800 | [diff] [blame] | 542 | |
| 543 | if ((sscanf(argv[i+1], "%o", &mode) != 1) || |
| 544 | get_sha1_hex(argv[i+2], sha1) || |
| 545 | add_cacheinfo(mode, sha1, argv[i+3], 0)) |
| 546 | die("git-update-index: --cacheinfo" |
| 547 | " cannot add %s", argv[i+3]); |
Linus Torvalds | 9945d98 | 2005-04-15 11:08:33 -0700 | [diff] [blame] | 548 | i += 3; |
| 549 | continue; |
| 550 | } |
Junio C Hamano | 3e09cdf | 2005-10-11 18:45:33 -0700 | [diff] [blame] | 551 | if (!strcmp(path, "--chmod=-x") || |
| 552 | !strcmp(path, "--chmod=+x")) { |
| 553 | if (argc <= i+1) |
| 554 | die("git-update-index: %s <path>", path); |
Alex Riesen | 227bdb1 | 2006-04-23 09:01:29 +0200 | [diff] [blame] | 555 | set_executable_bit = path[8]; |
Junio C Hamano | 3e09cdf | 2005-10-11 18:45:33 -0700 | [diff] [blame] | 556 | continue; |
| 557 | } |
Junio C Hamano | 5f73076 | 2006-02-08 21:15:24 -0800 | [diff] [blame] | 558 | if (!strcmp(path, "--assume-unchanged")) { |
| 559 | mark_valid_only = MARK_VALID; |
| 560 | continue; |
| 561 | } |
| 562 | if (!strcmp(path, "--no-assume-unchanged")) { |
| 563 | mark_valid_only = UNMARK_VALID; |
| 564 | continue; |
| 565 | } |
Bryan Larsen | df6e151 | 2005-07-08 16:52:12 -0700 | [diff] [blame] | 566 | if (!strcmp(path, "--info-only")) { |
| 567 | info_only = 1; |
| 568 | continue; |
| 569 | } |
Junio C Hamano | 0ff5bf7 | 2005-05-01 23:50:51 -0700 | [diff] [blame] | 570 | if (!strcmp(path, "--force-remove")) { |
Petr Baudis | 9b63f50 | 2005-05-31 18:52:43 +0200 | [diff] [blame] | 571 | force_remove = 1; |
Junio C Hamano | 0ff5bf7 | 2005-05-01 23:50:51 -0700 | [diff] [blame] | 572 | continue; |
| 573 | } |
Junio C Hamano | ee1bec3 | 2005-09-26 18:13:08 -0700 | [diff] [blame] | 574 | if (!strcmp(path, "-z")) { |
| 575 | line_termination = 0; |
| 576 | continue; |
| 577 | } |
| 578 | if (!strcmp(path, "--stdin")) { |
| 579 | if (i != argc - 1) |
| 580 | die("--stdin must be at the end"); |
| 581 | read_from_stdin = 1; |
| 582 | break; |
| 583 | } |
Junio C Hamano | d4dbf36d | 2005-10-07 03:42:00 -0700 | [diff] [blame] | 584 | if (!strcmp(path, "--index-info")) { |
Shawn Pearce | a41c175 | 2006-03-02 12:21:33 -0500 | [diff] [blame] | 585 | if (i != argc - 1) |
| 586 | die("--index-info must be at the end"); |
Junio C Hamano | d4dbf36d | 2005-10-07 03:42:00 -0700 | [diff] [blame] | 587 | allow_add = allow_replace = allow_remove = 1; |
| 588 | read_index_info(line_termination); |
Shawn Pearce | a41c175 | 2006-03-02 12:21:33 -0500 | [diff] [blame] | 589 | break; |
Junio C Hamano | d4dbf36d | 2005-10-07 03:42:00 -0700 | [diff] [blame] | 590 | } |
Junio C Hamano | 2bd452d | 2006-04-19 23:52:05 -0700 | [diff] [blame] | 591 | if (!strcmp(path, "--unresolve")) { |
Junio C Hamano | 09895c1 | 2006-05-05 17:50:06 -0700 | [diff] [blame] | 592 | has_errors = do_unresolve(argc - i, argv + i, |
| 593 | prefix, prefix_length); |
Junio C Hamano | 2bd452d | 2006-04-19 23:52:05 -0700 | [diff] [blame] | 594 | if (has_errors) |
| 595 | active_cache_changed = 0; |
| 596 | goto finish; |
| 597 | } |
Junio C Hamano | 83e77a2 | 2006-05-05 17:40:47 -0700 | [diff] [blame] | 598 | if (!strcmp(path, "--again")) { |
| 599 | has_errors = do_reupdate(argc - i, argv + i, |
| 600 | prefix, prefix_length); |
| 601 | if (has_errors) |
| 602 | active_cache_changed = 0; |
| 603 | goto finish; |
| 604 | } |
James Bottomley | c6e007b | 2005-04-24 15:14:16 -0700 | [diff] [blame] | 605 | if (!strcmp(path, "--ignore-missing")) { |
Linus Torvalds | 405e5b2 | 2006-05-19 09:56:35 -0700 | [diff] [blame] | 606 | refresh_flags |= REFRESH_IGNORE_MISSING; |
James Bottomley | c6e007b | 2005-04-24 15:14:16 -0700 | [diff] [blame] | 607 | continue; |
| 608 | } |
Junio C Hamano | caf4f58 | 2005-10-14 21:56:46 -0700 | [diff] [blame] | 609 | if (!strcmp(path, "--verbose")) { |
| 610 | verbose = 1; |
| 611 | continue; |
| 612 | } |
Petr Baudis | f6ab5bb | 2005-10-25 17:26:25 +0200 | [diff] [blame] | 613 | if (!strcmp(path, "-h") || !strcmp(path, "--help")) |
| 614 | usage(update_index_usage); |
Petr Baudis | 2de381f | 2005-04-13 02:28:48 -0700 | [diff] [blame] | 615 | die("unknown option %s", path); |
Linus Torvalds | 121481a | 2005-04-10 11:32:54 -0700 | [diff] [blame] | 616 | } |
Junio C Hamano | ee1bec3 | 2005-09-26 18:13:08 -0700 | [diff] [blame] | 617 | update_one(path, prefix, prefix_length); |
Alex Riesen | 227bdb1 | 2006-04-23 09:01:29 +0200 | [diff] [blame] | 618 | if (set_executable_bit) |
| 619 | chmod_path(set_executable_bit, path); |
Junio C Hamano | ee1bec3 | 2005-09-26 18:13:08 -0700 | [diff] [blame] | 620 | } |
| 621 | if (read_from_stdin) { |
| 622 | struct strbuf buf; |
| 623 | strbuf_init(&buf); |
| 624 | while (1) { |
Junio C Hamano | a94d994 | 2006-01-11 13:36:45 -0800 | [diff] [blame] | 625 | char *path_name; |
Junio C Hamano | fb69a76 | 2006-05-05 22:53:56 -0700 | [diff] [blame] | 626 | const char *p; |
Junio C Hamano | ee1bec3 | 2005-09-26 18:13:08 -0700 | [diff] [blame] | 627 | read_line(&buf, stdin, line_termination); |
| 628 | if (buf.eof) |
| 629 | break; |
Junio C Hamano | a94d994 | 2006-01-11 13:36:45 -0800 | [diff] [blame] | 630 | if (line_termination && buf.buf[0] == '"') |
| 631 | path_name = unquote_c_style(buf.buf, NULL); |
| 632 | else |
| 633 | path_name = buf.buf; |
Junio C Hamano | fb69a76 | 2006-05-05 22:53:56 -0700 | [diff] [blame] | 634 | p = prefix_path(prefix, prefix_length, path_name); |
| 635 | update_one(p, NULL, 0); |
| 636 | if (set_executable_bit) |
Alex Riesen | 227bdb1 | 2006-04-23 09:01:29 +0200 | [diff] [blame] | 637 | chmod_path(set_executable_bit, p); |
Johannes Schindelin | 0cc9e70 | 2006-05-07 00:02:53 +0200 | [diff] [blame] | 638 | if (p < path_name || p > path_name + strlen(path_name)) |
Junio C Hamano | fb69a76 | 2006-05-05 22:53:56 -0700 | [diff] [blame] | 639 | free((char*) p); |
Junio C Hamano | a94d994 | 2006-01-11 13:36:45 -0800 | [diff] [blame] | 640 | if (path_name != buf.buf) |
| 641 | free(path_name); |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 642 | } |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 643 | } |
Junio C Hamano | 2bd452d | 2006-04-19 23:52:05 -0700 | [diff] [blame] | 644 | |
| 645 | finish: |
Linus Torvalds | 5cd5ace | 2005-10-01 13:39:47 -0700 | [diff] [blame] | 646 | if (active_cache_changed) { |
| 647 | if (write_cache(newfd, active_cache, active_nr) || |
Junio C Hamano | 021b6e4 | 2006-06-06 12:51:49 -0700 | [diff] [blame] | 648 | commit_lock_file(&lock_file)) |
| 649 | die("Unable to write new index file"); |
Linus Torvalds | 5cd5ace | 2005-10-01 13:39:47 -0700 | [diff] [blame] | 650 | } |
Linus Torvalds | 9614b8d | 2005-04-11 15:39:26 -0700 | [diff] [blame] | 651 | |
Junio C Hamano | c4b83e6 | 2005-05-05 15:29:06 -0700 | [diff] [blame] | 652 | return has_errors ? 1 : 0; |
Linus Torvalds | e83c516 | 2005-04-07 15:13:13 -0700 | [diff] [blame] | 653 | } |