stagit

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

commit
142ed81f2852cd42d57eb3ac785b3fdb31c367ce
parent
1cdb24d9de53436b0749fd787dbc7d8e7afbecd5
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2020-03-26 16:25
do not render blobs as html

Diffstat

M Makefile 2 --
M compat.h 2 --
M stagit.c 62 ++++++-------------------------------------------------------
D strlcat.c 57 ---------------------------------------------------------
M style.css 9 ---------

5 files changed, 6 insertions, 126 deletions


diff --git a/Makefile b/Makefile

@@ -23,7 +23,6 @@ SRC = \
   23    23 	stagit.c\
   24    24 	stagit-index.c
   25    25 COMPATSRC = \
   26    -1 	strlcat.c\
   27    26 	strlcpy.c
   28    27 BIN = \
   29    28 	stagit\
@@ -37,7 +36,6 @@ DOC = \
   37    36 HDR = compat.h
   38    37 
   39    38 COMPATOBJ = \
   40    -1 	strlcat.o\
   41    39 	strlcpy.o
   42    40 
   43    41 OBJ = ${SRC:.c=.o} ${COMPATOBJ}

diff --git a/compat.h b/compat.h

@@ -1,4 +1,2 @@
    1    -1 #undef strlcat
    2    -1 size_t strlcat(char *, const char *, size_t);
    3     1 #undef strlcpy
    4     2 size_t strlcpy(char *, const char *, size_t);

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

