From 590724e3bb01a899e26200d0376be00bc213c62d Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Tue, 2 Aug 2016 10:45:40 -0300 Subject: [PATCH] sch2fig/git-file.c: keep the repo root search simple I originally planned to attach the (deleted) tail after splitting the path of existing things into path_to_repo and path_in_repo, but it's easier if we just do the search on the combined path. This means that stat() will fail while we're in the deleted part of the path. --- sch2fig/git-file.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/sch2fig/git-file.c b/sch2fig/git-file.c index 9e0cb0f..098f136 100644 --- a/sch2fig/git-file.c +++ b/sch2fig/git-file.c @@ -210,27 +210,20 @@ static char *canonical_path_into_repo(const char *repo_dir, const char *path) if (verbose > 1) fprintf(stderr, "full object path \"%s\"\n", tmp); - /* find which part of out path is inside the repo */ + /* 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); - /* - * This should never fail, unless someone has been changing - * things while we were searching. - */ - if (stat(tmp, &path_st) < 0) { - perror(tmp); - exit(1); - } - if (path_st.st_dev == repo_st.st_dev && + if (stat(tmp, &path_st) == 0 && + path_st.st_dev == repo_st.st_dev && path_st.st_ino == repo_st.st_ino) break; - /* another "this cannot happen" problem */ + /* "this cannot happen" */ if (tail == tmp) { fprintf(stderr, "divergent paths:\nrepo \"%s\"\nobject \"%s\"\n",