commit 92a684f46395bfe5077629585a4d140f6853f06d from: Stefan Sperling date: Mon Mar 12 20:34:38 2018 UTC show progress during checkout commit - c09a553dff65da50eb12a2ec1b10799f7dad0c73 commit + 92a684f46395bfe5077629585a4d140f6853f06d blob - 8d6ac0cdfc8e63e43ed004d20ff75c4de905db79 blob + f0cb1f809376e9f02e6fbc2a9d7fad01bc21b65f --- got/got.c +++ got/got.c @@ -133,6 +133,17 @@ usage_checkout(void) fprintf(stderr, "usage: %s checkout REPO_PATH [WORKTREE_PATH]\n", getprogname()); 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 * @@ -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; blob - 3bfc19180c2887cfa564c03866b4f69599e3d7cc blob + 9031acfb6d57082ebb9029f76a986a9545eb4912 --- include/got_worktree.h +++ include/got_worktree.h @@ -22,5 +22,7 @@ const struct got_error *got_worktree_open(struct got_w 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); blob - 1273d61371696cd7134c2bd6c2b3f3e6fa82946a blob + 0df2fb5583b53e04fc7439ed022b3d3cf8b44531 --- lib/worktree.c +++ 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 *workt 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;