report commit item status
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 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
diff --git a/got/got.c b/got/got.c
index a39387a..77eeffb 100644
--- a/got/got.c
+++ b/got/got.c
@@ -2133,7 +2133,8 @@ cmd_commit(int argc, char *argv[])
goto done;
error = got_worktree_commit(&id, worktree, path,
- "Stefan Sperling <stsp@stsp.name>", NULL, logmsg, repo);
+ "Stefan Sperling <stsp@stsp.name>", NULL, logmsg,
+ print_status, NULL, repo);
if (error)
goto done;
diff --git a/include/got_worktree.h b/include/got_worktree.h
index 27d9c4b..50c0ae7 100644
--- a/include/got_worktree.h
+++ b/include/got_worktree.h
@@ -177,4 +177,4 @@ const struct got_error *got_worktree_revert(struct got_worktree *,
*/
const struct got_error *got_worktree_commit(struct got_object_id **,
struct got_worktree *, const char *, const char *, const char *,
- const char *, struct got_repository *);
+ const char *, got_worktree_status_cb, void *, struct got_repository *);
diff --git a/lib/worktree.c b/lib/worktree.c
index a972caf..bcc5c7a 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -2290,12 +2290,15 @@ done:
static const struct got_error *write_tree(struct got_object_id **,
struct got_tree_object *, const char *, struct got_pathlist_head *,
+ got_worktree_status_cb status_cb, void *status_arg,
struct got_repository *);
static const struct got_error *
write_subtree(struct got_object_id **new_subtree_id,
struct got_tree_entry *te, const char *parent_path,
- struct got_pathlist_head *commitable_paths, struct got_repository *repo)
+ struct got_pathlist_head *commitable_paths,
+ got_worktree_status_cb status_cb, void *status_arg,
+ struct got_repository *repo)
{
const struct got_error *err = NULL;
struct got_tree_object *subtree;
@@ -2310,7 +2313,7 @@ write_subtree(struct got_object_id **new_subtree_id,
return err;
err = write_tree(new_subtree_id, subtree, subpath, commitable_paths,
- repo);
+ status_cb, status_arg, repo);
got_object_tree_close(subtree);
free(subpath);
return err;
@@ -2424,6 +2427,16 @@ insert_tree_entry(struct got_tree_entry *new_te,
}
static const struct got_error *
+report_ct_status(struct commitable *ct,
+ got_worktree_status_cb status_cb, void *status_arg)
+{
+ const char *ct_path = ct->path;
+ while (ct_path[0] == '/')
+ ct_path++;
+ return (*status_cb)(status_arg, ct->status, ct_path, ct->id);
+}
+
+static const struct got_error *
match_deleted_or_modified_ct(struct commitable **ctp,
struct got_tree_entry *te, const char *base_tree_path,
struct got_pathlist_head *commitable_paths)
@@ -2469,6 +2482,7 @@ static const struct got_error *
write_tree(struct got_object_id **new_tree_id,
struct got_tree_object *base_tree, const char *path_base_tree,
struct got_pathlist_head *commitable_paths,
+ got_worktree_status_cb status_cb, void *status_arg,
struct got_repository *repo)
{
const struct got_error *err = NULL;
@@ -2504,6 +2518,9 @@ write_tree(struct got_object_id **new_tree_id,
err = alloc_added_blob_tree_entry(&new_te, ct);
if (err)
goto done;
+ err = report_ct_status(ct, status_cb, status_arg);
+ if (err)
+ goto done;
} else {
char *subtree_path;
@@ -2523,7 +2540,7 @@ write_tree(struct got_object_id **new_tree_id,
goto done;
}
err = write_subtree(&new_te->id, NULL, subtree_path,
- commitable_paths, repo);
+ commitable_paths, status_cb, status_arg, repo);
free(subtree_path);
if (err)
goto done;
@@ -2546,7 +2563,8 @@ write_tree(struct got_object_id **new_tree_id,
goto done;
free(new_te->id);
err = write_subtree(&new_te->id, te,
- path_base_tree, commitable_paths, repo);
+ path_base_tree, commitable_paths,
+ status_cb, status_arg, repo);
if (err)
goto done;
err = insert_tree_entry(new_te, &paths);
@@ -2568,6 +2586,9 @@ write_tree(struct got_object_id **new_tree_id,
if (err)
goto done;
}
+ err = report_ct_status(ct, status_cb, status_arg);
+ if (err)
+ goto done;
} else {
/* Entry is unchanged; just copy it. */
err = got_object_tree_entry_dup(&new_te, te);
@@ -2598,8 +2619,9 @@ done:
const struct got_error *
got_worktree_commit(struct got_object_id **new_commit_id,
struct got_worktree *worktree, const char *ondisk_path,
- const char *author, const char *committer,
- const char *logmsg, struct got_repository *repo)
+ const char *author, const char *committer, const char *logmsg,
+ got_worktree_status_cb status_cb, void *status_arg,
+ struct got_repository *repo)
{
const struct got_error *err = NULL, *unlockerr = NULL;
struct collect_commitables_arg cc_arg;
@@ -2669,7 +2691,8 @@ got_worktree_commit(struct got_object_id **new_commit_id,
goto done;
/* Recursively write new tree objects. */
- err = write_tree(&new_tree_id, base_tree, "/", &commitable_paths, repo);
+ err = write_tree(&new_tree_id, base_tree, "/", &commitable_paths,
+ status_cb, status_arg, repo);
if (err)
goto done;
diff --git a/regress/cmdline/commit.sh b/regress/cmdline/commit.sh
index f621ba0..54f8171 100755
--- a/regress/cmdline/commit.sh
+++ b/regress/cmdline/commit.sh
@@ -19,8 +19,6 @@
function test_commit_basic {
local testroot=`test_init commit_basic`
- find $testroot/repo/.git/objects > /tmp/1
-
got checkout $testroot/repo $testroot/wt > /dev/null
ret="$?"
if [ "$ret" != "0" ]; then
@@ -38,12 +36,10 @@ function test_commit_basic {
(cd $testroot/wt && got commit -m 'test commit_basic' > $testroot/stdout)
- find $testroot/repo/.git/objects > /tmp/2
-
local head_rev=`git_show_head $testroot/repo`
- echo "M alpha" > $testroot/stdout.expected
- echo "D beta" >> $testroot/stdout.expected
- echo "A new" >> $testroot/stdout.expected
+ echo "A new" > $testroot/stdout.expected
+ echo "M alpha" >> $testroot/stdout.expected
+ echo "D beta" >> $testroot/stdout.expected
echo "created commit $head_rev" >> $testroot/stdout.expected
cmp $testroot/stdout.expected $testroot/stdout