remove ie->path_len; use path length stored in file index entry flags
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
diff --git a/lib/fileindex.c b/lib/fileindex.c
index 19f400a..bd382be 100644
--- a/lib/fileindex.c
+++ b/lib/fileindex.c
@@ -136,8 +136,7 @@ got_fileindex_entry_alloc(struct got_fileindex_entry **entry,
return err;
}
- (*entry)->path_len = strlen(relpath);
- len = (*entry)->path_len;
+ len = strlen(relpath);
if (len > GOT_FILEIDX_F_PATH_LEN)
len = GOT_FILEIDX_F_PATH_LEN;
(*entry)->flags |= len;
@@ -153,6 +152,12 @@ got_fileindex_entry_free(struct got_fileindex_entry *entry)
free(entry);
}
+size_t
+got_fileindex_entry_path_len(const struct got_fileindex_entry *ie)
+{
+ return (size_t)(ie->flags & GOT_FILEIDX_F_PATH_LEN);
+}
+
int
got_fileindex_entry_has_blob(struct got_fileindex_entry *ie)
{
@@ -207,7 +212,7 @@ got_fileindex_entry_get(struct got_fileindex *fileindex, const char *path,
struct got_fileindex_entry key;
memset(&key, 0, sizeof(key));
key.path = (char *)path;
- key.path_len = path_len;
+ key.flags = (path_len & GOT_FILEIDX_F_PATH_LEN);
return RB_FIND(got_fileindex_tree, &fileindex->entries, &key);
}
@@ -548,8 +553,6 @@ read_fileindex_entry(struct got_fileindex_entry **entryp, SHA1_CTX *ctx,
goto done;
err = read_fileindex_path(&entry->path, ctx, infile);
- if (err == NULL)
- entry->path_len = strlen(entry->path);
done:
if (err)
got_fileindex_entry_free(entry);
@@ -698,7 +701,7 @@ diff_fileindex_tree(struct got_fileindex *fileindex,
break;
}
cmp = got_path_cmp((*ie)->path, te_path,
- (*ie)->path_len, strlen(te_path));
+ got_fileindex_entry_path_len(*ie), strlen(te_path));
free(te_path);
if (cmp == 0) {
if (got_path_is_child((*ie)->path, path,
@@ -918,7 +921,8 @@ diff_fileindex_dir(struct got_fileindex *fileindex,
break;
}
cmp = got_path_cmp((*ie)->path, de_path,
- (*ie)->path_len, strlen(path) + 1 + de->d_namlen);
+ got_fileindex_entry_path_len(*ie),
+ strlen(path) + 1 + de->d_namlen);
free(de_path);
if (cmp == 0) {
err = cb->diff_old_new(cb_arg, *ie, de, path);
diff --git a/lib/got_lib_fileindex.h b/lib/got_lib_fileindex.h
index f9c7966..6e547e2 100644
--- a/lib/got_lib_fileindex.h
+++ b/lib/got_lib_fileindex.h
@@ -55,18 +55,21 @@ struct got_fileindex_entry {
* Variable length, and NUL-padded to a multiple of 8 on disk.
*/
char *path;
- size_t path_len; /* strlen(path) -- kept in memory only! */
};
struct got_fileindex;
RB_HEAD(got_fileindex_tree, got_fileindex_entry);
+size_t got_fileindex_entry_path_len(const struct got_fileindex_entry *);
+
static inline int
got_fileindex_cmp(const struct got_fileindex_entry *e1,
const struct got_fileindex_entry *e2)
{
- return got_path_cmp(e1->path, e2->path, e1->path_len, e2->path_len);
+ return got_path_cmp(e1->path, e2->path,
+ got_fileindex_entry_path_len(e1),
+ got_fileindex_entry_path_len(e2));
}
RB_PROTOTYPE(got_fileindex_tree, got_fileindex_entry, entry, got_fileindex_cmp);
@@ -90,6 +93,7 @@ const struct got_error *got_fileindex_entry_update(struct got_fileindex_entry *,
const struct got_error *got_fileindex_entry_alloc(struct got_fileindex_entry **,
const char *, const char *, uint8_t *, uint8_t *);
void got_fileindex_entry_free(struct got_fileindex_entry *);
+
struct got_fileindex *got_fileindex_alloc(void);
void got_fileindex_free(struct got_fileindex *);
const struct got_error *got_fileindex_write(struct got_fileindex *, FILE *);