Update patches

This commit is contained in:
Arun Prakash Jana 2022-07-29 22:41:17 +05:30
parent e73b57c78a
commit e298f7eeaf
No known key found for this signature in database
GPG key ID: A75979F35C080412
4 changed files with 65 additions and 67 deletions

View file

@ -25,6 +25,6 @@ Patch conflicts can be checked locally by running `make checkpatches` or by runn
Whenever patch conflicts occur on the latest master, pull requests resolving them are welcome. Let's say a conflict occurs in the `restorepreview` patch. The best way to resolve this conflict would be something along the lines of: Whenever patch conflicts occur on the latest master, pull requests resolving them are welcome. Let's say a conflict occurs in the `restorepreview` patch. The best way to resolve this conflict would be something along the lines of:
- Ensure you're on latest master and run `cp src/nnn.c src/nnn.c.orig && PATCH_OPTS="--merge" make O_RESTOREPREVIEW=1`. This will save a copy of the source from master in `src/nnn.c.orig` and generate conflict markers in `src/nnn.c`. - Ensure you're on latest master and run `PATCH_OPTS="--merge" make O_RESTOREPREVIEW=1`. This will generate the conflict markers in `src/nnn.c`.
- Next edit `src.nnn`, resolve all the conflicts around the conflict markers(`<<<<<<<`), and save. - Next edit `src/nnn.c`, resolve the conflicts around the conflict markers(`<<<<<<<`), and save.
- Then run `diff -u src/nnn.c.orig src/nnn.c > patch.diff` to generate the new patch file and copy the contents to `patches/restorepreview/mainline.diff` (keeping the description comment at the start of the file). - Then run `git diff > patch.diff && sed -i -e "/^$/{r patch.diff" -e "q;}" patches/restorepreview/mainline.diff` to update the patch.

View file

