From: Tracey Emery Subject: Supress progress for update and checkout To: gameoftrees@openbsd.org Date: Fri, 10 Sep 2021 14:25:27 -0600 Hello, The following supresses the output for update and checkout. Running these commands on large repos makes the terminal unusable. This simply adds a couple of new callbacks that don't printf output. Is there a better way to do this, or ok? -- Tracey Emery diff 0e33f8e0becf732ab33b3ce78c026790a651a5f9 /home/tracey/src/got blob - 02e13d54951c31a8f0e635a8f07be977d6861681 file + got/got.1 --- got/got.1 +++ got/got.1 @@ -493,7 +493,7 @@ and Git's garbage collector. .It Cm fe Short alias for .Cm fetch . -.It Cm checkout Oo Fl E Oc Oo Fl b Ar branch Oc Oo Fl c Ar commit Oc Oo Fl p Ar path-prefix Oc Ar repository-path Op Ar work-tree-path +.It Cm checkout Oo Fl E Oc Oo Fl b Ar branch Oc Oo Fl c Ar commit Oc Oo Fl p Ar path-prefix Oc Oo Fl q Oc Ar repository-path Op Ar work-tree-path Copy files from a repository into a new work tree. Show the status of each affected file, using the following status codes: .Bl -column YXZ description @@ -553,11 +553,13 @@ Restrict the work tree to a subset of the repository's Only files beneath the specified .Ar path-prefix will be checked out. +.It Fl q +Silence progress output. .El .It Cm co Short alias for .Cm checkout . -.It Cm update Oo Fl b Ar branch Oc Oo Fl c Ar commit Oc Op Ar path ... +.It Cm update Oo Fl b Ar branch Oc Oo Fl c Ar commit Oc Oo Fl q Oc Op Ar path ... Update an existing work tree to a different .Ar commit . Change existing files in the work tree as necessary to match file contents @@ -650,6 +652,8 @@ An abbreviated hash argument will be expanded to a ful automatically, provided the abbreviation is unique. If this option is not specified, the most recent commit on the work tree's branch will be used. +.It Fl q +Silence progress output. .El .It Cm up Short alias for blob - 51bedeed3942da484d0dfe4614307f848dcbd5ed file + got/got.c --- got/got.c +++ got/got.c @@ -2638,7 +2638,8 @@ __dead static void usage_checkout(void) { fprintf(stderr, "usage: %s checkout [-E] [-b branch] [-c commit] " - "[-p prefix] repository-path [worktree-path]\n", getprogname()); + "[-p prefix] [-q] repository-path [worktree-path]\n", + getprogname()); exit(1); } @@ -2679,6 +2680,23 @@ checkout_progress(void *arg, unsigned char status, con } static const struct got_error * +checkout_quiet(void *arg, unsigned char status, const char *path) +{ + struct got_checkout_progress_arg *a = arg; + + /* Base commit bump happens silently. */ + if (status == GOT_STATUS_BUMP_BASE) + return NULL; + + if (status == GOT_STATUS_BASE_REF_ERR) { + a->had_base_commit_ref_error = 1; + return NULL; + } + + return NULL; +} + +static const struct got_error * check_cancelled(void *arg) { if (sigint_received || sigpipe_received) @@ -2828,13 +2846,13 @@ cmd_checkout(int argc, char *argv[]) const char *branch_name = GOT_REF_HEAD; char *commit_id_str = NULL; char *cwd = NULL; - int ch, same_path_prefix, allow_nonempty = 0; + int ch, same_path_prefix, allow_nonempty = 0, quiet = 0; struct got_pathlist_head paths; struct got_checkout_progress_arg cpa; TAILQ_INIT(&paths); - while ((ch = getopt(argc, argv, "b:c:Ep:")) != -1) { + while ((ch = getopt(argc, argv, "b:c:Ep:q")) != -1) { switch (ch) { case 'b': branch_name = optarg; @@ -2850,6 +2868,9 @@ cmd_checkout(int argc, char *argv[]) case 'p': path_prefix = optarg; break; + case 'q': + quiet = 1; + break; default: usage_checkout(); /* NOTREACHED */ @@ -3002,8 +3023,12 @@ cmd_checkout(int argc, char *argv[]) goto done; cpa.worktree_path = worktree_path; cpa.had_base_commit_ref_error = 0; - error = got_worktree_checkout_files(worktree, &paths, repo, - checkout_progress, &cpa, check_cancelled, NULL); + if (quiet) + error = got_worktree_checkout_files(worktree, &paths, repo, + checkout_quiet, &cpa, check_cancelled, NULL); + else + error = got_worktree_checkout_files(worktree, &paths, repo, + checkout_progress, &cpa, check_cancelled, NULL); if (error != NULL) goto done; @@ -3045,7 +3070,8 @@ print_update_progress_stats(struct got_update_progress __dead static void usage_update(void) { - fprintf(stderr, "usage: %s update [-b branch] [-c commit] [path ...]\n", + fprintf(stderr, "usage: %s update [-b branch] [-c commit] [-q] " + "[path ...]\n", getprogname()); exit(1); } @@ -3079,6 +3105,31 @@ update_progress(void *arg, unsigned char status, const } static const struct got_error * +update_quiet(void *arg, unsigned char status, const char *path) +{ + struct got_update_progress_arg *upa = arg; + + if (status == GOT_STATUS_EXISTS || + status == GOT_STATUS_BASE_REF_ERR) + return NULL; + + upa->did_something = 1; + + /* Base commit bump happens silently. */ + if (status == GOT_STATUS_BUMP_BASE) + return NULL; + + if (status == GOT_STATUS_CONFLICT) + upa->conflicts++; + if (status == GOT_STATUS_OBSTRUCTED) + upa->obstructed++; + if (status == GOT_STATUS_CANNOT_UPDATE) + upa->not_updated++; + + return NULL; +} + +static const struct got_error * switch_head_ref(struct got_reference *head_ref, struct got_object_id *commit_id, struct got_worktree *worktree, struct got_repository *repo) @@ -3203,12 +3254,12 @@ cmd_update(int argc, char *argv[]) struct got_reference *head_ref = NULL; struct got_pathlist_head paths; struct got_pathlist_entry *pe; - int ch; + int ch, quiet = 0; struct got_update_progress_arg upa; TAILQ_INIT(&paths); - while ((ch = getopt(argc, argv, "b:c:")) != -1) { + while ((ch = getopt(argc, argv, "b:c:q")) != -1) { switch (ch) { case 'b': branch_name = optarg; @@ -3218,6 +3269,9 @@ cmd_update(int argc, char *argv[]) if (commit_id_str == NULL) return got_error_from_errno("strdup"); break; + case 'q': + quiet = 1; + break; default: usage_update(); /* NOTREACHED */ @@ -3339,8 +3393,12 @@ cmd_update(int argc, char *argv[]) } memset(&upa, 0, sizeof(upa)); - error = got_worktree_checkout_files(worktree, &paths, repo, - update_progress, &upa, check_cancelled, NULL); + if (quiet) + error = got_worktree_checkout_files(worktree, &paths, repo, + update_quiet, &upa, check_cancelled, NULL); + else + error = got_worktree_checkout_files(worktree, &paths, repo, + update_progress, &upa, check_cancelled, NULL); if (error != NULL) goto done;