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