@matheusbsbs / matheus-bagliano / commits / 7a51ed66f6
Fork 0

Make on-disk index representation separate from in-core one

This converts the index explicitly on read and write to its on-disk format, allowing the in-core format to contain more flags, and be simpler. In particular, the in-core format is now host-endian (as opposed to the on-disk one that is network endian in order to be able to be shared across machines) and as a result we can dispense with all the htonl/ntohl on accesses to the cache_entry fields. This will make it easier to make use of various temporary flags that do not exist in the on-disk format. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Linus Torvalds committed Jan 14, 2008 at 16:03 UTC 7a51ed66f653c248993b3c4a61932e47933d835e
21 files changed +217 -169
builtin-apply.c
+5 -5
@@ -1946,7 +1946,7 @@ static int read_file_or_gitlink(struct cache_entry *ce, struct strbuf *buf)
1946 if (!ce)
1947 return 0;
1948
1949 - if (S_ISGITLINK(ntohl(ce->ce_mode))) {
1949 + if (S_ISGITLINK(ce->ce_mode)) {
1950 strbuf_grow(buf, 100);
1951 strbuf_addf(buf, "Subproject commit %s\n", sha1_to_hex(ce->sha1));
1952 } else {
@@ -2023,7 +2023,7 @@ static int check_to_create_blob(const char *new_name, int ok_if_exists)
2023
2024 static int verify_index_match(struct cache_entry *ce, struct stat *st)
2025 {
2026 - if (S_ISGITLINK(ntohl(ce->ce_mode))) {
2026 + if (S_ISGITLINK(ce->ce_mode)) {
2027 if (!S_ISDIR(st->st_mode))
2028 return -1;
2029 return 0;
@@ -2082,12 +2082,12 @@ static int check_patch(struct patch *patch, struct patch *prev_patch)
2082 return error("%s: does not match index",
2083 old_name);
2084 if (cached)
2085 - st_mode = ntohl(ce->ce_mode);
2085 + st_mode = ce->ce_mode;
2086 } else if (stat_ret < 0)
2087 return error("%s: %s", old_name, strerror(errno));
2088
2089 if (!cached)
2090 - st_mode = ntohl(ce_mode_from_stat(ce, st.st_mode));
2090 + st_mode = ce_mode_from_stat(ce, st.st_mode);
2091
2092 if (patch->is_new < 0)
2093 patch->is_new = 0;
@@ -2388,7 +2388,7 @@ static void add_index_file(const char *path, unsigned mode, void *buf, unsigned
2388 ce = xcalloc(1, ce_size);
2389 memcpy(ce->name, path, namelen);
2390 ce->ce_mode = create_ce_mode(mode);
2391 - ce->ce_flags = htons(namelen);
2391 + ce->ce_flags = namelen;
2392 if (S_ISGITLINK(mode)) {
2393 const char *s = buf;
2394
builtin-blame.c
+1 -1
@@ -2092,7 +2092,7 @@ static struct commit *fake_working_tree_commit(const char *path, const char *con
2092 if (!mode) {
2093 int pos = cache_name_pos(path, len);
2094 if (0 <= pos)
2095 - mode = ntohl(active_cache[pos]->ce_mode);
2095 + mode = active_cache[pos]->ce_mode;
2096 else
2097 /* Let's not bother reading from HEAD tree */
2098 mode = S_IFREG | 0644;
builtin-commit.c
+1 -1
@@ -156,7 +156,7 @@ static int list_paths(struct path_list *list, const char *with_tree,
156
157 for (i = 0; i < active_nr; i++) {
158 struct cache_entry *ce = active_cache[i];
159 - if (ce->ce_flags & htons(CE_UPDATE))
159 + if (ce->ce_flags & CE_UPDATE)
160 continue;
161 if (!pathspec_match(pattern, m, ce->name, 0))
162 continue;
builtin-fsck.c
+1 -1
@@ -765,7 +765,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
765 struct blob *blob;
766 struct object *obj;
767
768 - mode = ntohl(active_cache[i]->ce_mode);
768 + mode = active_cache[i]->ce_mode;
769 if (S_ISGITLINK(mode))
770 continue;
771 blob = lookup_blob(active_cache[i]->sha1);
builtin-grep.c
+2 -2
@@ -331,7 +331,7 @@ static int external_grep(struct grep_opt *opt, const char **paths, int cached)
331 struct cache_entry *ce = active_cache[i];
332 char *name;
333 int kept;
334 - if (!S_ISREG(ntohl(ce->ce_mode)))
334 + if (!S_ISREG(ce->ce_mode))
335 continue;
336 if (!pathspec_matches(paths, ce->name))
337 continue;
@@ -387,7 +387,7 @@ static int grep_cache(struct grep_opt *opt, const char **paths, int cached)
387
388 for (nr = 0; nr < active_nr; nr++) {
389 struct cache_entry *ce = active_cache[nr];
390 - if (!S_ISREG(ntohl(ce->ce_mode)))
390 + if (!S_ISREG(ce->ce_mode))
391 continue;
392 if (!pathspec_matches(paths, ce->name))
393 continue;
builtin-ls-files.c
+5 -5
@@ -189,7 +189,7 @@ static void show_ce_entry(const char *tag, struct cache_entry *ce)
189 return;
190
191 if (tag && *tag && show_valid_bit &&
192 - (ce->ce_flags & htons(CE_VALID))) {
192 + (ce->ce_flags & CE_VALID)) {
193 static char alttag[4];
194 memcpy(alttag, tag, 3);
195 if (isalpha(tag[0]))
@@ -210,7 +210,7 @@ static void show_ce_entry(const char *tag, struct cache_entry *ce)
210 } else {
211 printf("%s%06o %s %d\t",
212 tag,
213 - ntohl(ce->ce_mode),
213 + ce->ce_mode,
214 abbrev ? find_unique_abbrev(ce->sha1,abbrev)
215 : sha1_to_hex(ce->sha1),
216 ce_stage(ce));
@@ -242,7 +242,7 @@ static void show_files(struct dir_struct *dir, const char *prefix)
242 continue;
243 if (show_unmerged && !ce_stage(ce))
244 continue;
245 - if (ce->ce_flags & htons(CE_UPDATE))
245 + if (ce->ce_flags & CE_UPDATE)
246 continue;
247 show_ce_entry(ce_stage(ce) ? tag_unmerged : tag_cached, ce);
248 }
@@ -350,7 +350,7 @@ void overlay_tree_on_cache(const char *tree_name, const char *prefix)
350 struct cache_entry *ce = active_cache[i];
351 if (!ce_stage(ce))
352 continue;
353 - ce->ce_flags |= htons(CE_STAGEMASK);
353 + ce->ce_flags |= CE_STAGEMASK;
354 }
355
356 if (prefix) {
@@ -379,7 +379,7 @@ void overlay_tree_on_cache(const char *tree_name, const char *prefix)
379 */
380 if (last_stage0 &&
381 !strcmp(last_stage0->name, ce->name))
382 - ce->ce_flags |= htons(CE_UPDATE);
382 + ce->ce_flags |= CE_UPDATE;
383 }
384 }
385 }
builtin-read-tree.c
+1 -2
@@ -45,8 +45,7 @@ static int read_cache_unmerged(void)
45 continue;
46 cache_tree_invalidate_path(active_cache_tree, ce->name);
47 last = ce;
48 - ce->ce_mode = 0;
49 - ce->ce_flags &= ~htons(CE_STAGEMASK);
48 + ce->ce_flags |= CE_REMOVE;
49 }
50 *dst++ = ce;
51 }
builtin-rerere.c
+2 -2
@@ -149,8 +149,8 @@ static int find_conflict(struct path_list *conflict)
149 if (ce_stage(e2) == 2 &&
150 ce_stage(e3) == 3 &&
151 ce_same_name(e2, e3) &&
152 - S_ISREG(ntohl(e2->ce_mode)) &&
153 - S_ISREG(ntohl(e3->ce_mode))) {
152 + S_ISREG(e2->ce_mode) &&
153 + S_ISREG(e3->ce_mode)) {
154 path_list_insert((const char *)e2->name, conflict);
155 i++; /* skip over both #2 and #3 */
156 }
builtin-update-index.c
+9 -9
@@ -47,10 +47,10 @@ static int mark_valid(const char *path)
47 if (0 <= pos) {
48 switch (mark_valid_only) {
49 case MARK_VALID:
50 - active_cache[pos]->ce_flags |= htons(CE_VALID);
50 + active_cache[pos]->ce_flags |= CE_VALID;
51 break;
52 case UNMARK_VALID:
53 - active_cache[pos]->ce_flags &= ~htons(CE_VALID);
53 + active_cache[pos]->ce_flags &= ~CE_VALID;
54 break;
55 }
56 cache_tree_invalidate_path(active_cache_tree, path);
@@ -95,7 +95,7 @@ static int add_one_path(struct cache_entry *old, const char *path, int len, stru
95 size = cache_entry_size(len);
96 ce = xcalloc(1, size);
97 memcpy(ce->name, path, len);
98 - ce->ce_flags = htons(len);
98 + ce->ce_flags = len;
99 fill_stat_cache_info(ce, st);
100 ce->ce_mode = ce_mode_from_stat(old, st->st_mode);
101
@@ -139,7 +139,7 @@ static int process_directory(const char *path, int len, struct stat *st)
139 /* Exact match: file or existing gitlink */
140 if (pos >= 0) {
141 struct cache_entry *ce = active_cache[pos];
142 - if (S_ISGITLINK(ntohl(ce->ce_mode))) {
142 + if (S_ISGITLINK(ce->ce_mode)) {
143
144 /* Do nothing to the index if there is no HEAD! */
145 if (resolve_gitlink_ref(path, "HEAD", sha1) < 0)
@@ -183,7 +183,7 @@ static int process_file(const char *path, int len, struct stat *st)
183 int pos = cache_name_pos(path, len);
184 struct cache_entry *ce = pos < 0 ? NULL : active_cache[pos];
185
186 - if (ce && S_ISGITLINK(ntohl(ce->ce_mode)))
186 + if (ce && S_ISGITLINK(ce->ce_mode))
187 return error("%s is already a gitlink, not replacing", path);
188
189 return add_one_path(ce, path, len, st);
@@ -226,7 +226,7 @@ static int add_cacheinfo(unsigned int mode, const unsigned char *sha1,
226 ce->ce_flags = create_ce_flags(len, stage);
227 ce->ce_mode = create_ce_mode(mode);
228 if (assume_unchanged)
229 - ce->ce_flags |= htons(CE_VALID);
229 + ce->ce_flags |= CE_VALID;
230 option = allow_add ? ADD_CACHE_OK_TO_ADD : 0;
231 option |= allow_replace ? ADD_CACHE_OK_TO_REPLACE : 0;
232 if (add_cache_entry(ce, option))
@@ -246,14 +246,14 @@ static void chmod_path(int flip, const char *path)
246 if (pos < 0)
247 goto fail;
248 ce = active_cache[pos];
249 - mode = ntohl(ce->ce_mode);
249 + mode = ce->ce_mode;
250 if (!S_ISREG(mode))
251 goto fail;
252 switch (flip) {
253 case '+':
254 - ce->ce_mode |= htonl(0111); break;
254 + ce->ce_mode |= 0111; break;
255 case '-':
256 - ce->ce_mode &= htonl(~0111); break;
256 + ce->ce_mode &= ~0111; break;
257 default:
258 goto fail;
259 }
cache-tree.c
+2 -2
@@ -320,13 +320,13 @@ static int update_one(struct cache_tree *it,
320 }
321 else {
322 sha1 = ce->sha1;
323 - mode = ntohl(ce->ce_mode);
323 + mode = ce->ce_mode;
324 entlen = pathlen - baselen;
325 }
326 if (mode != S_IFGITLINK && !missing_ok && !has_sha1_file(sha1))
327 return error("invalid object %s", sha1_to_hex(sha1));
328
329 - if (!ce->ce_mode)
329 + if (ce->ce_flags & CE_REMOVE)
330 continue; /* entry being removed */
331
332 strbuf_grow(&buffer, entlen + 100);
cache.h
+32 -14
@@ -94,48 +94,66 @@ struct cache_time {
94 * We save the fields in big-endian order to allow using the
95 * index file over NFS transparently.
96 */
97 +struct ondisk_cache_entry {
98 + struct cache_time ctime;
99 + struct cache_time mtime;
100 + unsigned int dev;
101 + unsigned int ino;
102 + unsigned int mode;
103 + unsigned int uid;
104 + unsigned int gid;
105 + unsigned int size;
106 + unsigned char sha1[20];
107 + unsigned short flags;
108 + char name[FLEX_ARRAY]; /* more */
109 +};
110 +
111 struct cache_entry {
98 - struct cache_time ce_ctime;
99 - struct cache_time ce_mtime;
112 + unsigned int ce_ctime;
113 + unsigned int ce_mtime;
114 unsigned int ce_dev;
115 unsigned int ce_ino;
116 unsigned int ce_mode;
117 unsigned int ce_uid;
118 unsigned int ce_gid;
119 unsigned int ce_size;
120 + unsigned int ce_flags;
121 unsigned char sha1[20];
107 - unsigned short ce_flags;
122 char name[FLEX_ARRAY]; /* more */
123 };
124
125 #define CE_NAMEMASK (0x0fff)
126 #define CE_STAGEMASK (0x3000)
113 -#define CE_UPDATE (0x4000)
127 #define CE_VALID (0x8000)
128 #define CE_STAGESHIFT 12
129
117 -#define create_ce_flags(len, stage) htons((len) | ((stage) << CE_STAGESHIFT))
118 -#define ce_namelen(ce) (CE_NAMEMASK & ntohs((ce)->ce_flags))
130 +/* In-memory only */
131 +#define CE_UPDATE (0x10000)
132 +#define CE_REMOVE (0x20000)
133 +
134 +#define create_ce_flags(len, stage) ((len) | ((stage) << CE_STAGESHIFT))
135 +#define ce_namelen(ce) (CE_NAMEMASK & (ce)->ce_flags)
136 #define ce_size(ce) cache_entry_size(ce_namelen(ce))
120 -#define ce_stage(ce) ((CE_STAGEMASK & ntohs((ce)->ce_flags)) >> CE_STAGESHIFT)
137 +#define ondisk_ce_size(ce) ondisk_cache_entry_size(ce_namelen(ce))
138 +#define ce_stage(ce) ((CE_STAGEMASK & (ce)->ce_flags) >> CE_STAGESHIFT)
139
140 #define ce_permissions(mode) (((mode) & 0100) ? 0755 : 0644)
141 static inline unsigned int create_ce_mode(unsigned int mode)
142 {
143 if (S_ISLNK(mode))
126 - return htonl(S_IFLNK);
144 + return S_IFLNK;
145 if (S_ISDIR(mode) || S_ISGITLINK(mode))
128 - return htonl(S_IFGITLINK);
129 - return htonl(S_IFREG | ce_permissions(mode));
146 + return S_IFGITLINK;
147 + return S_IFREG | ce_permissions(mode);
148 }
149 static inline unsigned int ce_mode_from_stat(struct cache_entry *ce, unsigned int mode)
150 {
151 extern int trust_executable_bit, has_symlinks;
152 if (!has_symlinks && S_ISREG(mode) &&
135 - ce && S_ISLNK(ntohl(ce->ce_mode)))
153 + ce && S_ISLNK(ce->ce_mode))
154 return ce->ce_mode;
155 if (!trust_executable_bit && S_ISREG(mode)) {
138 - if (ce && S_ISREG(ntohl(ce->ce_mode)))
156 + if (ce && S_ISREG(ce->ce_mode))
157 return ce->ce_mode;
158 return create_ce_mode(0666);
159 }
@@ -146,14 +164,14 @@ static inline unsigned int ce_mode_from_stat(struct cache_entry *ce, unsigned in
164 S_ISLNK(mode) ? S_IFLNK : S_ISDIR(mode) ? S_IFDIR : S_IFGITLINK)
165
166 #define cache_entry_size(len) ((offsetof(struct cache_entry,name) + (len) + 8) & ~7)
167 +#define ondisk_cache_entry_size(len) ((offsetof(struct ondisk_cache_entry,name) + (len) + 8) & ~7)
168
169 struct index_state {
170 struct cache_entry **cache;
171 unsigned int cache_nr, cache_alloc, cache_changed;
172 struct cache_tree *cache_tree;
173 time_t timestamp;
155 - void *mmap;
156 - size_t mmap_size;
174 + void *alloc;
175 };
176
177 extern struct index_state the_index;
diff-lib.c
+14 -18
@@ -37,7 +37,7 @@ static int get_mode(const char *path, int *mode)
37 if (!path || !strcmp(path, "/dev/null"))
38 *mode = 0;
39 else if (!strcmp(path, "-"))
40 - *mode = ntohl(create_ce_mode(0666));
40 + *mode = create_ce_mode(0666);
41 else if (stat(path, &st))
42 return error("Could not access '%s'", path);
43 else
@@ -384,7 +384,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
384 continue;
385 }
386 else
387 - dpath->mode = ntohl(ce_mode_from_stat(ce, st.st_mode));
387 + dpath->mode = ce_mode_from_stat(ce, st.st_mode);
388
389 while (i < entries) {
390 struct cache_entry *nce = active_cache[i];
@@ -398,10 +398,10 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
398 */
399 stage = ce_stage(nce);
400 if (2 <= stage) {
401 - int mode = ntohl(nce->ce_mode);
401 + int mode = nce->ce_mode;
402 num_compare_stages++;
403 hashcpy(dpath->parent[stage-2].sha1, nce->sha1);
404 - dpath->parent[stage-2].mode = ntohl(ce_mode_from_stat(nce, mode));
404 + dpath->parent[stage-2].mode = ce_mode_from_stat(nce, mode);
405 dpath->parent[stage-2].status =
406 DIFF_STATUS_MODIFIED;
407 }
@@ -442,15 +442,15 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
442 }
443 if (silent_on_removed)
444 continue;
445 - diff_addremove(&revs->diffopt, '-', ntohl(ce->ce_mode),
445 + diff_addremove(&revs->diffopt, '-', ce->ce_mode,
446 ce->sha1, ce->name, NULL);
447 continue;
448 }
449 changed = ce_match_stat(ce, &st, ce_option);
450 if (!changed && !DIFF_OPT_TST(&revs->diffopt, FIND_COPIES_HARDER))
451 continue;
452 - oldmode = ntohl(ce->ce_mode);
453 - newmode = ntohl(ce_mode_from_stat(ce, st.st_mode));
452 + oldmode = ce->ce_mode;
453 + newmode = ce_mode_from_stat(ce, st.st_mode);
454 diff_change(&revs->diffopt, oldmode, newmode,
455 ce->sha1, (changed ? null_sha1 : ce->sha1),
456 ce->name, NULL);
@@ -471,7 +471,7 @@ static void diff_index_show_file(struct rev_info *revs,
471 struct cache_entry *ce,
472 unsigned char *sha1, unsigned int mode)
473 {
474 - diff_addremove(&revs->diffopt, prefix[0], ntohl(mode),
474 + diff_addremove(&revs->diffopt, prefix[0], mode,
475 sha1, ce->name, NULL);
476 }
477
@@ -550,14 +550,14 @@ static int show_modified(struct rev_info *revs,
550 p->len = pathlen;
551 memcpy(p->path, new->name, pathlen);
552 p->path[pathlen] = 0;
553 - p->mode = ntohl(mode);
553 + p->mode = mode;
554 hashclr(p->sha1);
555 memset(p->parent, 0, 2 * sizeof(struct combine_diff_parent));
556 p->parent[0].status = DIFF_STATUS_MODIFIED;
557 - p->parent[0].mode = ntohl(new->ce_mode);
557 + p->parent[0].mode = new->ce_mode;
558 hashcpy(p->parent[0].sha1, new->sha1);
559 p->parent[1].status = DIFF_STATUS_MODIFIED;
560 - p->parent[1].mode = ntohl(old->ce_mode);
560 + p->parent[1].mode = old->ce_mode;
561 hashcpy(p->parent[1].sha1, old->sha1);
562 show_combined_diff(p, 2, revs->dense_combined_merges, revs);
563 free(p);
@@ -569,9 +569,6 @@ static int show_modified(struct rev_info *revs,
569 !DIFF_OPT_TST(&revs->diffopt, FIND_COPIES_HARDER))
570 return 0;
571
572 - mode = ntohl(mode);
573 - oldmode = ntohl(oldmode);
574 -
572 diff_change(&revs->diffopt, oldmode, mode,
573 old->sha1, sha1, old->name, NULL);
574 return 0;
@@ -628,7 +625,7 @@ static int diff_cache(struct rev_info *revs,
625 cached, match_missing))
626 break;
627 diff_unmerge(&revs->diffopt, ce->name,
631 - ntohl(ce->ce_mode), ce->sha1);
628 + ce->ce_mode, ce->sha1);
629 break;
630 case 3:
631 diff_unmerge(&revs->diffopt, ce->name,
@@ -664,7 +661,7 @@ static void mark_merge_entries(void)
661 struct cache_entry *ce = active_cache[i];
662 if (!ce_stage(ce))
663 continue;
667 - ce->ce_flags |= htons(CE_STAGEMASK);
664 + ce->ce_flags |= CE_STAGEMASK;
665 }
666 }
667
@@ -722,8 +719,7 @@ int do_diff_cache(const unsigned char *tree_sha1, struct diff_options *opt)
719 cache_tree_invalidate_path(active_cache_tree,
720 ce->name);
721 last = ce;
725 - ce->ce_mode = 0;
726 - ce->ce_flags &= ~htons(CE_STAGEMASK);
722 + ce->ce_flags |= CE_REMOVE;
723 }
724 *dst++ = ce;
725 }
dir.c
+1 -1
@@ -391,7 +391,7 @@ static enum exist_status directory_exists_in_index(const char *dirname, int len)
391 break;
392 if (endchar == '/')
393 return index_directory;
394 - if (!endchar && S_ISGITLINK(ntohl(ce->ce_mode)))
394 + if (!endchar && S_ISGITLINK(ce->ce_mode))
395 return index_gitdir;
396 }
397 return index_nonexistent;
entry.c
+3 -3
@@ -103,7 +103,7 @@ static int write_entry(struct cache_entry *ce, char *path, const struct checkout
103 int fd;
104 long wrote;
105
106 - switch (ntohl(ce->ce_mode) & S_IFMT) {
106 + switch (ce->ce_mode & S_IFMT) {
107 char *new;
108 struct strbuf buf;
109 unsigned long size;
@@ -129,7 +129,7 @@ static int write_entry(struct cache_entry *ce, char *path, const struct checkout
129 strcpy(path, ".merge_file_XXXXXX");
130 fd = mkstemp(path);
131 } else
132 - fd = create_file(path, ntohl(ce->ce_mode));
132 + fd = create_file(path, ce->ce_mode);
133 if (fd < 0) {
134 free(new);
135 return error("git-checkout-index: unable to create file %s (%s)",
@@ -221,7 +221,7 @@ int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *t
221 unlink(path);
222 if (S_ISDIR(st.st_mode)) {
223 /* If it is a gitlink, leave it alone! */
224 - if (S_ISGITLINK(ntohl(ce->ce_mode)))
224 + if (S_ISGITLINK(ce->ce_mode))
225 return 0;
226 if (!state->force)
227 return error("%s is a directory", path);
merge-index.c
+1 -1
@@ -48,7 +48,7 @@ static int merge_entry(int pos, const char *path)
48 break;
49 found++;
50 strcpy(hexbuf[stage], sha1_to_hex(ce->sha1));
51 - sprintf(ownbuf[stage], "%o", ntohl(ce->ce_mode));
51 + sprintf(ownbuf[stage], "%o", ce->ce_mode);
52 arguments[stage] = hexbuf[stage];
53 arguments[stage + 4] = ownbuf[stage];
54 } while (++pos < active_nr);
merge-recursive.c
+1 -1
@@ -333,7 +333,7 @@ static struct path_list *get_unmerged(void)
333 item->util = xcalloc(1, sizeof(struct stage_data));
334 }
335 e = item->util;
336 - e->stages[ce_stage(ce)].mode = ntohl(ce->ce_mode);
336 + e->stages[ce_stage(ce)].mode = ce->ce_mode;
337 hashcpy(e->stages[ce_stage(ce)].sha, ce->sha1);
338 }
339
reachable.c
+1 -1
@@ -176,7 +176,7 @@ static void add_cache_refs(struct rev_info *revs)
176 * lookup_blob() on them, to avoid populating the hash table
177 * with invalid information
178 */
179 - if (S_ISGITLINK(ntohl(active_cache[i]->ce_mode)))
179 + if (S_ISGITLINK(active_cache[i]->ce_mode))
180 continue;
181
182 lookup_blob(active_cache[i]->sha1);
read-cache.c
+118 -82
@@ -30,20 +30,16 @@ struct index_state the_index;
30 */
31 void fill_stat_cache_info(struct cache_entry *ce, struct stat *st)
32 {
33 - ce->ce_ctime.sec = htonl(st->st_ctime);
34 - ce->ce_mtime.sec = htonl(st->st_mtime);
35 -#ifdef USE_NSEC
36 - ce->ce_ctime.nsec = htonl(st->st_ctim.tv_nsec);
37 - ce->ce_mtime.nsec = htonl(st->st_mtim.tv_nsec);
38 -#endif
39 - ce->ce_dev = htonl(st->st_dev);
40 - ce->ce_ino = htonl(st->st_ino);
41 - ce->ce_uid = htonl(st->st_uid);
42 - ce->ce_gid = htonl(st->st_gid);
43 - ce->ce_size = htonl(st->st_size);
33 + ce->ce_ctime = st->st_ctime;
34 + ce->ce_mtime = st->st_mtime;
35 + ce->ce_dev = st->st_dev;
36 + ce->ce_ino = st->st_ino;
37 + ce->ce_uid = st->st_uid;
38 + ce->ce_gid = st->st_gid;
39 + ce->ce_size = st->st_size;
40
41 if (assume_unchanged)
46 - ce->ce_flags |= htons(CE_VALID);
42 + ce->ce_flags |= CE_VALID;
43 }
44
45 static int ce_compare_data(struct cache_entry *ce, struct stat *st)
@@ -116,7 +112,7 @@ static int ce_modified_check_fs(struct cache_entry *ce, struct stat *st)
112 return DATA_CHANGED;
113 break;
114 case S_IFDIR:
119 - if (S_ISGITLINK(ntohl(ce->ce_mode)))
115 + if (S_ISGITLINK(ce->ce_mode))
116 return 0;
117 default:
118 return TYPE_CHANGED;
@@ -128,14 +124,17 @@ static int ce_match_stat_basic(struct cache_entry *ce, struct stat *st)
124 {
125 unsigned int changed = 0;
126
131 - switch (ntohl(ce->ce_mode) & S_IFMT) {
127 + if (ce->ce_flags & CE_REMOVE)
128 + return MODE_CHANGED | DATA_CHANGED | TYPE_CHANGED;
129 +
130 + switch (ce->ce_mode & S_IFMT) {
131 case S_IFREG:
132 changed |= !S_ISREG(st->st_mode) ? TYPE_CHANGED : 0;
133 /* We consider only the owner x bit to be relevant for
134 * "mode changes"
135 */
136 if (trust_executable_bit &&
138 - (0100 & (ntohl(ce->ce_mode) ^ st->st_mode)))
137 + (0100 & (ce->ce_mode ^ st->st_mode)))
138 changed |= MODE_CHANGED;
139 break;
140 case S_IFLNK:
@@ -149,32 +148,18 @@ static int ce_match_stat_basic(struct cache_entry *ce, struct stat *st)
148 else if (ce_compare_gitlink(ce))
149 changed |= DATA_CHANGED;
150 return changed;
152 - case 0: /* Special case: unmerged file in index */
153 - return MODE_CHANGED | DATA_CHANGED | TYPE_CHANGED;
151 default:
155 - die("internal error: ce_mode is %o", ntohl(ce->ce_mode));
152 + die("internal error: ce_mode is %o", ce->ce_mode);
153 }
157 - if (ce->ce_mtime.sec != htonl(st->st_mtime))
158 - changed |= MTIME_CHANGED;
159 - if (ce->ce_ctime.sec != htonl(st->st_ctime))
160 - changed |= CTIME_CHANGED;
161 -
162 -#ifdef USE_NSEC
163 - /*
164 - * nsec seems unreliable - not all filesystems support it, so
165 - * as long as it is in the inode cache you get right nsec
166 - * but after it gets flushed, you get zero nsec.
167 - */
168 - if (ce->ce_mtime.nsec != htonl(st->st_mtim.tv_nsec))
154 + if (ce->ce_mtime != (unsigned int) st->st_mtime)
155 changed |= MTIME_CHANGED;
170 - if (ce->ce_ctime.nsec != htonl(st->st_ctim.tv_nsec))
156 + if (ce->ce_ctime != (unsigned int) st->st_ctime)
157 changed |= CTIME_CHANGED;
172 -#endif
158
174 - if (ce->ce_uid != htonl(st->st_uid) ||
175 - ce->ce_gid != htonl(st->st_gid))
159 + if (ce->ce_uid != (unsigned int) st->st_uid ||
160 + ce->ce_gid != (unsigned int) st->st_gid)
161 changed |= OWNER_CHANGED;
177 - if (ce->ce_ino != htonl(st->st_ino))
162 + if (ce->ce_ino != (unsigned int) st->st_ino)
163 changed |= INODE_CHANGED;
164
165 #ifdef USE_STDEV
@@ -183,11 +168,11 @@ static int ce_match_stat_basic(struct cache_entry *ce, struct stat *st)
168 * clients will have different views of what "device"
169 * the filesystem is on
170 */
186 - if (ce->ce_dev != htonl(st->st_dev))
171 + if (ce->ce_dev != (unsigned int) st->st_dev)
172 changed |= INODE_CHANGED;
173 #endif
174
190 - if (ce->ce_size != htonl(st->st_size))
175 + if (ce->ce_size != (unsigned int) st->st_size)
176 changed |= DATA_CHANGED;
177
178 return changed;
@@ -205,7 +190,7 @@ int ie_match_stat(struct index_state *istate,
190 * If it's marked as always valid in the index, it's
191 * valid whatever the checked-out copy says.
192 */
208 - if (!ignore_valid && (ce->ce_flags & htons(CE_VALID)))
193 + if (!ignore_valid && (ce->ce_flags & CE_VALID))
194 return 0;
195
196 changed = ce_match_stat_basic(ce, st);
@@ -228,7 +213,7 @@ int ie_match_stat(struct index_state *istate,
213 */
214 if (!changed &&
215 istate->timestamp &&
231 - istate->timestamp <= ntohl(ce->ce_mtime.sec)) {
216 + istate->timestamp <= ce->ce_mtime) {
217 if (assume_racy_is_modified)
218 changed |= DATA_CHANGED;
219 else
@@ -257,7 +242,7 @@ int ie_modified(struct index_state *istate,
242 * the length field is zero. For other cases the ce_size
243 * should match the SHA1 recorded in the index entry.
244 */
260 - if ((changed & DATA_CHANGED) && ce->ce_size != htonl(0))
245 + if ((changed & DATA_CHANGED) && ce->ce_size != 0)
246 return changed;
247
248 changed_fs = ce_modified_check_fs(ce, st);
@@ -320,7 +305,7 @@ int index_name_pos(struct index_state *istate, const char *name, int namelen)
305 while (last > first) {
306 int next = (last + first) >> 1;
307 struct cache_entry *ce = istate->cache[next];
323 - int cmp = cache_name_compare(name, namelen, ce->name, ntohs(ce->ce_flags));
308 + int cmp = cache_name_compare(name, namelen, ce->name, ce->ce_flags);
309 if (!cmp)
310 return next;
311 if (cmp < 0) {
@@ -405,7 +390,7 @@ int add_file_to_index(struct index_state *istate, const char *path, int verbose)
390 size = cache_entry_size(namelen);
391 ce = xcalloc(1, size);
392 memcpy(ce->name, path, namelen);
408 - ce->ce_flags = htons(namelen);
393 + ce->ce_flags = namelen;
394 fill_stat_cache_info(ce, &st);
395
396 if (trust_executable_bit && has_symlinks)
@@ -583,7 +568,7 @@ static int has_file_name(struct index_state *istate,
568 continue;
569 if (p->name[len] != '/')
570 continue;
586 - if (!ce_stage(p) && !p->ce_mode)
571 + if (p->ce_flags & CE_REMOVE)
572 continue;
573 retval = -1;
574 if (!ok_to_replace)
@@ -616,7 +601,7 @@ static int has_dir_name(struct index_state *istate,
601 }
602 len = slash - name;
603
619 - pos = index_name_pos(istate, name, ntohs(create_ce_flags(len, stage)));
604 + pos = index_name_pos(istate, name, create_ce_flags(len, stage));
605 if (pos >= 0) {
606 /*
607 * Found one, but not so fast. This could
@@ -679,7 +664,7 @@ static int check_file_directory_conflict(struct index_state *istate,
664 /*
665 * When ce is an "I am going away" entry, we allow it to be added
666 */
682 - if (!ce_stage(ce) && !ce->ce_mode)
667 + if (ce->ce_flags & CE_REMOVE)
668 return 0;
669
670 /*
@@ -704,7 +689,7 @@ static int add_index_entry_with_check(struct index_state *istate, struct cache_e
689 int skip_df_check = option & ADD_CACHE_SKIP_DFCHECK;
690
691 cache_tree_invalidate_path(istate->cache_tree, ce->name);
707 - pos = index_name_pos(istate, ce->name, ntohs(ce->ce_flags));
692 + pos = index_name_pos(istate, ce->name, ce->ce_flags);
693
694 /* existing match? Just replace it. */
695 if (pos >= 0) {
@@ -736,7 +721,7 @@ static int add_index_entry_with_check(struct index_state *istate, struct cache_e
721 if (!ok_to_replace)
722 return error("'%s' appears as both a file and as a directory",
723 ce->name);
739 - pos = index_name_pos(istate, ce->name, ntohs(ce->ce_flags));
724 + pos = index_name_pos(istate, ce->name, ce->ce_flags);
725 pos = -pos-1;
726 }
727 return pos + 1;
@@ -810,7 +795,7 @@ static struct cache_entry *refresh_cache_ent(struct index_state *istate,
795 * valid again, under "assume unchanged" mode.
796 */
797 if (ignore_valid && assume_unchanged &&
813 - !(ce->ce_flags & htons(CE_VALID)))
798 + !(ce->ce_flags & CE_VALID))
799 ; /* mark this one VALID again */
800 else
801 return ce;
@@ -826,7 +811,6 @@ static struct cache_entry *refresh_cache_ent(struct index_state *istate,
811 updated = xmalloc(size);
812 memcpy(updated, ce, size);
813 fill_stat_cache_info(updated, &st);
829 -
814 /*
815 * If ignore_valid is not set, we should leave CE_VALID bit
816 * alone. Otherwise, paths marked with --no-assume-unchanged
@@ -834,8 +818,8 @@ static struct cache_entry *refresh_cache_ent(struct index_state *istate,
818 * automatically, which is not really what we want.
819 */
820 if (!ignore_valid && assume_unchanged &&
837 - !(ce->ce_flags & htons(CE_VALID)))
838 - updated->ce_flags &= ~htons(CE_VALID);
821 + !(ce->ce_flags & CE_VALID))
822 + updated->ce_flags &= ~CE_VALID;
823
824 return updated;
825 }
@@ -880,7 +864,7 @@ int refresh_index(struct index_state *istate, unsigned int flags, const char **p
864 /* If we are doing --really-refresh that
865 * means the index is not valid anymore.
866 */
883 - ce->ce_flags &= ~htons(CE_VALID);
867 + ce->ce_flags &= ~CE_VALID;
868 istate->cache_changed = 1;
869 }
870 if (quiet)
@@ -942,16 +926,34 @@ int read_index(struct index_state *istate)
926 return read_index_from(istate, get_index_file());
927 }
928
929 +static void convert_from_disk(struct ondisk_cache_entry *ondisk, struct cache_entry *ce)
930 +{
931 + ce->ce_ctime = ntohl(ondisk->ctime.sec);
932 + ce->ce_mtime = ntohl(ondisk->mtime.sec);
933 + ce->ce_dev = ntohl(ondisk->dev);
934 + ce->ce_ino = ntohl(ondisk->ino);
935 + ce->ce_mode = ntohl(ondisk->mode);
936 + ce->ce_uid = ntohl(ondisk->uid);
937 + ce->ce_gid = ntohl(ondisk->gid);
938 + ce->ce_size = ntohl(ondisk->size);
939 + /* On-disk flags are just 16 bits */
940 + ce->ce_flags = ntohs(ondisk->flags);
941 + hashcpy(ce->sha1, ondisk->sha1);
942 + memcpy(ce->name, ondisk->name, ce_namelen(ce)+1);
943 +}
944 +
945 /* remember to discard_cache() before reading a different cache! */
946 int read_index_from(struct index_state *istate, const char *path)
947 {
948 int fd, i;
949 struct stat st;
950 - unsigned long offset;
950 + unsigned long src_offset, dst_offset;
951 struct cache_header *hdr;
952 + void *mmap;
953 + size_t mmap_size;
954
955 errno = EBUSY;
954 - if (istate->mmap)
956 + if (istate->alloc)
957 return istate->cache_nr;
958
959 errno = ENOENT;
@@ -967,31 +969,47 @@ int read_index_from(struct index_state *istate, const char *path)
969 die("cannot stat the open index (%s)", strerror(errno));
970
971 errno = EINVAL;
970 - istate->mmap_size = xsize_t(st.st_size);
971 - if (istate->mmap_size < sizeof(struct cache_header) + 20)
972 + mmap_size = xsize_t(st.st_size);
973 + if (mmap_size < sizeof(struct cache_header) + 20)
974 die("index file smaller than expected");
975
974 - istate->mmap = xmmap(NULL, istate->mmap_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
976 + mmap = xmmap(NULL, mmap_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
977 close(fd);
978 + if (mmap == MAP_FAILED)
979 + die("unable to map index file");
980
977 - hdr = istate->mmap;
978 - if (verify_hdr(hdr, istate->mmap_size) < 0)
981 + hdr = mmap;
982 + if (verify_hdr(hdr, mmap_size) < 0)
983 goto unmap;
984
985 istate->cache_nr = ntohl(hdr->hdr_entries);
986 istate->cache_alloc = alloc_nr(istate->cache_nr);
987 istate->cache = xcalloc(istate->cache_alloc, sizeof(struct cache_entry *));
988
985 - offset = sizeof(*hdr);
989 + /*
990 + * The disk format is actually larger than the in-memory format,
991 + * due to space for nsec etc, so even though the in-memory one
992 + * has room for a few more flags, we can allocate using the same
993 + * index size
994 + */
995 + istate->alloc = xmalloc(mmap_size);
996 +
997 + src_offset = sizeof(*hdr);
998 + dst_offset = 0;
999 for (i = 0; i < istate->cache_nr; i++) {
1000 + struct ondisk_cache_entry *disk_ce;
1001 struct cache_entry *ce;
1002
989 - ce = (struct cache_entry *)((char *)(istate->mmap) + offset);
990 - offset = offset + ce_size(ce);
1003 + disk_ce = (struct ondisk_cache_entry *)((char *)mmap + src_offset);
1004 + ce = (struct cache_entry *)((char *)istate->alloc + dst_offset);
1005 + convert_from_disk(disk_ce, ce);
1006 istate->cache[i] = ce;
1007 +
1008 + src_offset += ondisk_ce_size(ce);
1009 + dst_offset += ce_size(ce);
1010 }
1011 istate->timestamp = st.st_mtime;
994 - while (offset <= istate->mmap_size - 20 - 8) {
1012 + while (src_offset <= mmap_size - 20 - 8) {
1013 /* After an array of active_nr index entries,
1014 * there can be arbitrary number of extended
1015 * sections, each of which is prefixed with
@@ -999,40 +1017,36 @@ int read_index_from(struct index_state *istate, const char *path)
1017 * in 4-byte network byte order.
1018 */
1019 unsigned long extsize;
1002 - memcpy(&extsize, (char *)(istate->mmap) + offset + 4, 4);
1020 + memcpy(&extsize, (char *)mmap + src_offset + 4, 4);
1021 extsize = ntohl(extsize);
1022 if (read_index_extension(istate,
1005 - ((const char *) (istate->mmap)) + offset,
1006 - (char *) (istate->mmap) + offset + 8,
1023 + (const char *) mmap + src_offset,
1024 + (char *) mmap + src_offset + 8,
1025 extsize) < 0)
1026 goto unmap;
1009 - offset += 8;
1010 - offset += extsize;
1027 + src_offset += 8;
1028 + src_offset += extsize;
1029 }
1030 + munmap(mmap, mmap_size);
1031 return istate->cache_nr;
1032
1033 unmap:
1015 - munmap(istate->mmap, istate->mmap_size);
1034 + munmap(mmap, mmap_size);
1035 errno = EINVAL;
1036 die("index file corrupt");
1037 }
1038
1039 int discard_index(struct index_state *istate)
1040 {
1022 - int ret;
1023 -
1041 istate->cache_nr = 0;
1042 istate->cache_changed = 0;
1043 istate->timestamp = 0;
1044 cache_tree_free(&(istate->cache_tree));
1028 - if (istate->mmap == NULL)
1029 - return 0;
1030 - ret = munmap(istate->mmap, istate->mmap_size);
1031 - istate->mmap = NULL;
1032 - istate->mmap_size = 0;
1045 + free(istate->alloc);
1046 + istate->alloc = NULL;
1047
1048 /* no need to throw away allocated active_cache */
1035 - return ret;
1049 + return 0;
1050 }
1051
1052 #define WRITE_BUFFER_SIZE 8192
@@ -1144,10 +1158,32 @@ static void ce_smudge_racily_clean_entry(struct cache_entry *ce)
1158 * file, and never calls us, so the cached size information
1159 * for "frotz" stays 6 which does not match the filesystem.
1160 */
1147 - ce->ce_size = htonl(0);
1161 + ce->ce_size = 0;
1162 }
1163 }
1164
1165 +static int ce_write_entry(SHA_CTX *c, int fd, struct cache_entry *ce)
1166 +{
1167 + int size = ondisk_ce_size(ce);
1168 + struct ondisk_cache_entry *ondisk = xcalloc(1, size);
1169 +
1170 + ondisk->ctime.sec = htonl(ce->ce_ctime);
1171 + ondisk->ctime.nsec = 0;
1172 + ondisk->mtime.sec = htonl(ce->ce_mtime);
1173 + ondisk->mtime.nsec = 0;
1174 + ondisk->dev = htonl(ce->ce_dev);
1175 + ondisk->ino = htonl(ce->ce_ino);
1176 + ondisk->mode = htonl(ce->ce_mode);
1177 + ondisk->uid = htonl(ce->ce_uid);
1178 + ondisk->gid = htonl(ce->ce_gid);
1179 + ondisk->size = htonl(ce->ce_size);
1180 + hashcpy(ondisk->sha1, ce->sha1);
1181 + ondisk->flags = htons(ce->ce_flags);
1182 + memcpy(ondisk->name, ce->name, ce_namelen(ce));
1183 +
1184 + return ce_write(c, fd, ondisk, size);
1185 +}
1186 +
1187 int write_index(struct index_state *istate, int newfd)
1188 {
1189 SHA_CTX c;
@@ -1157,7 +1193,7 @@ int write_index(struct index_state *istate, int newfd)
1193 int entries = istate->cache_nr;
1194
1195 for (i = removed = 0; i < entries; i++)
1160 - if (!cache[i]->ce_mode)
1196 + if (cache[i]->ce_flags & CE_REMOVE)
1197 removed++;
1198
1199 hdr.hdr_signature = htonl(CACHE_SIGNATURE);
@@ -1170,12 +1206,12 @@ int write_index(struct index_state *istate, int newfd)
1206
1207 for (i = 0; i < entries; i++) {
1208 struct cache_entry *ce = cache[i];
1173 - if (!ce->ce_mode)
1209 + if (ce->ce_flags & CE_REMOVE)
1210 continue;
1211 if (istate->timestamp &&
1176 - istate->timestamp <= ntohl(ce->ce_mtime.sec))
1212 + istate->timestamp <= ce->ce_mtime)
1213 ce_smudge_racily_clean_entry(ce);
1178 - if (ce_write(&c, newfd, ce, ce_size(ce)) < 0)
1214 + if (ce_write_entry(&c, newfd, ce) < 0)
1215 return -1;
1216 }
1217
sha1_name.c
+1 -1
@@ -695,7 +695,7 @@ int get_sha1_with_mode(const char *name, unsigned char *sha1, unsigned *mode)
695 break;
696 if (ce_stage(ce) == stage) {
697 hashcpy(sha1, ce->sha1);
698 - *mode = ntohl(ce->ce_mode);
698 + *mode = ce->ce_mode;
699 return 0;
700 }
701 pos++;
tree.c
+2 -2
@@ -142,8 +142,8 @@ static int cmp_cache_name_compare(const void *a_, const void *b_)
142
143 ce1 = *((const struct cache_entry **)a_);
144 ce2 = *((const struct cache_entry **)b_);
145 - return cache_name_compare(ce1->name, ntohs(ce1->ce_flags),
146 - ce2->name, ntohs(ce2->ce_flags));
145 + return cache_name_compare(ce1->name, ce1->ce_flags,
146 + ce2->name, ce2->ce_flags);
147 }
148
149 int read_tree(struct tree *tree, int stage, const char **match)
unpack-trees.c
+14 -15
@@ -289,7 +289,6 @@ static struct checkout state;
289 static void check_updates(struct cache_entry **src, int nr,
290 struct unpack_trees_options *o)
291 {
292 - unsigned short mask = htons(CE_UPDATE);
292 unsigned cnt = 0, total = 0;
293 struct progress *progress = NULL;
294 char last_symlink[PATH_MAX];
@@ -297,7 +296,7 @@ static void check_updates(struct cache_entry **src, int nr,
296 if (o->update && o->verbose_update) {
297 for (total = cnt = 0; cnt < nr; cnt++) {
298 struct cache_entry *ce = src[cnt];
300 - if (!ce->ce_mode || ce->ce_flags & mask)
299 + if (ce->ce_flags & (CE_UPDATE | CE_REMOVE))
300 total++;
301 }
302
@@ -310,15 +309,15 @@ static void check_updates(struct cache_entry **src, int nr,
309 while (nr--) {
310 struct cache_entry *ce = *src++;
311
313 - if (!ce->ce_mode || ce->ce_flags & mask)
312 + if (ce->ce_flags & (CE_UPDATE | CE_REMOVE))
313 display_progress(progress, ++cnt);
315 - if (!ce->ce_mode) {
314 + if (ce->ce_flags & CE_REMOVE) {
315 if (o->update)
316 unlink_entry(ce->name, last_symlink);
317 continue;
318 }
320 - if (ce->ce_flags & mask) {
321 - ce->ce_flags &= ~mask;
319 + if (ce->ce_flags & CE_UPDATE) {
320 + ce->ce_flags &= ~CE_UPDATE;
321 if (o->update) {
322 checkout_entry(ce, &state, NULL);
323 *last_symlink = '\0';
@@ -408,7 +407,7 @@ static void verify_uptodate(struct cache_entry *ce,
407 * submodules that are marked to be automatically
408 * checked out.
409 */
411 - if (S_ISGITLINK(ntohl(ce->ce_mode)))
410 + if (S_ISGITLINK(ce->ce_mode))
411 return;
412 errno = 0;
413 }
@@ -450,7 +449,7 @@ static int verify_clean_subdirectory(struct cache_entry *ce, const char *action,
449 int cnt = 0;
450 unsigned char sha1[20];
451
453 - if (S_ISGITLINK(ntohl(ce->ce_mode)) &&
452 + if (S_ISGITLINK(ce->ce_mode) &&
453 resolve_gitlink_ref(ce->name, "HEAD", sha1) == 0) {
454 /* If we are not going to update the submodule, then
455 * we don't care.
@@ -481,7 +480,7 @@ static int verify_clean_subdirectory(struct cache_entry *ce, const char *action,
480 */
481 if (!ce_stage(ce)) {
482 verify_uptodate(ce, o);
484 - ce->ce_mode = 0;
483 + ce->ce_flags |= CE_REMOVE;
484 }
485 cnt++;
486 }
@@ -568,7 +567,7 @@ static void verify_absent(struct cache_entry *ce, const char *action,
567 cnt = cache_name_pos(ce->name, strlen(ce->name));
568 if (0 <= cnt) {
569 struct cache_entry *ce = active_cache[cnt];
571 - if (!ce_stage(ce) && !ce->ce_mode)
570 + if (ce->ce_flags & CE_REMOVE)
571 return;
572 }
573
@@ -580,7 +579,7 @@ static void verify_absent(struct cache_entry *ce, const char *action,
579 static int merged_entry(struct cache_entry *merge, struct cache_entry *old,
580 struct unpack_trees_options *o)
581 {
583 - merge->ce_flags |= htons(CE_UPDATE);
582 + merge->ce_flags |= CE_UPDATE;
583 if (old) {
584 /*
585 * See if we can re-use the old CE directly?
@@ -601,7 +600,7 @@ static int merged_entry(struct cache_entry *merge, struct cache_entry *old,
600 invalidate_ce_path(merge);
601 }
602
604 - merge->ce_flags &= ~htons(CE_STAGEMASK);
603 + merge->ce_flags &= ~CE_STAGEMASK;
604 add_cache_entry(merge, ADD_CACHE_OK_TO_ADD|ADD_CACHE_OK_TO_REPLACE);
605 return 1;
606 }
@@ -613,7 +612,7 @@ static int deleted_entry(struct cache_entry *ce, struct cache_entry *old,
612 verify_uptodate(old, o);
613 else
614 verify_absent(ce, "removed", o);
616 - ce->ce_mode = 0;
615 + ce->ce_flags |= CE_REMOVE;
616 add_cache_entry(ce, ADD_CACHE_OK_TO_ADD|ADD_CACHE_OK_TO_REPLACE);
617 invalidate_ce_path(ce);
618 return 1;
@@ -634,7 +633,7 @@ static void show_stage_entry(FILE *o,
633 else
634 fprintf(o, "%s%06o %s %d\t%s\n",
635 label,
637 - ntohl(ce->ce_mode),
636 + ce->ce_mode,
637 sha1_to_hex(ce->sha1),
638 ce_stage(ce),
639 ce->name);
@@ -920,7 +919,7 @@ int oneway_merge(struct cache_entry **src,
919 struct stat st;
920 if (lstat(old->name, &st) ||
921 ce_match_stat(old, &st, CE_MATCH_IGNORE_VALID))
923 - old->ce_flags |= htons(CE_UPDATE);
922 + old->ce_flags |= CE_UPDATE;
923 }
924 return keep_entry(old, o);
925 }