Skip to content

Commit d772223

Browse files
authored
Merge pull request #1182 from luukvbaal/patches
Fix gitstatus and rebase patches
2 parents e74aa95 + 541b936 commit d772223

File tree

4 files changed

+120
-121
lines changed

4 files changed

+120
-121
lines changed

patches/gitstatus/mainline.diff

+32-30
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,26 @@
66
# Authors: Luuk van Baal, @crides
77

88
diff --git a/src/nnn.c b/src/nnn.c
9-
index fe5d650..059c7bf 100644
9+
index 88263beb..597ff2b3 100644
1010
--- a/src/nnn.c
1111
+++ b/src/nnn.c
12-
@@ -277,6 +277,7 @@ typedef struct entry {
12+
@@ -285,6 +285,7 @@ typedef struct entry {
1313
uid_t uid; /* 4 bytes */
1414
gid_t gid; /* 4 bytes */
1515
#endif
1616
+ char git_status[2];
1717
} *pEntry;
1818

1919
/* Selection marker */
20-
@@ -333,6 +334,7 @@ typedef struct {
20+
@@ -341,6 +342,7 @@ typedef struct {
2121
uint_t cliopener : 1; /* All-CLI app opener */
2222
uint_t waitedit : 1; /* For ops that can't be detached, used EDITOR */
2323
uint_t rollover : 1; /* Roll over at edges */
2424
+ uint_t normalgit : 1; /* Show git status in normal mode */
2525
} settings;
2626

2727
/* Non-persistent program-internal states (alphabeical order) */
28-
@@ -382,7 +384,17 @@ typedef struct {
28+
@@ -390,7 +392,17 @@ typedef struct {
2929
} session_header_t;
3030
#endif
3131

@@ -43,28 +43,27 @@ index fe5d650..059c7bf 100644
4343

4444
/* Configuration, contexts */
4545
static settings cfg = {
46-
@@ -413,6 +425,7 @@ static settings cfg = {
46+
@@ -421,6 +433,7 @@ static settings cfg = {
4747
0, /* cliopener */
4848
0, /* waitedit */
4949
1, /* rollover */
5050
+ 0, /* normalgit */
5151
};
5252

5353
static context g_ctx[CTX_MAX] __attribute__ ((aligned));
54-
@@ -3781,6 +3794,39 @@ static char *get_kv_val(kv *kvarr, char *buf, int key, uchar_t max, uchar_t id)
55-
return NULL;
54+
@@ -3814,6 +3827,38 @@ static int get_kv_key(kv *kvarr, char *val, uchar_t max, uchar_t id)
55+
return -1;
5656
}
5757

5858
+static size_t get_git_statuses(const char *path)
5959
+{
6060
+ static char gitrev[] = "git rev-parse --show-toplevel 2>/dev/null";
61-
+ char workdir[PATH_MAX];
61+
+ char workdir[PATH_MAX], *ret;
6262
+ FILE *fp = popen(gitrev, "r");
6363
+
64-
+ fgets(workdir, PATH_MAX, fp);
64+
+ ret = fgets(workdir, PATH_MAX, fp);
6565
+ pclose(fp);
66-
+
67-
+ if (!workdir[0])
66+
+ if (!ret)
6867
+ return 0;
6968
+
7069
+ static char gitstat[] = "git -c core.quotePath= status --porcelain --ignored=matching -u ";
@@ -91,7 +90,7 @@ index fe5d650..059c7bf 100644
9190
static void resetdircolor(int flags)
9291
{
9392
/* Directories are always shown on top, clear the color when moving to first file */
94-
@@ -4118,6 +4164,10 @@ static void printent(const struct entry *ent, uint_t namecols, bool sel)
93+
@@ -4151,6 +4196,10 @@ static void printent(const struct entry *ent, uint_t namecols, bool sel)
9594

9695
uchar_t color_pair = get_color_pair_name_ind(ent, &ind, &attrs);
9796

@@ -102,36 +101,39 @@ index fe5d650..059c7bf 100644
102101
addch((ent->flags & FILE_SELECTED) ? '+' | A_REVERSE | A_BOLD : ' ');
103102

104103
if (g_state.oldcolor)
105-
@@ -5451,6 +5501,10 @@ static int dentfill(char *path, struct entry **ppdents)
104+
@@ -5548,6 +5597,11 @@ static int dentfill(char *path, struct entry **ppdents)
106105
attron(COLOR_PAIR(cfg.curctx + 1));
107106
}
108107

109108
+ char linkpath[PATH_MAX];
110109
+ if ((git_statuses.len = get_git_statuses(path)))
111-
+ realpath(path, linkpath);
110+
+ if (!realpath(path, linkpath))
111+
+ printwarn(NULL);
112112
+
113113
#if _POSIX_C_SOURCE >= 200112L
114114
posix_fadvise(fd, 0, 0, POSIX_FADV_SEQUENTIAL);
115115
#endif
116-
@@ -5649,6 +5703,34 @@ static int dentfill(char *path, struct entry **ppdents)
116+
@@ -5746,6 +5800,36 @@ static int dentfill(char *path, struct entry **ppdents)
117117
#endif
118118
}
119119

120120
+ if (git_statuses.len) {
121-
+ char dentpath[PATH_MAX];
122-
+ size_t pathlen = mkpath(linkpath, dentp->name, dentpath) - 1;
121+
+ char dentpath[PATH_MAX], prefix[PATH_MAX + 1];
122+
+ size_t pathlen = mkpath(linkpath, dentp->name, dentpath);
123+
+ snprintf(prefix, PATH_MAX + 1, "%s/", dentpath);
123124
+ dentp->git_status[0] = dentp->git_status[1] = '-';
124125
+
125126
+ if (dentp->flags & DIR_OR_DIRLNK) {
126127
+ for (size_t i = 0; i < git_statuses.len; ++i)
127-
+ if (is_prefix(git_statuses.statuses[i].path, dentpath, pathlen)) {
128-
+ dentp->git_status[0] = git_statuses.statuses[i].status[0];
129-
+ dentp->git_status[1] = git_statuses.statuses[i].status[1];
130-
+ if (dentp->git_status[1] != '!') {
128+
+ if (is_prefix(git_statuses.statuses[i].path, prefix, pathlen)) {
129+
+ if ((dentp->git_status[0] == '-') && (git_statuses.statuses[i].status[0] != '-'))
130+
+ dentp->git_status[0] = git_statuses.statuses[i].status[0];
131+
+ if ((dentp->git_status[1] == '-') && (git_statuses.statuses[i].status[1] != '-'))
132+
+ dentp->git_status[1] = git_statuses.statuses[i].status[1];
133+
+ if (git_statuses.statuses[i].status[1] != '!')
131134
+ git_statuses.show = TRUE;
132-
+ if (dentp->git_status[1] == '?')
133-
+ break;
134-
+ }
135+
+ if ((dentp->git_status[0] != '-') && (dentp->git_status[1] != '-'))
136+
+ break;
135137
+ }
136138
+ } else {
137139
+ for (size_t i = 0; i < git_statuses.len; ++i)
@@ -148,7 +150,7 @@ index fe5d650..059c7bf 100644
148150
++ndents;
149151
} while ((dp = readdir(dirp)));
150152

151-
@@ -6160,11 +6242,12 @@ static int adjust_cols(int n)
153+
@@ -6270,11 +6354,12 @@ static int adjust_cols(int n)
152154
#endif
153155
if (cfg.showdetail) {
154156
/* Fallback to light mode if less than 35 columns */
@@ -164,23 +166,23 @@ index fe5d650..059c7bf 100644
164166

165167
/* 2 columns for preceding space and indicator */
166168
return (n - 2);
167-
@@ -7913,6 +7996,7 @@ static void usage(void)
169+
@@ -8034,6 +8119,7 @@ static void usage(void)
168170
" -F val fifo mode [0:preview 1:explore]\n"
169171
#endif
170172
" -g regex filters\n"
171173
+ " -G always show git status\n"
172174
" -H show hidden files\n"
173175
" -J no auto-proceed on select\n"
174176
" -K detect key collision\n"
175-
@@ -8051,6 +8135,7 @@ static void cleanup(void)
176-
fflush(stdout);
177+
@@ -8174,6 +8260,7 @@ static void cleanup(void)
178+
free(hostname);
177179
}
178180
#endif
179181
+ free(git_statuses.statuses);
180182
free(selpath);
181183
free(plgpath);
182184
free(cfgpath);
183-
@@ -8095,7 +8180,7 @@ int main(int argc, char *argv[])
185+
@@ -8218,7 +8305,7 @@ int main(int argc, char *argv[])
184186

185187
while ((opt = (env_opts_id > 0
186188
? env_opts[--env_opts_id]
@@ -189,7 +191,7 @@ index fe5d650..059c7bf 100644
189191
switch (opt) {
190192
#ifndef NOFIFO
191193
case 'a':
192-
@@ -8146,6 +8231,9 @@ int main(int argc, char *argv[])
194+
@@ -8269,6 +8356,9 @@ int main(int argc, char *argv[])
193195
cfg.regex = 1;
194196
filterfn = &visible_re;
195197
break;

patches/gitstatus/namefirst.diff

+33-31
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,26 @@
77
# Authors: Luuk van Baal, @crides
88

99
diff --git a/src/nnn.c b/src/nnn.c
10-
index 2d33716..b190177 100644
10+
index 55f32e73..ed771826 100644
1111
--- a/src/nnn.c
1212
+++ b/src/nnn.c
13-
@@ -277,6 +277,7 @@ typedef struct entry {
13+
@@ -285,6 +285,7 @@ typedef struct entry {
1414
uid_t uid; /* 4 bytes */
1515
gid_t gid; /* 4 bytes */
1616
#endif
1717
+ char git_status[2];
1818
} *pEntry;
1919

2020
/* Selection marker */
21-
@@ -333,6 +334,7 @@ typedef struct {
21+
@@ -341,6 +342,7 @@ typedef struct {
2222
uint_t cliopener : 1; /* All-CLI app opener */
2323
uint_t waitedit : 1; /* For ops that can't be detached, used EDITOR */
2424
uint_t rollover : 1; /* Roll over at edges */
2525
+ uint_t normalgit : 1; /* Show git status in normal mode */
2626
} settings;
2727

2828
/* Non-persistent program-internal states (alphabeical order) */
29-
@@ -386,7 +388,17 @@ static struct {
29+
@@ -394,7 +396,17 @@ static struct {
3030
ushort_t maxnameln, maxsizeln, maxuidln, maxgidln, maxentln, uidln, gidln, printguid;
3131
} dtls;
3232

@@ -44,28 +44,27 @@ index 2d33716..b190177 100644
4444

4545
/* Configuration, contexts */
4646
static settings cfg = {
47-
@@ -417,6 +429,7 @@ static settings cfg = {
47+
@@ -425,6 +437,7 @@ static settings cfg = {
4848
0, /* cliopener */
4949
0, /* waitedit */
5050
1, /* rollover */
5151
+ 0, /* normalgit */
5252
};
5353

5454
static context g_ctx[CTX_MAX] __attribute__ ((aligned));
55-
@@ -3789,6 +3802,39 @@ static char *get_kv_val(kv *kvarr, char *buf, int key, uchar_t max, uchar_t id)
56-
return NULL;
55+
@@ -3822,6 +3835,38 @@ static int get_kv_key(kv *kvarr, char *val, uchar_t max, uchar_t id)
56+
return -1;
5757
}
5858

5959
+static size_t get_git_statuses(const char *path)
6060
+{
6161
+ static char gitrev[] = "git rev-parse --show-toplevel 2>/dev/null";
62-
+ char workdir[PATH_MAX];
62+
+ char workdir[PATH_MAX], *ret;
6363
+ FILE *fp = popen(gitrev, "r");
6464
+
65-
+ fgets(workdir, PATH_MAX, fp);
65+
+ ret = fgets(workdir, PATH_MAX, fp);
6666
+ pclose(fp);
67-
+
68-
+ if (!workdir[0])
67+
+ if (!ret)
6968
+ return 0;
7069
+
7170
+ static char gitstat[] = "git -c core.quotePath= status --porcelain --ignored=matching -u ";
@@ -92,7 +91,7 @@ index 2d33716..b190177 100644
9291
static void resetdircolor(int flags)
9392
{
9493
/* Directories are always shown on top, clear the color when moving to first file */
95-
@@ -4099,6 +4145,9 @@ static void printent(const struct entry *ent, uint_t namecols, bool sel)
94+
@@ -4132,6 +4177,9 @@ static void printent(const struct entry *ent, uint_t namecols, bool sel)
9695
int attrs = 0, namelen;
9796
uchar_t color_pair = get_color_pair_name_ind(ent, &ind, &attrs);
9897

@@ -102,36 +101,39 @@ index 2d33716..b190177 100644
102101
addch((ent->flags & FILE_SELECTED) ? '+' | A_REVERSE | A_BOLD : ' ');
103102

104103
if (g_state.oldcolor)
105-
@@ -5457,6 +5506,10 @@ static int dentfill(char *path, struct entry **ppdents)
104+
@@ -5554,6 +5602,11 @@ static int dentfill(char *path, struct entry **ppdents)
106105
attron(COLOR_PAIR(cfg.curctx + 1));
107106
}
108107

109108
+ char linkpath[PATH_MAX];
110109
+ if ((git_statuses.len = get_git_statuses(path)))
111-
+ realpath(path, linkpath);
110+
+ if (!realpath(path, linkpath))
111+
+ printwarn(NULL);
112112
+
113113
#if _POSIX_C_SOURCE >= 200112L
114114
posix_fadvise(fd, 0, 0, POSIX_FADV_SEQUENTIAL);
115115
#endif
116-
@@ -5655,6 +5708,34 @@ static int dentfill(char *path, struct entry **ppdents)
116+
@@ -5752,6 +5805,36 @@ static int dentfill(char *path, struct entry **ppdents)
117117
#endif
118118
}
119119

120120
+ if (git_statuses.len) {
121-
+ char dentpath[PATH_MAX];
122-
+ size_t pathlen = mkpath(linkpath, dentp->name, dentpath) - 1;
121+
+ char dentpath[PATH_MAX], prefix[PATH_MAX + 1];
122+
+ size_t pathlen = mkpath(linkpath, dentp->name, dentpath);
123+
+ snprintf(prefix, PATH_MAX + 1, "%s/", dentpath);
123124
+ dentp->git_status[0] = dentp->git_status[1] = '-';
124125
+
125126
+ if (dentp->flags & DIR_OR_DIRLNK) {
126127
+ for (size_t i = 0; i < git_statuses.len; ++i)
127-
+ if (is_prefix(git_statuses.statuses[i].path, dentpath, pathlen)) {
128-
+ dentp->git_status[0] = git_statuses.statuses[i].status[0];
129-
+ dentp->git_status[1] = git_statuses.statuses[i].status[1];
130-
+ if (dentp->git_status[1] != '!') {
128+
+ if (is_prefix(git_statuses.statuses[i].path, prefix, pathlen)) {
129+
+ if ((dentp->git_status[0] == '-') && (git_statuses.statuses[i].status[0] != '-'))
130+
+ dentp->git_status[0] = git_statuses.statuses[i].status[0];
131+
+ if ((dentp->git_status[1] == '-') && (git_statuses.statuses[i].status[1] != '-'))
132+
+ dentp->git_status[1] = git_statuses.statuses[i].status[1];
133+
+ if (git_statuses.statuses[i].status[1] != '!')
131134
+ git_statuses.show = TRUE;
132-
+ if (dentp->git_status[1] == '?')
133-
+ break;
134-
+ }
135+
+ if ((dentp->git_status[0] != '-') && (dentp->git_status[1] != '-'))
136+
+ break;
135137
+ }
136138
+ } else {
137139
+ for (size_t i = 0; i < git_statuses.len; ++i)
@@ -148,7 +150,7 @@ index 2d33716..b190177 100644
148150
++ndents;
149151
} while ((dp = readdir(dirp)));
150152

151-
@@ -6157,7 +6238,8 @@ static int adjust_cols(int n)
153+
@@ -6267,7 +6350,8 @@ static int adjust_cols(int n)
152154
cfg.showdetail ^= 1;
153155
else /* 2 more accounted for below */
154156
n -= (dtls.maxentln - 2 - dtls.maxnameln);
@@ -158,7 +160,7 @@ index 2d33716..b190177 100644
158160

159161
/* 2 columns for preceding space and indicator */
160162
return (n - 2);
161-
@@ -6312,7 +6394,7 @@ static void redraw(char *path)
163+
@@ -6422,7 +6506,7 @@ static void redraw(char *path)
162164
}
163165
#endif
164166
}
@@ -167,23 +169,23 @@ index 2d33716..b190177 100644
167169
}
168170

169171
ncols = adjust_cols(ncols);
170-
@@ -7919,6 +8001,7 @@ static void usage(void)
172+
@@ -8040,6 +8124,7 @@ static void usage(void)
171173
" -F val fifo mode [0:preview 1:explore]\n"
172174
#endif
173175
" -g regex filters\n"
174176
+ " -G always show git status\n"
175177
" -H show hidden files\n"
176178
" -J no auto-proceed on select\n"
177179
" -K detect key collision\n"
178-
@@ -8057,6 +8140,7 @@ static void cleanup(void)
179-
fflush(stdout);
180+
@@ -8180,6 +8265,7 @@ static void cleanup(void)
181+
free(hostname);
180182
}
181183
#endif
182184
+ free(git_statuses.statuses);
183185
free(selpath);
184186
free(plgpath);
185187
free(cfgpath);
186-
@@ -8101,7 +8185,7 @@ int main(int argc, char *argv[])
188+
@@ -8224,7 +8310,7 @@ int main(int argc, char *argv[])
187189

188190
while ((opt = (env_opts_id > 0
189191
? env_opts[--env_opts_id]
@@ -192,7 +194,7 @@ index 2d33716..b190177 100644
192194
switch (opt) {
193195
#ifndef NOFIFO
194196
case 'a':
195-
@@ -8152,6 +8236,9 @@ int main(int argc, char *argv[])
197+
@@ -8275,6 +8361,9 @@ int main(int argc, char *argv[])
196198
cfg.regex = 1;
197199
filterfn = &visible_re;
198200
break;

0 commit comments

Comments
 (0)