summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: cb7138b)
raw | patch | inline | side by side (parent: cb7138b)
author | Jonas Fonseca <fonseca@diku.dk> | |
Sat, 25 Oct 2008 19:29:51 +0000 (21:29 +0200) | ||
committer | Jonas Fonseca <fonseca@diku.dk> | |
Sat, 25 Oct 2008 19:52:33 +0000 (21:52 +0200) |
Adds suffixcmp() used for checking if the status entry name ends
with "/". Also use it for repository reference loading.
with "/". Also use it for repository reference loading.
NEWS | patch | blob | history | |
tig.c | patch | blob | history |
index a0f75c62eda56cd4562fc94902c4102a0ed11602..47b5af8f592744b80d6411938d062bd6a267f745 100644 (file)
--- a/NEWS
+++ b/NEWS
- Separate blame revision and file argument by "--" to avoid problems.
- Main view: fix redrawing of the last commit wrt. the revision graph.
- Fix waiting for input after executing a run request in pager mode.
+ - Status & stage view: refuse to open directories.
tig-0.12.1
----------
index 3394d407472d3317d9cf9cc9d311db445706944b..041e282fcf2e677bcea296b7fe01669091b90838 100644 (file)
--- a/tig.c
+++ b/tig.c
#define prefixcmp(str1, str2) \
strncmp(str1, str2, STRING_SIZE(str2))
+static inline int
+suffixcmp(const char *str, int slen, const char *suffix)
+{
+ size_t len = slen >= 0 ? slen : strlen(str);
+ size_t suffixlen = strlen(suffix);
+
+ return suffixlen < len ? strcmp(str + len - suffixlen, suffix) : -1;
+}
+
/* Shell quoting
*
* NOTE: The following is a slightly modified copy of the git project's shell
return REQ_NONE;
}
+ if (!suffixcmp(status->new.name, -1, "/")) {
+ report("Cannot display a directory");
+ return REQ_NONE;
+ }
+
opt_pipe = fopen(status->new.name, "r");
info = "Untracked file %s";
break;
if (!status_exists(&stage_status, stage_line_type))
return REQ_VIEW_CLOSE;
- if (stage_line_type == LINE_STAT_UNTRACKED)
+ if (stage_line_type == LINE_STAT_UNTRACKED) {
+ if (!suffixcmp(stage_status.new.name, -1, "/")) {
+ report("Cannot display a directory");
+ return REQ_NONE;
+ }
+
opt_pipe = fopen(stage_status.new.name, "r");
+ }
open_view(view, REQ_VIEW_STAGE, OPEN_REFRESH);
return REQ_NONE;
bool head = FALSE;
if (!prefixcmp(name, "refs/tags/")) {
- if (!strcmp(name + namelen - 3, "^{}")) {
+ if (!suffixcmp(name, namelen, "^{}")) {
namelen -= 3;
name[namelen] = 0;
if (refs_size > 0 && refs[refs_size - 1].ltag == TRUE)