Commit d7b62c98bea6955d39e6c792a38961da070c0da8

Stefan Sperling 2018-12-27T20:40:39

signal existing files in checkout progress output

diff --git a/got/got.c b/got/got.c
index 1041ba9..b873e79 100644
--- a/got/got.c
+++ b/got/got.c
@@ -178,14 +178,14 @@ usage_checkout(void)
 }
 
 static void
-checkout_progress(void *arg, const char *path)
+checkout_progress(void *arg, char status, const char *path)
 {
 	char *worktree_path = arg;
 
 	while (path[0] == '/')
 		path++;
 
-	printf("A  %s/%s\n", worktree_path, path);
+	printf("%c  %s/%s\n", status, worktree_path, path);
 }
 
 static const struct got_error *
diff --git a/include/got_worktree.h b/include/got_worktree.h
index 06af45d..3d89816 100644
--- a/include/got_worktree.h
+++ b/include/got_worktree.h
@@ -49,7 +49,7 @@ char *got_worktree_get_repo_path(struct got_worktree *);
 char  *got_worktree_get_head_ref_name(struct got_worktree *);
 
 /* A callback function which is invoked when a path is checked out. */
-typedef void (*got_worktree_checkout_cb)(void *, const char *);
+typedef void (*got_worktree_checkout_cb)(void *, char, const char *);
 
 /* A callback function which is invoked at cancellation points.
  * May return GOT_ERR_CANCELLED to abort the runing operation. */
diff --git a/lib/worktree.c b/lib/worktree.c
index 70d2944..4579ebe 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -403,7 +403,9 @@ apply_path_prefix(struct got_worktree *worktree, const char *path)
 
 static const struct got_error *
 add_file_on_disk(struct got_worktree *worktree, struct got_fileindex *fileindex,
-   const char *path, struct got_blob_object *blob, struct got_repository *repo)
+   const char *path, struct got_blob_object *blob, struct got_repository *repo,
+   got_worktree_checkout_cb progress_cb, void *progress_arg,
+   const char *progress_path)
 {
 	const struct got_error *err = NULL;
 	char *ondisk_path;
@@ -428,12 +430,16 @@ add_file_on_disk(struct got_worktree *worktree, struct got_fileindex *fileindex,
 				err = got_error(GOT_ERR_FILE_OBSTRUCTED);
 			} else {
 				/* TODO: Merge the file! */
+				(*progress_cb)(progress_arg, 'E',
+				    progress_path);
 				return NULL;
 			}
 		}
 		return err;
 	}
 
+	(*progress_cb)(progress_arg, 'A', progress_path);
+
 	hdrlen = got_object_blob_get_hdrlen(blob);
 	do {
 		const uint8_t *buf = got_object_blob_get_read_buf(blob);
@@ -552,7 +558,6 @@ tree_checkout_entry(struct got_worktree *worktree,
 	progress_path = path;
 	if (strncmp(progress_path, worktree->path_prefix, len) == 0)
 		progress_path += len;
-	(*progress_cb)(progress_arg, progress_path);
 
 	switch (obj->type) {
 	case GOT_OBJ_TYPE_BLOB:
@@ -561,7 +566,8 @@ tree_checkout_entry(struct got_worktree *worktree,
 		err = got_object_blob_open(&blob, repo, obj, 8192);
 		if (err)
 			goto done;
-		err = add_file_on_disk(worktree, fileindex, path, blob, repo);
+		err = add_file_on_disk(worktree, fileindex, path, blob, repo,
+		    progress_cb, progress_arg, progress_path);
 		break;
 	case GOT_OBJ_TYPE_TREE:
 		err = got_object_tree_open(&tree, repo, obj);
diff --git a/regress/worktree/worktree_test.c b/regress/worktree/worktree_test.c
index 9740973..61265ac 100644
--- a/regress/worktree/worktree_test.c
+++ b/regress/worktree/worktree_test.c
@@ -305,7 +305,7 @@ done:
 }
 
 static void
-process_cb(void *arg, const char *path)
+progress_cb(void *arg, char status, const char *path)
 {
 }
 
@@ -341,7 +341,7 @@ worktree_checkout(const char *repo_path)
 	if (err != NULL)
 		goto done;
 
-	err = got_worktree_checkout_files(worktree, repo, process_cb, NULL,
+	err = got_worktree_checkout_files(worktree, repo, progress_cb, NULL,
 	    NULL, NULL);
 	if (err != NULL)
 		goto done;