mirror of
git://projects.qi-hardware.com/eda-tools.git
synced 2024-12-01 20:01:52 +02:00
eeshow/: output progress messages with "progress"
This commit is contained in:
parent
5581a34444
commit
3e236d0456
@ -10,7 +10,26 @@
|
|||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
|
||||||
#include "diag.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);
|
||||||
|
}
|
||||||
|
@ -20,6 +20,14 @@
|
|||||||
* > 2: go wild !
|
* > 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 */
|
#endif /* !DIAG_H */
|
||||||
|
@ -89,8 +89,7 @@ static bool try_related(struct file *file)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (verbose)
|
progress(1, "reading %s\n", tmp);
|
||||||
fprintf(stderr, "reading %s\n", tmp);
|
|
||||||
|
|
||||||
free((char *) file->name);
|
free((char *) file->name);
|
||||||
file->name = tmp;
|
file->name = tmp;
|
||||||
@ -139,17 +138,14 @@ static void *open_vcs(struct file *file)
|
|||||||
free(tmp);
|
free(tmp);
|
||||||
return file->vcs;
|
return file->vcs;
|
||||||
}
|
}
|
||||||
if (verbose > 1)
|
progress(2, "could not open %s:%s\n", tmp, colon + 1);
|
||||||
fprintf(stderr, "could not open %s:%s\n",
|
|
||||||
tmp, colon + 1);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
} else {
|
} else {
|
||||||
file->vcs = vcs_git_open(NULL, file->name,
|
file->vcs = vcs_git_open(NULL, file->name,
|
||||||
file->related ? file->related->vcs : NULL);
|
file->related ? file->related->vcs : NULL);
|
||||||
if (file->vcs)
|
if (file->vcs)
|
||||||
return file->vcs;
|
return file->vcs;
|
||||||
if (verbose > 1)
|
progress(2, "could not open %s\n", file->name);
|
||||||
fprintf(stderr, "could not open %s\n", file->name);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -178,8 +174,7 @@ bool file_open(struct file *file, const char *name, const struct file *related)
|
|||||||
|
|
||||||
file->file = fopen(name, "r");
|
file->file = fopen(name, "r");
|
||||||
if (file->file) {
|
if (file->file) {
|
||||||
if (verbose)
|
progress(1, "reading %s\n", name);
|
||||||
fprintf(stderr, "reading %s\n", name);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -187,7 +182,7 @@ bool file_open(struct file *file, const char *name, const struct file *related)
|
|||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
if (verbose)
|
if (verbose)
|
||||||
perror(name);
|
perror(name); /* @@@ may need changing later */
|
||||||
|
|
||||||
if (!strchr(name, ':')) {
|
if (!strchr(name, ':')) {
|
||||||
if (!verbose)
|
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);
|
file->vcs = vcs_git_open(rev, name, related ? related->vcs : NULL);
|
||||||
if (file->vcs)
|
if (file->vcs)
|
||||||
return 1;
|
return 1;
|
||||||
if (verbose > 1)
|
progress(2, "could not open %s at %s\n", name, rev);
|
||||||
fprintf(stderr, "could not open %s at %s\n", name, rev);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,8 +76,7 @@ static git_repository *select_repo(const char *path)
|
|||||||
* So we trim off elements until we find a repository.
|
* So we trim off elements until we find a repository.
|
||||||
*/
|
*/
|
||||||
while (1) {
|
while (1) {
|
||||||
if (verbose > 2)
|
progress(3, "trying \"%s\"\n", tmp);
|
||||||
fprintf(stderr, "trying \"%s\"\n", tmp);
|
|
||||||
if (!git_repository_open_ext(&repo, *tmp ? tmp : "/",
|
if (!git_repository_open_ext(&repo, *tmp ? tmp : "/",
|
||||||
GIT_REPOSITORY_OPEN_CROSS_FS, NULL))
|
GIT_REPOSITORY_OPEN_CROSS_FS, NULL))
|
||||||
break;
|
break;
|
||||||
@ -165,9 +164,7 @@ static char *canonical_path_into_repo(const char *repo_dir, const char *path)
|
|||||||
end = tail = strchr(tmp, 0);
|
end = tail = strchr(tmp, 0);
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
if (verbose > 2)
|
progress(3, "probing \"%s\" tail \"%s\"\n", tmp, tail);
|
||||||
fprintf(stderr, "probing \"%s\" tail \"%s\"\n",
|
|
||||||
tmp, tail);
|
|
||||||
if (stat(tmp, &path_st) == 0)
|
if (stat(tmp, &path_st) == 0)
|
||||||
break;
|
break;
|
||||||
if (!tmp[1]) {
|
if (!tmp[1]) {
|
||||||
@ -183,8 +180,7 @@ static char *canonical_path_into_repo(const char *repo_dir, const char *path)
|
|||||||
|
|
||||||
/* remove . and .. from tail */
|
/* remove . and .. from tail */
|
||||||
|
|
||||||
if (verbose > 2)
|
progress(3, "input tail \"%s\"\n", tail);
|
||||||
fprintf(stderr, "input tail \"%s\"\n", tail);
|
|
||||||
from = to = tail;
|
from = to = tail;
|
||||||
while (1) {
|
while (1) {
|
||||||
if (!strncmp(from, "./", 2)) {
|
if (!strncmp(from, "./", 2)) {
|
||||||
@ -224,14 +220,12 @@ static char *canonical_path_into_repo(const char *repo_dir, const char *path)
|
|||||||
to--;
|
to--;
|
||||||
}
|
}
|
||||||
*to = 0;
|
*to = 0;
|
||||||
if (verbose > 2)
|
progress(3, "output tail \"%s\"\n", tail);
|
||||||
fprintf(stderr, "output tail \"%s\"\n", tail);
|
|
||||||
|
|
||||||
/* resolve all symlinks */
|
/* resolve all symlinks */
|
||||||
|
|
||||||
real = realpath(tmp, NULL);
|
real = realpath(tmp, NULL);
|
||||||
if (verbose > 2)
|
progress(3, "realpath(\"%s\") = \"%s\"\n", tmp, real);
|
||||||
fprintf(stderr, "realpath(\"%s\") = \"%s\"\n", tmp, real);
|
|
||||||
|
|
||||||
/* append tail */
|
/* append tail */
|
||||||
|
|
||||||
@ -245,16 +239,13 @@ static char *canonical_path_into_repo(const char *repo_dir, const char *path)
|
|||||||
free(tmp);
|
free(tmp);
|
||||||
tmp = tmp2;
|
tmp = tmp2;
|
||||||
|
|
||||||
if (verbose > 1)
|
progress(2, "full object path \"%s\"\n", tmp);
|
||||||
fprintf(stderr, "full object path \"%s\"\n", tmp);
|
|
||||||
|
|
||||||
/* find which part of our path is inside the repo */
|
/* find which part of our path is inside the repo */
|
||||||
|
|
||||||
end = tail = strchr(tmp, 0);
|
end = tail = strchr(tmp, 0);
|
||||||
while (1) {
|
while (1) {
|
||||||
if (verbose > 2)
|
progress(3, "trying \"%s\" tail \"%s\"\n", tmp, tail);
|
||||||
fprintf(stderr, "trying \"%s\" tail \"%s\"\n",
|
|
||||||
tmp, tail);
|
|
||||||
|
|
||||||
if (stat(tmp, &path_st) == 0 &&
|
if (stat(tmp, &path_st) == 0 &&
|
||||||
path_st.st_dev == repo_st.st_dev &&
|
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;
|
*slash = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (verbose > 1)
|
progress(2, "path in repo \"%s\"\n", tail);
|
||||||
fprintf(stderr, "path in repo \"%s\"\n", tail);
|
|
||||||
|
|
||||||
tmp2 = stralloc(tail);
|
tmp2 = stralloc(tail);
|
||||||
free(tmp);
|
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"))
|
if (len >= 5 && !strcmp(repo_path + len - 5, "/.git"))
|
||||||
repo_path[len == 5 ? 1 : len - 5] = 0;
|
repo_path[len == 5 ? 1 : len - 5] = 0;
|
||||||
|
|
||||||
if (verbose > 1)
|
progress(2, "repo dir \"%s\"\n", repo_path);
|
||||||
fprintf(stderr, "repo dir \"%s\"\n", repo_path);
|
|
||||||
|
|
||||||
canon_path = canonical_path_into_repo(repo_path, path);
|
canon_path = canonical_path_into_repo(repo_path, path);
|
||||||
free(repo_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);
|
fprintf(stderr, "%s\n", e->message);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
fprintf(stderr, "object %s\n", buf.ptr);
|
progress(3, "object %s\n", buf.ptr);
|
||||||
git_buf_free(&buf);
|
git_buf_free(&buf);
|
||||||
}
|
}
|
||||||
blob = (git_blob *) obj;
|
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);
|
entry = find_file(vcs_git->repo, vcs_git->tree, name);
|
||||||
if (!entry)
|
if (!entry)
|
||||||
return 0;
|
return 0;
|
||||||
if (verbose)
|
progress(1, "reading %s\n", name);
|
||||||
fprintf(stderr, "reading %s\n", name);
|
|
||||||
|
|
||||||
vcs_git->data = get_data(vcs_git, entry, &vcs_git->size);
|
vcs_git->data = get_data(vcs_git, entry, &vcs_git->size);
|
||||||
return 1;
|
return 1;
|
||||||
@ -418,8 +406,7 @@ static bool related_only_repo(struct vcs_git *vcs_git)
|
|||||||
const struct vcs_git *related = vcs_git->related;
|
const struct vcs_git *related = vcs_git->related;
|
||||||
char *tmp;
|
char *tmp;
|
||||||
|
|
||||||
if (verbose > 1)
|
progress(2, "trying graft \"%s\" \"%s\"\n",
|
||||||
fprintf(stderr, "trying graft \"%s\" \"%s\"\n",
|
|
||||||
related->name, vcs_git->name);
|
related->name, vcs_git->name);
|
||||||
tmp = file_graft_relative(related->name, vcs_git->name);
|
tmp = file_graft_relative(related->name, vcs_git->name);
|
||||||
if (!tmp)
|
if (!tmp)
|
||||||
@ -479,8 +466,7 @@ struct vcs_git *vcs_git_open(const char *revision, const char *name,
|
|||||||
fprintf(stderr, "%s: not found\n", name);
|
fprintf(stderr, "%s: not found\n", name);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
if (verbose > 1)
|
progress(2, "using repository %s\n",
|
||||||
fprintf(stderr, "using repository %s\n",
|
|
||||||
git_repository_path(vcs_git->repo));
|
git_repository_path(vcs_git->repo));
|
||||||
|
|
||||||
if (!revision)
|
if (!revision)
|
||||||
|
Loading…
Reference in New Issue
Block a user