summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2016-08-11 17:00:44 -0300
committerWerner Almesberger <werner@almesberger.net>2016-08-11 17:44:26 -0300
commit073b91b1273029b07e0f3028022b35aef54c7143 (patch)
tree0f141bae7d4c85e922727d4bfd0a5f058fcc35a8
parent53f1d782d0bb369da3bd7e2e3d09cd78c959ac9c (diff)
downloadeeshow-073b91b1273029b07e0f3028022b35aef54c7143.tar.gz
eeshow-073b91b1273029b07e0f3028022b35aef54c7143.tar.bz2
eeshow-073b91b1273029b07e0f3028022b35aef54c7143.zip
eeshow/: output progress messages with "progress"
-rw-r--r--diag.c21
-rw-r--r--diag.h10
-rw-r--r--file.c18
-rw-r--r--git-file.c44
4 files changed, 50 insertions, 43 deletions
diff --git a/diag.c b/diag.c
index c50b227..1650f81 100644
--- a/diag.c
+++ b/diag.c
@@ -10,7 +10,26 @@
* (at your option) any later version.
*/
+
+#include <stdarg.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+
#include "diag.h"
-int verbose = 0;
+unsigned verbose = 0;
+
+
+void progress(unsigned level, const char *fmt, ...)
+{
+ va_list ap;
+
+ if (level > verbose)
+ return;
+ va_start(ap, fmt);
+ fprintf(stderr, "%*s", level * 2, "");
+ vfprintf(stderr, fmt, ap);
+ va_end(ap);
+}
diff --git a/diag.h b/diag.h
index 8f22af4..8abac6f 100644
--- a/diag.h
+++ b/diag.h
@@ -20,6 +20,14 @@
* > 2: go wild !
*/
-extern int verbose;
+extern unsigned verbose;
+
+
+/*
+ * Progress message, used mainly for debugging. "level" is the minimum
+ * verbosity level required.
+ */
+
+void progress(unsigned level, const char *fmt, ...);
#endif /* !DIAG_H */
diff --git a/file.c b/file.c
index 233b1d1..fe687f5 100644
--- a/file.c
+++ b/file.c
@@ -89,8 +89,7 @@ static bool try_related(struct file *file)
return 0;
}
- if (verbose)
- fprintf(stderr, "reading %s\n", tmp);
+ progress(1, "reading %s\n", tmp);
free((char *) file->name);
file->name = tmp;
@@ -139,17 +138,14 @@ static void *open_vcs(struct file *file)
free(tmp);
return file->vcs;
}
- if (verbose > 1)
- fprintf(stderr, "could not open %s:%s\n",
- tmp, colon + 1);
+ progress(2, "could not open %s:%s\n", tmp, colon + 1);
return NULL;
} else {
file->vcs = vcs_git_open(NULL, file->name,
file->related ? file->related->vcs : NULL);
if (file->vcs)
return file->vcs;
- if (verbose > 1)
- fprintf(stderr, "could not open %s\n", file->name);
+ progress(2, "could not open %s\n", file->name);
return NULL;
}
}
@@ -178,8 +174,7 @@ bool file_open(struct file *file, const char *name, const struct file *related)
file->file = fopen(name, "r");
if (file->file) {
- if (verbose)
- fprintf(stderr, "reading %s\n", name);
+ progress(1, "reading %s\n", name);
return 1;
}
@@ -187,7 +182,7 @@ bool file_open(struct file *file, const char *name, const struct file *related)
return 1;
if (verbose)
- perror(name);
+ perror(name); /* @@@ may need changing later */
if (!strchr(name, ':')) {
if (!verbose)
@@ -216,8 +211,7 @@ bool file_open_revision(struct file *file, const char *rev, const char *name,
file->vcs = vcs_git_open(rev, name, related ? related->vcs : NULL);
if (file->vcs)
return 1;
- if (verbose > 1)
- fprintf(stderr, "could not open %s at %s\n", name, rev);
+ progress(2, "could not open %s at %s\n", name, rev);
return 0;
}
diff --git a/git-file.c b/git-file.c
index 74f26c3..b450155 100644
--- a/git-file.c
+++ b/git-file.c
@@ -76,8 +76,7 @@ static git_repository *select_repo(const char *path)
* So we trim off elements until we find a repository.
*/
while (1) {
- if (verbose > 2)
- fprintf(stderr, "trying \"%s\"\n", tmp);
+ progress(3, "trying \"%s\"\n", tmp);
if (!git_repository_open_ext(&repo, *tmp ? tmp : "/",
GIT_REPOSITORY_OPEN_CROSS_FS, NULL))
break;
@@ -165,9 +164,7 @@ static char *canonical_path_into_repo(const char *repo_dir, const char *path)
end = tail = strchr(tmp, 0);
while (1) {
- if (verbose > 2)
- fprintf(stderr, "probing \"%s\" tail \"%s\"\n",
- tmp, tail);
+ progress(3, "probing \"%s\" tail \"%s\"\n", tmp, tail);
if (stat(tmp, &path_st) == 0)
break;
if (!tmp[1]) {
@@ -183,8 +180,7 @@ static char *canonical_path_into_repo(const char *repo_dir, const char *path)
/* remove . and .. from tail */
- if (verbose > 2)
- fprintf(stderr, "input tail \"%s\"\n", tail);
+ progress(3, "input tail \"%s\"\n", tail);
from = to = tail;
while (1) {
if (!strncmp(from, "./", 2)) {
@@ -224,14 +220,12 @@ static char *canonical_path_into_repo(const char *repo_dir, const char *path)
to--;
}
*to = 0;
- if (verbose > 2)
- fprintf(stderr, "output tail \"%s\"\n", tail);
+ progress(3, "output tail \"%s\"\n", tail);
/* resolve all symlinks */
real = realpath(tmp, NULL);
- if (verbose > 2)
- fprintf(stderr, "realpath(\"%s\") = \"%s\"\n", tmp, real);
+ progress(3, "realpath(\"%s\") = \"%s\"\n", tmp, real);
/* append tail */
@@ -245,16 +239,13 @@ static char *canonical_path_into_repo(const char *repo_dir, const char *path)
free(tmp);
tmp = tmp2;
- if (verbose > 1)
- fprintf(stderr, "full object path \"%s\"\n", tmp);
+ progress(2, "full object path \"%s\"\n", tmp);
/* find which part of our path is inside the repo */
end = tail = strchr(tmp, 0);
while (1) {
- if (verbose > 2)
- fprintf(stderr, "trying \"%s\" tail \"%s\"\n",
- tmp, tail);
+ progress(3, "trying \"%s\" tail \"%s\"\n", tmp, tail);
if (stat(tmp, &path_st) == 0 &&
path_st.st_dev == repo_st.st_dev &&
@@ -277,8 +268,7 @@ static char *canonical_path_into_repo(const char *repo_dir, const char *path)
*slash = 0;
}
- if (verbose > 1)
- fprintf(stderr, "path in repo \"%s\"\n", tail);
+ progress(2, "path in repo \"%s\"\n", tail);
tmp2 = stralloc(tail);
free(tmp);
@@ -303,8 +293,7 @@ static git_tree_entry *find_file(git_repository *repo, git_tree *tree,
if (len >= 5 && !strcmp(repo_path + len - 5, "/.git"))
repo_path[len == 5 ? 1 : len - 5] = 0;
- if (verbose > 1)
- fprintf(stderr, "repo dir \"%s\"\n", repo_path);
+ progress(2, "repo dir \"%s\"\n", repo_path);
canon_path = canonical_path_into_repo(repo_path, path);
free(repo_path);
@@ -350,7 +339,7 @@ static const void *get_data(struct vcs_git *vcs_git, git_tree_entry *entry,
fprintf(stderr, "%s\n", e->message);
exit(1);
}
- fprintf(stderr, "object %s\n", buf.ptr);
+ progress(3, "object %s\n", buf.ptr);
git_buf_free(&buf);
}
blob = (git_blob *) obj;
@@ -381,8 +370,7 @@ static bool access_file_data(struct vcs_git *vcs_git, const char *name)
entry = find_file(vcs_git->repo, vcs_git->tree, name);
if (!entry)
return 0;
- if (verbose)
- fprintf(stderr, "reading %s\n", name);
+ progress(1, "reading %s\n", name);
vcs_git->data = get_data(vcs_git, entry, &vcs_git->size);
return 1;
@@ -418,9 +406,8 @@ static bool related_only_repo(struct vcs_git *vcs_git)
const struct vcs_git *related = vcs_git->related;
char *tmp;
- if (verbose > 1)
- fprintf(stderr, "trying graft \"%s\" \"%s\"\n",
- related->name, vcs_git->name);
+ progress(2, "trying graft \"%s\" \"%s\"\n",
+ related->name, vcs_git->name);
tmp = file_graft_relative(related->name, vcs_git->name);
if (!tmp)
return 0;
@@ -479,9 +466,8 @@ struct vcs_git *vcs_git_open(const char *revision, const char *name,
fprintf(stderr, "%s: not found\n", name);
goto fail;
}
- if (verbose > 1)
- fprintf(stderr, "using repository %s\n",
- git_repository_path(vcs_git->repo));
+ progress(2, "using repository %s\n",
+ git_repository_path(vcs_git->repo));
if (!revision)
revision = "HEAD";