Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 789 lines (713 sloc) 20.758 kB
8bc9a0c Add copyright notices.
Linus Torvalds authored
1 /*
2 * GIT - The information manager from hell
3 *
4 * Copyright (C) Linus Torvalds, 2005
5 */
e83c516 Initial revision of "git", the information manager from hell
Linus Torvalds authored
6 #include "cache.h"
973d6a2 update-index --index-info: adjust for funny-path quoting.
Junio C Hamano authored
7 #include "quote.h"
a6e5642 Use cache-tree in update-index.
Junio C Hamano authored
8 #include "cache-tree.h"
2bd452d git-update-index --unresolve
Junio C Hamano authored
9 #include "tree-walk.h"
fefe81c Make git-update-index a builtin
Lukas Sandström authored
10 #include "builtin.h"
e011054 @torvalds Teach git-update-index about gitlinks
torvalds authored
11 #include "refs.h"
4a39f79 @gitster resolve-undo: allow plumbing to clear the information
gitster authored
12 #include "resolve-undo.h"
e83c516 Initial revision of "git", the information manager from hell
Linus Torvalds authored
13
121481a Make "update-cache" a bit friendlier to use (and harder to mis-use).
Linus Torvalds authored
14 /*
15 * Default to not allowing changes to the list of files. The
16 * tool doesn't actually care, but this makes it harder to add
17 * files to the revision control by mistake by doing something
f18d244 @heikkiorsila Start conforming code to "git subcmd" style part 3
heikkiorsila authored
18 * like "git update-index *" and suddenly having all the object
121481a Make "update-cache" a bit friendlier to use (and harder to mis-use).
Linus Torvalds authored
19 * files be revision controlled.
20 */
caf4f58 Improve "git add" again.
Junio C Hamano authored
21 static int allow_add;
22 static int allow_remove;
23 static int allow_replace;
24 static int info_only;
9b63f50 @pasky [PATCH] Make git-update-cache --force-remove regular
pasky authored
25 static int force_remove;
caf4f58 Improve "git add" again.
Junio C Hamano authored
26 static int verbose;
96f1e58 remove unnecessary initializations
David Rientjes authored
27 static int mark_valid_only;
44a3691 @pclouds Introduce "skip-worktree" bit in index, teach Git to get/set this bit
pclouds authored
28 static int mark_skip_worktree_only;
83b327b @pclouds update-index: refactor mark_valid() in preparation for new options
pclouds authored
29 #define MARK_FLAG 1
30 #define UNMARK_FLAG 2
5f73076 "Assume unchanged" git
Junio C Hamano authored
31
28bea9e Check the format of more printf-type functions
Tarmigan Casebolt authored
32 __attribute__((format (printf, 1, 2)))
caf4f58 Improve "git add" again.
Junio C Hamano authored
33 static void report(const char *fmt, ...)
34 {
35 va_list vp;
36
37 if (!verbose)
38 return;
39
40 va_start(vp, fmt);
41 vprintf(fmt, vp);
42 putchar('\n');
43 va_end(vp);
44 }
45
83b327b @pclouds update-index: refactor mark_valid() in preparation for new options
pclouds authored
46 static int mark_ce_flags(const char *path, int flag, int mark)
5f73076 "Assume unchanged" git
Junio C Hamano authored
47 {
48 int namelen = strlen(path);
49 int pos = cache_name_pos(path, namelen);
50 if (0 <= pos) {
83b327b @pclouds update-index: refactor mark_valid() in preparation for new options
pclouds authored
51 if (mark)
52 active_cache[pos]->ce_flags |= flag;
53 else
54 active_cache[pos]->ce_flags &= ~flag;
a6e5642 Use cache-tree in update-index.
Junio C Hamano authored
55 cache_tree_invalidate_path(active_cache_tree, path);
5f73076 "Assume unchanged" git
Junio C Hamano authored
56 active_cache_changed = 1;
57 return 0;
58 }
59 return -1;
60 }
61
e011054 @torvalds Teach git-update-index about gitlinks
torvalds authored
62 static int remove_one_path(const char *path)
e83c516 Initial revision of "git", the information manager from hell
Linus Torvalds authored
63 {
e011054 @torvalds Teach git-update-index about gitlinks
torvalds authored
64 if (!allow_remove)
65 return error("%s: does not exist and --remove not passed", path);
66 if (remove_file_from_cache(path))
67 return error("%s: cannot remove from the index", path);
68 return 0;
69 }
a6e5642 Use cache-tree in update-index.
Junio C Hamano authored
70
e011054 @torvalds Teach git-update-index about gitlinks
torvalds authored
71 /*
72 * Handle a path that couldn't be lstat'ed. It's either:
73 * - missing file (ENOENT or ENOTDIR). That's ok if we're
74 * supposed to be removing it and the removal actually
75 * succeeds.
76 * - permission error. That's never ok.
77 */
78 static int process_lstat_error(const char *path, int err)
79 {
80 if (err == ENOENT || err == ENOTDIR)
81 return remove_one_path(path);
82 return error("lstat(\"%s\"): %s", path, strerror(errno));
83 }
a6e5642 Use cache-tree in update-index.
Junio C Hamano authored
84
e011054 @torvalds Teach git-update-index about gitlinks
torvalds authored
85 static int add_one_path(struct cache_entry *old, const char *path, int len, struct stat *st)
86 {
2263147 @torvalds Fix "git commit directory/" performance anomaly
torvalds authored
87 int option, size;
88 struct cache_entry *ce;
3e09cdf Use core.filemode.
Junio C Hamano authored
89
2263147 @torvalds Fix "git commit directory/" performance anomaly
torvalds authored
90 /* Was the old index entry already up-to-date? */
91 if (old && !ce_stage(old) && !ce_match_stat(old, st, 0))
92 return 0;
93
94 size = cache_entry_size(len);
95 ce = xcalloc(1, size);
e011054 @torvalds Teach git-update-index about gitlinks
torvalds authored
96 memcpy(ce->name, path, len);
7a51ed6 @torvalds Make on-disk index representation separate from in-core one
torvalds authored
97 ce->ce_flags = len;
e011054 @torvalds Teach git-update-index about gitlinks
torvalds authored
98 fill_stat_cache_info(ce, st);
99 ce->ce_mode = ce_mode_from_stat(old, st->st_mode);
ec1fcc1 Show original and resulting blob object info in diff output.
Junio C Hamano authored
100
e011054 @torvalds Teach git-update-index about gitlinks
torvalds authored
101 if (index_path(ce->sha1, path, st, !info_only))
ec1fcc1 Show original and resulting blob object info in diff output.
Junio C Hamano authored
102 return -1;
192268c Add git-update-cache --replace option.
Junio C Hamano authored
103 option = allow_add ? ADD_CACHE_OK_TO_ADD : 0;
104 option |= allow_replace ? ADD_CACHE_OK_TO_REPLACE : 0;
34143b2 [PATCH] Improve git-update-index error reporting
Petr Baudis authored
105 if (add_cache_entry(ce, option))
e011054 @torvalds Teach git-update-index about gitlinks
torvalds authored
106 return error("%s: cannot add to the index - missing --add option?", path);
34143b2 [PATCH] Improve git-update-index error reporting
Petr Baudis authored
107 return 0;
121481a Make "update-cache" a bit friendlier to use (and harder to mis-use).
Linus Torvalds authored
108 }
109
e011054 @torvalds Teach git-update-index about gitlinks
torvalds authored
110 /*
111 * Handle a path that was a directory. Four cases:
112 *
113 * - it's already a gitlink in the index, and we keep it that
114 * way, and update it if we can (if we cannot find the HEAD,
115 * we're going to keep it unchanged in the index!)
116 *
117 * - it's a *file* in the index, in which case it should be
118 * removed as a file if removal is allowed, since it doesn't
119 * exist as such any more. If removal isn't allowed, it's
120 * an error.
121 *
122 * (NOTE! This is old and arguably fairly strange behaviour.
123 * We might want to make this an error unconditionally, and
124 * use "--force-remove" if you actually want to force removal).
125 *
126 * - it used to exist as a subdirectory (ie multiple files with
127 * this particular prefix) in the index, in which case it's wrong
128 * to try to update it as a directory.
129 *
130 * - it doesn't exist at all in the index, but it is a valid
131 * git directory, and it should be *added* as a gitlink.
132 */
133 static int process_directory(const char *path, int len, struct stat *st)
134 {
135 unsigned char sha1[20];
136 int pos = cache_name_pos(path, len);
137
138 /* Exact match: file or existing gitlink */
139 if (pos >= 0) {
140 struct cache_entry *ce = active_cache[pos];
7a51ed6 @torvalds Make on-disk index representation separate from in-core one
torvalds authored
141 if (S_ISGITLINK(ce->ce_mode)) {
e011054 @torvalds Teach git-update-index about gitlinks
torvalds authored
142
143 /* Do nothing to the index if there is no HEAD! */
144 if (resolve_gitlink_ref(path, "HEAD", sha1) < 0)
145 return 0;
146
147 return add_one_path(ce, path, len, st);
148 }
149 /* Should this be an unconditional error? */
150 return remove_one_path(path);
151 }
152
153 /* Inexact match: is there perhaps a subdirectory match? */
154 pos = -pos-1;
155 while (pos < active_nr) {
156 struct cache_entry *ce = active_cache[pos++];
157
158 if (strncmp(ce->name, path, len))
159 break;
160 if (ce->name[len] > '/')
161 break;
162 if (ce->name[len] < '/')
163 continue;
164
165 /* Subdirectory match - error out */
166 return error("%s: is a directory - add individual files instead", path);
167 }
168
169 /* No match - should we add it as a gitlink? */
170 if (!resolve_gitlink_ref(path, "HEAD", sha1))
171 return add_one_path(NULL, path, len, st);
172
173 /* Error out. */
174 return error("%s: is a directory - add files inside instead", path);
175 }
176
177 static int process_path(const char *path)
178 {
b4d1690 @pclouds Teach Git to respect skip-worktree bit (reading part)
pclouds authored
179 int pos, len;
e011054 @torvalds Teach git-update-index about gitlinks
torvalds authored
180 struct stat st;
b4d1690 @pclouds Teach Git to respect skip-worktree bit (reading part)
pclouds authored
181 struct cache_entry *ce;
e011054 @torvalds Teach git-update-index about gitlinks
torvalds authored
182
806d13b @gitster update-index: refuse to add working tree items beyond symlinks
gitster authored
183 len = strlen(path);
5719989 lstat_cache(): swap func(length, string) into func(string, length)
Kjetil Barvik authored
184 if (has_symlink_leading_path(path, len))
806d13b @gitster update-index: refuse to add working tree items beyond symlinks
gitster authored
185 return error("'%s' is beyond a symbolic link", path);
186
b4d1690 @pclouds Teach Git to respect skip-worktree bit (reading part)
pclouds authored
187 pos = cache_name_pos(path, len);
188 ce = pos < 0 ? NULL : active_cache[pos];
189 if (ce && ce_skip_worktree(ce)) {
190 /*
191 * working directory version is assumed "good"
192 * so updating it does not make sense.
193 * On the other hand, removing it from index should work
194 */
195 if (allow_remove && remove_file_from_cache(path))
196 return error("%s: cannot remove from the index", path);
197 return 0;
198 }
199
e011054 @torvalds Teach git-update-index about gitlinks
torvalds authored
200 /*
201 * First things first: get the stat information, to decide
202 * what to do about the pathname!
203 */
204 if (lstat(path, &st) < 0)
205 return process_lstat_error(path, errno);
206
207 if (S_ISDIR(st.st_mode))
208 return process_directory(path, len, &st);
209
b4d1690 @pclouds Teach Git to respect skip-worktree bit (reading part)
pclouds authored
210 /*
211 * Process a regular file
212 */
213 if (ce && S_ISGITLINK(ce->ce_mode))
214 return error("%s is already a gitlink, not replacing", path);
215
216 return add_one_path(ce, path, len, &st);
e011054 @torvalds Teach git-update-index about gitlinks
torvalds authored
217 }
218
d23748a update-index: allow --index-info to add higher stages.
Junio C Hamano authored
219 static int add_cacheinfo(unsigned int mode, const unsigned char *sha1,
220 const char *path, int stage)
9945d98 Add "--cacheinfo" option to update-cache.
Linus Torvalds authored
221 {
192268c Add git-update-cache --replace option.
Junio C Hamano authored
222 int size, len, option;
9945d98 Add "--cacheinfo" option to update-cache.
Linus Torvalds authored
223 struct cache_entry *ce;
224
d23748a update-index: allow --index-info to add higher stages.
Junio C Hamano authored
225 if (!verify_path(path))
7e7abea @dmpot print an error message for invalid path
dmpot authored
226 return error("Invalid path '%s'", path);
9945d98 Add "--cacheinfo" option to update-cache.
Linus Torvalds authored
227
d23748a update-index: allow --index-info to add higher stages.
Junio C Hamano authored
228 len = strlen(path);
9945d98 Add "--cacheinfo" option to update-cache.
Linus Torvalds authored
229 size = cache_entry_size(len);
90321c1 Replace xmalloc+memset(0) with xcalloc.
Peter Eriksen authored
230 ce = xcalloc(1, size);
9945d98 Add "--cacheinfo" option to update-cache.
Linus Torvalds authored
231
e702496 @spearce Convert memcpy(a,b,20) to hashcpy(a,b).
spearce authored
232 hashcpy(ce->sha1, sha1);
d23748a update-index: allow --index-info to add higher stages.
Junio C Hamano authored
233 memcpy(ce->name, path, len);
234 ce->ce_flags = create_ce_flags(len, stage);
e447947 Be much more liberal about the file mode bits.
Linus Torvalds authored
235 ce->ce_mode = create_ce_mode(mode);
5f73076 "Assume unchanged" git
Junio C Hamano authored
236 if (assume_unchanged)
7a51ed6 @torvalds Make on-disk index representation separate from in-core one
torvalds authored
237 ce->ce_flags |= CE_VALID;
192268c Add git-update-cache --replace option.
Junio C Hamano authored
238 option = allow_add ? ADD_CACHE_OK_TO_ADD : 0;
239 option |= allow_replace ? ADD_CACHE_OK_TO_REPLACE : 0;
caf4f58 Improve "git add" again.
Junio C Hamano authored
240 if (add_cache_entry(ce, option))
241 return error("%s: cannot add to the index - missing --add option?",
d23748a update-index: allow --index-info to add higher stages.
Junio C Hamano authored
242 path);
243 report("add '%s'", path);
caf4f58 Improve "git add" again.
Junio C Hamano authored
244 return 0;
9945d98 Add "--cacheinfo" option to update-cache.
Linus Torvalds authored
245 }
246
227bdb1 @raalkml make update-index --chmod work with multiple files and --stdin
raalkml authored
247 static void chmod_path(int flip, const char *path)
3e09cdf Use core.filemode.
Junio C Hamano authored
248 {
249 int pos;
250 struct cache_entry *ce;
251 unsigned int mode;
f2a1934 update-cache: remove index lock file on SIGINT
Linus Torvalds authored
252
3e09cdf Use core.filemode.
Junio C Hamano authored
253 pos = cache_name_pos(path, strlen(path));
254 if (pos < 0)
227bdb1 @raalkml make update-index --chmod work with multiple files and --stdin
raalkml authored
255 goto fail;
3e09cdf Use core.filemode.
Junio C Hamano authored
256 ce = active_cache[pos];
7a51ed6 @torvalds Make on-disk index representation separate from in-core one
torvalds authored
257 mode = ce->ce_mode;
3e09cdf Use core.filemode.
Junio C Hamano authored
258 if (!S_ISREG(mode))
227bdb1 @raalkml make update-index --chmod work with multiple files and --stdin
raalkml authored
259 goto fail;
3e09cdf Use core.filemode.
Junio C Hamano authored
260 switch (flip) {
261 case '+':
7a51ed6 @torvalds Make on-disk index representation separate from in-core one
torvalds authored
262 ce->ce_mode |= 0111; break;
3e09cdf Use core.filemode.
Junio C Hamano authored
263 case '-':
7a51ed6 @torvalds Make on-disk index representation separate from in-core one
torvalds authored
264 ce->ce_mode &= ~0111; break;
3e09cdf Use core.filemode.
Junio C Hamano authored
265 default:
227bdb1 @raalkml make update-index --chmod work with multiple files and --stdin
raalkml authored
266 goto fail;
3e09cdf Use core.filemode.
Junio C Hamano authored
267 }
a6e5642 Use cache-tree in update-index.
Junio C Hamano authored
268 cache_tree_invalidate_path(active_cache_tree, path);
3e09cdf Use core.filemode.
Junio C Hamano authored
269 active_cache_changed = 1;
227bdb1 @raalkml make update-index --chmod work with multiple files and --stdin
raalkml authored
270 report("chmod %cx '%s'", flip, path);
271 return;
272 fail:
7e44c93 @gitster 'git foo' program identifies itself without dash in die() messages
gitster authored
273 die("git update-index: cannot chmod %cx '%s'", flip, path);
3e09cdf Use core.filemode.
Junio C Hamano authored
274 }
275
ee1bec3 update-index: --stdin and -z
Junio C Hamano authored
276 static void update_one(const char *path, const char *prefix, int prefix_length)
277 {
278 const char *p = prefix_path(prefix, prefix_length, path);
279 if (!verify_path(p)) {
280 fprintf(stderr, "Ignoring path %s\n", path);
fb69a76 update-index: plug memory leak from prefix_path()
Junio C Hamano authored
281 goto free_return;
ee1bec3 update-index: --stdin and -z
Junio C Hamano authored
282 }
5f73076 "Assume unchanged" git
Junio C Hamano authored
283 if (mark_valid_only) {
83b327b @pclouds update-index: refactor mark_valid() in preparation for new options
pclouds authored
284 if (mark_ce_flags(p, CE_VALID, mark_valid_only == MARK_FLAG))
5f73076 "Assume unchanged" git
Junio C Hamano authored
285 die("Unable to mark file %s", path);
fb69a76 update-index: plug memory leak from prefix_path()
Junio C Hamano authored
286 goto free_return;
5f73076 "Assume unchanged" git
Junio C Hamano authored
287 }
44a3691 @pclouds Introduce "skip-worktree" bit in index, teach Git to get/set this bit
pclouds authored
288 if (mark_skip_worktree_only) {
289 if (mark_ce_flags(p, CE_SKIP_WORKTREE, mark_skip_worktree_only == MARK_FLAG))
5f73076 "Assume unchanged" git
Junio C Hamano authored
290 die("Unable to mark file %s", path);
fb69a76 update-index: plug memory leak from prefix_path()
Junio C Hamano authored
291 goto free_return;
5f73076 "Assume unchanged" git
Junio C Hamano authored
292 }
293
ee1bec3 update-index: --stdin and -z
Junio C Hamano authored
294 if (force_remove) {
295 if (remove_file_from_cache(p))
7e44c93 @gitster 'git foo' program identifies itself without dash in die() messages
gitster authored
296 die("git update-index: unable to remove %s", path);
caf4f58 Improve "git add" again.
Junio C Hamano authored
297 report("remove '%s'", path);
fb69a76 update-index: plug memory leak from prefix_path()
Junio C Hamano authored
298 goto free_return;
ee1bec3 update-index: --stdin and -z
Junio C Hamano authored
299 }
e011054 @torvalds Teach git-update-index about gitlinks
torvalds authored
300 if (process_path(p))
301 die("Unable to process path %s", path);
caf4f58 Improve "git add" again.
Junio C Hamano authored
302 report("add '%s'", path);
fb69a76 update-index: plug memory leak from prefix_path()
Junio C Hamano authored
303 free_return:
0cc9e70 @dscho Fix users of prefix_path() to free() only when necessary
dscho authored
304 if (p < path || p > path + strlen(path))
4b25d09 @felipec Fix a bunch of pointer declarations (codestyle)
felipec authored
305 free((char *)p);
ee1bec3 update-index: --stdin and -z
Junio C Hamano authored
306 }
307
d4dbf36 update-index: read --show-index-info output from standard input.
Junio C Hamano authored
308 static void read_index_info(int line_termination)
309 {
f285a2d Replace calls to strbuf_init(&foo, 0) with STRBUF_INIT initializer
Brandon Casey authored
310 struct strbuf buf = STRBUF_INIT;
311 struct strbuf uq = STRBUF_INIT;
7fb1011 @MadCoder Rework unquote_c_style to work on a strbuf.
MadCoder authored
312
313 while (strbuf_getline(&buf, stdin, line_termination) != EOF) {
9c20a47 Teach update-index to read from ls-tree.
Junio C Hamano authored
314 char *ptr, *tab;
973d6a2 update-index --index-info: adjust for funny-path quoting.
Junio C Hamano authored
315 char *path_name;
d4dbf36 update-index: read --show-index-info output from standard input.
Junio C Hamano authored
316 unsigned char sha1[20];
317 unsigned int mode;
6aead43 @meyering sscanf/strtoul: parse integers robustly
meyering authored
318 unsigned long ul;
d23748a update-index: allow --index-info to add higher stages.
Junio C Hamano authored
319 int stage;
320
321 /* This reads lines formatted in one of three formats:
322 *
323 * (1) mode SP sha1 TAB path
f18d244 @heikkiorsila Start conforming code to "git subcmd" style part 3
heikkiorsila authored
324 * The first format is what "git apply --index-info"
d23748a update-index: allow --index-info to add higher stages.
Junio C Hamano authored
325 * reports, and used to reconstruct a partial tree
326 * that is used for phony merge base tree when falling
327 * back on 3-way merge.
328 *
329 * (2) mode SP type SP sha1 TAB path
f18d244 @heikkiorsila Start conforming code to "git subcmd" style part 3
heikkiorsila authored
330 * The second format is to stuff "git ls-tree" output
d23748a update-index: allow --index-info to add higher stages.
Junio C Hamano authored
331 * into the index file.
fefe81c Make git-update-index a builtin
Lukas Sandström authored
332 *
d23748a update-index: allow --index-info to add higher stages.
Junio C Hamano authored
333 * (3) mode SP sha1 SP stage TAB path
334 * This format is to put higher order stages into the
f18d244 @heikkiorsila Start conforming code to "git subcmd" style part 3
heikkiorsila authored
335 * index file and matches "git ls-files --stage" output.
d23748a update-index: allow --index-info to add higher stages.
Junio C Hamano authored
336 */
6aead43 @meyering sscanf/strtoul: parse integers robustly
meyering authored
337 errno = 0;
338 ul = strtoul(buf.buf, &ptr, 8);
339 if (ptr == buf.buf || *ptr != ' '
340 || errno || (unsigned int) ul != ul)
d4dbf36 update-index: read --show-index-info output from standard input.
Junio C Hamano authored
341 goto bad_line;
6aead43 @meyering sscanf/strtoul: parse integers robustly
meyering authored
342 mode = ul;
d4dbf36 update-index: read --show-index-info output from standard input.
Junio C Hamano authored
343
9c20a47 Teach update-index to read from ls-tree.
Junio C Hamano authored
344 tab = strchr(ptr, '\t');
345 if (!tab || tab - ptr < 41)
346 goto bad_line;
d23748a update-index: allow --index-info to add higher stages.
Junio C Hamano authored
347
2d49711 update-index --index-info: allow stage 0 entries.
Junio C Hamano authored
348 if (tab[-2] == ' ' && '0' <= tab[-1] && tab[-1] <= '3') {
d23748a update-index: allow --index-info to add higher stages.
Junio C Hamano authored
349 stage = tab[-1] - '0';
350 ptr = tab + 1; /* point at the head of path */
351 tab = tab - 2; /* point at tail of sha1 */
352 }
353 else {
354 stage = 0;
355 ptr = tab + 1; /* point at the head of path */
356 }
357
9c20a47 Teach update-index to read from ls-tree.
Junio C Hamano authored
358 if (get_sha1_hex(tab - 40, sha1) || tab[-41] != ' ')
359 goto bad_line;
973d6a2 update-index --index-info: adjust for funny-path quoting.
Junio C Hamano authored
360
7fb1011 @MadCoder Rework unquote_c_style to work on a strbuf.
MadCoder authored
361 path_name = ptr;
362 if (line_termination && path_name[0] == '"') {
363 strbuf_reset(&uq);
364 if (unquote_c_style(&uq, path_name, NULL)) {
7e44c93 @gitster 'git foo' program identifies itself without dash in die() messages
gitster authored
365 die("git update-index: bad quoting of path name");
7fb1011 @MadCoder Rework unquote_c_style to work on a strbuf.
MadCoder authored
366 }
367 path_name = uq.buf;
368 }
973d6a2 update-index --index-info: adjust for funny-path quoting.
Junio C Hamano authored
369
370 if (!verify_path(path_name)) {
371 fprintf(stderr, "Ignoring path %s\n", path_name);
d4dbf36 update-index: read --show-index-info output from standard input.
Junio C Hamano authored
372 continue;
373 }
374
375 if (!mode) {
376 /* mode == 0 means there is no such path -- remove */
973d6a2 update-index --index-info: adjust for funny-path quoting.
Junio C Hamano authored
377 if (remove_file_from_cache(path_name))
7e44c93 @gitster 'git foo' program identifies itself without dash in die() messages
gitster authored
378 die("git update-index: unable to remove %s",
d4dbf36 update-index: read --show-index-info output from standard input.
Junio C Hamano authored
379 ptr);
380 }
381 else {
382 /* mode ' ' sha1 '\t' name
383 * ptr[-1] points at tab,
384 * ptr[-41] is at the beginning of sha1
385 */
386 ptr[-42] = ptr[-1] = 0;
d23748a update-index: allow --index-info to add higher stages.
Junio C Hamano authored
387 if (add_cacheinfo(mode, sha1, path_name, stage))
7e44c93 @gitster 'git foo' program identifies itself without dash in die() messages
gitster authored
388 die("git update-index: unable to update %s",
973d6a2 update-index --index-info: adjust for funny-path quoting.
Junio C Hamano authored
389 path_name);
d4dbf36 update-index: read --show-index-info output from standard input.
Junio C Hamano authored
390 }
391 continue;
392
393 bad_line:
394 die("malformed index info %s", buf.buf);
395 }
e6c019d @MadCoder Drop strbuf's 'eof' marker, and make read_line a first class citizen.
MadCoder authored
396 strbuf_release(&buf);
7fb1011 @MadCoder Rework unquote_c_style to work on a strbuf.
MadCoder authored
397 strbuf_release(&uq);
d4dbf36 update-index: read --show-index-info output from standard input.
Junio C Hamano authored
398 }
399
f6ab5bb Add usage string to git-update-index
Petr Baudis authored
400 static const char update_index_usage[] =
44a3691 @pclouds Introduce "skip-worktree" bit in index, teach Git to get/set this bit
pclouds authored
401 "git update-index [-q] [--add] [--replace] [--remove] [--unmerged] [--refresh] [--really-refresh] [--cacheinfo] [--chmod=(+|-)x] [--assume-unchanged] [--skip-worktree|--no-skip-worktree] [--info-only] [--force-remove] [--stdin] [--index-info] [--unresolve] [--again | -g] [--ignore-missing] [-z] [--verbose] [--] <file>...";
f6ab5bb Add usage string to git-update-index
Petr Baudis authored
402
2bd452d git-update-index --unresolve
Junio C Hamano authored
403 static unsigned char head_sha1[20];
404 static unsigned char merge_head_sha1[20];
405
406 static struct cache_entry *read_one_ent(const char *which,
407 unsigned char *ent, const char *path,
408 int namelen, int stage)
409 {
410 unsigned mode;
411 unsigned char sha1[20];
412 int size;
413 struct cache_entry *ce;
414
415 if (get_tree_entry(ent, path, sha1, &mode)) {
83e77a2 update-index --again
Junio C Hamano authored
416 if (which)
417 error("%s: not in %s branch.", path, which);
2bd452d git-update-index --unresolve
Junio C Hamano authored
418 return NULL;
419 }
420 if (mode == S_IFDIR) {
83e77a2 update-index --again
Junio C Hamano authored
421 if (which)
422 error("%s: not a blob in %s branch.", path, which);
2bd452d git-update-index --unresolve
Junio C Hamano authored
423 return NULL;
424 }
425 size = cache_entry_size(namelen);
426 ce = xcalloc(1, size);
427
e702496 @spearce Convert memcpy(a,b,20) to hashcpy(a,b).
spearce authored
428 hashcpy(ce->sha1, sha1);
2bd452d git-update-index --unresolve
Junio C Hamano authored
429 memcpy(ce->name, path, namelen);
430 ce->ce_flags = create_ce_flags(namelen, stage);
431 ce->ce_mode = create_ce_mode(mode);
432 return ce;
433 }
434
435 static int unresolve_one(const char *path)
436 {
437 int namelen = strlen(path);
438 int pos;
439 int ret = 0;
440 struct cache_entry *ce_2 = NULL, *ce_3 = NULL;
441
442 /* See if there is such entry in the index. */
443 pos = cache_name_pos(path, namelen);
8aa3856 @gitster resolve-undo: teach "update-index --unresolve" to use resolve-undo info
gitster authored
444 if (0 <= pos) {
445 /* already merged */
446 pos = unmerge_cache_entry_at(pos);
447 if (pos < active_nr) {
448 struct cache_entry *ce = active_cache[pos];
449 if (ce_stage(ce) &&
450 ce_namelen(ce) == namelen &&
451 !memcmp(ce->name, path, namelen))
452 return 0;
453 }
454 /* no resolve-undo information; fall back */
455 } else {
2bd452d git-update-index --unresolve
Junio C Hamano authored
456 /* If there isn't, either it is unmerged, or
457 * resolved as "removed" by mistake. We do not
458 * want to do anything in the former case.
459 */
460 pos = -pos-1;
461 if (pos < active_nr) {
462 struct cache_entry *ce = active_cache[pos];
463 if (ce_namelen(ce) == namelen &&
464 !memcmp(ce->name, path, namelen)) {
465 fprintf(stderr,
466 "%s: skipping still unmerged path.\n",
467 path);
468 goto free_return;
469 }
470 }
471 }
472
473 /* Grab blobs from given path from HEAD and MERGE_HEAD,
474 * stuff HEAD version in stage #2,
475 * stuff MERGE_HEAD version in stage #3.
476 */
477 ce_2 = read_one_ent("our", head_sha1, path, namelen, 2);
478 ce_3 = read_one_ent("their", merge_head_sha1, path, namelen, 3);
479
480 if (!ce_2 || !ce_3) {
481 ret = -1;
482 goto free_return;
483 }
a89fccd Do not use memcmp(sha1_1, sha1_2, 20) with hardcoded length.
David Rientjes authored
484 if (!hashcmp(ce_2->sha1, ce_3->sha1) &&
2bd452d git-update-index --unresolve
Junio C Hamano authored
485 ce_2->ce_mode == ce_3->ce_mode) {
486 fprintf(stderr, "%s: identical in both, skipping.\n",
487 path);
488 goto free_return;
489 }
490
491 remove_file_from_cache(path);
492 if (add_cache_entry(ce_2, ADD_CACHE_OK_TO_ADD)) {
493 error("%s: cannot add our version to the index.", path);
494 ret = -1;
495 goto free_return;
496 }
497 if (!add_cache_entry(ce_3, ADD_CACHE_OK_TO_ADD))
498 return 0;
499 error("%s: cannot add their version to the index.", path);
500 ret = -1;
501 free_return:
502 free(ce_2);
503 free(ce_3);
504 return ret;
505 }
506
507 static void read_head_pointers(void)
508 {
913c983 @dscho Fix git-update-index --again
dscho authored
509 if (read_ref("HEAD", head_sha1))
d753070 @aspotashev remove trailing LF in die() messages
aspotashev authored
510 die("No HEAD -- no initial commit yet?");
913c983 @dscho Fix git-update-index --again
dscho authored
511 if (read_ref("MERGE_HEAD", merge_head_sha1)) {
2bd452d git-update-index --unresolve
Junio C Hamano authored
512 fprintf(stderr, "Not in the middle of a merge.\n");
513 exit(0);
514 }
515 }
516
09895c1 update-index --unresolve: work from a subdirectory.
Junio C Hamano authored
517 static int do_unresolve(int ac, const char **av,
518 const char *prefix, int prefix_length)
2bd452d git-update-index --unresolve
Junio C Hamano authored
519 {
520 int i;
521 int err = 0;
522
523 /* Read HEAD and MERGE_HEAD; if MERGE_HEAD does not exist, we
524 * are not doing a merge, so exit with success status.
525 */
526 read_head_pointers();
527
528 for (i = 1; i < ac; i++) {
529 const char *arg = av[i];
09895c1 update-index --unresolve: work from a subdirectory.
Junio C Hamano authored
530 const char *p = prefix_path(prefix, prefix_length, arg);
531 err |= unresolve_one(p);
0cc9e70 @dscho Fix users of prefix_path() to free() only when necessary
dscho authored
532 if (p < arg || p > arg + strlen(arg))
4b25d09 @felipec Fix a bunch of pointer declarations (codestyle)
felipec authored
533 free((char *)p);
2bd452d git-update-index --unresolve
Junio C Hamano authored
534 }
535 return err;
536 }
537
83e77a2 update-index --again
Junio C Hamano authored
538 static int do_reupdate(int ac, const char **av,
539 const char *prefix, int prefix_length)
540 {
541 /* Read HEAD and run update-index on paths that are
542 * merged and already different between index and HEAD.
543 */
544 int pos;
545 int has_head = 1;
0cc9e70 @dscho Fix users of prefix_path() to free() only when necessary
dscho authored
546 const char **pathspec = get_pathspec(prefix, av + 1);
83e77a2 update-index --again
Junio C Hamano authored
547
913c983 @dscho Fix git-update-index --again
dscho authored
548 if (read_ref("HEAD", head_sha1))
83e77a2 update-index --again
Junio C Hamano authored
549 /* If there is no HEAD, that means it is an initial
550 * commit. Update everything in the index.
551 */
552 has_head = 0;
553 redo:
554 for (pos = 0; pos < active_nr; pos++) {
555 struct cache_entry *ce = active_cache[pos];
556 struct cache_entry *old = NULL;
557 int save_nr;
22293b9 update-index --again: take optional pathspecs
Junio C Hamano authored
558
559 if (ce_stage(ce) || !ce_path_match(ce, pathspec))
83e77a2 update-index --again
Junio C Hamano authored
560 continue;
561 if (has_head)
562 old = read_one_ent(NULL, head_sha1,
563 ce->name, ce_namelen(ce), 0);
564 if (old && ce->ce_mode == old->ce_mode &&
a89fccd Do not use memcmp(sha1_1, sha1_2, 20) with hardcoded length.
David Rientjes authored
565 !hashcmp(ce->sha1, old->sha1)) {
83e77a2 update-index --again
Junio C Hamano authored
566 free(old);
567 continue; /* unchanged */
568 }
569 /* Be careful. The working tree may not have the
570 * path anymore, in which case, under 'allow_remove',
571 * or worse yet 'allow_replace', active_nr may decrease.
572 */
573 save_nr = active_nr;
574 update_one(ce->name + prefix_length, prefix, prefix_length);
575 if (save_nr != active_nr)
576 goto redo;
577 }
578 return 0;
579 }
580
a633fca Call setup_git_directory() much earlier
Linus Torvalds authored
581 int cmd_update_index(int argc, const char **argv, const char *prefix)
e83c516 Initial revision of "git", the information manager from hell
Linus Torvalds authored
582 {
ee1bec3 update-index: --stdin and -z
Junio C Hamano authored
583 int i, newfd, entries, has_errors = 0, line_termination = '\n';
121481a Make "update-cache" a bit friendlier to use (and harder to mis-use).
Linus Torvalds authored
584 int allow_options = 1;
ee1bec3 update-index: --stdin and -z
Junio C Hamano authored
585 int read_from_stdin = 0;
586 int prefix_length = prefix ? strlen(prefix) : 0;
227bdb1 @raalkml make update-index --chmod work with multiple files and --stdin
raalkml authored
587 char set_executable_bit = 0;
405e5b2 Libify the index refresh logic
Linus Torvalds authored
588 unsigned int refresh_flags = 0;
7b802b8 update-index: do not die too early in a read-only repository.
Junio C Hamano authored
589 int lock_error = 0;
fefe81c Make git-update-index a builtin
Lukas Sandström authored
590 struct lock_file *lock_file;
bb233d6 Add support for a "GIT_INDEX_FILE" environment variable.
Linus Torvalds authored
591
ef90d6d @dscho Provide git_config with a callback-data parameter
dscho authored
592 git_config(git_default_config, NULL);
3e09cdf Use core.filemode.
Junio C Hamano authored
593
fefe81c Make git-update-index a builtin
Lukas Sandström authored
594 /* We can't free this memory, it becomes part of a linked list parsed atexit() */
928e47e @dscho Initialize lock_file struct to all zero.
dscho authored
595 lock_file = xcalloc(1, sizeof(struct lock_file));
fefe81c Make git-update-index a builtin
Lukas Sandström authored
596
30ca07a _GIT_INDEX_OUTPUT: allow plumbing to output to an alternative index f…
Junio C Hamano authored
597 newfd = hold_locked_index(lock_file, 0);
7b802b8 update-index: do not die too early in a read-only repository.
Junio C Hamano authored
598 if (newfd < 0)
599 lock_error = errno;
9614b8d Fix stale index.lock file removal using "atexit()".
Linus Torvalds authored
600
e83c516 Initial revision of "git", the information manager from hell
Linus Torvalds authored
601 entries = read_cache();
9614b8d Fix stale index.lock file removal using "atexit()".
Linus Torvalds authored
602 if (entries < 0)
2de381f @pasky [PATCH] Consolidate the error handling
pasky authored
603 die("cache corrupted");
e83c516 Initial revision of "git", the information manager from hell
Linus Torvalds authored
604
605 for (i = 1 ; i < argc; i++) {
6b5ee13 Diff clean-up.
Junio C Hamano authored
606 const char *path = argv[i];
9ebe6cf @raalkml Fix git-update-index to work with relative pathnames.
raalkml authored
607 const char *p;
121481a Make "update-cache" a bit friendlier to use (and harder to mis-use).
Linus Torvalds authored
608
609 if (allow_options && *path == '-') {
610 if (!strcmp(path, "--")) {
611 allow_options = 0;
612 continue;
613 }
0ed3715 Add "-q" flag to git-update-cache
Linus Torvalds authored
614 if (!strcmp(path, "-q")) {
405e5b2 Libify the index refresh logic
Linus Torvalds authored
615 refresh_flags |= REFRESH_QUIET;
0ed3715 Add "-q" flag to git-update-cache
Linus Torvalds authored
616 continue;
617 }
5fdeacb @dscho Teach update-index about --ignore-submodules
dscho authored
618 if (!strcmp(path, "--ignore-submodules")) {
619 refresh_flags |= REFRESH_IGNORE_SUBMODULES;
620 continue;
621 }
121481a Make "update-cache" a bit friendlier to use (and harder to mis-use).
Linus Torvalds authored
622 if (!strcmp(path, "--add")) {
623 allow_add = 1;
624 continue;
625 }
192268c Add git-update-cache --replace option.
Junio C Hamano authored
626 if (!strcmp(path, "--replace")) {
627 allow_replace = 1;
628 continue;
629 }
121481a Make "update-cache" a bit friendlier to use (and harder to mis-use).
Linus Torvalds authored
630 if (!strcmp(path, "--remove")) {
631 allow_remove = 1;
632 continue;
633 }
5d1a5c0 [PATCH] Better error reporting for "git status"
Linus Torvalds authored
634 if (!strcmp(path, "--unmerged")) {
405e5b2 Libify the index refresh logic
Linus Torvalds authored
635 refresh_flags |= REFRESH_UNMERGED;
5d1a5c0 [PATCH] Better error reporting for "git status"
Linus Torvalds authored
636 continue;
637 }
121481a Make "update-cache" a bit friendlier to use (and harder to mis-use).
Linus Torvalds authored
638 if (!strcmp(path, "--refresh")) {
f83eafd @pclouds update-index: fix worktree setup
pclouds authored
639 setup_work_tree();
405e5b2 Libify the index refresh logic
Linus Torvalds authored
640 has_errors |= refresh_cache(refresh_flags);
5f73076 "Assume unchanged" git
Junio C Hamano authored
641 continue;
642 }
643 if (!strcmp(path, "--really-refresh")) {
f83eafd @pclouds update-index: fix worktree setup
pclouds authored
644 setup_work_tree();
405e5b2 Libify the index refresh logic
Linus Torvalds authored
645 has_errors |= refresh_cache(REFRESH_REALLY | refresh_flags);
121481a Make "update-cache" a bit friendlier to use (and harder to mis-use).
Linus Torvalds authored
646 continue;
647 }
9945d98 Add "--cacheinfo" option to update-cache.
Linus Torvalds authored
648 if (!strcmp(path, "--cacheinfo")) {
d23748a update-index: allow --index-info to add higher stages.
Junio C Hamano authored
649 unsigned char sha1[20];
650 unsigned int mode;
651
b3f94c4 Fix git-update-cache --cacheinfo error message.
Junio C Hamano authored
652 if (i+3 >= argc)
7e44c93 @gitster 'git foo' program identifies itself without dash in die() messages
gitster authored
653 die("git update-index: --cacheinfo <mode> <sha1> <path>");
d23748a update-index: allow --index-info to add higher stages.
Junio C Hamano authored
654
6e6db39 @awhitcroft fix up strtoul_ui error handling
awhitcroft authored
655 if (strtoul_ui(argv[i+1], 8, &mode) ||
d23748a update-index: allow --index-info to add higher stages.
Junio C Hamano authored
656 get_sha1_hex(argv[i+2], sha1) ||
657 add_cacheinfo(mode, sha1, argv[i+3], 0))
7e44c93 @gitster 'git foo' program identifies itself without dash in die() messages
gitster authored
658 die("git update-index: --cacheinfo"
d23748a update-index: allow --index-info to add higher stages.
Junio C Hamano authored
659 " cannot add %s", argv[i+3]);
9945d98 Add "--cacheinfo" option to update-cache.
Linus Torvalds authored
660 i += 3;
661 continue;
662 }
3e09cdf Use core.filemode.
Junio C Hamano authored
663 if (!strcmp(path, "--chmod=-x") ||
664 !strcmp(path, "--chmod=+x")) {
665 if (argc <= i+1)
7e44c93 @gitster 'git foo' program identifies itself without dash in die() messages
gitster authored
666 die("git update-index: %s <path>", path);
227bdb1 @raalkml make update-index --chmod work with multiple files and --stdin
raalkml authored
667 set_executable_bit = path[8];
3e09cdf Use core.filemode.
Junio C Hamano authored
668 continue;
669 }
5f73076 "Assume unchanged" git
Junio C Hamano authored
670 if (!strcmp(path, "--assume-unchanged")) {
83b327b @pclouds update-index: refactor mark_valid() in preparation for new options
pclouds authored
671 mark_valid_only = MARK_FLAG;
5f73076 "Assume unchanged" git
Junio C Hamano authored
672 continue;
673 }
674 if (!strcmp(path, "--no-assume-unchanged")) {
83b327b @pclouds update-index: refactor mark_valid() in preparation for new options
pclouds authored
675 mark_valid_only = UNMARK_FLAG;
5f73076 "Assume unchanged" git
Junio C Hamano authored
676 continue;
677 }
44a3691 @pclouds Introduce "skip-worktree" bit in index, teach Git to get/set this bit
pclouds authored
678 if (!strcmp(path, "--no-skip-worktree")) {
679 mark_skip_worktree_only = UNMARK_FLAG;
680 continue;
681 }
682 if (!strcmp(path, "--skip-worktree")) {
683 mark_skip_worktree_only = MARK_FLAG;
5f73076 "Assume unchanged" git
Junio C Hamano authored
684 continue;
685 }
df6e151 @bryanlarsen [PATCH] Add --info-only option to git-update-cache.
bryanlarsen authored
686 if (!strcmp(path, "--info-only")) {
687 info_only = 1;
688 continue;
689 }
0ff5bf7 Implement git-update-cache --force-remove <path>
Junio C Hamano authored
690 if (!strcmp(path, "--force-remove")) {
9b63f50 @pasky [PATCH] Make git-update-cache --force-remove regular
pasky authored
691 force_remove = 1;
0ff5bf7 Implement git-update-cache --force-remove <path>
Junio C Hamano authored
692 continue;
693 }
ee1bec3 update-index: --stdin and -z
Junio C Hamano authored
694 if (!strcmp(path, "-z")) {
695 line_termination = 0;
696 continue;
697 }
698 if (!strcmp(path, "--stdin")) {
699 if (i != argc - 1)
700 die("--stdin must be at the end");
701 read_from_stdin = 1;
702 break;
703 }
d4dbf36 update-index: read --show-index-info output from standard input.
Junio C Hamano authored
704 if (!strcmp(path, "--index-info")) {
a41c175 @spearce Prevent --index-info from ignoring -z.
spearce authored
705 if (i != argc - 1)
706 die("--index-info must be at the end");
d4dbf36 update-index: read --show-index-info output from standard input.
Junio C Hamano authored
707 allow_add = allow_replace = allow_remove = 1;
708 read_index_info(line_termination);
a41c175 @spearce Prevent --index-info from ignoring -z.
spearce authored
709 break;
d4dbf36 update-index: read --show-index-info output from standard input.
Junio C Hamano authored
710 }
2bd452d git-update-index --unresolve
Junio C Hamano authored
711 if (!strcmp(path, "--unresolve")) {
09895c1 update-index --unresolve: work from a subdirectory.
Junio C Hamano authored
712 has_errors = do_unresolve(argc - i, argv + i,
713 prefix, prefix_length);
2bd452d git-update-index --unresolve
Junio C Hamano authored
714 if (has_errors)
715 active_cache_changed = 0;
716 goto finish;
717 }
7099c9c update-index -g
Junio C Hamano authored
718 if (!strcmp(path, "--again") || !strcmp(path, "-g")) {
f83eafd @pclouds update-index: fix worktree setup
pclouds authored
719 setup_work_tree();
83e77a2 update-index --again
Junio C Hamano authored
720 has_errors = do_reupdate(argc - i, argv + i,
721 prefix, prefix_length);
722 if (has_errors)
723 active_cache_changed = 0;
724 goto finish;
725 }
c6e007b [PATCH] update-cache: add "--ignore-missing" option
James Bottomley authored
726 if (!strcmp(path, "--ignore-missing")) {
405e5b2 Libify the index refresh logic
Linus Torvalds authored
727 refresh_flags |= REFRESH_IGNORE_MISSING;
c6e007b [PATCH] update-cache: add "--ignore-missing" option
James Bottomley authored
728 continue;
729 }
caf4f58 Improve "git add" again.
Junio C Hamano authored
730 if (!strcmp(path, "--verbose")) {
731 verbose = 1;
732 continue;
733 }
4a39f79 @gitster resolve-undo: allow plumbing to clear the information
gitster authored
734 if (!strcmp(path, "--clear-resolve-undo")) {
735 resolve_undo_clear();
736 continue;
737 }
f6ab5bb Add usage string to git-update-index
Petr Baudis authored
738 if (!strcmp(path, "-h") || !strcmp(path, "--help"))
739 usage(update_index_usage);
2de381f @pasky [PATCH] Consolidate the error handling
pasky authored
740 die("unknown option %s", path);
121481a Make "update-cache" a bit friendlier to use (and harder to mis-use).
Linus Torvalds authored
741 }
f83eafd @pclouds update-index: fix worktree setup
pclouds authored
742 setup_work_tree();
9ebe6cf @raalkml Fix git-update-index to work with relative pathnames.
raalkml authored
743 p = prefix_path(prefix, prefix_length, path);
744 update_one(p, NULL, 0);
227bdb1 @raalkml make update-index --chmod work with multiple files and --stdin
raalkml authored
745 if (set_executable_bit)
9ebe6cf @raalkml Fix git-update-index to work with relative pathnames.
raalkml authored
746 chmod_path(set_executable_bit, p);
747 if (p < path || p > path + strlen(path))
4b25d09 @felipec Fix a bunch of pointer declarations (codestyle)
felipec authored
748 free((char *)p);
ee1bec3 update-index: --stdin and -z
Junio C Hamano authored
749 }
750 if (read_from_stdin) {
f285a2d Replace calls to strbuf_init(&foo, 0) with STRBUF_INIT initializer
Brandon Casey authored
751 struct strbuf buf = STRBUF_INIT, nbuf = STRBUF_INIT;
7fb1011 @MadCoder Rework unquote_c_style to work on a strbuf.
MadCoder authored
752
f83eafd @pclouds update-index: fix worktree setup
pclouds authored
753 setup_work_tree();
7fb1011 @MadCoder Rework unquote_c_style to work on a strbuf.
MadCoder authored
754 while (strbuf_getline(&buf, stdin, line_termination) != EOF) {
fb69a76 update-index: plug memory leak from prefix_path()
Junio C Hamano authored
755 const char *p;
7fb1011 @MadCoder Rework unquote_c_style to work on a strbuf.
MadCoder authored
756 if (line_termination && buf.buf[0] == '"') {
757 strbuf_reset(&nbuf);
758 if (unquote_c_style(&nbuf, buf.buf, NULL))
759 die("line is badly quoted");
760 strbuf_swap(&buf, &nbuf);
761 }
762 p = prefix_path(prefix, prefix_length, buf.buf);
fb69a76 update-index: plug memory leak from prefix_path()
Junio C Hamano authored
763 update_one(p, NULL, 0);
764 if (set_executable_bit)
227bdb1 @raalkml make update-index --chmod work with multiple files and --stdin
raalkml authored
765 chmod_path(set_executable_bit, p);
7fb1011 @MadCoder Rework unquote_c_style to work on a strbuf.
MadCoder authored
766 if (p < buf.buf || p > buf.buf + buf.len)
767 free((char *)p);
9b63f50 @pasky [PATCH] Make git-update-cache --force-remove regular
pasky authored
768 }
7fb1011 @MadCoder Rework unquote_c_style to work on a strbuf.
MadCoder authored
769 strbuf_release(&nbuf);
e6c019d @MadCoder Drop strbuf's 'eof' marker, and make read_line a first class citizen.
MadCoder authored
770 strbuf_release(&buf);
e83c516 Initial revision of "git", the information manager from hell
Linus Torvalds authored
771 }
2bd452d git-update-index --unresolve
Junio C Hamano authored
772
773 finish:
5cd5ace [PATCH] Re-instate index file write optimization
Linus Torvalds authored
774 if (active_cache_changed) {
7b802b8 update-index: do not die too early in a read-only repository.
Junio C Hamano authored
775 if (newfd < 0) {
776 if (refresh_flags & REFRESH_QUIET)
777 exit(128);
e43a6fd @moy More friendly message when locking the index fails.
moy authored
778 unable_to_lock_index_die(get_index_file(), lock_error);
7b802b8 update-index: do not die too early in a read-only repository.
Junio C Hamano authored
779 }
5cd5ace [PATCH] Re-instate index file write optimization
Linus Torvalds authored
780 if (write_cache(newfd, active_cache, active_nr) ||
4ed7cd3 Improve use of lockfile API
Brandon Casey authored
781 commit_locked_index(lock_file))
021b6e4 Make index file locking code reusable to others.
Junio C Hamano authored
782 die("Unable to write new index file");
5cd5ace [PATCH] Re-instate index file write optimization
Linus Torvalds authored
783 }
9614b8d Fix stale index.lock file removal using "atexit()".
Linus Torvalds authored
784
fefe81c Make git-update-index a builtin
Lukas Sandström authored
785 rollback_lock_file(lock_file);
786
c4b83e6 Do not write out new index if nothing has changed.
Junio C Hamano authored
787 return has_errors ? 1 : 0;
e83c516 Initial revision of "git", the information manager from hell
Linus Torvalds authored
788 }
Something went wrong with that request. Please try again.