Commit 23721109e309187ba1da65d068dc11ccf30fe835

Stefan Sperling 2018-10-22T23:47:25

fix logging /sys in tog while /sys symlink exists on disk

diff --git a/got/got.c b/got/got.c
index 398bd39..d390e0e 100644
--- a/got/got.c
+++ b/got/got.c
@@ -551,7 +551,7 @@ cmd_log(int argc, char *argv[])
 		goto done;
 	}
 
-	error = got_repo_map_path(&in_repo_path, repo, path);
+	error = got_repo_map_path(&in_repo_path, repo, path, 1);
 	if (error != NULL)
 		goto done;
 	if (in_repo_path) {
@@ -749,7 +749,7 @@ cmd_blame(int argc, char *argv[])
 	if (error != NULL)
 		goto done;
 
-	error = got_repo_map_path(&in_repo_path, repo, path);
+	error = got_repo_map_path(&in_repo_path, repo, path, 1);
 	if (error != NULL)
 		goto done;
 
@@ -905,7 +905,7 @@ cmd_tree(int argc, char *argv[])
 	if (error != NULL)
 		goto done;
 
-	error = got_repo_map_path(&in_repo_path, repo, path);
+	error = got_repo_map_path(&in_repo_path, repo, path, 1);
 	if (error != NULL)
 		goto done;
 
diff --git a/include/got_repository.h b/include/got_repository.h
index 2fd4ddd..37f50bb 100644
--- a/include/got_repository.h
+++ b/include/got_repository.h
@@ -45,4 +45,4 @@ int got_repo_is_bare(struct got_repository *);
 
 /* Attempt to map an arbitrary path to a path within the repository. */
 const struct got_error *got_repo_map_path(char **, struct got_repository *,
-    const char *);
+    const char *, int);
diff --git a/lib/repository.c b/lib/repository.c
index d45495d..d82e38e 100644
--- a/lib/repository.c
+++ b/lib/repository.c
@@ -433,13 +433,13 @@ got_repo_close(struct got_repository *repo)
 
 const struct got_error *
 got_repo_map_path(char **in_repo_path, struct got_repository *repo,
-    const char *input_path)
+    const char *input_path, int check_disk)
 {
 	const struct got_error *err = NULL;
 	char *repo_abspath = NULL, *cwd = NULL;
 	struct stat sb;
 	size_t repolen, cwdlen, len;
-	char *canonpath, *path;
+	char *canonpath, *path = NULL;
 
 	*in_repo_path = NULL;
 
@@ -464,7 +464,9 @@ got_repo_map_path(char **in_repo_path, struct got_repository *repo,
 
 	/* TODO: Call "get in-repository path of work-tree node" API. */
 
-	if (lstat(canonpath, &sb) != 0) {
+	if (!check_disk)
+		path = strdup(canonpath);
+	else if (lstat(canonpath, &sb) != 0) {
 		if (errno != ENOENT) {
 			err = got_error_from_errno();
 			goto done;
diff --git a/tog/tog.c b/tog/tog.c
index 220eb8c..c90730d 100644
--- a/tog/tog.c
+++ b/tog/tog.c
@@ -270,7 +270,7 @@ static const struct got_error *input_diff_view(struct tog_view **,
 static const struct got_error* close_diff_view(struct tog_view *);
 
 static const struct got_error *open_log_view(struct tog_view *,
-    struct got_object_id *, struct got_repository *, const char *);
+    struct got_object_id *, struct got_repository *, const char *, int);
 static const struct got_error * show_log_view(struct tog_view *);
 static const struct got_error *input_log_view(struct tog_view **,
     struct tog_view **, struct tog_view **, struct tog_view *, int);
@@ -1360,7 +1360,7 @@ close_log_view(struct tog_view *view)
 
 static const struct got_error *
 open_log_view(struct tog_view *view, struct got_object_id *start_id,
-    struct got_repository *repo, const char *path)
+    struct got_repository *repo, const char *path, int check_disk)
 {
 	const struct got_error *err = NULL;
 	struct tog_log_view_state *s = &view->state.log;
@@ -1368,7 +1368,7 @@ open_log_view(struct tog_view *view, struct got_object_id *start_id,
 	struct got_commit_graph *thread_graph = NULL;
 	int errcode;
 
-	err = got_repo_map_path(&s->in_repo_path, repo, path);
+	err = got_repo_map_path(&s->in_repo_path, repo, path, check_disk);
 	if (err != NULL)
 		goto done;
 
@@ -1566,7 +1566,7 @@ input_log_view(struct tog_view **new_view, struct tog_view **dead_view,
 				if (lv == NULL)
 					return got_error_from_errno();
 				err = open_log_view(lv, s->start_id, s->repo,
-				    parent_path);
+				    parent_path, 0);
 				if (err)
 					return err;;
 				if (view_is_parent_view(view))
@@ -1669,7 +1669,7 @@ cmd_log(int argc, char *argv[])
 		error = got_error_from_errno();
 		goto done;
 	}
-	error = open_log_view(view, start_id, repo, path);
+	error = open_log_view(view, start_id, repo, path, 1);
 	if (error)
 		goto done;
 	error = view_loop(view);
@@ -2755,7 +2755,7 @@ cmd_blame(int argc, char *argv[])
 	if (error != NULL)
 		return error;
 
-	error = got_repo_map_path(&in_repo_path, repo, path);
+	error = got_repo_map_path(&in_repo_path, repo, path, 1);
 	if (error != NULL)
 		goto done;
 
@@ -3048,7 +3048,7 @@ log_tree_entry(struct tog_view **new_view, int begin_x,
 	if (err)
 		return err;
 
-	err = open_log_view(log_view, commit_id, repo, path);
+	err = open_log_view(log_view, commit_id, repo, path, 0);
 	if (err)
 		view_close(log_view);
 	else