@ -12,7 +12,7 @@ index f8a2c58..157cea5 100644
@@ -265,6 +265,25 @@ @@ -265,6 +265,25 @@
#define FREE 0 #define FREE 0
#define CAPACITY 1 #define CAPACITY 1
+/* Git icons */ +/* Git icons */
+#ifdef NERD +#ifdef NERD
+#define GIT_ADD "" +#define GIT_ADD ""
@ -41,7 +41,7 @@ index f8a2c58..157cea5 100644
#endif #endif
+ char git_status[2][5]; + char git_status[2][5];
} *pEntry; } *pEntry;
/* Selection marker */ /* Selection marker */
@@ -344,6 +364,7 @@ typedef struct { @@ -344,6 +364,7 @@ typedef struct {
uint_t cliopener : 1; /* All-CLI app opener */ uint_t cliopener : 1; /* All-CLI app opener */
@ -49,12 +49,12 @@ index f8a2c58..157cea5 100644
uint_t rollover : 1; /* Roll over at edges */ uint_t rollover : 1; /* Roll over at edges */
+ uint_t normalgit : 1; /* Show git status in normal mode */ + uint_t normalgit : 1; /* Show git status in normal mode */
} settings; } settings;
/* Non-persistent program-internal states (alphabeical order) */ /* Non-persistent program-internal states (alphabeical order) */
@@ -394,7 +415,17 @@ typedef struct { @@ -394,7 +415,17 @@ typedef struct {
} session_header_t; } session_header_t;
#endif #endif
+typedef struct { +typedef struct {
+ char status[2]; + char status[2];
+ char path[PATH_MAX]; + char path[PATH_MAX];
@ -66,13 +66,13 @@ index f8a2c58..157cea5 100644
+ size_t len; + size_t len;
+ git_status_t *statuses; + git_status_t *statuses;
+} git_statuses; +} git_statuses;
/* Configuration, contexts */ /* Configuration, contexts */
static settings cfg = { static settings cfg = {
@@ -3819,6 +3850,56 @@ static int get_kv_key(kv *kvarr, char *val, uchar_t max, uchar_t id) @@ -3819,6 +3850,56 @@ static int get_kv_key(kv *kvarr, char *val, uchar_t max, uchar_t id)
return -1; return -1;
} }
+static size_t get_git_statuses(const char *path) +static size_t get_git_statuses(const char *path)
+{ +{
+ static char gitrev[] = "git rev-parse --show-toplevel 2>/dev/null"; + static char gitrev[] = "git rev-parse --show-toplevel 2>/dev/null";
@ -127,20 +127,20 @@ index f8a2c58..157cea5 100644
{ {
/* Directories are always shown on top, clear the color when moving to first file */ /* Directories are always shown on top, clear the color when moving to first file */
@@ -4163,6 +4244,10 @@ static void printent(const struct entry *ent, uint_t namecols, bool sel) @@ -4163,6 +4244,10 @@ static void printent(const struct entry *ent, uint_t namecols, bool sel)
uchar_t color_pair = get_color_pair_name_ind(ent, &ind, &attrs); uchar_t color_pair = get_color_pair_name_ind(ent, &ind, &attrs);
+ if (git_statuses.show && (cfg.showdetail || cfg.normalgit)) + if (git_statuses.show && (cfg.showdetail || cfg.normalgit))
+ printw("%*s%s%s", (cfg.normalgit && !cfg.showdetail) ? 1 : 0, "", + printw("%*s%s%s", (cfg.normalgit && !cfg.showdetail) ? 1 : 0, "",
+ ent->git_status[0], ent->git_status[1]); + ent->git_status[0], ent->git_status[1]);
+ +
addch((ent->flags & FILE_SELECTED) ? '+' | A_REVERSE | A_BOLD : ' '); addch((ent->flags & FILE_SELECTED) ? '+' | A_REVERSE | A_BOLD : ' ');
if (g_state.oldcolor) if (g_state.oldcolor)
@@ -5629,6 +5714,11 @@ static int dentfill(char *path, struct entry **ppdents) @@ -5629,6 +5714,11 @@ static int dentfill(char *path, struct entry **ppdents)
attron(COLOR_PAIR(cfg.curctx + 1)); attron(COLOR_PAIR(cfg.curctx + 1));
} }
+ char linkpath[PATH_MAX]; + char linkpath[PATH_MAX];
+ if ((git_statuses.len = get_git_statuses(path))) + if ((git_statuses.len = get_git_statuses(path)))
+ if (!realpath(path, linkpath)) + if (!realpath(path, linkpath))
@ -152,7 +152,7 @@ index f8a2c58..157cea5 100644
@@ -5829,6 +5919,29 @@ static int dentfill(char *path, struct entry **ppdents) @@ -5829,6 +5919,29 @@ static int dentfill(char *path, struct entry **ppdents)
#endif #endif
} }
+ if (git_statuses.len) { + if (git_statuses.len) {
+ char dentpath[PATH_MAX]; + char dentpath[PATH_MAX];
+ size_t pathlen = mkpath(linkpath, dentp->name, dentpath); + size_t pathlen = mkpath(linkpath, dentp->name, dentpath);
@ -178,7 +178,7 @@ index f8a2c58..157cea5 100644
+ +
++ndents; ++ndents;
} while ((dp = readdir(dirp))); } while ((dp = readdir(dirp)));
@@ -6372,11 +6485,12 @@ static int adjust_cols(int n) @@ -6372,11 +6485,12 @@ static int adjust_cols(int n)
#endif #endif
if (cfg.showdetail) { if (cfg.showdetail) {
@ -192,7 +192,7 @@ index f8a2c58..157cea5 100644
+ n -= (git_statuses.show ? 34 : 32); + n -= (git_statuses.show ? 34 : 32);
+ } else if (cfg.normalgit && git_statuses.show) + } else if (cfg.normalgit && git_statuses.show)
+ n -= 3; + n -= 3;
/* 2 columns for preceding space and indicator */ /* 2 columns for preceding space and indicator */
return (n - 2); return (n - 2);
@@ -8148,6 +8262,7 @@ static void usage(void) @@ -8148,6 +8262,7 @@ static void usage(void)
@ -212,11 +212,11 @@ index f8a2c58..157cea5 100644
free(plgpath); free(plgpath);
free(cfgpath); free(cfgpath);
@@ -8330,7 +8446,7 @@ int main(int argc, char *argv[]) @@ -8330,7 +8446,7 @@ int main(int argc, char *argv[])
while ((opt = (env_opts_id > 0 while ((opt = (env_opts_id > 0
? env_opts[--env_opts_id] ? env_opts[--env_opts_id]
- : getopt(argc, argv, "aAb:cCdDeEfF:gHiJKl:nop:P:QrRs:St:T:uUVxh"))) != -1) { - : getopt(argc, argv, "aAb:BcCdDeEfF:gHiJKl:nop:P:QrRs:St:T:uUVxh"))) != -1) {
+ : getopt(argc, argv, "aAb:cCdDeEfF:gGHiJKl:nop:P:QrRs:St:T:uUVxh"))) != -1) { + : getopt(argc, argv, "aAb:BcCdDeEfF:gGHiJKl:nop:P:QrRs:St:T:uUVxh"))) != -1) {
switch (opt) { switch (opt) {
#ifndef NOFIFO #ifndef NOFIFO
case 'a': case 'a':

View file

@ -218,8 +218,8 @@ index ee1f5beb..91aab231 100644
while ((opt = (env_opts_id > 0 while ((opt = (env_opts_id > 0
? env_opts[--env_opts_id] ? env_opts[--env_opts_id]
- : getopt(argc, argv, "aAb:cCdDeEfF:gHiJKl:nop:P:QrRs:St:T:uUVxh"))) != -1) { - : getopt(argc, argv, "aAb:BcCdDeEfF:gHiJKl:nop:P:QrRs:St:T:uUVxh"))) != -1) {
+ : getopt(argc, argv, "aAb:cCdDeEfF:gGHiJKl:nop:P:QrRs:St:T:uUVxh"))) != -1) { + : getopt(argc, argv, "aAb:BcCdDeEfF:gGHiJKl:nop:P:QrRs:St:T:uUVxh"))) != -1) {
switch (opt) { switch (opt) {
#ifndef NOFIFO #ifndef NOFIFO
case 'a': case 'a':

View file

@ -7,30 +7,28 @@
# Authors: Luuk van Baal # Authors: Luuk van Baal
diff --git a/src/nnn.c b/src/nnn.c diff --git a/src/nnn.c b/src/nnn.c
index 6b0c1dc5..2aac557b 100644 index b10143a4..76d6bc5b 100644
--- a/src/nnn.c --- a/src/nnn.c
+++ b/src/nnn.c +++ b/src/nnn.c
@@ -372,7 +372,8 @@ typedef struct { @@ -374,6 +374,7 @@ typedef struct {
uint_t stayonsel : 1; /* Disable auto-advance on selection */
uint_t trash : 2; /* Trash method 0: rm -rf, 1: trash-cli, 2: gio trash */ uint_t trash : 2; /* Trash method 0: rm -rf, 1: trash-cli, 2: gio trash */
uint_t uidgid : 1; /* Show owner and group info */ uint_t uidgid : 1; /* Show owner and group info */
- uint_t reserved : 6; /* Adjust when adding/removing a field */ uint_t usebsdtar : 1; /* Use bsdtar as default archive utility */
+ uint_t previewer : 1; /* Run state of previewer */ + uint_t previewer : 1; /* Run state of previewer */
+ uint_t reserved : 5; /* Adjust when adding/removing a field */ uint_t reserved : 5; /* Adjust when adding/removing a field */
} runstate; } runstate;
/* Contexts or workspaces */ @@ -500,6 +501,9 @@ static char g_tmpfpath[TMP_LEN_MAX] __attribute__ ((aligned));
@@ -521,6 +522,9 @@ static char g_tmpfpath[TMP_LEN_MAX] __attribute__ ((aligned));
/* Buffer to store plugins control pipe location */ /* Buffer to store plugins control pipe location */
static char g_pipepath[TMP_LEN_MAX] __attribute__ ((aligned)); static char g_pipepath[TMP_LEN_MAX] __attribute__ ((aligned));
+/* Buffer to store preview plugins control pipe location */ +/* Buffer to store preview plugins control pipe location */
+static char g_ppipepath[TMP_LEN_MAX] __attribute__ ((aligned)); +static char g_ppipepath[TMP_LEN_MAX] __attribute__ ((aligned));
+ +
/* Non-persistent runtime states */ /* Non-persistent runtime states */
static runstate g_state; static runstate g_state;
@@ -697,12 +701,13 @@ static const char * const messages[] = { @@ -676,12 +680,13 @@ static const char * const messages[] = {
#define NNN_FCOLORS 5 #define NNN_FCOLORS 5
#define NNNLVL 6 #define NNNLVL 6
#define NNN_PIPE 7 #define NNN_PIPE 7
@ -47,10 +45,10 @@ index 6b0c1dc5..2aac557b 100644
+#define NNN_ORDER 12 +#define NNN_ORDER 12
+#define NNN_HELP 13 /* strings end here */ +#define NNN_HELP 13 /* strings end here */
+#define NNN_TRASH 14 /* flags begin here */ +#define NNN_TRASH 14 /* flags begin here */
static const char * const env_cfg[] = { static const char * const env_cfg[] = {
"NNN_OPTS", "NNN_OPTS",
@@ -713,6 +718,7 @@ static const char * const env_cfg[] = { @@ -692,6 +697,7 @@ static const char * const env_cfg[] = {
"NNN_FCOLORS", "NNN_FCOLORS",
"NNNLVL", "NNNLVL",
"NNN_PIPE", "NNN_PIPE",
@ -58,16 +56,16 @@ index 6b0c1dc5..2aac557b 100644
"NNN_MCLICK", "NNN_MCLICK",
"NNN_SEL", "NNN_SEL",
"NNN_ARCHIVE", "NNN_ARCHIVE",
@@ -859,7 +865,7 @@ static int set_sort_flags(int r); @@ -833,7 +839,7 @@ static int set_sort_flags(int r);
static void statusbar(char *path); static void statusbar(char *path);
static bool get_output(char *file, char *arg1, char *arg2, int fdout, bool multi, bool page); static bool get_output(char *file, char *arg1, char *arg2, int fdout, bool multi, bool page);
#ifndef NOFIFO #ifndef NOFIFO
-static void notify_fifo(bool force); -static void notify_fifo(bool force);
+static void notify_fifo(bool force, bool closepreview); +static void notify_fifo(bool force, bool closepreview);
#endif #endif
/* Functions */ /* Functions */
@@ -3071,7 +3077,7 @@ try_quit: @@ -3022,7 +3028,7 @@ try_quit:
} else { } else {
#ifndef NOFIFO #ifndef NOFIFO
if (!g_state.fifomode) if (!g_state.fifomode)
@ -76,14 +74,14 @@ index 6b0c1dc5..2aac557b 100644
#endif #endif
escaped = TRUE; escaped = TRUE;
settimeout(); settimeout();
@@ -5183,15 +5189,20 @@ static void run_cmd_as_plugin(const char *file, char *runfile, uchar_t flags) @@ -5120,15 +5126,20 @@ static void run_cmd_as_plugin(const char *file, char *runfile, uchar_t flags)
static bool plctrl_init(void) static bool plctrl_init(void)
{ {
- size_t len; - size_t len;
+ size_t len, lenbuf; + size_t len, lenbuf;
+ pid_t pid = getpid(); + pid_t pid = getpid();
/* g_tmpfpath is used to generate tmp file names */ /* g_tmpfpath is used to generate tmp file names */
g_tmpfpath[tmpfplen - 1] = '\0'; g_tmpfpath[tmpfplen - 1] = '\0';
- len = xstrsncpy(g_pipepath, g_tmpfpath, TMP_LEN_MAX); - len = xstrsncpy(g_pipepath, g_tmpfpath, TMP_LEN_MAX);
@ -98,13 +96,13 @@ index 6b0c1dc5..2aac557b 100644
+ xstrsncpy(g_ppipepath + len - 1, xitoa(pid), TMP_LEN_MAX - len); + xstrsncpy(g_ppipepath + len - 1, xitoa(pid), TMP_LEN_MAX - len);
setenv(env_cfg[NNN_PIPE], g_pipepath, TRUE); setenv(env_cfg[NNN_PIPE], g_pipepath, TRUE);
+ setenv(env_cfg[NNN_PPIPE], g_ppipepath, TRUE); + setenv(env_cfg[NNN_PPIPE], g_ppipepath, TRUE);
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
@@ -5220,6 +5231,21 @@ static ssize_t read_nointr(int fd, void *buf, size_t count) @@ -5157,6 +5168,21 @@ static ssize_t read_nointr(int fd, void *buf, size_t count)
return len; return len;
} }
+void *previewpipe(void *arg __attribute__ ((unused))) +void *previewpipe(void *arg __attribute__ ((unused)))
+{ +{
+ int fd, buf; + int fd, buf;
@ -123,19 +121,19 @@ index 6b0c1dc5..2aac557b 100644
static char *readpipe(int fd, char *ctxnum, char **path) static char *readpipe(int fd, char *ctxnum, char **path)
{ {
char ctx, *nextpath = NULL; char ctx, *nextpath = NULL;
@@ -5904,7 +5930,7 @@ static void populate(char *path, char *lastname) @@ -5841,7 +5867,7 @@ static void populate(char *path, char *lastname)
} }
#ifndef NOFIFO #ifndef NOFIFO
-static void notify_fifo(bool force) -static void notify_fifo(bool force)
+static void notify_fifo(bool force, bool closepreview) +static void notify_fifo(bool force, bool closepreview)
{ {
if (!fifopath) if (!fifopath)
return; return;
@@ -5920,6 +5946,12 @@ static void notify_fifo(bool force) @@ -5857,6 +5883,12 @@ static void notify_fifo(bool force)
} }
} }
+ if (closepreview) { + if (closepreview) {
+ if (write(fifofd, "close\n", 6) != 6) + if (write(fifofd, "close\n", 6) != 6)
+ xerror(); + xerror();
@ -143,9 +141,9 @@ index 6b0c1dc5..2aac557b 100644
+ } + }
+ +
static struct entry lastentry; static struct entry lastentry;
if (!force && !memcmp(&lastentry, &pdents[cur], sizeof(struct entry))) if (!force && !memcmp(&lastentry, &pdents[cur], sizeof(struct entry))) // NOLINT
@@ -5952,7 +5984,7 @@ static void send_to_explorer(int *presel) @@ -5889,7 +5921,7 @@ static void send_to_explorer(int *presel)
if (fd > 1) if (fd > 1)
close(fd); close(fd);
} else } else
@ -153,17 +151,17 @@ index 6b0c1dc5..2aac557b 100644
+ notify_fifo(TRUE, FALSE); /* Send opened path to NNN_FIFO */ + notify_fifo(TRUE, FALSE); /* Send opened path to NNN_FIFO */
} }
#endif #endif
@@ -5985,7 +6017,7 @@ static void move_cursor(int target, int ignore_scrolloff) @@ -5922,7 +5954,7 @@ static void move_cursor(int target, int ignore_scrolloff)
#ifndef NOFIFO #ifndef NOFIFO
if (!g_state.fifomode) if (!g_state.fifomode)
- notify_fifo(FALSE); /* Send hovered path to NNN_FIFO */ - notify_fifo(FALSE); /* Send hovered path to NNN_FIFO */
+ notify_fifo(FALSE, FALSE); /* Send hovered path to NNN_FIFO */ + notify_fifo(FALSE, FALSE); /* Send hovered path to NNN_FIFO */
#endif #endif
} }
@@ -6603,7 +6635,7 @@ static bool browse(char *ipath, const char *session, int pkey) @@ -6539,7 +6571,7 @@ static bool browse(char *ipath, const char *session, int pkey)
pEntry pent; pEntry pent;
enum action sel; enum action sel;
struct stat sb; struct stat sb;
@ -172,7 +170,7 @@ index 6b0c1dc5..2aac557b 100644
const uchar_t opener_flags = (cfg.cliopener ? F_CLI : (F_NOTRACE | F_NOSTDIN | F_NOWAIT)); const uchar_t opener_flags = (cfg.cliopener ? F_CLI : (F_NOTRACE | F_NOSTDIN | F_NOWAIT));
bool watch = FALSE, cd = TRUE; bool watch = FALSE, cd = TRUE;
ino_t inode = 0; ino_t inode = 0;
@@ -6861,7 +6893,7 @@ nochange: @@ -6797,7 +6829,7 @@ nochange:
move_cursor(r, 1); move_cursor(r, 1);
#ifndef NOFIFO #ifndef NOFIFO
else if ((event.bstate == BUTTON1_PRESSED) && !g_state.fifomode) else if ((event.bstate == BUTTON1_PRESSED) && !g_state.fifomode)
@ -181,7 +179,7 @@ index 6b0c1dc5..2aac557b 100644
#endif #endif
/* Handle right click selection */ /* Handle right click selection */
if (event.bstate == BUTTON3_PRESSED) { if (event.bstate == BUTTON3_PRESSED) {
@@ -7030,7 +7062,14 @@ nochange: @@ -6959,7 +6991,14 @@ nochange:
&& strstr(g_buf, "text") && strstr(g_buf, "text")
#endif #endif
) { ) {
@ -196,13 +194,13 @@ index 6b0c1dc5..2aac557b 100644
if (cfg.filtermode) { if (cfg.filtermode) {
presel = FILTER; presel = FILTER;
clearfilter(); clearfilter();
@@ -7340,8 +7379,14 @@ nochange: @@ -7272,8 +7311,14 @@ nochange:
copycurname(); copycurname();
goto nochange; goto nochange;
case SEL_EDIT: case SEL_EDIT:
+ if (g_state.previewer) + if (g_state.previewer)
+ notify_fifo(FALSE, TRUE); + notify_fifo(FALSE, TRUE);
if (!(g_state.picker || g_state.fifomode)) if (!(g_state.picker || g_state.fifomode))
spawn(editor, newpath, NULL, NULL, F_CLI); spawn(editor, newpath, NULL, NULL, F_CLI);
+ if (g_state.previewer) { + if (g_state.previewer) {
+ pkey = previewkey; + pkey = previewkey;
@ -211,7 +209,7 @@ index 6b0c1dc5..2aac557b 100644
continue; continue;
default: /* SEL_LOCK */ default: /* SEL_LOCK */
lock_terminal(); lock_terminal();
@@ -7710,6 +7755,7 @@ nochange: @@ -7642,6 +7687,7 @@ nochange:
cd = FALSE; cd = FALSE;
goto begin; goto begin;
} }
@ -219,10 +217,10 @@ index 6b0c1dc5..2aac557b 100644
case SEL_PLUGIN: case SEL_PLUGIN:
/* Check if directory is accessible */ /* Check if directory is accessible */
if (!xdiraccess(plgpath)) { if (!xdiraccess(plgpath)) {
@@ -7735,6 +7781,12 @@ nochange: @@ -7667,6 +7713,12 @@ nochange:
goto nochange; goto nochange;
} }
+ if (xstrcmp(tmp, "preview-tui") == 0) { + if (xstrcmp(tmp, "preview-tui") == 0) {
+ previewkey = r; + previewkey = r;
+ pthread_t tid; + pthread_t tid;
@ -232,7 +230,7 @@ index 6b0c1dc5..2aac557b 100644
if (tmp[0] == '-' && tmp[1]) { if (tmp[0] == '-' && tmp[1]) {
++tmp; ++tmp;
r = FALSE; /* Do not refresh dir after completion */ r = FALSE; /* Do not refresh dir after completion */
@@ -7789,7 +7841,13 @@ nochange: @@ -7722,7 +7774,13 @@ nochange:
case SEL_SHELL: // fallthrough case SEL_SHELL: // fallthrough
case SEL_LAUNCH: // fallthrough case SEL_LAUNCH: // fallthrough
case SEL_PROMPT: case SEL_PROMPT:
@ -243,10 +241,10 @@ index 6b0c1dc5..2aac557b 100644
+ pkey = previewkey; + pkey = previewkey;
+ goto run_plugin; + goto run_plugin;
+ } + }
/* Continue in type-to-nav mode, if enabled */ /* Continue in type-to-nav mode, if enabled */
if (cfg.filtermode) if (cfg.filtermode)
@@ -8329,8 +8387,10 @@ static void cleanup(void) @@ -8263,8 +8321,10 @@ static void cleanup(void)
if (g_state.autofifo) if (g_state.autofifo)
unlink(fifopath); unlink(fifopath);
#endif #endif
@ -258,8 +256,8 @@ index 6b0c1dc5..2aac557b 100644
#ifdef DEBUG #ifdef DEBUG
disabledbg(); disabledbg();
#endif #endif
@@ -8828,7 +8888,7 @@ int main(int argc, char *argv[]) @@ -8769,7 +8829,7 @@ int main(int argc, char *argv[])
#ifndef NOFIFO #ifndef NOFIFO
if (!g_state.fifomode) if (!g_state.fifomode)
- notify_fifo(FALSE); - notify_fifo(FALSE);