stagit

Line numbers on blob pages

Eivind Uggedal contact@arjunchoudhary.com

commit: e2f23d4 parent: 8b22e5d
2 files changed, 38 insertions(+), 6 deletions(-)
Mstyle.css+14-1
Murmoms.c+24-5
M · style.css +14, -1
 1@@ -21,6 +21,15 @@ a:hover {
 2 	text-decoration: underline;
 3 }
 4 
 5+#blob a {
 6+	color: #777;
 7+}
 8+
 9+#blob a:hover {
10+	color: blue;
11+	text-decoration: none;
12+}
13+
14 table thead td {
15 	font-weight: bold;
16 }
17@@ -29,10 +38,14 @@ table td {
18 	padding: 0 0.4em;
19 }
20 
21-#content table tr:hover td {
22+#log tr:hover td, #files tr:hover td {
23 	background-color: #eee;
24 }
25 
26+td.num {
27+	text-align: right;
28+}
29+
30 .desc {
31 	color: #777;
32 }
M · urmoms.c +24, -5
 1@@ -241,7 +241,28 @@ printtimeshort(FILE *fp, const git_time *intime)
 2 void
 3 writeblobhtml(FILE *fp, const git_blob *blob)
 4 {
 5-	xmlencode(fp, git_blob_rawcontent(blob), (size_t)git_blob_rawsize(blob));
 6+	off_t i = 0;
 7+	size_t n = 1;
 8+	char *nfmt = "<a href=\"#l%d\" id=\"l%d\">%d</a>\n";
 9+	const char *s = git_blob_rawcontent(blob);
10+	git_off_t len = git_blob_rawsize(blob);
11+
12+	fputs("<table id=\"blob\"><tr><td class=\"num\"><pre>\n", fp);
13+
14+	if (len) {
15+		fprintf(fp, nfmt, n, n, n);
16+		while (i < len - 1) {
17+			if (s[i] == '\n') {
18+				n++;
19+				fprintf(fp, nfmt, n, n, n);
20+			}
21+			i++;
22+		}
23+	}
24+
25+	fputs("</pre></td><td><pre>\n", fp);
26+	xmlencode(fp, s, (size_t)len);
27+	fputs("</pre></td></tr></table>\n", fp);
28 }
29 
30 void
31@@ -392,7 +413,7 @@ writelog(FILE *fp)
32 	git_revwalk_simplify_first_parent(w);
33 
34 	/* TODO: also make "expanded" log ? (with message body) */
35-	fputs("<table><thead>\n<tr><td>Age</td><td>Commit message</td><td>Author</td>"
36+	fputs("<table id=\"log\"><thead>\n<tr><td>Age</td><td>Commit message</td><td>Author</td>"
37 	      "<td>Files</td><td>+</td><td>-</td></tr>\n</thead><tbody>\n", fp);
38 	while (!git_revwalk_next(&id, w)) {
39 		relpath = "";
40@@ -553,11 +574,9 @@ writeblob(const git_index_entry *entry)
41 	if (git_blob_is_binary((git_blob *)obj)) {
42 		fprintf(fp, "<p>Binary file</p>\n");
43 	} else {
44-		fputs("<pre>\n", fp);
45 		writeblobhtml(fp, (git_blob *)obj);
46 		if (ferror(fp))
47 			err(1, "fwrite");
48-		fputs("</pre>\n", fp);
49 	}
50 	git_object_free(obj);
51 	writefooter(fp);
52@@ -575,7 +594,7 @@ writefiles(FILE *fp)
53 	git_index *index;
54 	size_t count, i;
55 
56-	fputs("<table><thead>\n"
57+	fputs("<table id=\"files\"><thead>\n"
58 	      "<tr><td>Mode</td><td>Name</td><td>Size</td></tr>\n"
59 	      "</thead><tbody>\n", fp);
60