summaryrefslogtreecommitdiff
path: root/file
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2016-09-04 13:43:05 (GMT)
committerWerner Almesberger <werner@almesberger.net>2016-09-04 13:47:50 (GMT)
commitf610e9857baf67d75043ed3a90accb3a7d7cc176 (patch)
treecfcfbdb2e69e366c504f18d1e8de8ba1e30f65d2 /file
parent147ad32101633099e7d29b9999348fc1b53090b0 (diff)
downloadeeshow-f610e9857baf67d75043ed3a90accb3a7d7cc176.zip
eeshow-f610e9857baf67d75043ed3a90accb3a7d7cc176.tar.gz
eeshow-f610e9857baf67d75043ed3a90accb3a7d7cc176.tar.bz2
file/git-file.c (canonical_path_into_repo): avoid fatal error if we leave repo
Instead, we give up and let the caller look for alternatives.
Diffstat (limited to 'file')
-rw-r--r--file/git-file.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/file/git-file.c b/file/git-file.c
index 3d67f8f..149143c 100644
--- a/file/git-file.c
+++ b/file/git-file.c
@@ -222,6 +222,20 @@ static char *canonical_path_into_repo(const char *repo_dir, const char *path)
progress(2, "full object path \"%s\"", tmp);
+ /*
+ * Re-validate path. If this fails, just give up and leave it to
+ * caller to implement fallbacks to save the day.
+ *
+ * @@@ we should also check if we've ended up in a different repo
+ * @@@ we could try to search again, with the new path. Crossing
+ * from repo back to file could get "interesting".
+ */
+
+ if (!select_repo(tmp)) {
+ error("%s: outside repository", tmp);
+ return NULL;
+ }
+
/* find which part of our path is inside the repo */
end = tail = strchr(tmp, 0);
@@ -237,7 +251,7 @@ static char *canonical_path_into_repo(const char *repo_dir, const char *path)
/* "this cannot happen" */
if (tail == tmp || !slash)
- fatal("divergent paths:\nrepo \"%s\"\nobject \"%s\"\n",
+ fatal("divergent paths:\nrepo \"%s\"\nobject \"%s\"",
repo_dir, tail);
if (tail != end)
@@ -276,6 +290,8 @@ static git_tree_entry *find_file(git_repository *repo, git_tree *tree,
canon_path = canonical_path_into_repo(repo_path, path);
free(repo_path);
+ if (!canon_path)
+ return NULL;
if (git_tree_entry_bypath(&entry, tree, canon_path)) {
perror_git(path);