Update gitstatus patch (#1074)

This commit is contained in:
luukvbaal 2021-06-18 01:32:44 +02:00 committed by GitHub
parent 640a56e1cc
commit 02b5b15001
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 114 additions and 175 deletions

View File

@ -8,7 +8,7 @@
# Authors: @crides, Luuk van Baal # Authors: @crides, Luuk van Baal
diff --git a/src/nnn.c b/src/nnn.c diff --git a/src/nnn.c b/src/nnn.c
index 402d905..e10035b 100644 index 67523fe6..c965bd1c 100644
--- a/src/nnn.c --- a/src/nnn.c
+++ b/src/nnn.c +++ b/src/nnn.c
@@ -105,6 +105,7 @@ @@ -105,6 +105,7 @@
@ -19,33 +19,15 @@ index 402d905..e10035b 100644
#if !defined(alloca) && defined(__GNUC__) #if !defined(alloca) && defined(__GNUC__)
/* /*
@@ -244,6 +245,16 @@ typedef unsigned int uint_t; @@ -265,6 +266,7 @@ typedef struct entry {
typedef unsigned char uchar_t;
typedef unsigned short ushort_t;
typedef unsigned long long ulong_t;
+typedef enum {
+ GIT_COLUMN_STATUS_UNMOD = 0,
+ GIT_COLUMN_STATUS_NEW,
+ GIT_COLUMN_STATUS_MODIFIED,
+ GIT_COLUMN_STATUS_DELETED,
+ GIT_COLUMN_STATUS_RENAMED,
+ GIT_COLUMN_STATUS_TYPE_CHANGE,
+ GIT_COLUMN_STATUS_IGNORED,
+ GIT_COLUMN_STATUS_CONFLICTED,
+} git_column_status_t;
/* STRUCTURES */
@@ -263,6 +274,8 @@ typedef struct entry {
uid_t uid; /* 4 bytes */ uid_t uid; /* 4 bytes */
gid_t gid; /* 4 bytes */ gid_t gid; /* 4 bytes */
#endif #endif
+ git_column_status_t status_indexed; + git_status_t git_status;
+ git_column_status_t status_staged;
} *pEntry; } *pEntry;
/* Key-value pairs from env */ /* Key-value pairs from env */
@@ -313,6 +326,7 @@ typedef struct { @@ -315,6 +317,7 @@ typedef struct {
uint_t cliopener : 1; /* All-CLI app opener */ uint_t cliopener : 1; /* All-CLI app opener */
uint_t waitedit : 1; /* For ops that can't be detached, used EDITOR */ uint_t waitedit : 1; /* For ops that can't be detached, used EDITOR */
uint_t rollover : 1; /* Roll over at edges */ uint_t rollover : 1; /* Roll over at edges */
@ -53,7 +35,7 @@ index 402d905..e10035b 100644
} settings; } settings;
/* Non-persistent program-internal states */ /* Non-persistent program-internal states */
@@ -362,7 +376,18 @@ typedef struct { @@ -363,7 +366,19 @@ typedef struct {
} session_header_t; } session_header_t;
#endif #endif
@ -65,6 +47,7 @@ index 402d905..e10035b 100644
+typedef struct { +typedef struct {
+ simple_git_status_t *statuses; + simple_git_status_t *statuses;
+ size_t len; + size_t len;
+ bool show;
+} simple_git_statuses_t; +} simple_git_statuses_t;
+ +
/* GLOBALS */ /* GLOBALS */
@ -72,7 +55,7 @@ index 402d905..e10035b 100644
/* Configuration, contexts */ /* Configuration, contexts */
static settings cfg = { static settings cfg = {
@@ -393,6 +418,7 @@ static settings cfg = { @@ -394,6 +409,7 @@ static settings cfg = {
0, /* cliopener */ 0, /* cliopener */
0, /* waitedit */ 0, /* waitedit */
1, /* rollover */ 1, /* rollover */
@ -80,41 +63,26 @@ index 402d905..e10035b 100644
}; };
static context g_ctx[CTX_MAX] __attribute__ ((aligned)); static context g_ctx[CTX_MAX] __attribute__ ((aligned));
@@ -3464,6 +3490,80 @@ static char *get_kv_val(kv *kvarr, char *buf, int key, uchar_t max, uchar_t id) @@ -3498,6 +3514,66 @@ static char *get_kv_val(kv *kvarr, char *buf, int key, uchar_t max, uchar_t id)
return NULL; return NULL;
} }
+static git_column_status_t git_get_indexed_status(const uint32_t status) { +static void print_gitstatus(git_status_t status) {
+ if (status & GIT_STATUS_INDEX_NEW) return GIT_COLUMN_STATUS_NEW; + if (status & GIT_STATUS_INDEX_NEW) addch('N' | (g_state.oldcolor ? COLOR_PAIR(1) : COLOR_PAIR(C_EXE)));
+ if (status & GIT_STATUS_INDEX_MODIFIED) return GIT_COLUMN_STATUS_MODIFIED; + else if (status & GIT_STATUS_INDEX_MODIFIED) addch('M' | (g_state.oldcolor ? COLOR_PAIR(1) : COLOR_PAIR(4)));
+ if (status & GIT_STATUS_INDEX_DELETED) return GIT_COLUMN_STATUS_DELETED; + else if (status & GIT_STATUS_INDEX_DELETED) addch('D' | (g_state.oldcolor ? COLOR_PAIR(1) : COLOR_PAIR(C_UND)));
+ if (status & GIT_STATUS_INDEX_RENAMED) return GIT_COLUMN_STATUS_RENAMED; + else if (status & GIT_STATUS_INDEX_RENAMED) addch('R' | (g_state.oldcolor ? COLOR_PAIR(1) : COLOR_PAIR(C_CHR)));
+ if (status & GIT_STATUS_INDEX_TYPECHANGE) return GIT_COLUMN_STATUS_TYPE_CHANGE; + else if (status & GIT_STATUS_INDEX_TYPECHANGE) addch('T' | (g_state.oldcolor ? COLOR_PAIR(1) : COLOR_PAIR(C_HRD)));
+ return GIT_COLUMN_STATUS_UNMOD; + else addch('-' | 0);
+}
+ +
+static git_column_status_t git_get_staged_status(const uint32_t status) { + if (status & GIT_STATUS_WT_NEW) addch('N' | (g_state.oldcolor ? COLOR_PAIR(1) : COLOR_PAIR(C_EXE)));
+ if (status & GIT_STATUS_WT_NEW) return GIT_COLUMN_STATUS_NEW; + else if (status & GIT_STATUS_WT_MODIFIED) addch('M' | (g_state.oldcolor ? COLOR_PAIR(1) : COLOR_PAIR(4)));
+ if (status & GIT_STATUS_WT_MODIFIED) return GIT_COLUMN_STATUS_MODIFIED; + else if (status & GIT_STATUS_WT_DELETED) addch('D' | (g_state.oldcolor ? COLOR_PAIR(1) : COLOR_PAIR(C_UND)));
+ if (status & GIT_STATUS_WT_DELETED) return GIT_COLUMN_STATUS_DELETED; + else if (status & GIT_STATUS_WT_RENAMED) addch('R' | (g_state.oldcolor ? COLOR_PAIR(1) : COLOR_PAIR(C_CHR)));
+ if (status & GIT_STATUS_WT_RENAMED) return GIT_COLUMN_STATUS_RENAMED; + else if (status & GIT_STATUS_WT_TYPECHANGE) addch('T' | (g_state.oldcolor ? COLOR_PAIR(1) : COLOR_PAIR(C_HRD)));
+ if (status & GIT_STATUS_WT_TYPECHANGE) return GIT_COLUMN_STATUS_TYPE_CHANGE; + else if (status & GIT_STATUS_IGNORED) addch('I' | 0);
+ if (status & GIT_STATUS_IGNORED) return GIT_COLUMN_STATUS_IGNORED; + else if (status & GIT_STATUS_CONFLICTED) addch('U' | (g_state.oldcolor ? COLOR_PAIR(1) : COLOR_PAIR(C_UND)));
+ if (status & GIT_STATUS_CONFLICTED) return GIT_COLUMN_STATUS_CONFLICTED; + else addch('-' | 0);
+ return GIT_COLUMN_STATUS_UNMOD;
+}
+
+static void print_gitstatus(git_column_status_t status) {
+ switch (status) {
+ case GIT_COLUMN_STATUS_UNMOD: addch('-' | 0); break;
+ case GIT_COLUMN_STATUS_NEW: addch('N' | (g_state.oldcolor ? COLOR_PAIR(1) : COLOR_PAIR(C_EXE))); break;
+ case GIT_COLUMN_STATUS_MODIFIED: addch('M' | (g_state.oldcolor ? COLOR_PAIR(1) : COLOR_PAIR(4))); break;
+ case GIT_COLUMN_STATUS_DELETED: addch('D' | (g_state.oldcolor ? COLOR_PAIR(1) : COLOR_PAIR(C_UND))); break;
+ case GIT_COLUMN_STATUS_RENAMED: addch('R' | (g_state.oldcolor ? COLOR_PAIR(1) : COLOR_PAIR(C_CHR))); break;
+ case GIT_COLUMN_STATUS_TYPE_CHANGE: addch('T' | (g_state.oldcolor ? COLOR_PAIR(1) : COLOR_PAIR(C_HRD))); break;
+ case GIT_COLUMN_STATUS_IGNORED: addch('I' | 0); break;
+ case GIT_COLUMN_STATUS_CONFLICTED: addch('U' | (g_state.oldcolor ? COLOR_PAIR(1) : COLOR_PAIR(C_UND))); break;
+ }
+} +}
+ +
+static simple_git_statuses_t statuses_from_path(const char *path) { +static simple_git_statuses_t statuses_from_path(const char *path) {
@ -156,26 +124,26 @@ index 402d905..e10035b 100644
+ +
+ free(git_statuses.statuses); + free(git_statuses.statuses);
+ git_statuses.len = 0; + git_statuses.len = 0;
+ git_statuses.show = FALSE;
+} +}
+ +
static void resetdircolor(int flags) static void resetdircolor(int flags)
{ {
/* 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 */
@@ -3800,6 +3900,13 @@ static void printent(const struct entry *ent, uint_t namecols, bool sel) @@ -3835,6 +3911,12 @@ 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.len && (cfg.showdetail || cfg.normalgit)) { + if (git_statuses.show && (cfg.showdetail || cfg.normalgit)) {
+ if (cfg.normalgit && !cfg.showdetail) + if (cfg.normalgit && !cfg.showdetail)
+ addch(' '); + addch(' ');
+ print_gitstatus(ent->status_indexed); + print_gitstatus(ent->git_status);
+ print_gitstatus(ent->status_staged);
+ } + }
+ +
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)
@@ -5119,6 +5226,10 @@ static int dentfill(char *path, struct entry **ppdents) @@ -5160,6 +5242,10 @@ static int dentfill(char *path, struct entry **ppdents)
attron(COLOR_PAIR(cfg.curctx + 1)); attron(COLOR_PAIR(cfg.curctx + 1));
} }
@ -186,30 +154,31 @@ index 402d905..e10035b 100644
#if _POSIX_C_SOURCE >= 200112L #if _POSIX_C_SOURCE >= 200112L
posix_fadvise(fd, 0, 0, POSIX_FADV_SEQUENTIAL); posix_fadvise(fd, 0, 0, POSIX_FADV_SEQUENTIAL);
#endif #endif
@@ -5316,6 +5427,22 @@ static int dentfill(char *path, struct entry **ppdents) @@ -5357,6 +5443,23 @@ static int dentfill(char *path, struct entry **ppdents)
#endif #endif
} }
+ if (git_statuses.len) { + if (git_statuses.len) {
+ char *dentpath = abspath(dentp->name, path); + char *dentpath = abspath(dentp->name, path);
+ namebuflen = xstrlen(dentpath); + namebuflen = xstrlen(dentpath);
+ uint merged_status = 0; + dentp->git_status = GIT_STATUS_CURRENT;
+ +
+ for (size_t i = 0; i < git_statuses.len; ++i) + for (size_t i = 0; i < git_statuses.len; ++i)
+ if (!(dentp->flags & DIR_OR_LINK_TO_DIR) ? !xstrcmp(git_statuses.statuses[i].path, dentpath) : + if (git_statuses.statuses[i].status)
+ (is_prefix(git_statuses.statuses[i].path, dentpath, namebuflen) && + if ((dentp->flags & DIR_OR_LINK_TO_DIR) ? (is_prefix(git_statuses.statuses[i].path, dentpath, namebuflen) &&
+ (namebuflen <= xstrlen(git_statuses.statuses[i].path)))) + namebuflen <= xstrlen(git_statuses.statuses[i].path)) : !xstrcmp(git_statuses.statuses[i].path, dentpath)) {
+ merged_status |= git_statuses.statuses[i].status; + if (git_statuses.statuses[i].status != GIT_STATUS_IGNORED)
+ git_statuses.show = TRUE;
+ dentp->git_status |= git_statuses.statuses[i].status;
+ }
+ +
+ dentp->status_indexed = git_get_indexed_status(merged_status);
+ dentp->status_staged = git_get_staged_status(merged_status);
+ free(dentpath); + free(dentpath);
+ } + }
+ +
++ndents; ++ndents;
} while ((dp = readdir(dirp))); } while ((dp = readdir(dirp)));
@@ -5834,16 +5961,16 @@ static int adjust_cols(int n) @@ -5873,16 +5976,16 @@ static int adjust_cols(int n)
#endif #endif
if (cfg.showdetail) { if (cfg.showdetail) {
/* Fallback to light mode if less than 35 columns */ /* Fallback to light mode if less than 35 columns */
@ -219,25 +188,25 @@ index 402d905..e10035b 100644
else { else {
/* 2 more accounted for below */ /* 2 more accounted for below */
- n -= 32; - n -= 32;
+ n -= 34; + n -= (git_statuses.show ? 34 : 32);
} }
} }
/* 2 columns for preceding space and indicator */ /* 2 columns for preceding space and indicator */
- return (n - 2); - return (n - 2);
+ return (n - ((cfg.normalgit && !cfg.showdetail) ? 5 : 2)); + return (n - ((git_statuses.show && (cfg.normalgit && !cfg.showdetail)) ? 5 : 2));
} }
static void draw_line(char *path, int ncols) static void draw_line(char *path, int ncols)
@@ -7574,6 +7701,7 @@ static void usage(void) @@ -7608,6 +7711,7 @@ static void usage(void)
" -f use readline history file\n"
#endif #endif
" -F show fortune\n"
" -g regex filters\n" " -g regex filters\n"
+ " -G always show git status\n" + " -G always show git status\n"
" -H show hidden files\n" " -H show hidden files\n"
" -J no auto-proceed on select\n" " -J no auto-proceed on select\n"
" -K detect key collision\n" " -K detect key collision\n"
@@ -7712,6 +7840,8 @@ static void cleanup(void) @@ -7746,6 +7850,8 @@ static void cleanup(void)
fflush(stdout); fflush(stdout);
} }
#endif #endif
@ -246,16 +215,16 @@ index 402d905..e10035b 100644
free(selpath); free(selpath);
free(plgpath); free(plgpath);
free(cfgpath); free(cfgpath);
@@ -7756,7 +7886,7 @@ int main(int argc, char *argv[]) @@ -7790,7 +7896,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:cCdDeEfgHJKl:nop:P:QrRs:St:T:uUVwxh"))) != -1) { - : getopt(argc, argv, "aAb:cCdDeEfgHJKl:nop:P:QrRs:St:T:uUVwxX:h"))) != -1) {
+ : getopt(argc, argv, "aAb:cCdDeEfgGHJKl:nop:P:QrRs:St:T:uUVwxh"))) != -1) { + : getopt(argc, argv, "aAb:cCdDeEfgGHJKl:nop:P:QrRs:St:T:uUVwxX:h"))) != -1) {
switch (opt) { switch (opt) {
#ifndef NOFIFO #ifndef NOFIFO
case 'a': case 'a':
@@ -7800,6 +7930,9 @@ int main(int argc, char *argv[]) @@ -7831,6 +7937,9 @@ int main(int argc, char *argv[])
cfg.regex = 1; cfg.regex = 1;
filterfn = &visible_re; filterfn = &visible_re;
break; break;
@ -265,7 +234,7 @@ index 402d905..e10035b 100644
case 'H': case 'H':
cfg.showhidden = 1; cfg.showhidden = 1;
break; break;
@@ -7907,6 +8040,7 @@ int main(int argc, char *argv[]) @@ -7938,6 +8047,7 @@ int main(int argc, char *argv[])
return EXIT_FAILURE; return EXIT_FAILURE;
atexit(cleanup); atexit(cleanup);

View File

@ -10,7 +10,7 @@
# Authors: @crides, Luuk van Baal # Authors: @crides, Luuk van Baal
diff --git a/src/nnn.c b/src/nnn.c diff --git a/src/nnn.c b/src/nnn.c
index 9141d78..de4d9f0 100644 index b8b222d4..80ef884f 100644
--- a/src/nnn.c --- a/src/nnn.c
+++ b/src/nnn.c +++ b/src/nnn.c
@@ -105,6 +105,7 @@ @@ -105,6 +105,7 @@
@ -21,33 +21,15 @@ index 9141d78..de4d9f0 100644
#if !defined(alloca) && defined(__GNUC__) #if !defined(alloca) && defined(__GNUC__)
/* /*
@@ -244,6 +245,16 @@ typedef unsigned int uint_t; @@ -265,6 +266,7 @@ typedef struct entry {
typedef unsigned char uchar_t;
typedef unsigned short ushort_t;
typedef unsigned long long ulong_t;
+typedef enum {
+ GIT_COLUMN_STATUS_UNMOD = 0,
+ GIT_COLUMN_STATUS_NEW,
+ GIT_COLUMN_STATUS_MODIFIED,
+ GIT_COLUMN_STATUS_DELETED,
+ GIT_COLUMN_STATUS_RENAMED,
+ GIT_COLUMN_STATUS_TYPE_CHANGE,
+ GIT_COLUMN_STATUS_IGNORED,
+ GIT_COLUMN_STATUS_CONFLICTED,
+} git_column_status_t;
/* STRUCTURES */
@@ -262,6 +273,8 @@ typedef struct entry {
#ifndef NOUG
uid_t uid; /* 4 bytes */ uid_t uid; /* 4 bytes */
gid_t gid; /* 4 bytes */ gid_t gid; /* 4 bytes */
+ git_column_status_t status_indexed;
+ git_column_status_t status_staged;
#endif #endif
+ git_status_t git_status;
} *pEntry; } *pEntry;
@@ -313,6 +326,7 @@ typedef struct { /* Key-value pairs from env */
@@ -315,6 +317,7 @@ typedef struct {
uint_t cliopener : 1; /* All-CLI app opener */ uint_t cliopener : 1; /* All-CLI app opener */
uint_t waitedit : 1; /* For ops that can't be detached, used EDITOR */ uint_t waitedit : 1; /* For ops that can't be detached, used EDITOR */
uint_t rollover : 1; /* Roll over at edges */ uint_t rollover : 1; /* Roll over at edges */
@ -55,7 +37,7 @@ index 9141d78..de4d9f0 100644
} settings; } settings;
/* Non-persistent program-internal states */ /* Non-persistent program-internal states */
@@ -366,7 +380,18 @@ static struct { @@ -367,7 +370,19 @@ static struct {
ushort_t maxnameln, maxsizeln, maxuidln, maxgidln, maxentln, uidln, gidln, printguid; ushort_t maxnameln, maxsizeln, maxuidln, maxgidln, maxentln, uidln, gidln, printguid;
} dtls; } dtls;
@ -67,6 +49,7 @@ index 9141d78..de4d9f0 100644
+typedef struct { +typedef struct {
+ simple_git_status_t *statuses; + simple_git_status_t *statuses;
+ size_t len; + size_t len;
+ bool show;
+} simple_git_statuses_t; +} simple_git_statuses_t;
+ +
/* GLOBALS */ /* GLOBALS */
@ -74,7 +57,7 @@ index 9141d78..de4d9f0 100644
/* Configuration, contexts */ /* Configuration, contexts */
static settings cfg = { static settings cfg = {
@@ -397,6 +422,7 @@ static settings cfg = { @@ -398,6 +413,7 @@ static settings cfg = {
0, /* cliopener */ 0, /* cliopener */
0, /* waitedit */ 0, /* waitedit */
1, /* rollover */ 1, /* rollover */
@ -82,41 +65,26 @@ index 9141d78..de4d9f0 100644
}; };
static context g_ctx[CTX_MAX] __attribute__ ((aligned)); static context g_ctx[CTX_MAX] __attribute__ ((aligned));
@@ -3472,6 +3498,79 @@ static char *get_kv_val(kv *kvarr, char *buf, int key, uchar_t max, uchar_t id) @@ -3506,6 +3522,66 @@ static char *get_kv_val(kv *kvarr, char *buf, int key, uchar_t max, uchar_t id)
return NULL; return NULL;
} }
+static git_column_status_t git_get_indexed_status(const uint32_t status) { +static void print_gitstatus(git_status_t status) {
+ if (status & GIT_STATUS_INDEX_NEW) return GIT_COLUMN_STATUS_NEW; + if (status & GIT_STATUS_INDEX_NEW) addch('N' | (g_state.oldcolor ? COLOR_PAIR(1) : COLOR_PAIR(C_EXE)));
+ if (status & GIT_STATUS_INDEX_MODIFIED) return GIT_COLUMN_STATUS_MODIFIED; + else if (status & GIT_STATUS_INDEX_MODIFIED) addch('M' | (g_state.oldcolor ? COLOR_PAIR(1) : COLOR_PAIR(4)));
+ if (status & GIT_STATUS_INDEX_DELETED) return GIT_COLUMN_STATUS_DELETED; + else if (status & GIT_STATUS_INDEX_DELETED) addch('D' | (g_state.oldcolor ? COLOR_PAIR(1) : COLOR_PAIR(C_UND)));
+ if (status & GIT_STATUS_INDEX_RENAMED) return GIT_COLUMN_STATUS_RENAMED; + else if (status & GIT_STATUS_INDEX_RENAMED) addch('R' | (g_state.oldcolor ? COLOR_PAIR(1) : COLOR_PAIR(C_CHR)));
+ if (status & GIT_STATUS_INDEX_TYPECHANGE) return GIT_COLUMN_STATUS_TYPE_CHANGE; + else if (status & GIT_STATUS_INDEX_TYPECHANGE) addch('T' | (g_state.oldcolor ? COLOR_PAIR(1) : COLOR_PAIR(C_HRD)));
+ return GIT_COLUMN_STATUS_UNMOD; + else addch('-' | 0);
+}
+ +
+static git_column_status_t git_get_staged_status(const uint32_t status) { + if (status & GIT_STATUS_WT_NEW) addch('N' | (g_state.oldcolor ? COLOR_PAIR(1) : COLOR_PAIR(C_EXE)));
+ if (status & GIT_STATUS_WT_NEW) return GIT_COLUMN_STATUS_NEW; + else if (status & GIT_STATUS_WT_MODIFIED) addch('M' | (g_state.oldcolor ? COLOR_PAIR(1) : COLOR_PAIR(4)));
+ if (status & GIT_STATUS_WT_MODIFIED) return GIT_COLUMN_STATUS_MODIFIED; + else if (status & GIT_STATUS_WT_DELETED) addch('D' | (g_state.oldcolor ? COLOR_PAIR(1) : COLOR_PAIR(C_UND)));
+ if (status & GIT_STATUS_WT_DELETED) return GIT_COLUMN_STATUS_DELETED; + else if (status & GIT_STATUS_WT_RENAMED) addch('R' | (g_state.oldcolor ? COLOR_PAIR(1) : COLOR_PAIR(C_CHR)));
+ if (status & GIT_STATUS_WT_RENAMED) return GIT_COLUMN_STATUS_RENAMED; + else if (status & GIT_STATUS_WT_TYPECHANGE) addch('T' | (g_state.oldcolor ? COLOR_PAIR(1) : COLOR_PAIR(C_HRD)));
+ if (status & GIT_STATUS_WT_TYPECHANGE) return GIT_COLUMN_STATUS_TYPE_CHANGE; + else if (status & GIT_STATUS_IGNORED) addch('I' | 0);
+ if (status & GIT_STATUS_IGNORED) return GIT_COLUMN_STATUS_IGNORED; + else if (status & GIT_STATUS_CONFLICTED) addch('U' | (g_state.oldcolor ? COLOR_PAIR(1) : COLOR_PAIR(C_UND)));
+ if (status & GIT_STATUS_CONFLICTED) return GIT_COLUMN_STATUS_CONFLICTED; + else addch('-' | 0);
+ return GIT_COLUMN_STATUS_UNMOD;
+}
+
+static void print_gitstatus(git_column_status_t status) {
+ switch (status) {
+ case GIT_COLUMN_STATUS_UNMOD: addch('-' | 0); break;
+ case GIT_COLUMN_STATUS_NEW: addch('N' | (g_state.oldcolor ? COLOR_PAIR(1) : COLOR_PAIR(C_EXE))); break;
+ case GIT_COLUMN_STATUS_MODIFIED: addch('M' | (g_state.oldcolor ? COLOR_PAIR(1) : COLOR_PAIR(4))); break;
+ case GIT_COLUMN_STATUS_DELETED: addch('D' | (g_state.oldcolor ? COLOR_PAIR(1) : COLOR_PAIR(C_UND))); break;
+ case GIT_COLUMN_STATUS_RENAMED: addch('R' | (g_state.oldcolor ? COLOR_PAIR(1) : COLOR_PAIR(C_CHR))); break;
+ case GIT_COLUMN_STATUS_TYPE_CHANGE: addch('T' | (g_state.oldcolor ? COLOR_PAIR(1) : COLOR_PAIR(C_HRD))); break;
+ case GIT_COLUMN_STATUS_IGNORED: addch('I' | 0); break;
+ case GIT_COLUMN_STATUS_CONFLICTED: addch('U' | (g_state.oldcolor ? COLOR_PAIR(1) : COLOR_PAIR(C_UND))); break;
+ }
+} +}
+ +
+static simple_git_statuses_t statuses_from_path(const char *path) { +static simple_git_statuses_t statuses_from_path(const char *path) {
@ -157,25 +125,26 @@ index 9141d78..de4d9f0 100644
+ free(git_statuses.statuses[i].path); + free(git_statuses.statuses[i].path);
+ +
+ free(git_statuses.statuses); + free(git_statuses.statuses);
+ git_statuses.len = 0;
+ git_statuses.show = FALSE;
+} +}
+ +
static void resetdircolor(int flags) static void resetdircolor(int flags)
{ {
/* 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 */
@@ -3781,6 +3880,12 @@ static void printent(const struct entry *ent, uint_t namecols, bool sel) @@ -3816,6 +3892,11 @@ static void printent(const struct entry *ent, uint_t namecols, bool sel)
int attrs = 0, namelen; int attrs = 0, namelen;
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.len && (cfg.showdetail || cfg.normalgit)) { + if (git_statuses.show && (cfg.showdetail || cfg.normalgit)) {
+ addch(' '); + addch(' ');
+ print_gitstatus(ent->status_indexed); + print_gitstatus(ent->git_status);
+ print_gitstatus(ent->status_staged);
+ } + }
+ +
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)
@@ -5125,6 +5230,10 @@ static int dentfill(char *path, struct entry **ppdents) @@ -5166,6 +5247,10 @@ static int dentfill(char *path, struct entry **ppdents)
attron(COLOR_PAIR(cfg.curctx + 1)); attron(COLOR_PAIR(cfg.curctx + 1));
} }
@ -186,56 +155,57 @@ index 9141d78..de4d9f0 100644
#if _POSIX_C_SOURCE >= 200112L #if _POSIX_C_SOURCE >= 200112L
posix_fadvise(fd, 0, 0, POSIX_FADV_SEQUENTIAL); posix_fadvise(fd, 0, 0, POSIX_FADV_SEQUENTIAL);
#endif #endif
@@ -5322,6 +5431,22 @@ static int dentfill(char *path, struct entry **ppdents) @@ -5363,6 +5448,23 @@ static int dentfill(char *path, struct entry **ppdents)
#endif #endif
} }
+ if (git_statuses.len) { + if (git_statuses.len) {
+ char *dentpath = abspath(dentp->name, path); + char *dentpath = abspath(dentp->name, path);
+ namebuflen = xstrlen(dentpath); + namebuflen = xstrlen(dentpath);
+ uint merged_status = 0; + dentp->git_status = GIT_STATUS_CURRENT;
+ +
+ for (size_t i = 0; i < git_statuses.len; ++i) + for (size_t i = 0; i < git_statuses.len; ++i)
+ if (!(dentp->flags & DIR_OR_LINK_TO_DIR) ? !xstrcmp(git_statuses.statuses[i].path, dentpath) : + if (git_statuses.statuses[i].status)
+ (is_prefix(git_statuses.statuses[i].path, dentpath, namebuflen) && + if ((dentp->flags & DIR_OR_LINK_TO_DIR) ? (is_prefix(git_statuses.statuses[i].path, dentpath, namebuflen) &&
+ (namebuflen <= xstrlen(git_statuses.statuses[i].path)))) + namebuflen <= xstrlen(git_statuses.statuses[i].path)) : !xstrcmp(git_statuses.statuses[i].path, dentpath)) {
+ merged_status |= git_statuses.statuses[i].status; + if (git_statuses.statuses[i].status != GIT_STATUS_IGNORED)
+ git_statuses.show = TRUE;
+ dentp->git_status |= git_statuses.statuses[i].status;
+ }
+ +
+ dentp->status_indexed = git_get_indexed_status(merged_status);
+ dentp->status_staged = git_get_staged_status(merged_status);
+ free(dentpath); + free(dentpath);
+ } + }
+ +
++ndents; ++ndents;
} while ((dp = readdir(dirp))); } while ((dp = readdir(dirp)));
@@ -5834,7 +5959,7 @@ static int adjust_cols(int n) @@ -5873,7 +5975,7 @@ static int adjust_cols(int n)
} }
/* 2 columns for preceding space and indicator */ /* 2 columns for preceding space and indicator */
- return (n - 2); - return (n - 2);
+ return (n - ((cfg.normalgit && !cfg.showdetail) ? 5 : 2)); + return (n - ((git_statuses.show && (cfg.normalgit && !cfg.showdetail)) ? 5 : 2));
} }
static void draw_line(char *path, int ncols) static void draw_line(char *path, int ncols)
@@ -5972,7 +6097,7 @@ static void redraw(char *path) @@ -6011,7 +6113,7 @@ static void redraw(char *path)
#endif #endif
} }
} }
- dtls.maxentln = dtls.maxnameln + dtls.maxsizeln + (dtls.printguid ? (dtls.maxuidln + dtls.maxgidln) : 0) + (g_state.uidgid ? 26 : 23); - dtls.maxentln = dtls.maxnameln + dtls.maxsizeln + (dtls.printguid ? (dtls.maxuidln + dtls.maxgidln) : 0) + (g_state.uidgid ? 26 : 23);
+ dtls.maxentln = dtls.maxnameln + dtls.maxsizeln + (dtls.printguid ? (dtls.maxuidln + dtls.maxgidln) : 0) + (g_state.uidgid ? 29 : 26); + dtls.maxentln = dtls.maxnameln + dtls.maxsizeln + (dtls.printguid ? (dtls.maxuidln + dtls.maxgidln) : 0) + (git_statuses.show ? 3 : 0) + (g_state.uidgid ? 26 : 23);
ncols = adjust_cols(ncols); ncols = adjust_cols(ncols);
@@ -7576,6 +7701,7 @@ static void usage(void) @@ -7610,6 +7712,7 @@ static void usage(void)
" -f use readline history file\n"
#endif #endif
" -F show fortune\n"
" -g regex filters\n" " -g regex filters\n"
+ " -G always show git status\n" + " -G always show git status\n"
" -H show hidden files\n" " -H show hidden files\n"
" -J no auto-proceed on select\n" " -J no auto-proceed on select\n"
" -K detect key collision\n" " -K detect key collision\n"
@@ -7714,6 +7840,8 @@ static void cleanup(void) @@ -7748,6 +7851,8 @@ static void cleanup(void)
fflush(stdout); fflush(stdout);
} }
#endif #endif
@ -244,16 +214,16 @@ index 9141d78..de4d9f0 100644
free(selpath); free(selpath);
free(plgpath); free(plgpath);
free(cfgpath); free(cfgpath);
@@ -7758,7 +7886,7 @@ int main(int argc, char *argv[]) @@ -7792,7 +7897,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:cCdDeEfgHJKl:nop:P:QrRs:St:T:uUVwxh"))) != -1) { - : getopt(argc, argv, "aAb:cCdDeEfgHJKl:nop:P:QrRs:St:T:uUVwxX:h"))) != -1) {
+ : getopt(argc, argv, "aAb:cCdDeEfgGHJKl:nop:P:QrRs:St:T:uUVwxh"))) != -1) { + : getopt(argc, argv, "aAb:cCdDeEfgGHJKl:nop:P:QrRs:St:T:uUVwxX:h"))) != -1) {
switch (opt) { switch (opt) {
#ifndef NOFIFO #ifndef NOFIFO
case 'a': case 'a':
@@ -7802,6 +7930,9 @@ int main(int argc, char *argv[]) @@ -7833,6 +7938,9 @@ int main(int argc, char *argv[])
cfg.regex = 1; cfg.regex = 1;
filterfn = &visible_re; filterfn = &visible_re;
break; break;
@ -263,7 +233,7 @@ index 9141d78..de4d9f0 100644
case 'H': case 'H':
cfg.showhidden = 1; cfg.showhidden = 1;
break; break;
@@ -7909,6 +8040,7 @@ int main(int argc, char *argv[]) @@ -7940,6 +8048,7 @@ int main(int argc, char *argv[])
return EXIT_FAILURE; return EXIT_FAILURE;
atexit(cleanup); atexit(cleanup);

View File

@ -4,10 +4,10 @@
# Author: Luuk van Baal # Author: Luuk van Baal
diff --git a/src/nnn.c b/src/nnn.c diff --git a/src/nnn.c b/src/nnn.c
index d83d7f6..22402fa 100644 index eabe30f0..d8dc5925 100644
--- a/src/nnn.c --- a/src/nnn.c
+++ b/src/nnn.c +++ b/src/nnn.c
@@ -362,6 +362,10 @@ typedef struct { @@ -363,6 +363,10 @@ typedef struct {
} session_header_t; } session_header_t;
#endif #endif
@ -18,8 +18,8 @@ index d83d7f6..22402fa 100644
/* GLOBALS */ /* GLOBALS */
/* Configuration, contexts */ /* Configuration, contexts */
@@ -1038,10 +1042,12 @@ static char *getpwname(uid_t uid) @@ -1039,10 +1043,12 @@ static char *getpwname(uid_t uid)
static char *namecache = NULL; static char *namecache;
if (uidcache != uid) { if (uidcache != uid) {
+ if (dtls.maxuidln && !dtls.printguid) dtls.printguid = 1; + if (dtls.maxuidln && !dtls.printguid) dtls.printguid = 1;
@ -31,8 +31,8 @@ index d83d7f6..22402fa 100644
} }
return namecache ? namecache : xitoa(uid); return namecache ? namecache : xitoa(uid);
@@ -1053,10 +1059,12 @@ static char *getgrname(gid_t gid) @@ -1054,10 +1060,12 @@ static char *getgrname(gid_t gid)
static char *grpcache = NULL; static char *grpcache;
if (gidcache != gid) { if (gidcache != gid) {
+ if (dtls.maxgidln && !dtls.printguid) dtls.printguid = 1; + if (dtls.maxgidln && !dtls.printguid) dtls.printguid = 1;
@ -44,7 +44,7 @@ index d83d7f6..22402fa 100644
} }
return grpcache ? grpcache : xitoa(gid); return grpcache ? grpcache : xitoa(gid);
@@ -3479,14 +3487,13 @@ static void resetdircolor(int flags) @@ -3509,14 +3517,13 @@ static void resetdircolor(int flags)
* Max supported str length: NAME_MAX; * Max supported str length: NAME_MAX;
*/ */
#ifdef NOLC #ifdef NOLC
@ -62,7 +62,7 @@ index d83d7f6..22402fa 100644
{ {
wchar_t * const wbuf = (wchar_t *)g_buf; wchar_t * const wbuf = (wchar_t *)g_buf;
wchar_t *buf = wbuf; wchar_t *buf = wbuf;
@@ -3510,7 +3517,7 @@ static wchar_t *unescape(const char *str, uint_t maxcols) @@ -3541,7 +3548,7 @@ static wchar_t *unescape(const char *str, uint_t maxcols)
++buf; ++buf;
} }
@ -71,7 +71,7 @@ index d83d7f6..22402fa 100644
} }
static off_t get_size(off_t size, off_t *pval, uint_t comp) static off_t get_size(off_t size, off_t *pval, uint_t comp)
@@ -3771,33 +3778,7 @@ static uchar_t get_color_pair_name_ind(const struct entry *ent, char *pind, int @@ -3802,33 +3809,7 @@ static uchar_t get_color_pair_name_ind(const struct entry *ent, char *pind, int
static void printent(const struct entry *ent, uint_t namecols, bool sel) static void printent(const struct entry *ent, uint_t namecols, bool sel)
{ {
char ind = '\0'; char ind = '\0';
@ -106,7 +106,7 @@ index d83d7f6..22402fa 100644
uchar_t color_pair = get_color_pair_name_ind(ent, &ind, &attrs); uchar_t color_pair = get_color_pair_name_ind(ent, &ind, &attrs);
addch((ent->flags & FILE_SELECTED) ? '+' | A_REVERSE | A_BOLD : ' '); addch((ent->flags & FILE_SELECTED) ? '+' | A_REVERSE | A_BOLD : ' ');
@@ -3822,15 +3803,40 @@ static void printent(const struct entry *ent, uint_t namecols, bool sel) @@ -3853,15 +3834,40 @@ static void printent(const struct entry *ent, uint_t namecols, bool sel)
++namecols; ++namecols;
#ifndef NOLC #ifndef NOLC
@ -150,7 +150,7 @@ index d83d7f6..22402fa 100644
} }
static void savecurctx(settings *curcfg, char *path, char *curname, int nextctx) static void savecurctx(settings *curcfg, char *path, char *curname, int nextctx)
@@ -5814,18 +5820,6 @@ static void statusbar(char *path) @@ -5849,18 +5855,6 @@ static void statusbar(char *path)
tocursor(); tocursor();
} }
@ -169,7 +169,7 @@ index d83d7f6..22402fa 100644
static int adjust_cols(int n) static int adjust_cols(int n)
{ {
/* Calculate the number of cols available to print entry name */ /* Calculate the number of cols available to print entry name */
@@ -5833,13 +5827,10 @@ static int adjust_cols(int n) @@ -5868,13 +5862,10 @@ static int adjust_cols(int n)
n -= (g_state.oldcolor ? 0 : 1 + xstrlen(ICON_PADDING_LEFT) + xstrlen(ICON_PADDING_RIGHT)); n -= (g_state.oldcolor ? 0 : 1 + xstrlen(ICON_PADDING_LEFT) + xstrlen(ICON_PADDING_RIGHT));
#endif #endif
if (cfg.showdetail) { if (cfg.showdetail) {
@ -186,7 +186,7 @@ index d83d7f6..22402fa 100644
} }
/* 2 columns for preceding space and indicator */ /* 2 columns for preceding space and indicator */
@@ -5877,8 +5868,6 @@ static void draw_line(char *path, int ncols) @@ -5912,8 +5903,6 @@ static void draw_line(char *path, int ncols)
if (dir) if (dir)
attroff(COLOR_PAIR(cfg.curctx + 1) | A_BOLD); attroff(COLOR_PAIR(cfg.curctx + 1) | A_BOLD);
@ -195,7 +195,7 @@ index d83d7f6..22402fa 100644
statusbar(path); statusbar(path);
} }
@@ -5970,6 +5959,21 @@ static void redraw(char *path) @@ -6005,6 +5994,21 @@ static void redraw(char *path)
attroff(A_UNDERLINE | COLOR_PAIR(cfg.curctx + 1)); attroff(A_UNDERLINE | COLOR_PAIR(cfg.curctx + 1));
@ -217,7 +217,7 @@ index d83d7f6..22402fa 100644
ncols = adjust_cols(ncols); ncols = adjust_cols(ncols);
/* Go to first entry */ /* Go to first entry */
@@ -6011,8 +6015,6 @@ static void redraw(char *path) @@ -6046,8 +6050,6 @@ static void redraw(char *path)
#endif #endif
} }