mirror of
https://github.com/jarun/nnn.git
synced 2024-11-24 11:51:27 +00:00
Update gitstatus patch (#1048)
This commit is contained in:
parent
14be56057c
commit
c205177ac6
|
@ -5,7 +5,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 d83d7f6..b23218e 100644
|
index d83d7f6..7940077 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 @@
|
||||||
|
@ -33,15 +33,15 @@ index d83d7f6..b23218e 100644
|
||||||
|
|
||||||
/* STRUCTURES */
|
/* STRUCTURES */
|
||||||
|
|
||||||
@@ -258,6 +269,8 @@ typedef struct entry {
|
@@ -263,6 +274,8 @@ typedef struct entry {
|
||||||
ulong_t blocks : 40; /* 5 bytes (enough for 512 TiB in 512B blocks allocated) */
|
uid_t uid; /* 4 bytes */
|
||||||
ulong_t nlen : 16; /* 2 bytes (length of file name) */
|
gid_t gid; /* 4 bytes */
|
||||||
ulong_t flags : 8; /* 1 byte (flags specific to the file) */
|
#endif
|
||||||
+ git_column_status_t status_indexed;
|
+ git_column_status_t status_indexed;
|
||||||
+ git_column_status_t status_staged;
|
+ git_column_status_t status_staged;
|
||||||
};
|
} *pEntry;
|
||||||
#ifndef NOUG
|
|
||||||
uid_t uid; /* 4 bytes */
|
/* Key-value pairs from env */
|
||||||
@@ -362,7 +375,18 @@ typedef struct {
|
@@ -362,7 +375,18 @@ typedef struct {
|
||||||
} session_header_t;
|
} session_header_t;
|
||||||
#endif
|
#endif
|
||||||
|
@ -61,7 +61,7 @@ index d83d7f6..b23218e 100644
|
||||||
|
|
||||||
/* Configuration, contexts */
|
/* Configuration, contexts */
|
||||||
static settings cfg = {
|
static settings cfg = {
|
||||||
@@ -3464,6 +3488,79 @@ static char *get_kv_val(kv *kvarr, char *buf, int key, uchar_t max, uchar_t id)
|
@@ -3464,6 +3488,80 @@ static char *get_kv_val(kv *kvarr, char *buf, int key, uchar_t max, uchar_t id)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,17 +131,18 @@ index d83d7f6..b23218e 100644
|
||||||
+ return statuses;
|
+ return statuses;
|
||||||
+}
|
+}
|
||||||
+
|
+
|
||||||
+static void statuses_free(simple_git_statuses_t statuses) {
|
+static void git_statuses_free(void) {
|
||||||
+ for (size_t i = 0; i < statuses.len; ++i)
|
+ for (size_t i = 0; i < git_statuses.len; ++i)
|
||||||
+ free(statuses.statuses[i].path);
|
+ free(git_statuses.statuses[i].path);
|
||||||
+
|
+
|
||||||
+ free(statuses.statuses);
|
+ free(git_statuses.statuses);
|
||||||
|
+ git_statuses.len = 0;
|
||||||
+}
|
+}
|
||||||
+
|
+
|
||||||
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 */
|
||||||
@@ -3794,6 +3891,11 @@ static void printent(const struct entry *ent, uint_t namecols, bool sel)
|
@@ -3794,6 +3892,11 @@ static void printent(const struct entry *ent, uint_t namecols, bool sel)
|
||||||
|
|
||||||
if (attrs)
|
if (attrs)
|
||||||
attroff(attrs);
|
attroff(attrs);
|
||||||
|
@ -153,13 +154,12 @@ index d83d7f6..b23218e 100644
|
||||||
}
|
}
|
||||||
|
|
||||||
attrs = 0;
|
attrs = 0;
|
||||||
@@ -5119,6 +5221,11 @@ static int dentfill(char *path, struct entry **ppdents)
|
@@ -5119,6 +5222,10 @@ static int dentfill(char *path, struct entry **ppdents)
|
||||||
attron(COLOR_PAIR(cfg.curctx + 1));
|
attron(COLOR_PAIR(cfg.curctx + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
+ if (git_statuses.len)
|
+ if (git_statuses.len)
|
||||||
+ statuses_free(git_statuses);
|
+ git_statuses_free();
|
||||||
+ if (cfg.showdetail)
|
|
||||||
+ git_statuses = statuses_from_path(path);
|
+ git_statuses = statuses_from_path(path);
|
||||||
+
|
+
|
||||||
#if _POSIX_C_SOURCE >= 200112L
|
#if _POSIX_C_SOURCE >= 200112L
|
||||||
|
@ -173,7 +173,7 @@ index d83d7f6..b23218e 100644
|
||||||
+ uint merged_status = 0;
|
+ uint merged_status = 0;
|
||||||
+ char *dentpath = abspath(dentp->name, path);
|
+ char *dentpath = abspath(dentp->name, path);
|
||||||
+
|
+
|
||||||
+ 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) {
|
+ if (dentp->flags & DIR_OR_LINK_TO_DIR) {
|
||||||
+ size_t dentlen = xstrlen(dentpath);
|
+ size_t dentlen = xstrlen(dentpath);
|
||||||
+
|
+
|
||||||
|
@ -199,7 +199,7 @@ index d83d7f6..b23218e 100644
|
||||||
+ if (n < 38)
|
+ if (n < 38)
|
||||||
cfg.showdetail ^= 1;
|
cfg.showdetail ^= 1;
|
||||||
else {
|
else {
|
||||||
/* 3 more accounted for below */
|
/* 2 more accounted for below */
|
||||||
- n -= 32;
|
- n -= 32;
|
||||||
+ n -= 34;
|
+ n -= 34;
|
||||||
}
|
}
|
||||||
|
@ -209,7 +209,7 @@ index d83d7f6..b23218e 100644
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
+ statuses_free(git_statuses);
|
+ git_statuses_free();
|
||||||
+ git_libgit2_shutdown();
|
+ git_libgit2_shutdown();
|
||||||
free(selpath);
|
free(selpath);
|
||||||
free(plgpath);
|
free(plgpath);
|
||||||
|
|
|
@ -6,7 +6,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 22402fa..33be591 100644
|
index 9b55d5d..240ace2 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 @@
|
||||||
|
@ -34,15 +34,15 @@ index 22402fa..33be591 100644
|
||||||
|
|
||||||
/* STRUCTURES */
|
/* STRUCTURES */
|
||||||
|
|
||||||
@@ -258,6 +269,8 @@ typedef struct entry {
|
@@ -262,6 +273,8 @@ typedef struct entry {
|
||||||
ulong_t blocks : 40; /* 5 bytes (enough for 512 TiB in 512B blocks allocated) */
|
|
||||||
ulong_t nlen : 16; /* 2 bytes (length of file name) */
|
|
||||||
ulong_t flags : 8; /* 1 byte (flags specific to the file) */
|
|
||||||
+ git_column_status_t status_indexed;
|
|
||||||
+ git_column_status_t status_staged;
|
|
||||||
};
|
|
||||||
#ifndef NOUG
|
#ifndef NOUG
|
||||||
uid_t uid; /* 4 bytes */
|
uid_t uid; /* 4 bytes */
|
||||||
|
gid_t gid; /* 4 bytes */
|
||||||
|
+ git_column_status_t status_indexed;
|
||||||
|
+ git_column_status_t status_staged;
|
||||||
|
#endif
|
||||||
|
} *pEntry;
|
||||||
|
|
||||||
@@ -366,7 +379,18 @@ static struct {
|
@@ -366,7 +379,18 @@ static struct {
|
||||||
ushort_t maxnameln, maxsizeln, maxuidln, maxgidln, maxentln, uidln, gidln, printguid;
|
ushort_t maxnameln, maxsizeln, maxuidln, maxgidln, maxentln, uidln, gidln, printguid;
|
||||||
} dtls;
|
} dtls;
|
||||||
|
@ -62,7 +62,7 @@ index 22402fa..33be591 100644
|
||||||
|
|
||||||
/* Configuration, contexts */
|
/* Configuration, contexts */
|
||||||
static settings cfg = {
|
static settings cfg = {
|
||||||
@@ -3472,6 +3496,85 @@ static char *get_kv_val(kv *kvarr, char *buf, int key, uchar_t max, uchar_t id)
|
@@ -3472,6 +3496,79 @@ static char *get_kv_val(kv *kvarr, char *buf, int key, uchar_t max, uchar_t id)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,12 +99,6 @@ index 22402fa..33be591 100644
|
||||||
+ }
|
+ }
|
||||||
+}
|
+}
|
||||||
+
|
+
|
||||||
+static bool starts_with(const char *const s, const char *const start) {
|
|
||||||
+ const size_t start_len = xstrlen(start);
|
|
||||||
+
|
|
||||||
+ return (start_len <= xstrlen(s)) && !strncmp(s, start, start_len);
|
|
||||||
+}
|
|
||||||
+
|
|
||||||
+static simple_git_statuses_t statuses_from_path(const char *path) {
|
+static simple_git_statuses_t statuses_from_path(const char *path) {
|
||||||
+ git_repository *repo;
|
+ git_repository *repo;
|
||||||
+ git_buf ret = { .ptr = NULL, .asize = 0, .size = 0 };
|
+ git_buf ret = { .ptr = NULL, .asize = 0, .size = 0 };
|
||||||
|
@ -138,17 +132,17 @@ index 22402fa..33be591 100644
|
||||||
+ return statuses;
|
+ return statuses;
|
||||||
+}
|
+}
|
||||||
+
|
+
|
||||||
+static void statuses_free(simple_git_statuses_t statuses) {
|
+static void git_statuses_free(void) {
|
||||||
+ for (size_t i = 0; i < statuses.len; ++i)
|
+ for (size_t i = 0; i < git_statuses.len; ++i)
|
||||||
+ free(statuses.statuses[i].path);
|
+ free(git_statuses.statuses[i].path);
|
||||||
+
|
+
|
||||||
+ free(statuses.statuses);
|
+ free(git_statuses.statuses);
|
||||||
+}
|
+}
|
||||||
+
|
+
|
||||||
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 */
|
||||||
@@ -3783,6 +3886,12 @@ static void printent(const struct entry *ent, uint_t namecols, bool sel)
|
@@ -3783,6 +3880,12 @@ static void printent(const struct entry *ent, uint_t namecols, bool sel)
|
||||||
|
|
||||||
addch((ent->flags & FILE_SELECTED) ? '+' | A_REVERSE | A_BOLD : ' ');
|
addch((ent->flags & FILE_SELECTED) ? '+' | A_REVERSE | A_BOLD : ' ');
|
||||||
|
|
||||||
|
@ -161,32 +155,38 @@ index 22402fa..33be591 100644
|
||||||
if (g_state.oldcolor)
|
if (g_state.oldcolor)
|
||||||
resetdircolor(ent->flags);
|
resetdircolor(ent->flags);
|
||||||
else {
|
else {
|
||||||
@@ -5125,6 +5234,11 @@ static int dentfill(char *path, struct entry **ppdents)
|
@@ -5125,6 +5228,10 @@ static int dentfill(char *path, struct entry **ppdents)
|
||||||
attron(COLOR_PAIR(cfg.curctx + 1));
|
attron(COLOR_PAIR(cfg.curctx + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
+ if (git_statuses.len)
|
+ if (git_statuses.len)
|
||||||
+ statuses_free(git_statuses);
|
+ git_statuses_free();
|
||||||
+ if (cfg.showdetail)
|
|
||||||
+ git_statuses = statuses_from_path(path);
|
+ git_statuses = statuses_from_path(path);
|
||||||
+
|
+
|
||||||
#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 +5436,18 @@ static int dentfill(char *path, struct entry **ppdents)
|
@@ -5322,6 +5429,25 @@ static int dentfill(char *path, struct entry **ppdents)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
+ if (git_statuses.len) {
|
+ if (git_statuses.len) {
|
||||||
+ uint merged_status = 0;
|
+ uint merged_status = 0;
|
||||||
|
+ char *dentpath = abspath(dentp->name, path);
|
||||||
+
|
+
|
||||||
+ 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) ? starts_with(git_statuses.statuses[i].path, abspath(dentp->name, path))
|
+ if (dentp->flags & DIR_OR_LINK_TO_DIR) {
|
||||||
+ : !xstrcmp(git_statuses.statuses[i].path, abspath(dentp->name, path)))
|
+ size_t dentlen = xstrlen(dentpath);
|
||||||
|
+
|
||||||
|
+ if ((dentlen <= xstrlen(git_statuses.statuses[i].path)) && is_prefix(git_statuses.statuses[i].path, dentpath, dentlen))
|
||||||
+ merged_status |= git_statuses.statuses[i].status;
|
+ merged_status |= git_statuses.statuses[i].status;
|
||||||
|
+ } else if (!xstrcmp(git_statuses.statuses[i].path, dentpath))
|
||||||
|
+ merged_status |= git_statuses.statuses[i].status;
|
||||||
|
+ }
|
||||||
+
|
+
|
||||||
+ dentp->status_indexed = git_get_indexed_status(merged_status);
|
+ dentp->status_indexed = git_get_indexed_status(merged_status);
|
||||||
+ dentp->status_staged = git_get_staged_status(merged_status);
|
+ dentp->status_staged = git_get_staged_status(merged_status);
|
||||||
|
+ free(dentpath);
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
++ndents;
|
++ndents;
|
||||||
|
@ -205,7 +205,7 @@ index 22402fa..33be591 100644
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
+ statuses_free(git_statuses);
|
+ git_statuses_free();
|
||||||
+ git_libgit2_shutdown();
|
+ git_libgit2_shutdown();
|
||||||
free(selpath);
|
free(selpath);
|
||||||
free(plgpath);
|
free(plgpath);
|
||||||
|
|
|
@ -178,7 +178,7 @@ index d83d7f6..22402fa 100644
|
||||||
+ if (n < (dtls.maxentln + 1 - dtls.maxnameln))
|
+ if (n < (dtls.maxentln + 1 - dtls.maxnameln))
|
||||||
cfg.showdetail ^= 1;
|
cfg.showdetail ^= 1;
|
||||||
- else {
|
- else {
|
||||||
- /* 3 more accounted for below */
|
- /* 2 more accounted for below */
|
||||||
- n -= 32;
|
- n -= 32;
|
||||||
- }
|
- }
|
||||||
+ else
|
+ else
|
||||||
|
|
Loading…
Reference in a new issue