Skip to content

Commit 7a51ed6

Browse files
committed
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 <[email protected]>
1 parent ce33288 commit 7a51ed6

21 files changed

+217
-169
lines changed

builtin-apply.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1946,7 +1946,7 @@ static int read_file_or_gitlink(struct cache_entry *ce, struct strbuf *buf)
19461946
if (!ce)
19471947
return 0;
19481948

1949-
if (S_ISGITLINK(ntohl(ce->ce_mode))) {
1949+
if (S_ISGITLINK(ce->ce_mode)) {
19501950
strbuf_grow(buf, 100);
19511951
strbuf_addf(buf, "Subproject commit %s\n", sha1_to_hex(ce->sha1));
19521952
} else {
@@ -2023,7 +2023,7 @@ static int check_to_create_blob(const char *new_name, int ok_if_exists)
20232023

20242024
static int verify_index_match(struct cache_entry *ce, struct stat *st)
20252025
{
2026-
if (S_ISGITLINK(ntohl(ce->ce_mode))) {
2026+
if (S_ISGITLINK(ce->ce_mode)) {
20272027
if (!S_ISDIR(st->st_mode))
20282028
return -1;
20292029
return 0;
@@ -2082,12 +2082,12 @@ static int check_patch(struct patch *patch, struct patch *prev_patch)
20822082
return error("%s: does not match index",
20832083
old_name);
20842084
if (cached)
2085-
st_mode = ntohl(ce->ce_mode);
2085+
st_mode = ce->ce_mode;
20862086
} else if (stat_ret < 0)
20872087
return error("%s: %s", old_name, strerror(errno));
20882088

20892089
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);
20912091

20922092
if (patch->is_new < 0)
20932093
patch->is_new = 0;
@@ -2388,7 +2388,7 @@ static void add_index_file(const char *path, unsigned mode, void *buf, unsigned
23882388
ce = xcalloc(1, ce_size);
23892389
memcpy(ce->name, path, namelen);
23902390
ce->ce_mode = create_ce_mode(mode);
2391-
ce->ce_flags = htons(namelen);
2391+
ce->ce_flags = namelen;
23922392
if (S_ISGITLINK(mode)) {
23932393
const char *s = buf;
23942394

builtin-blame.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2092,7 +2092,7 @@ static struct commit *fake_working_tree_commit(const char *path, const char *con
20922092
if (!mode) {
20932093
int pos = cache_name_pos(path, len);
20942094
if (0 <= pos)
2095-
mode = ntohl(active_cache[pos]->ce_mode);
2095+
mode = active_cache[pos]->ce_mode;
20962096
else
20972097
/* Let's not bother reading from HEAD tree */
20982098
mode = S_IFREG | 0644;

builtin-commit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ static int list_paths(struct path_list *list, const char *with_tree,
156156

157157
for (i = 0; i < active_nr; i++) {
158158
struct cache_entry *ce = active_cache[i];
159-
if (ce->ce_flags & htons(CE_UPDATE))
159+
if (ce->ce_flags & CE_UPDATE)
160160
continue;
161161
if (!pathspec_match(pattern, m, ce->name, 0))
162162
continue;

builtin-fsck.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
765765
struct blob *blob;
766766
struct object *obj;
767767

768-
mode = ntohl(active_cache[i]->ce_mode);
768+
mode = active_cache[i]->ce_mode;
769769
if (S_ISGITLINK(mode))
770770
continue;
771771
blob = lookup_blob(active_cache[i]->sha1);

builtin-grep.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ static int external_grep(struct grep_opt *opt, const char **paths, int cached)
331331
struct cache_entry *ce = active_cache[i];
332332
char *name;
333333
int kept;
334-
if (!S_ISREG(ntohl(ce->ce_mode)))
334+
if (!S_ISREG(ce->ce_mode))
335335
continue;
336336
if (!pathspec_matches(paths, ce->name))
337337
continue;
@@ -387,7 +387,7 @@ static int grep_cache(struct grep_opt *opt, const char **paths, int cached)
387387

388388
for (nr = 0; nr < active_nr; nr++) {
389389
struct cache_entry *ce = active_cache[nr];
390-
if (!S_ISREG(ntohl(ce->ce_mode)))
390+
if (!S_ISREG(ce->ce_mode))
391391
continue;
392392
if (!pathspec_matches(paths, ce->name))
393393
continue;

builtin-ls-files.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ static void show_ce_entry(const char *tag, struct cache_entry *ce)
189189
return;
190190

191191
if (tag && *tag && show_valid_bit &&
192-
(ce->ce_flags & htons(CE_VALID))) {
192+
(ce->ce_flags & CE_VALID)) {
193193
static char alttag[4];
194194
memcpy(alttag, tag, 3);
195195
if (isalpha(tag[0]))
@@ -210,7 +210,7 @@ static void show_ce_entry(const char *tag, struct cache_entry *ce)
210210
} else {
211211
printf("%s%06o %s %d\t",
212212
tag,
213-
ntohl(ce->ce_mode),
213+
ce->ce_mode,
214214
abbrev ? find_unique_abbrev(ce->sha1,abbrev)
215215
: sha1_to_hex(ce->sha1),
216216
ce_stage(ce));
@@ -242,7 +242,7 @@ static void show_files(struct dir_struct *dir, const char *prefix)
242242
continue;
243243
if (show_unmerged && !ce_stage(ce))
244244
continue;
245-
if (ce->ce_flags & htons(CE_UPDATE))
245+
if (ce->ce_flags & CE_UPDATE)
246246
continue;
247247
show_ce_entry(ce_stage(ce) ? tag_unmerged : tag_cached, ce);
248248
}
@@ -350,7 +350,7 @@ void overlay_tree_on_cache(const char *tree_name, const char *prefix)
350350
struct cache_entry *ce = active_cache[i];
351351
if (!ce_stage(ce))
352352
continue;
353-
ce->ce_flags |= htons(CE_STAGEMASK);
353+
ce->ce_flags |= CE_STAGEMASK;
354354
}
355355

356356
if (prefix) {
@@ -379,7 +379,7 @@ void overlay_tree_on_cache(const char *tree_name, const char *prefix)
379379
*/
380380
if (last_stage0 &&
381381
!strcmp(last_stage0->name, ce->name))
382-
ce->ce_flags |= htons(CE_UPDATE);
382+
ce->ce_flags |= CE_UPDATE;
383383
}
384384
}
385385
}

builtin-read-tree.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ static int read_cache_unmerged(void)
4545
continue;
4646
cache_tree_invalidate_path(active_cache_tree, ce->name);
4747
last = ce;
48-
ce->ce_mode = 0;
49-
ce->ce_flags &= ~htons(CE_STAGEMASK);
48+
ce->ce_flags |= CE_REMOVE;
5049
}
5150
*dst++ = ce;
5251
}

builtin-rerere.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ static int find_conflict(struct path_list *conflict)
149149
if (ce_stage(e2) == 2 &&
150150
ce_stage(e3) == 3 &&
151151
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)) {
154154
path_list_insert((const char *)e2->name, conflict);
155155
i++; /* skip over both #2 and #3 */
156156
}

builtin-update-index.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ static int mark_valid(const char *path)
4747
if (0 <= pos) {
4848
switch (mark_valid_only) {
4949
case MARK_VALID:
50-
active_cache[pos]->ce_flags |= htons(CE_VALID);
50+
active_cache[pos]->ce_flags |= CE_VALID;
5151
break;
5252
case UNMARK_VALID:
53-
active_cache[pos]->ce_flags &= ~htons(CE_VALID);
53+
active_cache[pos]->ce_flags &= ~CE_VALID;
5454
break;
5555
}
5656
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
9595
size = cache_entry_size(len);
9696
ce = xcalloc(1, size);
9797
memcpy(ce->name, path, len);
98-
ce->ce_flags = htons(len);
98+
ce->ce_flags = len;
9999
fill_stat_cache_info(ce, st);
100100
ce->ce_mode = ce_mode_from_stat(old, st->st_mode);
101101

@@ -139,7 +139,7 @@ static int process_directory(const char *path, int len, struct stat *st)
139139
/* Exact match: file or existing gitlink */
140140
if (pos >= 0) {
141141
struct cache_entry *ce = active_cache[pos];
142-
if (S_ISGITLINK(ntohl(ce->ce_mode))) {
142+
if (S_ISGITLINK(ce->ce_mode)) {
143143

144144
/* Do nothing to the index if there is no HEAD! */
145145
if (resolve_gitlink_ref(path, "HEAD", sha1) < 0)
@@ -183,7 +183,7 @@ static int process_file(const char *path, int len, struct stat *st)
183183
int pos = cache_name_pos(path, len);
184184
struct cache_entry *ce = pos < 0 ? NULL : active_cache[pos];
185185

186-
if (ce && S_ISGITLINK(ntohl(ce->ce_mode)))
186+
if (ce && S_ISGITLINK(ce->ce_mode))
187187
return error("%s is already a gitlink, not replacing", path);
188188

189189
return add_one_path(ce, path, len, st);
@@ -226,7 +226,7 @@ static int add_cacheinfo(unsigned int mode, const unsigned char *sha1,
226226
ce->ce_flags = create_ce_flags(len, stage);
227227
ce->ce_mode = create_ce_mode(mode);
228228
if (assume_unchanged)
229-
ce->ce_flags |= htons(CE_VALID);
229+
ce->ce_flags |= CE_VALID;
230230
option = allow_add ? ADD_CACHE_OK_TO_ADD : 0;
231231
option |= allow_replace ? ADD_CACHE_OK_TO_REPLACE : 0;
232232
if (add_cache_entry(ce, option))
@@ -246,14 +246,14 @@ static void chmod_path(int flip, const char *path)
246246
if (pos < 0)
247247
goto fail;
248248
ce = active_cache[pos];
249-
mode = ntohl(ce->ce_mode);
249+
mode = ce->ce_mode;
250250
if (!S_ISREG(mode))
251251
goto fail;
252252
switch (flip) {
253253
case '+':
254-
ce->ce_mode |= htonl(0111); break;
254+
ce->ce_mode |= 0111; break;
255255
case '-':
256-
ce->ce_mode &= htonl(~0111); break;
256+
ce->ce_mode &= ~0111; break;
257257
default:
258258
goto fail;
259259
}

cache-tree.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,13 +320,13 @@ static int update_one(struct cache_tree *it,
320320
}
321321
else {
322322
sha1 = ce->sha1;
323-
mode = ntohl(ce->ce_mode);
323+
mode = ce->ce_mode;
324324
entlen = pathlen - baselen;
325325
}
326326
if (mode != S_IFGITLINK && !missing_ok && !has_sha1_file(sha1))
327327
return error("invalid object %s", sha1_to_hex(sha1));
328328

329-
if (!ce->ce_mode)
329+
if (ce->ce_flags & CE_REMOVE)
330330
continue; /* entry being removed */
331331

332332
strbuf_grow(&buffer, entlen + 100);

0 commit comments

Comments
 (0)