Introduction
Introduction Statistics Contact Development Disclaimer Help
treplace file size with line count for text files - stagit - static git page ge…
git clone git://src.adamsgaard.dk/stagit
Log
Files
Refs
README
LICENSE
---
commit 79fab7c6faf78d7bcc0c870359138617aee24c7d
parent 50dccf0e3ba06bcd732ac5c38c8b326cebc6c097
Author: Quentin Rameau <[email protected]>
Date: Sun, 10 Jan 2016 00:47:22 +0100
replace file size with line count for text files
Keep the number of line when writing text blobs and print it in the
index file tree instead of the size. Still print the size otherwise.
Diffstat:
M config.def.h | 1 +
M stagit.c | 25 ++++++++++++++++---------
2 files changed, 17 insertions(+), 9 deletions(-)
---
diff --git a/config.def.h b/config.def.h
t@@ -1,2 +1,3 @@
/* See LICENSE file for copyright and license details. */
static const unsigned summarylen = 70; /* summary length in the log */
+static const int showlinecount = 1; /* display line count or file size in f…
diff --git a/stagit.c b/stagit.c
t@@ -282,11 +282,11 @@ writefooter(FILE *fp)
return !fputs("</div>\n</body>\n</html>\n", fp);
}
-void
+int
writeblobhtml(FILE *fp, const git_blob *blob)
{
off_t i;
- size_t n = 1;
+ size_t n = 0;
char *nfmt = "<a href=\"#l%d\" id=\"l%d\">%d</a>\n";
const char *s = git_blob_rawcontent(blob);
git_off_t len = git_blob_rawsize(blob);
t@@ -294,6 +294,7 @@ writeblobhtml(FILE *fp, const git_blob *blob)
fputs("<table id=\"blob\"><tr><td class=\"num\"><pre>\n", fp);
if (len) {
+ n++;
fprintf(fp, nfmt, n, n, n);
for (i = 0; i < len - 1; i++) {
if (s[i] == '\n') {
t@@ -306,6 +307,8 @@ writeblobhtml(FILE *fp, const git_blob *blob)
fputs("</pre></td><td><pre>\n", fp);
xmlencode(fp, s, (size_t)len);
fputs("</pre></td></tr></table>\n", fp);
+
+ return n;
}
void
t@@ -573,12 +576,13 @@ writeblob(git_object *obj, const char *fpath, const char…
char tmp[PATH_MAX] = "";
char *d;
const char *p;
+ int lc = 0;
FILE *fp;
d = xdirname(fpath);
if (mkdirp(d)) {
free(d);
- return 1;
+ return -1;
}
free(d);
t@@ -600,7 +604,7 @@ writeblob(git_object *obj, const char *fpath, const char *…
if (git_blob_is_binary((git_blob *)obj)) {
fputs("<p>Binary file</p>\n", fp);
} else {
- writeblobhtml(fp, (git_blob *)obj);
+ lc = writeblobhtml(fp, (git_blob *)obj);
if (ferror(fp))
err(1, "fwrite");
}
t@@ -609,7 +613,7 @@ writeblob(git_object *obj, const char *fpath, const char *…
relpath = "";
- return 0;
+ return lc;
}
const char *
t@@ -663,7 +667,7 @@ writefilestree(FILE *fp, git_tree *tree, const char *branc…
git_object *obj = NULL;
git_off_t filesize;
size_t count, i;
- int ret;
+ int lc, ret;
count = git_tree_entrycount(tree);
for (i = 0; i < count; i++) {
t@@ -694,15 +698,18 @@ writefilestree(FILE *fp, git_tree *tree, const char *bra…
filename);
filesize = git_blob_rawsize((git_blob *)obj);
+ lc = writeblob(obj, filepath, filename, filesize);
+
fputs("<tr><td>", fp);
fputs(filemode(git_tree_entry_filemode(entry)), fp);
fprintf(fp, "</td><td><a href=\"%s%s\">", relpath, filepath);
xmlencode(fp, filename, strlen(filename));
fputs("</a></td><td class=\"num\">", fp);
- fprintf(fp, "%ju", (uintmax_t)filesize);
+ if (showlinecount && lc > 0)
+ fprintf(fp, "%dL", lc);
+ else
+ fprintf(fp, "%jub", (uintmax_t)filesize);
fputs("</td></tr>\n", fp);
-
- writeblob(obj, filepath, filename, filesize);
}
return 0;
You are viewing proxied material from mx1.adamsgaard.dk. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.