Fix gitstatus regression/restore preview conflict

This commit is contained in:
Luuk van Baal 2021-10-09 02:36:22 +02:00
parent 1020f37320
commit 17bf7c97f6
3 changed files with 38 additions and 31 deletions

View file

@ -6,7 +6,7 @@
# Authors: Luuk van Baal, @crides
diff --git a/src/nnn.c b/src/nnn.c
index 88263beb..597ff2b3 100644
index 897c32f1..00b57c2e 100644
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -285,6 +285,7 @@ typedef struct entry {
@ -61,6 +61,7 @@ index 88263beb..597ff2b3 100644
+ char workdir[PATH_MAX], *ret;
+ FILE *fp = popen(gitrev, "r");
+
+ git_statuses.show = FALSE;
+ ret = fgets(workdir, PATH_MAX, fp);
+ pclose(fp);
+ if (!ret)
@ -69,7 +70,6 @@ index 88263beb..597ff2b3 100644
+ static char gitstat[] = "git -c core.quotePath= status --porcelain --ignored=matching -u ";
+ char pathspec[PATH_MAX], status[PATH_MAX];
+ size_t i = -1;
+ git_statuses.show = FALSE;
+ workdir[xstrlen(workdir) - 1] = '\0';
+ snprintf(pathspec, PATH_MAX, "%s\"%s\"%s 2>/dev/null", gitstat, path, cfg.showhidden ? "" : "/*");
+ fp = popen(pathspec, "r");
@ -113,17 +113,20 @@ index 88263beb..597ff2b3 100644
#if _POSIX_C_SOURCE >= 200112L
posix_fadvise(fd, 0, 0, POSIX_FADV_SEQUENTIAL);
#endif
@@ -5746,6 +5800,36 @@ static int dentfill(char *path, struct entry **ppdents)
@@ -5746,6 +5800,39 @@ static int dentfill(char *path, struct entry **ppdents)
#endif
}
+ if (git_statuses.len) {
+ char dentpath[PATH_MAX], prefix[PATH_MAX + 1];
+ char dentpath[PATH_MAX];
+ size_t pathlen = mkpath(linkpath, dentp->name, dentpath);
+ snprintf(prefix, PATH_MAX + 1, "%s/", dentpath);
+ dentp->git_status[0] = dentp->git_status[1] = '-';
+
+ if (dentp->flags & DIR_OR_DIRLNK) {
+ char prefix[PATH_MAX];
+ memccpy(prefix, dentpath, '\0', PATH_MAX);
+ prefix[pathlen - 1] = '/';
+
+ for (size_t i = 0; i < git_statuses.len; ++i)
+ if (is_prefix(git_statuses.statuses[i].path, prefix, pathlen)) {
+ if ((dentp->git_status[0] == '-') && (git_statuses.statuses[i].status[0] != '-'))
@ -150,7 +153,7 @@ index 88263beb..597ff2b3 100644
++ndents;
} while ((dp = readdir(dirp)));
@@ -6270,11 +6354,12 @@ static int adjust_cols(int n)
@@ -6270,11 +6357,12 @@ static int adjust_cols(int n)
#endif
if (cfg.showdetail) {
/* Fallback to light mode if less than 35 columns */
@ -166,7 +169,7 @@ index 88263beb..597ff2b3 100644
/* 2 columns for preceding space and indicator */
return (n - 2);
@@ -8034,6 +8119,7 @@ static void usage(void)
@@ -8030,6 +8118,7 @@ static void usage(void)
" -F val fifo mode [0:preview 1:explore]\n"
#endif
" -g regex filters\n"
@ -174,7 +177,7 @@ index 88263beb..597ff2b3 100644
" -H show hidden files\n"
" -J no auto-proceed on select\n"
" -K detect key collision\n"
@@ -8174,6 +8260,7 @@ static void cleanup(void)
@@ -8170,6 +8259,7 @@ static void cleanup(void)
free(hostname);
}
#endif
@ -182,7 +185,7 @@ index 88263beb..597ff2b3 100644
free(selpath);
free(plgpath);
free(cfgpath);
@@ -8218,7 +8305,7 @@ int main(int argc, char *argv[])
@@ -8214,7 +8304,7 @@ int main(int argc, char *argv[])
while ((opt = (env_opts_id > 0
? env_opts[--env_opts_id]
@ -191,7 +194,7 @@ index 88263beb..597ff2b3 100644
switch (opt) {
#ifndef NOFIFO
case 'a':
@@ -8269,6 +8356,9 @@ int main(int argc, char *argv[])
@@ -8265,6 +8355,9 @@ int main(int argc, char *argv[])
cfg.regex = 1;
filterfn = &visible_re;
break;

View file

@ -7,7 +7,7 @@
# Authors: Luuk van Baal, @crides
diff --git a/src/nnn.c b/src/nnn.c
index 55f32e73..ed771826 100644
index 5801e28e..8a88d5e7 100644
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -285,6 +285,7 @@ typedef struct entry {
@ -52,7 +52,7 @@ index 55f32e73..ed771826 100644
};
static context g_ctx[CTX_MAX] __attribute__ ((aligned));
@@ -3822,6 +3835,38 @@ static int get_kv_key(kv *kvarr, char *val, uchar_t max, uchar_t id)
@@ -3822,6 +3835,39 @@ static int get_kv_key(kv *kvarr, char *val, uchar_t max, uchar_t id)
return -1;
}
@ -62,6 +62,7 @@ index 55f32e73..ed771826 100644
+ char workdir[PATH_MAX], *ret;
+ FILE *fp = popen(gitrev, "r");
+
+ git_statuses.show = FALSE;
+ ret = fgets(workdir, PATH_MAX, fp);
+ pclose(fp);
+ if (!ret)
@ -91,7 +92,7 @@ index 55f32e73..ed771826 100644
static void resetdircolor(int flags)
{
/* Directories are always shown on top, clear the color when moving to first file */
@@ -4132,6 +4177,9 @@ static void printent(const struct entry *ent, uint_t namecols, bool sel)
@@ -4132,6 +4178,9 @@ static void printent(const struct entry *ent, uint_t namecols, bool sel)
int attrs = 0, namelen;
uchar_t color_pair = get_color_pair_name_ind(ent, &ind, &attrs);
@ -101,7 +102,7 @@ index 55f32e73..ed771826 100644
addch((ent->flags & FILE_SELECTED) ? '+' | A_REVERSE | A_BOLD : ' ');
if (g_state.oldcolor)
@@ -5554,6 +5602,11 @@ static int dentfill(char *path, struct entry **ppdents)
@@ -5554,6 +5603,11 @@ static int dentfill(char *path, struct entry **ppdents)
attron(COLOR_PAIR(cfg.curctx + 1));
}
@ -113,17 +114,20 @@ index 55f32e73..ed771826 100644
#if _POSIX_C_SOURCE >= 200112L
posix_fadvise(fd, 0, 0, POSIX_FADV_SEQUENTIAL);
#endif
@@ -5752,6 +5805,36 @@ static int dentfill(char *path, struct entry **ppdents)
@@ -5752,6 +5806,39 @@ static int dentfill(char *path, struct entry **ppdents)
#endif
}
+ if (git_statuses.len) {
+ char dentpath[PATH_MAX], prefix[PATH_MAX + 1];
+ char dentpath[PATH_MAX];
+ size_t pathlen = mkpath(linkpath, dentp->name, dentpath);
+ snprintf(prefix, PATH_MAX + 1, "%s/", dentpath);
+ dentp->git_status[0] = dentp->git_status[1] = '-';
+
+ if (dentp->flags & DIR_OR_DIRLNK) {
+ char prefix[PATH_MAX];
+ memccpy(prefix, dentpath, '\0', PATH_MAX);
+ prefix[pathlen - 1] = '/';
+
+ for (size_t i = 0; i < git_statuses.len; ++i)
+ if (is_prefix(git_statuses.statuses[i].path, prefix, pathlen)) {
+ if ((dentp->git_status[0] == '-') && (git_statuses.statuses[i].status[0] != '-'))
@ -150,7 +154,7 @@ index 55f32e73..ed771826 100644
++ndents;
} while ((dp = readdir(dirp)));
@@ -6267,7 +6350,8 @@ static int adjust_cols(int n)
@@ -6267,7 +6354,8 @@ static int adjust_cols(int n)
cfg.showdetail ^= 1;
else /* 2 more accounted for below */
n -= (dtls.maxentln - 2 - dtls.maxnameln);
@ -160,7 +164,7 @@ index 55f32e73..ed771826 100644
/* 2 columns for preceding space and indicator */
return (n - 2);
@@ -6422,7 +6506,7 @@ static void redraw(char *path)
@@ -6422,7 +6510,7 @@ static void redraw(char *path)
}
#endif
}
@ -169,7 +173,7 @@ index 55f32e73..ed771826 100644
}
ncols = adjust_cols(ncols);
@@ -8040,6 +8124,7 @@ static void usage(void)
@@ -8036,6 +8124,7 @@ static void usage(void)
" -F val fifo mode [0:preview 1:explore]\n"
#endif
" -g regex filters\n"
@ -177,7 +181,7 @@ index 55f32e73..ed771826 100644
" -H show hidden files\n"
" -J no auto-proceed on select\n"
" -K detect key collision\n"
@@ -8180,6 +8265,7 @@ static void cleanup(void)
@@ -8176,6 +8265,7 @@ static void cleanup(void)
free(hostname);
}
#endif
@ -185,7 +189,7 @@ index 55f32e73..ed771826 100644
free(selpath);
free(plgpath);
free(cfgpath);
@@ -8224,7 +8310,7 @@ int main(int argc, char *argv[])
@@ -8220,7 +8310,7 @@ int main(int argc, char *argv[])
while ((opt = (env_opts_id > 0
? env_opts[--env_opts_id]
@ -194,7 +198,7 @@ index 55f32e73..ed771826 100644
switch (opt) {
#ifndef NOFIFO
case 'a':
@@ -8275,6 +8361,9 @@ int main(int argc, char *argv[])
@@ -8271,6 +8361,9 @@ int main(int argc, char *argv[])
cfg.regex = 1;
filterfn = &visible_re;
break;

View file

@ -4,7 +4,7 @@
# Authors: Luuk van Baal
diff --git a/src/nnn.c b/src/nnn.c
index 88263beb..8aa24712 100644
index 897c32f1..cf589bc8 100644
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -367,7 +367,8 @@ typedef struct {
@ -193,22 +193,22 @@ index 88263beb..8aa24712 100644
if (cfg.filtermode) {
presel = FILTER;
clearfilter();
@@ -7206,7 +7245,14 @@ nochange:
@@ -7206,8 +7245,14 @@ nochange:
copycurname();
goto nochange;
case SEL_EDIT:
+ if (g_state.previewer)
+ notify_fifo(FALSE, TRUE);
spawn(editor, newpath, NULL, NULL, F_CLI);
if (!g_state.picker)
spawn(editor, newpath, NULL, NULL, F_CLI);
+ if (g_state.previewer) {
+ pkey = previewkey;
+ goto run_plugin;
+ }
+
continue;
default: /* SEL_LOCK */
lock_terminal();
@@ -7566,6 +7612,7 @@ nochange:
@@ -7567,6 +7612,7 @@ nochange:
goto begin;
}
@ -216,7 +216,7 @@ index 88263beb..8aa24712 100644
case SEL_PLUGIN:
/* Check if directory is accessible */
if (!xdiraccess(plgpath)) {
@@ -7591,6 +7638,12 @@ nochange:
@@ -7592,6 +7638,12 @@ nochange:
goto nochange;
}
@ -229,7 +229,7 @@ index 88263beb..8aa24712 100644
if (tmp[0] == '-' && tmp[1]) {
++tmp;
r = FALSE; /* Do not refresh dir after completion */
@@ -8189,8 +8242,10 @@ static void cleanup(void)
@@ -8185,8 +8237,10 @@ static void cleanup(void)
if (g_state.autofifo)
unlink(fifopath);
#endif
@ -241,7 +241,7 @@ index 88263beb..8aa24712 100644
#ifdef DEBUG
disabledbg();
#endif
@@ -8689,7 +8744,7 @@ int main(int argc, char *argv[])
@@ -8690,7 +8744,7 @@ int main(int argc, char *argv[])
#ifndef NOFIFO
if (!g_state.fifomode)