Compare commits
No commits in common. "0eb570ebaebe7c243d0d6a7ac760e45c5c2e7976" and "a9f6d9fe9682189df7dabd81ed586d51bc31b656" have entirely different histories.
0eb570ebae
...
a9f6d9fe96
4 changed files with 25 additions and 85 deletions
2
LICENSE
2
LICENSE
|
@ -1,6 +1,6 @@
|
|||
MIT/X Consortium License
|
||||
|
||||
(c) 2015-2022 Hiltjo Posthuma <hiltjo@codemadness.org>
|
||||
(c) 2015-2021 Hiltjo Posthuma <hiltjo@codemadness.org>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a
|
||||
copy of this software and associated documentation files (the "Software"),
|
||||
|
|
2
Makefile
2
Makefile
|
@ -1,7 +1,7 @@
|
|||
.POSIX:
|
||||
|
||||
NAME = stagit
|
||||
VERSION = 1.0
|
||||
VERSION = 0.9.6
|
||||
|
||||
# paths
|
||||
PREFIX = /usr/local
|
||||
|
|
|
@ -28,28 +28,6 @@ joinpath(char *buf, size_t bufsiz, const char *path, const char *path2)
|
|||
path, path[0] && path[strlen(path) - 1] != '/' ? "/" : "", path2);
|
||||
}
|
||||
|
||||
/* Percent-encode, see RFC3986 section 2.1. */
|
||||
void
|
||||
percentencode(FILE *fp, const char *s, size_t len)
|
||||
{
|
||||
static char tab[] = "0123456789ABCDEF";
|
||||
unsigned char uc;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; *s && i < len; s++, i++) {
|
||||
uc = *s;
|
||||
/* NOTE: do not encode '/' for paths or ",-." */
|
||||
if (uc < ',' || uc >= 127 || (uc >= ':' && uc <= '@') ||
|
||||
uc == '[' || uc == ']') {
|
||||
putc('%', fp);
|
||||
putc(tab[(uc >> 4) & 0x0f], fp);
|
||||
putc(tab[uc & 0x0f], fp);
|
||||
} else {
|
||||
putc(uc, fp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Escape characters below as HTML 2.0 / XML 1.0. */
|
||||
void
|
||||
xmlencode(FILE *fp, const char *s, size_t len)
|
||||
|
@ -140,7 +118,7 @@ writelog(FILE *fp)
|
|||
*p = '\0';
|
||||
|
||||
fputs("<tr><td><a href=\"", fp);
|
||||
percentencode(fp, stripped_name, strlen(stripped_name));
|
||||
xmlencode(fp, stripped_name, strlen(stripped_name));
|
||||
fputs("/log.html\">", fp);
|
||||
xmlencode(fp, stripped_name, strlen(stripped_name));
|
||||
fputs("</a></td><td>", fp);
|
||||
|
@ -173,11 +151,7 @@ main(int argc, char *argv[])
|
|||
return 1;
|
||||
}
|
||||
|
||||
/* do not search outside the git repository:
|
||||
GIT_CONFIG_LEVEL_APP is the highest level currently */
|
||||
git_libgit2_init();
|
||||
for (i = 1; i <= GIT_CONFIG_LEVEL_APP; i++)
|
||||
git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, i, "");
|
||||
|
||||
#ifdef __OpenBSD__
|
||||
if (pledge("stdio rpath", NULL) == -1)
|
||||
|
|
78
stagit.c
78
stagit.c
|
@ -71,7 +71,7 @@ static char *licensefiles[] = { "HEAD:LICENSE", "HEAD:LICENSE.md", "HEAD:COPYING
|
|||
static char *license;
|
||||
static char *readmefiles[] = { "HEAD:README", "HEAD:README.md" };
|
||||
static char *readme;
|
||||
static long long nlogcommits = -1; /* -1 indicates not used */
|
||||
static long long nlogcommits = -1; /* < 0 indicates not used */
|
||||
|
||||
/* cache */
|
||||
static git_oid lastoid;
|
||||
|
@ -359,28 +359,6 @@ efopen(const char *filename, const char *flags)
|
|||
return fp;
|
||||
}
|
||||
|
||||
/* Percent-encode, see RFC3986 section 2.1. */
|
||||
void
|
||||
percentencode(FILE *fp, const char *s, size_t len)
|
||||
{
|
||||
static char tab[] = "0123456789ABCDEF";
|
||||
unsigned char uc;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; *s && i < len; s++, i++) {
|
||||
uc = *s;
|
||||
/* NOTE: do not encode '/' for paths or ",-." */
|
||||
if (uc < ',' || uc >= 127 || (uc >= ':' && uc <= '@') ||
|
||||
uc == '[' || uc == ']') {
|
||||
putc('%', fp);
|
||||
putc(tab[(uc >> 4) & 0x0f], fp);
|
||||
putc(tab[uc & 0x0f], fp);
|
||||
} else {
|
||||
putc(uc, fp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Escape characters below as HTML 2.0 / XML 1.0. */
|
||||
void
|
||||
xmlencode(FILE *fp, const char *s, size_t len)
|
||||
|
@ -502,12 +480,10 @@ writeheader(FILE *fp, const char *title)
|
|||
fputs(" - ", fp);
|
||||
xmlencode(fp, description, strlen(description));
|
||||
fprintf(fp, "</title>\n<link rel=\"icon\" type=\"image/png\" href=\"%s../favicon.png\" />\n", relpath);
|
||||
fputs("<link rel=\"alternate\" type=\"application/atom+xml\" title=\"", fp);
|
||||
xmlencode(fp, name, strlen(name));
|
||||
fprintf(fp, " Atom Feed\" href=\"%satom.xml\" />\n", relpath);
|
||||
fputs("<link rel=\"alternate\" type=\"application/atom+xml\" title=\"", fp);
|
||||
xmlencode(fp, name, strlen(name));
|
||||
fprintf(fp, " Atom Feed (tags)\" href=\"%stags.xml\" />\n", relpath);
|
||||
fprintf(fp, "<link rel=\"alternate\" type=\"application/atom+xml\" title=\"%s Atom Feed\" href=\"%satom.xml\" />\n",
|
||||
name, relpath);
|
||||
fprintf(fp, "<link rel=\"alternate\" type=\"application/atom+xml\" title=\"%s Atom Feed (tags)\" href=\"%stags.xml\" />\n",
|
||||
name, relpath);
|
||||
fprintf(fp, "<link rel=\"stylesheet\" type=\"text/css\" href=\"%s../style.css\" />\n", relpath);
|
||||
fputs("</head>\n<body>\n<table><tr><td>", fp);
|
||||
fprintf(fp, "<a href=\"../%s\"><img src=\"%s../logo.png\" alt=\"\" width=\"32\" height=\"32\" /></a>",
|
||||
|
@ -519,7 +495,7 @@ writeheader(FILE *fp, const char *title)
|
|||
fputs("</span></td></tr>", fp);
|
||||
if (cloneurl[0]) {
|
||||
fputs("<tr class=\"url\"><td></td><td>git clone <a href=\"", fp);
|
||||
xmlencode(fp, cloneurl, strlen(cloneurl)); /* not percent-encoded */
|
||||
xmlencode(fp, cloneurl, strlen(cloneurl));
|
||||
fputs("\">", fp);
|
||||
xmlencode(fp, cloneurl, strlen(cloneurl));
|
||||
fputs("</a></td></tr>", fp);
|
||||
|
@ -562,15 +538,14 @@ writeblobhtml(FILE *fp, const git_blob *blob)
|
|||
continue;
|
||||
n++;
|
||||
fprintf(fp, nfmt, n, n, n);
|
||||
xmlencodeline(fp, &s[prev], i - prev + 1);
|
||||
putc('\n', fp);
|
||||
xmlencode(fp, &s[prev], i - prev + 1);
|
||||
prev = i + 1;
|
||||
}
|
||||
/* trailing data */
|
||||
if ((len - prev) > 0) {
|
||||
n++;
|
||||
fprintf(fp, nfmt, n, n, n);
|
||||
xmlencodeline(fp, &s[prev], len - prev);
|
||||
xmlencode(fp, &s[prev], len - prev);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -593,7 +568,7 @@ printcommit(FILE *fp, struct commitinfo *ci)
|
|||
fputs("<b>Author:</b> ", fp);
|
||||
xmlencode(fp, ci->author->name, strlen(ci->author->name));
|
||||
fputs(" <<a href=\"mailto:", fp);
|
||||
xmlencode(fp, ci->author->email, strlen(ci->author->email)); /* not percent-encoded */
|
||||
xmlencode(fp, ci->author->email, strlen(ci->author->email));
|
||||
fputs("\">", fp);
|
||||
xmlencode(fp, ci->author->email, strlen(ci->author->email));
|
||||
fputs("</a>>\n<b>Date:</b> ", fp);
|
||||
|
@ -688,11 +663,11 @@ printshowfile(FILE *fp, struct commitinfo *ci)
|
|||
patch = ci->deltas[i]->patch;
|
||||
delta = git_patch_get_delta(patch);
|
||||
fprintf(fp, "<b>diff --git a/<a id=\"h%zu\" href=\"%sfile/", i, relpath);
|
||||
percentencode(fp, delta->old_file.path, strlen(delta->old_file.path));
|
||||
xmlencode(fp, delta->old_file.path, strlen(delta->old_file.path));
|
||||
fputs(".html\">", fp);
|
||||
xmlencode(fp, delta->old_file.path, strlen(delta->old_file.path));
|
||||
fprintf(fp, "</a> b/<a href=\"%sfile/", relpath);
|
||||
percentencode(fp, delta->new_file.path, strlen(delta->new_file.path));
|
||||
xmlencode(fp, delta->new_file.path, strlen(delta->new_file.path));
|
||||
fprintf(fp, ".html\">");
|
||||
xmlencode(fp, delta->new_file.path, strlen(delta->new_file.path));
|
||||
fprintf(fp, "</a></b>\n");
|
||||
|
@ -764,7 +739,6 @@ writelog(FILE *fp, const git_oid *oid)
|
|||
git_oid id;
|
||||
char path[PATH_MAX], oidstr[GIT_OID_HEXSZ + 1];
|
||||
FILE *fpfile;
|
||||
size_t remcommits = 0;
|
||||
int r;
|
||||
|
||||
git_revwalk_new(&w, repo);
|
||||
|
@ -784,11 +758,8 @@ writelog(FILE *fp, const git_oid *oid)
|
|||
|
||||
/* optimization: if there are no log lines to write and
|
||||
the commit file already exists: skip the diffstat */
|
||||
if (!nlogcommits) {
|
||||
remcommits++;
|
||||
if (!r)
|
||||
continue;
|
||||
}
|
||||
if (!nlogcommits && !r)
|
||||
continue;
|
||||
|
||||
if (!(ci = commitinfo_getbyoid(&id)))
|
||||
break;
|
||||
|
@ -796,10 +767,15 @@ writelog(FILE *fp, const git_oid *oid)
|
|||
if (commitinfo_getstats(ci) == -1)
|
||||
goto err;
|
||||
|
||||
if (nlogcommits != 0) {
|
||||
if (nlogcommits < 0) {
|
||||
writelogline(fp, ci);
|
||||
if (nlogcommits > 0)
|
||||
nlogcommits--;
|
||||
} else if (nlogcommits > 0) {
|
||||
writelogline(fp, ci);
|
||||
nlogcommits--;
|
||||
if (!nlogcommits && ci->parentoid[0])
|
||||
fputs("<tr><td></td><td colspan=\"5\">"
|
||||
"More commits remaining [...]</td>"
|
||||
"</tr>\n", fp);
|
||||
}
|
||||
|
||||
if (cachefile)
|
||||
|
@ -821,12 +797,6 @@ err:
|
|||
}
|
||||
git_revwalk_free(w);
|
||||
|
||||
if (nlogcommits == 0 && remcommits != 0) {
|
||||
fprintf(fp, "<tr><td></td><td colspan=\"5\">"
|
||||
"%zu more commits remaining, fetch the repository"
|
||||
"</td></tr>\n", remcommits);
|
||||
}
|
||||
|
||||
relpath = "";
|
||||
|
||||
return 0;
|
||||
|
@ -1065,7 +1035,7 @@ writefilestree(FILE *fp, git_tree *tree, const char *path)
|
|||
fputs("<tr><td>", fp);
|
||||
fputs(filemode(git_tree_entry_filemode(entry)), fp);
|
||||
fprintf(fp, "</td><td><a href=\"%s", relpath);
|
||||
percentencode(fp, filepath, strlen(filepath));
|
||||
xmlencode(fp, filepath, strlen(filepath));
|
||||
fputs("\">", fp);
|
||||
xmlencode(fp, entrypath, strlen(entrypath));
|
||||
fputs("</a></td><td class=\"num\" align=\"right\">", fp);
|
||||
|
@ -1220,11 +1190,7 @@ main(int argc, char *argv[])
|
|||
if (!realpath(repodir, repodirabs))
|
||||
err(1, "realpath");
|
||||
|
||||
/* do not search outside the git repository:
|
||||
GIT_CONFIG_LEVEL_APP is the highest level currently */
|
||||
git_libgit2_init();
|
||||
for (i = 1; i <= GIT_CONFIG_LEVEL_APP; i++)
|
||||
git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, i, "");
|
||||
|
||||
#ifdef __OpenBSD__
|
||||
if (unveil(repodir, "r") == -1)
|
||||
|
|
Loading…
Reference in a new issue