Further gitstatus cleanup/fixes (#1046)

This commit is contained in:
luukvbaal 2021-06-03 11:01:27 +02:00 committed by GitHub
parent 29ef232301
commit f3eac98678
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 151 additions and 165 deletions

View File

@ -3,26 +3,25 @@
# Dependencies: libgit2 # Dependencies: libgit2
# #
# 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 562622f..96d946a 100644 index d83d7f6..b23218e 100644
--- a/src/nnn.c --- a/src/nnn.c
+++ b/src/nnn.c +++ b/src/nnn.c
@@ -127,6 +127,8 @@ @@ -105,6 +105,7 @@
#include "qsort.h" #include <wchar.h>
#endif #include <pwd.h>
#include <grp.h>
+#include <git2.h> +#include <git2.h>
+
/* Macro definitions */ #if !defined(alloca) && defined(__GNUC__)
#define VERSION "4.0" /*
#define GENERAL_INFO "BSD 2-Clause\nhttps://github.com/jarun/nnn" @@ -244,6 +245,16 @@ typedef unsigned int uint_t;
@@ -245,6 +247,18 @@ typedef unsigned char uchar_t; typedef unsigned char uchar_t;
typedef unsigned short ushort_t; typedef unsigned short ushort_t;
typedef unsigned long long ulong_t; typedef unsigned long long ulong_t;
+typedef enum { +typedef enum {
+ GIT_COLUMN_STATUS_NONE = 0, + GIT_COLUMN_STATUS_UNMOD = 0,
+ GIT_COLUMN_STATUS_UNMOD,
+ GIT_COLUMN_STATUS_NEW, + GIT_COLUMN_STATUS_NEW,
+ GIT_COLUMN_STATUS_MODIFIED, + GIT_COLUMN_STATUS_MODIFIED,
+ GIT_COLUMN_STATUS_DELETED, + GIT_COLUMN_STATUS_DELETED,
@ -31,11 +30,10 @@ index 562622f..96d946a 100644
+ GIT_COLUMN_STATUS_IGNORED, + GIT_COLUMN_STATUS_IGNORED,
+ GIT_COLUMN_STATUS_CONFLICTED, + GIT_COLUMN_STATUS_CONFLICTED,
+} git_column_status_t; +} git_column_status_t;
+
/* STRUCTURES */ /* STRUCTURES */
/* Directory entry */ @@ -258,6 +269,8 @@ typedef struct entry {
@@ -258,6 +272,8 @@ typedef struct entry {
ulong_t blocks : 40; /* 5 bytes (enough for 512 TiB in 512B blocks allocated) */ 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 nlen : 16; /* 2 bytes (length of file name) */
ulong_t flags : 8; /* 1 byte (flags specific to the file) */ ulong_t flags : 8; /* 1 byte (flags specific to the file) */
@ -44,7 +42,7 @@ index 562622f..96d946a 100644
}; };
#ifndef NOUG #ifndef NOUG
uid_t uid; /* 4 bytes */ uid_t uid; /* 4 bytes */
@@ -362,7 +378,18 @@ typedef struct { @@ -362,7 +375,18 @@ typedef struct {
} session_header_t; } session_header_t;
#endif #endif
@ -63,9 +61,9 @@ index 562622f..96d946a 100644
/* Configuration, contexts */ /* Configuration, contexts */
static settings cfg = { static settings cfg = {
@@ -809,6 +836,92 @@ static void notify_fifo(bool force); @@ -3464,6 +3488,79 @@ static char *get_kv_val(kv *kvarr, char *buf, int key, uchar_t max, uchar_t id)
return NULL;
/* Functions */ }
+static git_column_status_t git_get_indexed_status(const uint32_t status) { +static git_column_status_t git_get_indexed_status(const uint32_t status) {
+ if (status & GIT_STATUS_INDEX_NEW) return GIT_COLUMN_STATUS_NEW; + if (status & GIT_STATUS_INDEX_NEW) return GIT_COLUMN_STATUS_NEW;
@ -89,7 +87,6 @@ index 562622f..96d946a 100644
+ +
+static void print_gitstatus(git_column_status_t status) { +static void print_gitstatus(git_column_status_t status) {
+ switch (status) { + switch (status) {
+ case GIT_COLUMN_STATUS_NONE: break;
+ case GIT_COLUMN_STATUS_UNMOD: addch('-' | 0); break; + 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_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_MODIFIED: addch('M' | (g_state.oldcolor ? COLOR_PAIR(1) : COLOR_PAIR(4))); break;
@ -101,42 +98,30 @@ index 562622f..96d946a 100644
+ } + }
+} +}
+ +
+static bool starts_with(const char *const s, const char *const start) {
+ const size_t start_len = strlen(start);
+
+ return (start_len <= strlen(s)) && (0 == strncmp(s, start, start_len));
+}
+
+static size_t mkpath(const char *dir, const char *name, char *out);
+static simple_git_statuses_t statuses_from_path(const char *path) { +static simple_git_statuses_t statuses_from_path(const char *path) {
+ simple_git_statuses_t statuses = { .statuses = NULL, .len = 0 };
+ git_buf ret = { .ptr = 0, .asize = 0, .size = 0 };
+ git_repository *repo; + git_repository *repo;
+ git_buf ret = { .ptr = NULL, .asize = 0, .size = 0 };
+ simple_git_statuses_t statuses = { .statuses = NULL, .len = 0 };
+ git_repository_discover(&ret, path, false, NULL); + git_repository_discover(&ret, path, false, NULL);
+ git_repository_open(&repo, ret.ptr); + git_repository_open(&repo, ret.ptr);
+ git_buf_dispose(&ret); + git_buf_dispose(&ret);
+ +
+ if (repo) { + if (repo) {
+ git_status_list *status_list = NULL; + char buf[PATH_MAX];
+ const char *workdir = git_repository_workdir(repo);
+ git_status_list *status_list;
+
+ git_status_list_new(&status_list, repo, NULL); + git_status_list_new(&status_list, repo, NULL);
+ statuses.len = git_status_list_entrycount(status_list); + statuses.len = git_status_list_entrycount(status_list);
+ statuses.statuses = malloc(statuses.len * sizeof(simple_git_status_t)); + statuses.statuses = malloc(statuses.len * sizeof(simple_git_status_t));
+ const char *workdir = git_repository_workdir(repo);
+ +
+ for (size_t i = 0; i < statuses.len; i ++) { + for (size_t i = 0; i < statuses.len; ++i) {
+ const git_status_entry *status_ent = git_status_byindex(status_list, i); + const git_status_entry *status_ent = git_status_byindex(status_list, i);
+ const char *entry_path = status_ent->head_to_index ? status_ent->head_to_index->old_file.path + const char *entry_path = status_ent->head_to_index ? status_ent->head_to_index->old_file.path
+ : status_ent->index_to_workdir->old_file.path; + : status_ent->index_to_workdir->old_file.path;
+ char *joined = malloc(PATH_MAX * sizeof(char));
+ mkpath(workdir, entry_path, joined);
+ char *canon_path = realpath(joined, NULL);
+
+ if (canon_path) {
+ statuses.statuses[i].path = canon_path;
+ free(joined);
+ } else
+ statuses.statuses[i].path = joined;
+ +
+ xstrsncpy(buf, workdir, xstrlen(workdir));
+ statuses.statuses[i].path = abspath(entry_path, buf);
+ statuses.statuses[i].status = status_ent->status; + statuses.statuses[i].status = status_ent->status;
+ } + }
+ +
@ -147,83 +132,89 @@ index 562622f..96d946a 100644
+} +}
+ +
+static void statuses_free(simple_git_statuses_t statuses) { +static void statuses_free(simple_git_statuses_t statuses) {
+ for (size_t i = 0; i < statuses.len; i ++) + for (size_t i = 0; i < statuses.len; ++i)
+ free(statuses.statuses[i].path); + free(statuses.statuses[i].path);
+ +
+ free(statuses.statuses); + free(statuses.statuses);
+} +}
+ +
static void sigint_handler(int UNUSED(sig)) static void resetdircolor(int flags)
{ {
g_state.interrupt = 1; /* Directories are always shown on top, clear the color when moving to first file */
@@ -3794,6 +3907,12 @@ static void printent(const struct entry *ent, uint_t namecols, bool sel) @@ -3794,6 +3891,11 @@ static void printent(const struct entry *ent, uint_t namecols, bool sel)
if (attrs) if (attrs)
attroff(attrs); attroff(attrs);
+ +
+ if (ent->status_indexed != GIT_COLUMN_STATUS_NONE) + if (git_statuses.len) {
+ addch(' '); + print_gitstatus(ent->status_indexed);
+ + print_gitstatus(ent->status_staged);
+ print_gitstatus(ent->status_indexed); + }
+ print_gitstatus(ent->status_staged);
} }
attrs = 0; attrs = 0;
@@ -3809,6 +3928,7 @@ static void printent(const struct entry *ent, uint_t namecols, bool sel) @@ -5119,6 +5221,11 @@ static int dentfill(char *path, struct entry **ppdents)
color_pair = C_MIS; attron(COLOR_PAIR(cfg.curctx + 1));
if (color_pair && fcolors[color_pair]) }
attrs |= COLOR_PAIR(color_pair);
+
#ifdef ICONS_ENABLED
print_icon(ent, attrs);
#endif
@@ -5088,6 +5208,9 @@ static int dentfill(char *path, struct entry **ppdents)
struct stat sb_path, sb;
DIR *dirp = opendir(path);
+ statuses_free(git_statuses); + if (git_statuses.len)
+ git_statuses = statuses_from_path(path); + statuses_free(git_statuses);
+ if (cfg.showdetail)
+ git_statuses = statuses_from_path(path);
+ +
ndents = 0; #if _POSIX_C_SOURCE >= 200112L
posix_fadvise(fd, 0, 0, POSIX_FADV_SEQUENTIAL);
DPRINTF_S(__func__);
@@ -5277,6 +5400,26 @@ static int dentfill(char *path, struct entry **ppdents)
dentp->gid = sb.st_gid;
#endif #endif
@@ -5316,6 +5423,25 @@ static int dentfill(char *path, struct entry **ppdents)
#endif
}
+ if (git_statuses.len) { + if (git_statuses.len) {
+ uint32_t merged_status = 0; + uint merged_status = 0;
+ char joined[PATH_MAX]; + char *dentpath = abspath(dentp->name, path);
+ mkpath(path, dentp->name, joined);
+ char *real = realpath(joined, NULL);
+ char *canon_path = real ? real : joined;
+ +
+ for (size_t i = 0; i < git_statuses.len; i ++) + for (size_t i = 0; i < git_statuses.len; i ++) {
+ if (((dentp->mode & S_IFMT) == S_IFDIR) ? starts_with(git_statuses.statuses[i].path, canon_path) : + if (dentp->flags & DIR_OR_LINK_TO_DIR) {
+ !xstrcmp(git_statuses.statuses[i].path, canon_path) || starts_with(canon_path, git_statuses.statuses[i].path)) + size_t dentlen = xstrlen(dentpath);
+ merged_status |= git_statuses.statuses[i].status; +
+ if ((dentlen <= xstrlen(git_statuses.statuses[i].path)) && is_prefix(git_statuses.statuses[i].path, dentpath, dentlen))
+ 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(real); + free(dentpath);
+ } else {
+ dentp->status_indexed = GIT_COLUMN_STATUS_NONE;
+ dentp->status_staged = GIT_COLUMN_STATUS_NONE;
+ } + }
+ +
dentp->flags = S_ISDIR(sb.st_mode) ? 0 : ((sb.st_nlink > 1) ? HARD_LINK : 0); ++ndents;
if (entflags) { } while ((dp = readdir(dirp)));
dentp->flags |= entflags;
@@ -7712,6 +7855,8 @@ static void cleanup(void) @@ -5834,11 +5960,11 @@ static int adjust_cols(int n)
#endif
if (cfg.showdetail) {
/* Fallback to light mode if less than 35 columns */
- if (n < 36)
+ if (n < 38)
cfg.showdetail ^= 1;
else {
/* 3 more accounted for below */
- n -= 32;
+ n -= 34;
}
}
@@ -7712,6 +7838,8 @@ static void cleanup(void)
fflush(stdout); fflush(stdout);
} }
#endif #endif
+ statuses_free(git_statuses); + statuses_free(git_statuses);
+ git_libgit2_shutdown(); + git_libgit2_shutdown();
free(selpath); free(selpath);
free(plgpath); free(plgpath);
free(cfgpath); free(cfgpath);
@@ -7907,6 +8052,7 @@ int main(int argc, char *argv[]) @@ -7907,6 +8035,7 @@ int main(int argc, char *argv[])
return EXIT_FAILURE; return EXIT_FAILURE;
atexit(cleanup); atexit(cleanup);

View File

@ -3,26 +3,26 @@
# #
# Dependencies: libgit2 # Dependencies: libgit2
# #
# Authors: @crides, Luuk van Baaldiff --git a/src/nnn.c b/src/nnn.c # Authors: @crides, Luuk van Baal
index d66e5da..5770f1a 100644
diff --git a/src/nnn.c b/src/nnn.c
index 22402fa..33be591 100644
--- a/src/nnn.c --- a/src/nnn.c
+++ b/src/nnn.c +++ b/src/nnn.c
@@ -127,6 +127,8 @@ @@ -105,6 +105,7 @@
#include "qsort.h" #include <wchar.h>
#endif #include <pwd.h>
#include <grp.h>
+#include <git2.h> +#include <git2.h>
+
/* Macro definitions */ #if !defined(alloca) && defined(__GNUC__)
#define VERSION "4.0" /*
#define GENERAL_INFO "BSD 2-Clause\nhttps://github.com/jarun/nnn" @@ -244,6 +245,16 @@ typedef unsigned int uint_t;
@@ -245,6 +247,18 @@ typedef unsigned char uchar_t; typedef unsigned char uchar_t;
typedef unsigned short ushort_t; typedef unsigned short ushort_t;
typedef unsigned long long ulong_t; typedef unsigned long long ulong_t;
+typedef enum { +typedef enum {
+ GIT_COLUMN_STATUS_NONE = 0, + GIT_COLUMN_STATUS_UNMOD = 0,
+ GIT_COLUMN_STATUS_UNMOD,
+ GIT_COLUMN_STATUS_NEW, + GIT_COLUMN_STATUS_NEW,
+ GIT_COLUMN_STATUS_MODIFIED, + GIT_COLUMN_STATUS_MODIFIED,
+ GIT_COLUMN_STATUS_DELETED, + GIT_COLUMN_STATUS_DELETED,
@ -31,11 +31,10 @@ index d66e5da..5770f1a 100644
+ GIT_COLUMN_STATUS_IGNORED, + GIT_COLUMN_STATUS_IGNORED,
+ GIT_COLUMN_STATUS_CONFLICTED, + GIT_COLUMN_STATUS_CONFLICTED,
+} git_column_status_t; +} git_column_status_t;
+
/* STRUCTURES */ /* STRUCTURES */
/* Directory entry */ @@ -258,6 +269,8 @@ typedef struct entry {
@@ -258,6 +272,8 @@ typedef struct entry {
ulong_t blocks : 40; /* 5 bytes (enough for 512 TiB in 512B blocks allocated) */ 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 nlen : 16; /* 2 bytes (length of file name) */
ulong_t flags : 8; /* 1 byte (flags specific to the file) */ ulong_t flags : 8; /* 1 byte (flags specific to the file) */
@ -44,7 +43,7 @@ index d66e5da..5770f1a 100644
}; };
#ifndef NOUG #ifndef NOUG
uid_t uid; /* 4 bytes */ uid_t uid; /* 4 bytes */
@@ -366,7 +382,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;
@ -63,9 +62,9 @@ index d66e5da..5770f1a 100644
/* Configuration, contexts */ /* Configuration, contexts */
static settings cfg = { static settings cfg = {
@@ -813,6 +840,92 @@ static void notify_fifo(bool force); @@ -3472,6 +3496,85 @@ static char *get_kv_val(kv *kvarr, char *buf, int key, uchar_t max, uchar_t id)
return NULL;
/* Functions */ }
+static git_column_status_t git_get_indexed_status(const uint32_t status) { +static git_column_status_t git_get_indexed_status(const uint32_t status) {
+ if (status & GIT_STATUS_INDEX_NEW) return GIT_COLUMN_STATUS_NEW; + if (status & GIT_STATUS_INDEX_NEW) return GIT_COLUMN_STATUS_NEW;
@ -89,7 +88,6 @@ index d66e5da..5770f1a 100644
+ +
+static void print_gitstatus(git_column_status_t status) { +static void print_gitstatus(git_column_status_t status) {
+ switch (status) { + switch (status) {
+ case GIT_COLUMN_STATUS_NONE: break;
+ case GIT_COLUMN_STATUS_UNMOD: addch('-' | 0); break; + 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_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_MODIFIED: addch('M' | (g_state.oldcolor ? COLOR_PAIR(1) : COLOR_PAIR(4))); break;
@ -102,41 +100,35 @@ index d66e5da..5770f1a 100644
+} +}
+ +
+static bool starts_with(const char *const s, const char *const start) { +static bool starts_with(const char *const s, const char *const start) {
+ const size_t start_len = strlen(start); + const size_t start_len = xstrlen(start);
+ +
+ return (start_len <= strlen(s)) && (0 == strncmp(s, start, start_len)); + return (start_len <= xstrlen(s)) && !strncmp(s, start, start_len);
+} +}
+ +
+static size_t mkpath(const char *dir, const char *name, char *out);
+static simple_git_statuses_t statuses_from_path(const char *path) { +static simple_git_statuses_t statuses_from_path(const char *path) {
+ simple_git_statuses_t statuses = { .statuses = NULL, .len = 0 };
+ git_buf ret = { .ptr = 0, .asize = 0, .size = 0 };
+ git_repository *repo; + git_repository *repo;
+ git_buf ret = { .ptr = NULL, .asize = 0, .size = 0 };
+ simple_git_statuses_t statuses = { .statuses = NULL, .len = 0 };
+ git_repository_discover(&ret, path, false, NULL); + git_repository_discover(&ret, path, false, NULL);
+ git_repository_open(&repo, ret.ptr); + git_repository_open(&repo, ret.ptr);
+ git_buf_dispose(&ret); + git_buf_dispose(&ret);
+ +
+ if (repo) { + if (repo) {
+ git_status_list *status_list = NULL; + char buf[PATH_MAX];
+ const char *workdir = git_repository_workdir(repo);
+ git_status_list *status_list;
+
+ git_status_list_new(&status_list, repo, NULL); + git_status_list_new(&status_list, repo, NULL);
+ statuses.len = git_status_list_entrycount(status_list); + statuses.len = git_status_list_entrycount(status_list);
+ statuses.statuses = malloc(statuses.len * sizeof(simple_git_status_t)); + statuses.statuses = malloc(statuses.len * sizeof(simple_git_status_t));
+ const char *workdir = git_repository_workdir(repo);
+ +
+ for (size_t i = 0; i < statuses.len; i ++) { + for (size_t i = 0; i < statuses.len; ++i) {
+ const git_status_entry *status_ent = git_status_byindex(status_list, i); + const git_status_entry *status_ent = git_status_byindex(status_list, i);
+ const char *entry_path = status_ent->head_to_index ? status_ent->head_to_index->old_file.path + const char *entry_path = status_ent->head_to_index ? status_ent->head_to_index->old_file.path
+ : status_ent->index_to_workdir->old_file.path; + : status_ent->index_to_workdir->old_file.path;
+ char *joined = malloc(PATH_MAX * sizeof(char));
+ mkpath(workdir, entry_path, joined);
+ char *canon_path = realpath(joined, NULL);
+
+ if (canon_path) {
+ statuses.statuses[i].path = canon_path;
+ free(joined);
+ } else
+ statuses.statuses[i].path = joined;
+ +
+ xstrsncpy(buf, workdir, xstrlen(workdir));
+ statuses.statuses[i].path = abspath(entry_path, buf);
+ statuses.statuses[i].status = status_ent->status; + statuses.statuses[i].status = status_ent->status;
+ } + }
+ +
@ -147,76 +139,78 @@ index d66e5da..5770f1a 100644
+} +}
+ +
+static void statuses_free(simple_git_statuses_t statuses) { +static void statuses_free(simple_git_statuses_t statuses) {
+ for (size_t i = 0; i < statuses.len; i ++) + for (size_t i = 0; i < statuses.len; ++i)
+ free(statuses.statuses[i].path); + free(statuses.statuses[i].path);
+ +
+ free(statuses.statuses); + free(statuses.statuses);
+} +}
+ +
static void sigint_handler(int UNUSED(sig)) static void resetdircolor(int flags)
{ {
g_state.interrupt = 1; /* Directories are always shown on top, clear the color when moving to first file */
@@ -3783,6 +3896,13 @@ static void printent(const struct entry *ent, uint_t namecols, bool sel) @@ -3783,6 +3886,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 : ' ');
+ if (cfg.showdetail) { + if (cfg.showdetail && git_statuses.len) {
+ print_gitstatus(ent->status_indexed); + print_gitstatus(ent->status_indexed);
+ print_gitstatus(ent->status_staged); + print_gitstatus(ent->status_staged);
+ if (ent->status_indexed != GIT_COLUMN_STATUS_NONE) + addch(' ');
+ addch(' ');
+ } + }
+ +
if (g_state.oldcolor) if (g_state.oldcolor)
resetdircolor(ent->flags); resetdircolor(ent->flags);
else { else {
@@ -5094,6 +5214,9 @@ static int dentfill(char *path, struct entry **ppdents) @@ -5125,6 +5234,11 @@ static int dentfill(char *path, struct entry **ppdents)
struct stat sb_path, sb; attron(COLOR_PAIR(cfg.curctx + 1));
DIR *dirp = opendir(path); }
+ statuses_free(git_statuses); + if (git_statuses.len)
+ git_statuses = statuses_from_path(path); + statuses_free(git_statuses);
+ if (cfg.showdetail)
+ git_statuses = statuses_from_path(path);
+ +
ndents = 0; #if _POSIX_C_SOURCE >= 200112L
posix_fadvise(fd, 0, 0, POSIX_FADV_SEQUENTIAL);
DPRINTF_S(__func__);
@@ -5283,6 +5406,26 @@ static int dentfill(char *path, struct entry **ppdents)
dentp->gid = sb.st_gid;
#endif #endif
@@ -5322,6 +5436,18 @@ static int dentfill(char *path, struct entry **ppdents)
#endif
}
+ if (git_statuses.len) { + if (git_statuses.len) {
+ uint32_t merged_status = 0; + uint merged_status = 0;
+ char joined[PATH_MAX];
+ mkpath(path, dentp->name, joined);
+ char *real = realpath(joined, NULL);
+ char *canon_path = real ? real : joined;
+ +
+ for (size_t i = 0; i < git_statuses.len; i ++) + for (size_t i = 0; i < git_statuses.len; i ++)
+ if (((dentp->mode & S_IFMT) == S_IFDIR) ? starts_with(git_statuses.statuses[i].path, canon_path) : + if ((dentp->flags & DIR_OR_LINK_TO_DIR) ? starts_with(git_statuses.statuses[i].path, abspath(dentp->name, path))
+ !xstrcmp(git_statuses.statuses[i].path, canon_path) || starts_with(canon_path, git_statuses.statuses[i].path)) + : !xstrcmp(git_statuses.statuses[i].path, abspath(dentp->name, path)))
+ merged_status |= git_statuses.statuses[i].status; + 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(real);
+ } else {
+ dentp->status_indexed = GIT_COLUMN_STATUS_NONE;
+ dentp->status_staged = GIT_COLUMN_STATUS_NONE;
+ } + }
+ +
dentp->flags = S_ISDIR(sb.st_mode) ? 0 : ((sb.st_nlink > 1) ? HARD_LINK : 0); ++ndents;
if (entflags) { } while ((dp = readdir(dirp)));
dentp->flags |= entflags;
@@ -7714,6 +7857,8 @@ static void cleanup(void) @@ -5972,7 +6098,7 @@ static void redraw(char *path)
#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 ? 29 : 26);
ncols = adjust_cols(ncols);
@@ -7714,6 +7840,8 @@ static void cleanup(void)
fflush(stdout); fflush(stdout);
} }
#endif #endif
+ statuses_free(git_statuses); + statuses_free(git_statuses);
+ git_libgit2_shutdown(); + git_libgit2_shutdown();
free(selpath); free(selpath);
free(plgpath); free(plgpath);
free(cfgpath); free(cfgpath);
@@ -7909,6 +8054,7 @@ int main(int argc, char *argv[]) @@ -7909,6 +8037,7 @@ int main(int argc, char *argv[])
return EXIT_FAILURE; return EXIT_FAILURE;
atexit(cleanup); atexit(cleanup);

View File

@ -2,8 +2,9 @@
# columns when a directory contains different users/groups. # columns when a directory contains different users/groups.
# #
# 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 562622fa..d66e5dac 100644 index d83d7f6..22402fa 100644
--- a/src/nnn.c --- a/src/nnn.c
+++ b/src/nnn.c +++ b/src/nnn.c
@@ -362,6 +362,10 @@ typedef struct { @@ -362,6 +362,10 @@ typedef struct {
@ -211,7 +212,7 @@ index 562622fa..d66e5dac 100644
+#endif +#endif
+ } + }
+ } + }
+ dtls.maxentln = dtls.maxnameln + dtls.maxsizeln + dtls.maxuidln + dtls.maxgidln + (g_state.uidgid ? 29 : 26); + dtls.maxentln = dtls.maxnameln + dtls.maxsizeln + (dtls.printguid ? (dtls.maxuidln + dtls.maxgidln) : 0) + (g_state.uidgid ? 26 : 23);
+ +
ncols = adjust_cols(ncols); ncols = adjust_cols(ncols);