allow controlling verbosity of 'got clone' with -q and -v options
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 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
diff --git a/got/got.1 b/got/got.1
index 1808e18..1e1b77c 100644
--- a/got/got.1
+++ b/got/got.1
@@ -200,7 +200,7 @@ will be checked out.
.It Cm co
Short alias for
.Cm checkout .
-.It Cm clone Ar repository-URL Op Ar target-directory
+.It Cm clone Oo Fl q Oc Oo Fl v Oc Ar repository-URL Op Ar target-directory
Clone a Git repository at the specified
.Ar repository-URL
into the specified
@@ -239,6 +239,24 @@ to use:
.It ssh
Short alias for git+ssh.
.El
+.Pp
+The options for
+.Cm got clone
+are as follows:
+.Bl -tag -width Ds
+.It Fl q
+Suppress progress reporting output.
+The same option will be passed to
+.Xr ssh 1
+if applicable.
+.It Fl v
+Increase the verbosity of progress reporting output.
+The same option will be passed to
+.Xr ssh 1
+if applicable.
+Multiple -v options increase the verbosity.
+The maximum is 3.
+.El
.It Cm update Oo Fl b Ar branch Oc Oo Fl c Ar commit Oc Op Ar path ...
Update an existing work tree to a different commit.
Show the status of each affected file, using the following status codes:
diff --git a/got/got.c b/got/got.c
index ed5822f..799c85e 100644
--- a/got/got.c
+++ b/got/got.c
@@ -808,7 +808,7 @@ done:
__dead static void
usage_clone(void)
{
- fprintf(stderr, "usage: %s clone repository-url [target-directory]\n",
+ fprintf(stderr, "usage: %s clone [-q] [-v] repository-url [target-directory]\n",
getprogname());
exit(1);
}
@@ -974,6 +974,7 @@ struct got_fetch_progress_arg {
char last_scaled_size[FMT_SCALED_STRSIZE];
int last_p_indexed;
int last_p_resolved;
+ int verbosity;
};
static const struct got_error *
@@ -985,6 +986,9 @@ fetch_progress(void *arg, const char *message, off_t packfile_size,
int p_indexed, p_resolved;
int print_size = 0, print_indexed = 0, print_resolved = 0;
+ if (a->verbosity < 0)
+ return NULL;
+
if (message && message[0] != '\0' && message[0] != '\n') {
printf("\rserver: %s", message);
if (strchr(message, '\n') == 0)
@@ -1025,10 +1029,17 @@ fetch_progress(void *arg, const char *message, off_t packfile_size,
printf("\r");
if (print_size)
printf("%*s fetched", FMT_SCALED_STRSIZE, scaled_size);
- if (print_indexed)
+ if (print_indexed) {
printf("; indexing %d%%", p_indexed);
- if (print_resolved)
+ if (a->verbosity > 0)
+ printf(" (%d/%d)", nobj_indexed, nobj_total);
+ }
+ if (print_resolved) {
printf("; resolving deltas %d%%", p_resolved);
+ if (a->verbosity > 0)
+ printf(" (%d/%d)", nobj_resolved,
+ nobj_total - nobj_loose);
+ }
if (print_size || print_indexed || print_resolved)
fflush(stdout);
@@ -1058,12 +1069,22 @@ cmd_clone(int argc, char *argv[])
char *gitconfig = NULL;
FILE *gitconfig_file = NULL;
ssize_t n;
+ int verbosity = 0;
TAILQ_INIT(&refs);
TAILQ_INIT(&symrefs);
- while ((ch = getopt(argc, argv, "")) != -1) {
+ while ((ch = getopt(argc, argv, "vq")) != -1) {
switch (ch) {
+ case 'v':
+ if (verbosity < 0)
+ verbosity = 0;
+ else if (verbosity < 3)
+ verbosity++;
+ break;
+ case 'q':
+ verbosity = -1;
+ break;
default:
usage_clone();
break;
@@ -1148,15 +1169,18 @@ cmd_clone(int argc, char *argv[])
if (error)
goto done;
- error = got_fetch_connect(&fetchfd, proto, host, port, server_path);
+ error = got_fetch_connect(&fetchfd, proto, host, port, server_path,
+ verbosity);
if (error)
goto done;
- printf("Connected to %s:%s\n", host, port);
+ if (verbosity >= 0)
+ printf("Connected to %s:%s\n", host, port);
fpa.last_scaled_size[0] = '\0';
fpa.last_p_indexed = -1;
fpa.last_p_resolved = -1;
+ fpa.verbosity = verbosity;
error = got_fetch_pack(&pack_hash, &refs, &symrefs, fetchfd,
repo, fetch_progress, &fpa);
if (error)
@@ -1165,7 +1189,8 @@ cmd_clone(int argc, char *argv[])
error = got_object_id_str(&id_str, pack_hash);
if (error)
goto done;
- printf("Fetched %s.pack\n", id_str);
+ if (verbosity >= 0)
+ printf("Fetched %s.pack\n", id_str);
free(id_str);
/* Set up references provided with the pack file. */
@@ -1222,8 +1247,10 @@ cmd_clone(int argc, char *argv[])
if (error)
goto done;
- printf("Setting %s to %s\n", GOT_REF_HEAD,
- got_ref_get_symref_target(symref));
+ if (verbosity > 1) {
+ printf("Setting %s to %s\n", GOT_REF_HEAD,
+ got_ref_get_symref_target(symref));
+ }
error = got_ref_write(symref, repo);
got_ref_close(symref);
diff --git a/include/got_fetch.h b/include/got_fetch.h
index f0f4c2b..d7b583b 100644
--- a/include/got_fetch.h
+++ b/include/got_fetch.h
@@ -38,11 +38,14 @@ const struct got_error *got_fetch_parse_uri(char **, char **, char **,
/*
* Attempt to open a connection to a server using the provided protocol
* scheme, hostname port number (as a string) and server-side path.
+ * A verbosity level can be specified; it currently controls the amount
+ * of -v options passed to ssh(1). If the level is -1 ssh(1) will be run
+ * with the -q option.
* If successful return an open file descriptor for the connection which can
* be passed to other functions below, and must be disposed of with close(2).
*/
const struct got_error *got_fetch_connect(int *, const char *, const char *,
- const char *, const char *);
+ const char *, const char *, int);
/* A callback function which gets invoked with progress information to print. */
typedef const struct got_error *(*got_fetch_progress_cb)(void *,
diff --git a/lib/fetch.c b/lib/fetch.c
index 4a328e6..c82af73 100644
--- a/lib/fetch.c
+++ b/lib/fetch.c
@@ -66,6 +66,10 @@
#define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
#endif
+#ifndef MIN
+#define MIN(_a,_b) ((_a) < (_b) ? (_a) : (_b))
+#endif
+
static int
hassuffix(char *base, char *suf)
{
@@ -80,14 +84,30 @@ hassuffix(char *base, char *suf)
static const struct got_error *
dial_ssh(int *fetchfd, const char *host, const char *port, const char *path,
- const char *direction)
+ const char *direction, int verbosity)
{
const struct got_error *error = NULL;
int pid, pfd[2];
char cmd[64];
+ char *argv[9];
+ int i = 0;
*fetchfd = -1;
+ argv[0] = GOT_FETCH_PATH_SSH;
+ if (verbosity == -1) {
+ argv[1 + i++] = "-q";
+ } else {
+ /* ssh(1) allows up to 3 "-v" options. */
+ for (i = 0; i < MIN(3, verbosity); i++)
+ argv[1 + i] = "-v";
+ }
+ argv[1 + i] = "--";
+ argv[2 + i] = (char *)host;
+ argv[3 + i] = (char *)cmd;
+ argv[4 + i] = (char *)path;
+ argv[5 + i] = NULL;
+
if (pipe(pfd) == -1)
return got_error_from_errno("pipe");
@@ -105,8 +125,7 @@ dial_ssh(int *fetchfd, const char *host, const char *port, const char *path,
n = snprintf(cmd, sizeof(cmd), "git-%s-pack", direction);
if (n < 0 || n >= sizeof(cmd))
err(1, "snprintf");
- if (execl(GOT_FETCH_PATH_SSH, GOT_FETCH_PATH_SSH, "--",
- host, cmd, path, NULL) == -1)
+ if (execv(GOT_FETCH_PATH_SSH, argv) == -1)
err(1, "execl");
abort(); /* not reached */
} else {
@@ -186,14 +205,15 @@ done:
const struct got_error *
got_fetch_connect(int *fetchfd, const char *proto, const char *host,
- const char *port, const char *server_path)
+ const char *port, const char *server_path, int verbosity)
{
const struct got_error *err = NULL;
*fetchfd = -1;
if (strcmp(proto, "ssh") == 0 || strcmp(proto, "git+ssh") == 0)
- err = dial_ssh(fetchfd, host, port, server_path, "upload");
+ err = dial_ssh(fetchfd, host, port, server_path, "upload",
+ verbosity);
else if (strcmp(proto, "git") == 0)
err = dial_git(fetchfd, host, port, server_path, "upload");
else if (strcmp(proto, "http") == 0 || strcmp(proto, "git+http") == 0)