@@ -381,38 +381,6 @@ writefooter(FILE *fp)
  381   381 	fputs("</div>\n</body>\n</html>\n", fp);
  382   382 }
  383   383 
  384    -1 int
  385    -1 writeblobhtml(FILE *fp, const git_blob *blob)
  386    -1 {
  387    -1 	size_t n = 0, i, prev;
  388    -1 	const char *nfmt = "<a href=\"#l%d\" class=\"line\" id=\"l%d\">%7d</a> ";
  389    -1 	const char *s = git_blob_rawcontent(blob);
  390    -1 	git_off_t len = git_blob_rawsize(blob);
  391    -1 
  392    -1 	fputs("<pre id=\"blob\">\n", fp);
  393    -1 
  394    -1 	if (len > 0) {
  395    -1 		for (i = 0, prev = 0; i < (size_t)len; i++) {
  396    -1 			if (s[i] != '\n')
  397    -1 				continue;
  398    -1 			n++;
  399    -1 			fprintf(fp, nfmt, n, n, n);
  400    -1 			xmlencode(fp, &s[prev], i - prev + 1);
  401    -1 			prev = i + 1;
  402    -1 		}
  403    -1 		/* trailing data */
  404    -1 		if ((len - prev) > 0) {
  405    -1 			n++;
  406    -1 			fprintf(fp, nfmt, n, n, n);
  407    -1 			xmlencode(fp, &s[prev], len - prev);
  408    -1 		}
  409    -1 	}
  410    -1 
  411    -1 	fputs("</pre>\n", fp);
  412    -1 
  413    -1 	return n;
  414    -1 }
  415    -1 
  416   384 void
  417   385 writereadmehtml(FILE *fp, const git_blob *blob)
  418   386 {
@@ -768,8 +736,9 @@ int
  768   736 writeblob(git_object *obj, const char *fpath, const char *filename, git_off_t filesize)
  769   737 {
  770   738 	char tmp[PATH_MAX] = "", *d;
  771    -1 	const char *p;
  772   739 	int lc = 0;
   -1   740 	git_off_t len;
   -1   741 	const void *raw;
  773   742 	FILE *fp;
  774   743 
  775   744 	if (strlcpy(tmp, fpath, sizeof(tmp)) >= sizeof(tmp))
@@ -779,31 +748,12 @@ writeblob(git_object *obj, const char *fpath, const char *filename, git_off_t fi
  779   748 	if (mkdirp(d))
  780   749 		return -1;
  781   750 
  782    -1 	for (p = fpath, tmp[0] = '\0'; *p; p++) {
  783    -1 		if (*p == '/' && strlcat(tmp, "../", sizeof(tmp)) >= sizeof(tmp))
  784    -1 			errx(1, "path truncated: '../%s'", tmp);
  785    -1 	}
  786    -1 	relpath = tmp;
  787    -1 
  788   751 	fp = efopen(fpath, "w");
  789    -1 	writeheader(fp, filename);
  790    -1 	fputs("<p> ", fp);
  791    -1 	xmlencode(fp, filename, strlen(filename));
  792    -1 	fprintf(fp, " (%juB)", (uintmax_t)filesize);
  793    -1 	fputs("</p><hr/>", fp);
  794    -1 
  795    -1 	if (git_blob_is_binary((git_blob *)obj)) {
  796    -1 		fputs("<p>Binary file.</p>\n", fp);
  797    -1 	} else {
  798    -1 		lc = writeblobhtml(fp, (git_blob *)obj);
  799    -1 		if (ferror(fp))
  800    -1 			err(1, "fwrite");
  801    -1 	}
  802    -1 	writefooter(fp);
   -1   752 	len = git_blob_rawsize((git_blob *)obj);
   -1   753 	raw = git_blob_rawcontent((git_blob *)obj);
   -1   754 	fwrite(raw, 1, len, fp);
  803   755 	fclose(fp);
  804   756 
  805    -1 	relpath = "";
  806    -1 
  807   757 	return lc;
  808   758 }
  809   759 
@@ -867,7 +817,7 @@ writefilestree(FILE *fp, git_tree *tree, const char *path)
  867   817 			return -1;
  868   818 		joinpath(entrypath, sizeof(entrypath), path, entryname);
  869   819 
  870    -1 		r = snprintf(filepath, sizeof(filepath), "file/%s.html",
   -1   820 		r = snprintf(filepath, sizeof(filepath), "file/%s",
  871   821 		         entrypath);
  872   822 		if (r < 0 || (size_t)r >= sizeof(filepath))
  873   823 			errx(1, "path truncated: 'file/%s.html'", entrypath);

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

@@ -1,57 +0,0 @@
    1    -1 /*	$OpenBSD: strlcat.c,v 1.15 2015/03/02 21:41:08 millert Exp $	*/
    2    -1 
    3    -1 /*
    4    -1  * Copyright (c) 1998, 2015 Todd C. Miller <Todd.Miller@courtesan.com>
    5    -1  *
    6    -1  * Permission to use, copy, modify, and distribute this software for any
    7    -1  * purpose with or without fee is hereby granted, provided that the above
    8    -1  * copyright notice and this permission notice appear in all copies.
    9    -1  *
   10    -1  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
   11    -1  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
   12    -1  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
   13    -1  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
   14    -1  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
   15    -1  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
   16    -1  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
   17    -1  */
   18    -1 
   19    -1 #include <sys/types.h>
   20    -1 #include <string.h>
   21    -1 
   22    -1 #include "compat.h"
   23    -1 
   24    -1 /*
   25    -1  * Appends src to string dst of size dsize (unlike strncat, dsize is the
   26    -1  * full size of dst, not space left).  At most dsize-1 characters
   27    -1  * will be copied.  Always NUL terminates (unless dsize <= strlen(dst)).
   28    -1  * Returns strlen(src) + MIN(dsize, strlen(initial dst)).
   29    -1  * If retval >= dsize, truncation occurred.
   30    -1  */
   31    -1 size_t
   32    -1 strlcat(char *dst, const char *src, size_t dsize)
   33    -1 {
   34    -1 	const char *odst = dst;
   35    -1 	const char *osrc = src;
   36    -1 	size_t n = dsize;
   37    -1 	size_t dlen;
   38    -1 
   39    -1 	/* Find the end of dst and adjust bytes left but don't go past end. */
   40    -1 	while (n-- != 0 && *dst != '\0')
   41    -1 		dst++;
   42    -1 	dlen = dst - odst;
   43    -1 	n = dsize - dlen;
   44    -1 
   45    -1 	if (n-- == 0)
   46    -1 		return(dlen + strlen(src));
   47    -1 	while (*src != '\0') {
   48    -1 		if (n != 0) {
   49    -1 			*dst++ = *src;
   50    -1 			n--;
   51    -1 		}
   52    -1 		src++;
   53    -1 	}
   54    -1 	*dst = '\0';
   55    -1 
   56    -1 	return(dlen + (src - osrc));	/* count does not include NUL */
   57    -1 }

diff --git a/style.css b/style.css

@@ -28,15 +28,6 @@ a.line {
   28    28 	text-decoration: none;
   29    29 }
   30    30 
   31    -1 #blob a {
   32    -1 	color: #777;
   33    -1 }
   34    -1 
   35    -1 #blob a:hover {
   36    -1 	color: blue;
   37    -1 	text-decoration: none;
   38    -1 }
   39    -1 
   40    31 table thead td {
   41    32 	font-weight: bold;
   42    33 }