|
|
stagit-gopher: add -l option: limit the amount of commits for the log.gph file - stagit-gopher - static git page generator for gopher |
|
|
 |
git clone git://git.codemadness.org/stagit-gopher (git://git.codemadness.org) |
|
|
 |
Log |
|
|
 |
Files |
|
|
 |
Refs |
|
|
 |
README |
|
|
 |
LICENSE |
|
|
|
--- |
|
|
 |
commit b5cdcadb391b8f27bced0273013ae5ba2189cde9 |
|
|
 |
parent fa9a155a4a631fe2f384e9f7516a9a03f2f53c70 |
|
|
 |
Author: Hiltjo Posthuma <hiltjo@codemadness.org> (mailto://) |
application/vnd.lotus-organizer |
|
|
Date: Sun, 21 Jan 2018 16:47:48 +0100 |
|
|
|
|
|
|
|
stagit-gopher: add -l option: limit the amount of commits for the log.gph file |
|
|
|
|
|
|
|
Diffstat: |
|
|
|
M stagit-gopher.1 | 14 +++++++++++++- |
|
|
|
M stagit-gopher.c | 46 ++++++++++++++++++++++++------- |
|
|
|
|
|
|
|
2 files changed, 49 insertions(+), 11 deletions(-) |
|
|
|
--- |
|
|
 |
diff --git a/stagit-gopher.1 b/stagit-gopher.1 |
|
|
|
@@ -1,4 +1,4 @@ |
|
|
|
-.Dd Jun 23, 2017 |
|
|
|
+.Dd Januari 21, 2018 |
|
|
|
.Dt STAGIT-GOPHER 1 |
|
|
|
.Os |
|
|
|
.Sh NAME |
|
|
|
@@ -8,6 +8,7 @@ |
|
|
|
.Nm |
|
|
|
.Op Fl b Ar baseprefix |
|
|
|
.Op Fl c Ar cachefile |
|
|
|
+.Op Fl l Ar commits |
|
|
|
.Ar repodir |
|
|
|
.Sh DESCRIPTION |
|
|
|
.Nm |
|
|
|
@@ -29,8 +30,19 @@ will store the last commit id and the entries in the Gopher index. |
|
|
|
It is up to the user to make sure the state of the |
|
|
|
.Ar cachefile |
|
|
|
is in sync with the history of the repository. |
|
|
|
+.It Fl l Ar commits |
|
|
|
+Write a maximum number of |
|
|
|
+.Ar commits |
|
|
|
+to the log.gph file only. |
|
|
|
+However the commit files are written as usual. |
|
|
|
.El |
|
|
|
.Pp |
|
|
|
+The options |
|
|
|
+.Fl c |
|
|
|
+and |
|
|
|
+.Fl l |
|
|
|
+cannot be used at the same time. |
|
|
|
+.Pp |
|
|
|
The following files will be written: |
|
|
|
.Bl -tag -width Ds |
|
|
|
.It atom.xml |
|
|
 |
diff --git a/stagit-gopher.c b/stagit-gopher.c |
|
|
|
@@ -59,6 +59,7 @@ static char *strippedname = ""; |
|
|
|
static char description[255]; |
|
|
|
static char cloneurl[1024]; |
|
|
|
static int haslicense, hasreadme, hassubmodules; |
|
|
|
+static long long nlogcommits = -1; /* < 0 indicates not used */ |
|
|
|
|
|
|
|
/* cache */ |
|
|
|
static git_oid lastoid; |
|
|
|
@@ -661,7 +662,7 @@ writelog(FILE *fp, const git_oid *oid) |
|
|
|
struct commitinfo *ci; |
|
|
|
git_revwalk *w = NULL; |
|
|
|
git_oid id; |
|
|
|
- char path[PATH_MAX]; |
|
|
|
+ char path[PATH_MAX], oidstr[GIT_OID_HEXSZ + 1]; |
|
|
|
FILE *fpfile; |
|
|
|
int r; |
|
|
|
|
|
|
|
@@ -673,20 +674,34 @@ writelog(FILE *fp, const git_oid *oid) |
|
|
|
while (!git_revwalk_next(&id, w)) { |
|
|
|
if (cachefile && !memcmp(&id, &lastoid, sizeof(id))) |
|
|
|
break; |
|
|
|
+ |
|
|
|
+ git_oid_tostr(oidstr, sizeof(oidstr), &id); |
|
|
|
+ r = snprintf(path, sizeof(path), "commit/%s.gph", oidstr); |
|
|
|
+ if (r == -1 || (size_t)r >= sizeof(path)) |
|
|
|
+ errx(1, "path truncated: 'commit/%s.gph'", oidstr); |
|
|
|
+ r = access(path, F_OK); |
|
|
|
+ |
|
|
|
+ /* optimization: if there are no log lines to write and |
|
|
|
+ the commit file already exists: skip the diffstat */ |
|
|
|
+ if (!nlogcommits && !r) |
|
|
|
+ continue; |
|
|
|
+ |
|
|
|
if (!(ci = commitinfo_getbyoid(&id))) |
|
|
|
break; |
|
|
|
|
|
|
|
- writelogline(fp, ci); |
|
|
|
+ if (nlogcommits < 0) { |
|
|
|
+ writelogline(fp, ci); |
|
|
|
+ } else if (nlogcommits > 0) { |
|
|
|
+ writelogline(fp, ci); |
|
|
|
+ nlogcommits--; |
|
|
|
+ } |
|
|
|
+ |
|
|
|
if (cachefile) |
|
|
|
writelogline(wcachefp, ci); |
|
|
|
|
|
|
|
- r = snprintf(path, sizeof(path), "commit/%s.gph", ci->oid); |
|
|
|
- if (r == -1 || (size_t)r >= sizeof(path)) |
|
|
|
- errx(1, "path truncated: 'commit/%s.gph'", ci->oid); |
|
|
|
- |
|
|
|
/* check if file exists if so skip it */ |
|
|
|
- if (access(path, F_OK)) { |
|
|
|
- /* lookup stats: only required here */ |
|
|
|
+ if (r) { |
|
|
|
+ /* lookup stats: only required here for gopher */ |
|
|
|
if (commitinfo_getstats(ci) == -1) |
|
|
|
goto err; |
|
|
|
|
|
|
|
@@ -1073,7 +1088,7 @@ err: |
|
|
|
void |
|
|
|
usage(char *argv0) |
|
|
|
{ |
|
|
|
- fprintf(stderr, "%s [-b baseprefix] [-c cachefile] repodir\n", argv0); |
|
|
|
+ fprintf(stderr, "%s [-b baseprefix] [-c cachefile] [-l commits] repodir\n", argv0); |
|
|
|
exit(1); |
|
|
|
} |
|
|
|
|
|
|
|
@@ -1105,9 +1120,20 @@ main(int argc, char *argv[]) |
|
|
|
usage(argv[0]); |
|
|
|
relpath = argv[++i]; |
|
|
|
} else if (argv[i][1] == 'c') { |
|
|
|
- if (i + 1 >= argc) |
|
|
|
+ if (nlogcommits > 0 || i + 1 >= argc) |
|
|
|
usage(argv[0]); |
|
|
|
cachefile = argv[++i]; |
|
|
|
+ } else if (argv[i][1] == 'l') { |
|
|
|
+ if (cachefile || i + 1 >= argc) |
|
|
|
+ usage(argv[0]); |
|
|
|
+ errno = 0; |
|
|
|
+ nlogcommits = strtoll(argv[++i], &p, 10); |
|
|
|
+ if (argv[i][0] == '\0' || *p != '\0' || |
|
|
|
+ nlogcommits <= 0) |
|
|
|
+ usage(argv[0]); |
|
|
|
+ if (errno == ERANGE && (nlogcommits == LLONG_MAX || |
|
|
|
+ nlogcommits == LLONG_MIN)) |
|
|
|
+ usage(argv[0]); |
|
|
|
} |
|
|
|
} |
|
|
|
if (!cachefile && pledge("stdio rpath wpath cpath", NULL) == -1) |
|