report base commit of fileindex entries to status callback
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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
diff --git a/got/got.c b/got/got.c
index 9469b96..dcd21cd 100644
--- a/got/got.c
+++ b/got/got.c
@@ -1053,7 +1053,7 @@ struct print_diff_arg {
static const struct got_error *
print_diff(void *arg, unsigned char status, const char *path,
- struct got_object_id *id)
+ struct got_object_id *blob_id, struct got_object_id *commit_id)
{
struct print_diff_arg *a = arg;
const struct got_error *err = NULL;
@@ -1073,7 +1073,7 @@ print_diff(void *arg, unsigned char status, const char *path,
}
if (status != GOT_STATUS_ADD) {
- err = got_object_open_as_blob(&blob1, a->repo, id, 8192);
+ err = got_object_open_as_blob(&blob1, a->repo, blob_id, 8192);
if (err)
goto done;
@@ -1660,7 +1660,7 @@ usage_status(void)
static const struct got_error *
print_status(void *arg, unsigned char status, const char *path,
- struct got_object_id *id)
+ struct got_object_id *blob_id, struct got_object_id *commit_id)
{
printf("%c %s\n", status, path);
return NULL;
diff --git a/include/got_worktree.h b/include/got_worktree.h
index adefc19..37547bf 100644
--- a/include/got_worktree.h
+++ b/include/got_worktree.h
@@ -130,7 +130,8 @@ const struct got_error *got_worktree_checkout_files(struct got_worktree *,
/* A callback function which is invoked to report a path's status. */
typedef const struct got_error *(*got_worktree_status_cb)(void *,
- unsigned char, const char *, struct got_object_id *);
+ unsigned char, const char *, struct got_object_id *,
+ struct got_object_id *);
/*
* Report the status of paths in the work tree.
diff --git a/lib/worktree.c b/lib/worktree.c
index 262e110..562647c 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -1594,12 +1594,14 @@ report_file_status(struct got_fileindex_entry *ie, const char *abspath,
const struct got_error *err = NULL;
unsigned char status = GOT_STATUS_NO_CHANGE;
struct stat sb;
- struct got_object_id id;
+ struct got_object_id blob_id, commit_id;
err = get_file_status(&status, &sb, ie, abspath, repo);
if (err == NULL && status != GOT_STATUS_NO_CHANGE) {
- memcpy(id.sha1, ie->blob_sha1, SHA1_DIGEST_LENGTH);
- err = (*status_cb)(status_arg, status, ie->path, &id);
+ memcpy(blob_id.sha1, ie->blob_sha1, SHA1_DIGEST_LENGTH);
+ memcpy(commit_id.sha1, ie->commit_sha1, SHA1_DIGEST_LENGTH);
+ err = (*status_cb)(status_arg, status, ie->path, &blob_id,
+ &commit_id);
}
return err;
}
@@ -1639,7 +1641,7 @@ static const struct got_error *
status_old(void *arg, struct got_fileindex_entry *ie, const char *parent_path)
{
struct diff_dir_cb_arg *a = arg;
- struct got_object_id id;
+ struct got_object_id blob_id, commit_id;
unsigned char status;
if (a->cancel_cb && a->cancel_cb(a->cancel_arg))
@@ -1648,12 +1650,14 @@ status_old(void *arg, struct got_fileindex_entry *ie, const char *parent_path)
if (!got_path_is_child(parent_path, a->status_path, a->status_path_len))
return NULL;
- memcpy(id.sha1, ie->blob_sha1, SHA1_DIGEST_LENGTH);
+ memcpy(blob_id.sha1, ie->blob_sha1, SHA1_DIGEST_LENGTH);
+ memcpy(commit_id.sha1, ie->commit_sha1, SHA1_DIGEST_LENGTH);
if (got_fileindex_entry_has_file_on_disk(ie))
status = GOT_STATUS_MISSING;
else
status = GOT_STATUS_DELETE;
- return (*a->status_cb)(a->status_arg, status, ie->path, &id);
+ return (*a->status_cb)(a->status_arg, status, ie->path, &blob_id,
+ &commit_id);
}
static const struct got_error *
@@ -1684,7 +1688,7 @@ status_new(void *arg, struct dirent *de, const char *parent_path)
}
err = (*a->status_cb)(a->status_arg, GOT_STATUS_UNVERSIONED, path,
- NULL);
+ NULL, NULL);
if (parent_path[0])
free(path);
return err;
@@ -2244,7 +2248,7 @@ struct collect_commitables_arg {
static const struct got_error *
collect_commitables(void *arg, unsigned char status, const char *relpath,
- struct got_object_id *id)
+ struct got_object_id *blob_id, struct got_object_id *commit_id)
{
struct collect_commitables_arg *a = arg;
const struct got_error *err = NULL;
@@ -2305,7 +2309,7 @@ collect_commitables(void *arg, unsigned char status, const char *relpath,
ct->status = status;
ct->blob_id = NULL; /* will be filled in when blob gets created */
if (ct->status != GOT_STATUS_ADD) {
- ct->base_blob_id = got_object_id_dup(id);
+ ct->base_blob_id = got_object_id_dup(blob_id);
if (ct->base_blob_id == NULL) {
err = got_error_from_errno("got_object_id_dup");
goto done;
@@ -2472,7 +2476,7 @@ report_ct_status(struct got_commitable *ct,
const char *ct_path = ct->path;
while (ct_path[0] == '/')
ct_path++;
- return (*status_cb)(status_arg, ct->status, ct_path, ct->blob_id);
+ return (*status_cb)(status_arg, ct->status, ct_path, ct->blob_id, NULL);
}
static const struct got_error *