store base commit of each blob in file index
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
diff --git a/lib/fileindex.c b/lib/fileindex.c
index 86250c1..a6bdde1 100644
--- a/lib/fileindex.c
+++ b/lib/fileindex.c
@@ -29,7 +29,8 @@
const struct got_error *
got_fileindex_entry_alloc(struct got_fileindex_entry **entry,
- const char *ondisk_path, const char *relpath, uint8_t *blob_sha1)
+ const char *ondisk_path, const char *relpath, uint8_t *blob_sha1,
+ uint8_t *commit_sha1)
{
struct stat sb;
size_t len;
@@ -63,6 +64,7 @@ got_fileindex_entry_alloc(struct got_fileindex_entry **entry,
(*entry)->mode |= ((sb.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO)) <<
GOT_INDEX_ENTRY_MODE_PERMS_SHIFT);
memcpy((*entry)->blob_sha1, blob_sha1, SHA1_DIGEST_LENGTH);
+ memcpy((*entry)->commit_sha1, commit_sha1, SHA1_DIGEST_LENGTH);
len = strlen(relpath);
if (len > GOT_INDEX_ENTRY_F_PATH_LEN)
len = GOT_INDEX_ENTRY_F_PATH_LEN;
@@ -213,6 +215,11 @@ write_fileindex_entry(SHA1_CTX *ctx, struct got_fileindex_entry *entry,
if (n != SHA1_DIGEST_LENGTH)
return got_ferror(outfile, GOT_ERR_IO);
+ SHA1Update(ctx, entry->commit_sha1, SHA1_DIGEST_LENGTH);
+ n = fwrite(entry->commit_sha1, 1, SHA1_DIGEST_LENGTH, outfile);
+ if (n != SHA1_DIGEST_LENGTH)
+ return got_ferror(outfile, GOT_ERR_IO);
+
err = write_fileindex_val32(ctx, entry->flags, outfile);
if (err)
return err;
@@ -383,6 +390,13 @@ read_fileindex_entry(struct got_fileindex_entry **entryp, SHA1_CTX *ctx,
}
SHA1Update(ctx, entry->blob_sha1, SHA1_DIGEST_LENGTH);
+ n = fread(entry->commit_sha1, 1, SHA1_DIGEST_LENGTH, infile);
+ if (n != SHA1_DIGEST_LENGTH) {
+ err = got_ferror(infile, GOT_ERR_IO);
+ goto done;
+ }
+ SHA1Update(ctx, entry->commit_sha1, SHA1_DIGEST_LENGTH);
+
err = read_fileindex_val32(&entry->flags, ctx, infile);
if (err)
goto done;
diff --git a/lib/got_lib_fileindex.h b/lib/got_lib_fileindex.h
index d0855be..e8716e8 100644
--- a/lib/got_lib_fileindex.h
+++ b/lib/got_lib_fileindex.h
@@ -45,6 +45,9 @@ struct got_fileindex_entry {
/* SHA1 of corresponding blob in repository. */
uint8_t blob_sha1[SHA1_DIGEST_LENGTH];
+ /* SHA1 of corresponding base commit in repository. */
+ uint8_t commit_sha1[SHA1_DIGEST_LENGTH];
+
uint32_t flags;
#define GOT_INDEX_ENTRY_F_PATH_LEN 0x00000fff
#define GOT_INDEX_ENTRY_F_STAGE 0x00003000
@@ -83,7 +86,7 @@ struct got_fileindex_hdr {
};
const struct got_error *got_fileindex_entry_alloc(struct got_fileindex_entry **,
- const char *, const char *, uint8_t *);
+ 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 *);
diff --git a/lib/worktree.c b/lib/worktree.c
index 4656e2e..f8d6e1c 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -461,7 +461,8 @@ add_file_on_disk(struct got_worktree *worktree, struct got_fileindex *fileindex,
fsync(fd);
err = got_fileindex_entry_alloc(&entry, ondisk_path,
- apply_path_prefix(worktree, path), blob->id.sha1);
+ apply_path_prefix(worktree, path), blob->id.sha1,
+ worktree->base_commit_id->sha1);
if (err)
goto done;