diff options
author | Ori Bernstein <ori@eigenstate.org> | 2021-06-20 17:07:33 +0000 |
---|---|---|
committer | Ori Bernstein <ori@eigenstate.org> | 2021-06-20 17:07:33 +0000 |
commit | eeb0f9a9dad1c09ba2c0985b1af2c99b1bebe4c1 (patch) | |
tree | 3e30a74e9b49ddae0484f4a888390cbbeb29596c /sys/src/cmd/git | |
parent | a87a4b763f58eb51ccfd5a9a394258c9398176aa (diff) |
git/log: handle absolute paths gracefully.
strip off the repo prefix if the path given
is absolute, and then look up as though it
was rooted in the repo.
Diffstat (limited to 'sys/src/cmd/git')
-rw-r--r-- | sys/src/cmd/git/log.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/sys/src/cmd/git/log.c b/sys/src/cmd/git/log.c index 4f2c7f809..2a0692aba 100644 --- a/sys/src/cmd/git/log.c +++ b/sys/src/cmd/git/log.c @@ -282,7 +282,7 @@ void main(int argc, char **argv) { char path[1024], repo[1024], *p, *r; - int i; + int i, nrepo; ARGBEGIN{ case 'e': @@ -301,15 +301,21 @@ main(int argc, char **argv) if(findrepo(repo, sizeof(repo)) == -1) sysfatal("find root: %r"); + nrepo = strlen(repo); if(argc != 0){ if(getwd(path, sizeof(path)) == nil) sysfatal("getwd: %r"); - if(strlen(path) < strlen(repo)) - sysfatal("path changed"); - p = path + strlen(repo); + if(strncmp(path, repo, nrepo) != 0) + sysfatal("path shifted??"); + p = path + nrepo; pathfilt = emalloc(sizeof(Pfilt)); for(i = 0; i < argc; i++){ - r = smprint("./%s/%s", p, argv[i]); + if(*argv[i] == '/'){ + if(strncmp(argv[i], repo, nrepo) != 0) + continue; + r = smprint("./%s", argv[i]+nrepo); + }else + r = smprint("./%s/%s", p, argv[i]); cleanname(r); filteradd(pathfilt, r); free(r); |