annotate symlinks with @ in 'got tree' and 'tog tree'
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
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");
}