From: Tracey Emery Subject: got status -q To: gameoftrees@openbsd.org Date: Mon, 13 Sep 2021 15:06:43 -0600 Hello, This diff suppresses the output of unversioned files in got status. Is this of interest to anyone? It'll be super handy for me, especially in ports where there is constant churn in mystuff, and not everything I was to version. Yes, I know got status -s can solve this problem, but -q is a lot quicker. Thoughts? -- Tracey Emery diff 4ad4a1ec452e58730b6d841ae6a044ff53827e15 /home/tracey/src/got blob - 562571621fea9038dfaca7cfec630342fde17210 file + got/got.1 --- got/got.1 +++ got/got.1 @@ -658,7 +658,7 @@ Silence progress output. .It Cm up Short alias for .Cm update . -.It Cm status Oo Fl I Oc Oo Fl s Ar status-codes Oc Op Ar path ... +.It Cm status Oo Fl I Oc Oo Fl s Ar status-codes Oc Oo Fl q Oc Op Ar path ... Show the current modification status of files in a work tree, using the following status codes: .Bl -column YXZ description @@ -711,6 +711,8 @@ argument. Any combination of codes from the above list of possible status codes may be specified. For staged files, status codes displayed in either column will be matched. +.It Fl q +Suppress the output of any unversioned files. .El .Pp For compatibility with blob - e0fa2127a56f4fd45394cbea92d0f7cbe3ce866f file + got/got.c --- got/got.c +++ got/got.c @@ -5224,31 +5224,41 @@ done: __dead static void usage_status(void) { - fprintf(stderr, "usage: %s status [-I] [-s status-codes ] [path ...]\n", - getprogname()); + fprintf(stderr, "usage: %s status [-I] [-s status-codes ] [-q] " + "[path ...]\n", getprogname()); exit(1); } +struct got_status_arg { + char *status_codes; + int verbosity; +}; + static const struct got_error * print_status(void *arg, unsigned char status, unsigned char staged_status, const char *path, struct got_object_id *blob_id, struct got_object_id *staged_blob_id, struct got_object_id *commit_id, int dirfd, const char *de_name) { + struct got_status_arg *st = arg; + if (status == staged_status && (status == GOT_STATUS_DELETE)) status = GOT_STATUS_NO_CHANGE; - if (arg) { - char *status_codes = arg; - size_t ncodes = strlen(status_codes); + if (st != NULL && st->status_codes) { + size_t ncodes = strlen(st->status_codes); int i; for (i = 0; i < ncodes ; i++) { - if (status == status_codes[i] || - staged_status == status_codes[i]) + if (status == st->status_codes[i] || + staged_status == st->status_codes[i]) break; } if (i == ncodes) return NULL; } + + if (st != NULL && st->verbosity < 0 && status == GOT_STATUS_UNVERSIONED) + return NULL; + printf("%c%c %s\n", status, staged_status, path); return NULL; } @@ -5259,14 +5269,19 @@ cmd_status(int argc, char *argv[]) const struct got_error *error = NULL; struct got_repository *repo = NULL; struct got_worktree *worktree = NULL; - char *cwd = NULL, *status_codes = NULL;; + struct got_status_arg st; + char *cwd = NULL; struct got_pathlist_head paths; struct got_pathlist_entry *pe; int ch, i, no_ignores = 0; TAILQ_INIT(&paths); - while ((ch = getopt(argc, argv, "Is:")) != -1) { + memset(&st, 0, sizeof(st)); + st.status_codes = NULL; + st.verbosity = 0; + + while ((ch = getopt(argc, argv, "Is:q")) != -1) { switch (ch) { case 'I': no_ignores = 1; @@ -5289,8 +5304,11 @@ cmd_status(int argc, char *argv[]) optarg[i]); } } - status_codes = optarg; + st.status_codes = optarg; break; + case 'q': + st.verbosity = -1; + break; default: usage_status(); /* NOTREACHED */ @@ -5333,7 +5351,7 @@ cmd_status(int argc, char *argv[]) goto done; error = got_worktree_status(worktree, &paths, repo, no_ignores, - print_status, status_codes, check_cancelled, NULL); + print_status, &st, check_cancelled, NULL); done: TAILQ_FOREACH(pe, &paths, entry) free((char *)pe->path);