stagit

static git page generator  https://git.ce9e.org
git clone https://git.ce9e.org/stagit.git

commit
31392c13cf805602c6e4a46695a27325d908f3fb
parent
2f2ecde5c38db848cf6286aca9fc0f73137244e6
Author
Hiltjo Posthuma <hiltjo@codemadness.org>
Date
2018-01-21 15:47
stagit: add -l option: limit the amount of commits for the log.html file

Diffstat

M stagit.1 14 +++++++++++++-
M stagit.c 49 +++++++++++++++++++++++++++++++++++++------------

2 files changed, 50 insertions, 13 deletions


diff --git a/stagit.1 b/stagit.1

@@ -1,4 +1,4 @@
    1    -1 .Dd May 1, 2016
   -1     1 .Dd Januari 21, 2018
    2     2 .Dt STAGIT 1
    3     3 .Os
    4     4 .Sh NAME
@@ -7,6 +7,7 @@
    7     7 .Sh SYNOPSIS
    8     8 .Nm
    9     9 .Op Fl c Ar cachefile
   -1    10 .Op Fl l Ar commits
   10    11 .Ar repodir
   11    12 .Sh DESCRIPTION
   12    13 .Nm
@@ -25,8 +26,19 @@ will store the last commit id and the entries in the HTML table.
   25    26 It is up to the user to make sure the state of the
   26    27 .Ar cachefile
   27    28 is in sync with the history of the repository.
   -1    29 .It Fl l Ar commits
   -1    30 Write a maximum number of
   -1    31 .Ar commits
   -1    32 to the log.html file only.
   -1    33 However the commit files are written as usual.
   28    34 .El
   29    35 .Pp
   -1    36 The options
   -1    37 .Fl c
   -1    38 and
   -1    39 .Fl l
   -1    40 cannot be used at the same time.
   -1    41 .Pp
   30    42 The following files will be written:
   31    43 .Bl -tag -width Ds
   32    44 .It atom.xml

diff --git a/stagit.c b/stagit.c

@@ -57,6 +57,7 @@ static char *strippedname = "";
   57    57 static char description[255];
   58    58 static char cloneurl[1024];
   59    59 static int haslicense, hasreadme, hassubmodules;
   -1    60 static long long nlogcommits = -1; /* < 0 indicates not used */
   60    61 
   61    62 /* cache */
   62    63 static git_oid lastoid;
@@ -558,7 +559,7 @@ writelog(FILE *fp, const git_oid *oid)
  558   559 	struct commitinfo *ci;
  559   560 	git_revwalk *w = NULL;
  560   561 	git_oid id;
  561    -1 	char path[PATH_MAX];
   -1   562 	char path[PATH_MAX], oidstr[GIT_OID_HEXSZ + 1];
  562   563 	FILE *fpfile;
  563   564 	int r;
  564   565 
@@ -572,24 +573,37 @@ writelog(FILE *fp, const git_oid *oid)
  572   573 
  573   574 		if (cachefile && !memcmp(&id, &lastoid, sizeof(id)))
  574   575 			break;
   -1   576 
   -1   577 		git_oid_tostr(oidstr, sizeof(oidstr), &id);
   -1   578 		r = snprintf(path, sizeof(path), "commit/%s.html", oidstr);
   -1   579 		if (r == -1 || (size_t)r >= sizeof(path))
   -1   580 			errx(1, "path truncated: 'commit/%s.html'", oidstr);
   -1   581 		r = access(path, F_OK);
   -1   582 
   -1   583 		/* optimization: if there are no log lines to write and
   -1   584 		   the commit file already exists: skip the diffstat */
   -1   585 		if (!nlogcommits && !r)
   -1   586 			continue;
   -1   587 
  575   588 		if (!(ci = commitinfo_getbyoid(&id)))
  576   589 			break;
  577    -1 		/* lookup stats: only required here */
   -1   590 		/* diffstat: for stagit HTML required for the log.html line */
  578   591 		if (commitinfo_getstats(ci) == -1)
  579   592 			goto err;
  580   593 
  581    -1 		writelogline(fp, ci);
   -1   594 		if (nlogcommits < 0) {
   -1   595 			writelogline(fp, ci);
   -1   596 		} else if (nlogcommits > 0) {
   -1   597 			writelogline(fp, ci);
   -1   598 			nlogcommits--;
   -1   599 		}
   -1   600 
  582   601 		if (cachefile)
  583   602 			writelogline(wcachefp, ci);
  584   603 
  585    -1 		relpath = "../";
  586    -1 
  587    -1 		r = snprintf(path, sizeof(path), "commit/%s.html", ci->oid);
  588    -1 		if (r == -1 || (size_t)r >= sizeof(path))
  589    -1 			errx(1, "path truncated: 'commit/%s.html'", ci->oid);
  590    -1 
  591   604 		/* check if file exists if so skip it */
  592    -1 		if (access(path, F_OK)) {
   -1   605 		if (r) {
   -1   606 			relpath = "../";
  593   607 			fpfile = efopen(path, "w");
  594   608 			writeheader(fpfile, ci->summary);
  595   609 			fputs("<pre>", fpfile);
@@ -986,7 +1000,7 @@ err:
  986  1000 void
  987  1001 usage(char *argv0)
  988  1002 {
  989    -1 	fprintf(stderr, "%s [-c cachefile] repodir\n", argv0);
   -1  1003 	fprintf(stderr, "%s [-c cachefile] [-l commits] repodir\n", argv0);
  990  1004 	exit(1);
  991  1005 }
  992  1006 
@@ -1012,9 +1026,20 @@ main(int argc, char *argv[])
 1012  1026 				usage(argv[0]);
 1013  1027 			repodir = argv[i];
 1014  1028 		} else if (argv[i][1] == 'c') {
 1015    -1 			if (i + 1 >= argc)
   -1  1029 			if (nlogcommits > 0 || i + 1 >= argc)
 1016  1030 				usage(argv[0]);
 1017  1031 			cachefile = argv[++i];
   -1  1032 		} else if (argv[i][1] == 'l') {
   -1  1033 			if (cachefile || i + 1 >= argc)
   -1  1034 				usage(argv[0]);
   -1  1035 			errno = 0;
   -1  1036 			nlogcommits = strtoll(argv[++i], &p, 10);
   -1  1037 			if (argv[i][0] == '\0' || *p != '\0' ||
   -1  1038 			    nlogcommits <= 0)
   -1  1039 				usage(argv[0]);
   -1  1040 			if (errno == ERANGE && (nlogcommits == LLONG_MAX ||
   -1  1041 			    nlogcommits == LLONG_MIN))
   -1  1042 				usage(argv[0]);
 1018  1043 		}
 1019  1044 	}
 1020  1045 	if (!cachefile && pledge("stdio rpath wpath cpath", NULL) == -1)