Commit 848d6979f98ff53e56da96dc75ed4aee31f42c31

Stefan Sperling 2019-08-12T13:43:17

annotate symlinks with @ in 'got tree' and 'tog tree'

diff --git a/got/got.1 b/got/got.1
index 491e31a..00c7548 100644
--- a/got/got.1
+++ b/got/got.1
@@ -394,6 +394,7 @@ directory path in the repository.
 Entries shown in this listing may carry one of the following trailing
 annotations:
 .Bl -column YXZ description
+.It @ Ta entry is a symbolic link
 .It / Ta entry is a directory
 .It * Ta entry is an executable file
 .El
diff --git a/got/got.c b/got/got.c
index df69fef..486e9fe 100644
--- a/got/got.c
+++ b/got/got.c
@@ -2252,14 +2252,21 @@ print_entry(struct got_tree_entry *te, const char *id, const char *path,
     const char *root_path)
 {
 	int is_root_path = (strcmp(path, root_path) == 0);
+	const char *modestr = "";
 
 	path += strlen(root_path);
 	while (path[0] == '/')
 		path++;
 
+	if (S_ISLNK(te->mode))
+		modestr = "@";
+	else if (S_ISDIR(te->mode))
+		modestr = "/";
+	else if (te->mode & S_IXUSR)
+		modestr = "*";
+
 	printf("%s%s%s%s%s\n", id ? id : "", path,
-	    is_root_path ? "" : "/", te->name,
-	    S_ISDIR(te->mode) ? "/" : ((te->mode & S_IXUSR) ? "*" : ""));
+	    is_root_path ? "" : "/", te->name, modestr);
 }
 
 static const struct got_error *
diff --git a/tog/tog.1 b/tog/tog.1
index 701d0e9..a7499ae 100644
--- a/tog/tog.1
+++ b/tog/tog.1
@@ -242,6 +242,13 @@ If the
 .Ar repository path
 is omitted, assume the repository is located in the current working directory.
 .Pp
+Displayed tree entries may carry one of the following trailing annotations:
+.Bl -column YXZ description
+.It @ Ta entry is a symbolic link
+.It / Ta entry is a directory
+.It * Ta entry is an executable file
+.El
+.Pp
 The key bindings for
 .Cm tog tree
 are as follows:
diff --git a/tog/tog.c b/tog/tog.c
index 9ff3553..9acbb83 100644
--- a/tog/tog.c
+++ b/tog/tog.c
@@ -3852,6 +3852,7 @@ draw_tree_entries(struct tog_view *view,
 
 	while (te) {
 		char *line = NULL, *id_str = NULL;
+		const char *modestr = "";
 
 		if (show_ids) {
 			err = got_object_id_str(&id_str, te->id);
@@ -3859,9 +3860,14 @@ draw_tree_entries(struct tog_view *view,
 				return got_error_from_errno(
 				    "got_object_id_str");
 		}
+		if (S_ISLNK(te->mode))
+			modestr = "@";
+		else if (S_ISDIR(te->mode))
+			modestr = "/";
+		else if (te->mode & S_IXUSR)
+			modestr = "*";
 		if (asprintf(&line, "%s  %s%s", id_str ? id_str : "",
-		    te->name, S_ISDIR(te->mode) ? "/" :
-		    ((te->mode & S_IXUSR) ? "*" : "")) == -1) {
+		    te->name, modestr) == -1) {
 			free(id_str);
 			return got_error_from_errno("asprintf");
 		}