show progress during checkout
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
diff --git a/got/got.c b/got/got.c
index 8d6ac0c..f0cb1f8 100644
--- a/got/got.c
+++ b/got/got.c
@@ -135,6 +135,17 @@ usage_checkout(void)
exit(1);
}
+static void
+checkout_progress(void *arg, const char *path)
+{
+ char *worktree_path = arg;
+
+ while (path[0] == '/')
+ path++;
+
+ printf("A %s/%s\n", worktree_path, path);
+}
+
const struct got_error *
cmd_checkout(int argc, char *argv[])
{
@@ -173,8 +184,6 @@ cmd_checkout(int argc, char *argv[])
} else
usage_checkout();
- printf("%s %s %s %s\n", getprogname(), argv[0], repo_path, worktree_path);
-
error = got_repo_open(&repo, repo_path);
if (error != NULL)
goto done;
@@ -190,7 +199,8 @@ cmd_checkout(int argc, char *argv[])
if (error != NULL)
goto done;
- error = got_worktree_checkout_files(worktree, head_ref, repo);
+ error = got_worktree_checkout_files(worktree, head_ref, repo,
+ checkout_progress, worktree_path);
if (error != NULL)
goto done;
diff --git a/include/got_worktree.h b/include/got_worktree.h
index 3bfc191..9031acf 100644
--- a/include/got_worktree.h
+++ b/include/got_worktree.h
@@ -22,5 +22,7 @@ const struct got_error *got_worktree_open(struct got_worktree **, const char *);
void got_worktree_close(struct got_worktree *);
char *got_worktree_get_repo_path(struct got_worktree *);
char *got_worktree_get_head_ref_name(struct got_worktree *);
+typedef void (*got_worktree_checkout_cb)(void *, const char *);
const struct got_error *got_worktree_checkout_files(struct got_worktree *,
- struct got_reference *, struct got_repository *);
+ struct got_reference *, struct got_repository *,
+ got_worktree_checkout_cb progress_cb, void *progress_arg);
diff --git a/lib/worktree.c b/lib/worktree.c
index 1273d61..0df2fb5 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -463,12 +463,14 @@ done:
static const struct got_error *
tree_checkout(struct got_worktree *, struct got_fileindex *,
- struct got_tree_object *, const char *, struct got_repository *);
+ struct got_tree_object *, const char *, struct got_repository *,
+ got_worktree_checkout_cb progress_cb, void *progress_arg);
static const struct got_error *
tree_checkout_entry(struct got_worktree *worktree,
struct got_fileindex *fileindex, struct got_tree_entry *te,
- const char *parent, struct got_repository *repo)
+ const char *parent, struct got_repository *repo,
+ got_worktree_checkout_cb progress_cb, void *progress_arg)
{
const struct got_error *err = NULL;
struct got_object *obj = NULL;
@@ -493,6 +495,8 @@ tree_checkout_entry(struct got_worktree *worktree,
if (err)
goto done;
+ (*progress_cb)(progress_arg, path);
+
switch (got_object_get_type(obj)) {
case GOT_OBJ_TYPE_BLOB:
if (strlen(worktree->path_prefix) >= strlen(path))
@@ -511,7 +515,8 @@ tree_checkout_entry(struct got_worktree *worktree,
if (err)
break;
}
- err = tree_checkout(worktree, fileindex, tree, path, repo);
+ err = tree_checkout(worktree, fileindex, tree, path, repo,
+ progress_cb, progress_arg);
break;
default:
break;
@@ -531,7 +536,8 @@ done:
static const struct got_error *
tree_checkout(struct got_worktree *worktree,
struct got_fileindex *fileindex, struct got_tree_object *tree,
- const char *path, struct got_repository *repo)
+ const char *path, struct got_repository *repo,
+ got_worktree_checkout_cb progress_cb, void *progress_arg)
{
const struct got_error *err = NULL;
struct got_tree_entry *te;
@@ -543,7 +549,8 @@ tree_checkout(struct got_worktree *worktree,
return NULL;
SIMPLEQ_FOREACH(te, &tree->entries, entry) {
- err = tree_checkout_entry(worktree, fileindex, te, path, repo);
+ err = tree_checkout_entry(worktree, fileindex, te, path, repo,
+ progress_cb, progress_arg);
if (err)
break;
}
@@ -553,7 +560,8 @@ tree_checkout(struct got_worktree *worktree,
const struct got_error *
got_worktree_checkout_files(struct got_worktree *worktree,
- struct got_reference *head_ref, struct got_repository *repo)
+ struct got_reference *head_ref, struct got_repository *repo,
+ got_worktree_checkout_cb progress_cb, void *progress_arg)
{
const struct got_error *err = NULL, *unlockerr;
struct got_object_id *commit_id = NULL;
@@ -616,7 +624,8 @@ got_worktree_checkout_files(struct got_worktree *worktree,
if (err)
goto done;
- err = tree_checkout(worktree, fileindex, tree, "/", repo);
+ err = tree_checkout(worktree, fileindex, tree, "/", repo,
+ progress_cb, progress_arg);
if (err)
goto done;