X-Git-Url: https://git.armaanb.net/?a=blobdiff_plain;f=src%2Fstagit.c;h=6b45b3601b9f86b36f18aa3655992f02103b6e28;hb=1426ca963932ab7521eb40914f98ff0cc9e00ffb;hp=6e20754ed9fe82f23f4ba30789bc13d31aef08d1;hpb=14794fb8e99c0dcf8f6bdde7f612bd13cf1d513c;p=stagit.git
diff --git a/src/stagit.c b/src/stagit.c
index 6e20754..6b45b36 100644
--- a/src/stagit.c
+++ b/src/stagit.c
@@ -8,14 +8,19 @@
#include ", fp);
xmlencode(fp, filename, strlen(filename));
- fprintf(fp, " (%juB)", (uintmax_t)filesize);
- fputs("
\n", fp);
- fprintf(fp, "",
+ fprintf(fp, "",
relpath, relpath);
fputs(" ", fp);
xmlencode(fp, strippedname, strlen(strippedname));
- fputs("
", fp);
+ fputs(" ", fp);
if (cloneurl[0]) {
@@ -387,6 +415,8 @@ writeheader(FILE *fp, const char *title)
if (license)
fprintf(fp, " | LICENSE",
relpath, license);
+ fprintf(fp, " | Download",
+ relpath, strippedname);
fputs("", fp);
xmlencode(fp, description, strlen(description));
fputs("
\n%s
", s);
+#endif
}
- int
+void
writeblobhtml(const char *filename, FILE *fp, const git_blob *blob)
{
- int lc = 0;
const char *s = git_blob_rawcontent(blob);
git_off_t len = git_blob_rawsize(blob);
if (len > 0) {
- lc = call_chroma(filename, fp, s, len);
+ call_chroma(filename, fp, s, len);
}
-
- return lc;
}
- void
+void
printcommit(FILE *fp, struct commitinfo *ci)
{
fprintf(fp, "commit %s\n",
@@ -473,7 +522,7 @@ printcommit(FILE *fp, struct commitinfo *ci)
}
}
- void
+void
printshowfile(FILE *fp, struct commitinfo *ci)
{
const git_diff_delta *delta;
@@ -588,8 +637,9 @@ printshowfile(FILE *fp, struct commitinfo *ci)
fprintf(fp, "-",
i, j, k, i, j, k);
else
- fputc(' ', fp);
- xmlencode(fp, line->content, line->content_len);
+ putc(' ', fp);
+ xmlencodeline(fp, line->content, line->content_len);
+ putc('\n', fp);
if (line->old_lineno == -1 || line->new_lineno == -1)
fputs("", fp);
}
@@ -777,20 +827,36 @@ writeatom(FILE *fp)
return 0;
}
-int
+float
+rounder(float var)
+{
+ int value = var * 10 + .5;
+ return value / 10.0;
+}
+
+const char *
+convertbytes(int bytes)
+{
+ bytes = (float)bytes;
+ static char outp[25];
+ if (bytes < 1024) sprintf(outp, "%u %s", bytes, "B");
+ else if (bytes < 1048576) sprintf(outp, "%0.1f %s", rounder(bytes/1024.0), "K");
+ else sprintf(outp, "%0.1f %s", rounder(bytes/1048576.0), "M");
+ return outp;
+}
+
+void
writeblob(git_object *obj, const char *fpath, const char *filename, git_off_t filesize)
{
char tmp[PATH_MAX] = "", *d;
const char *p;
- int lc = 0;
FILE *fp;
if (strlcpy(tmp, fpath, sizeof(tmp)) >= sizeof(tmp))
errx(1, "path truncated: '%s'", fpath);
if (!(d = dirname(tmp)))
err(1, "dirname");
- if (mkdirp(d))
- return -1;
+ mkdirp(d);
for (p = fpath, tmp[0] = '\0'; *p; p++) {
if (*p == '/' && strlcat(tmp, "../", sizeof(tmp)) >= sizeof(tmp))
@@ -802,22 +868,41 @@ writeblob(git_object *obj, const char *fpath, const char *filename, git_off_t fi
writeheader(fp, filename);
fputs("
", fp);
+ fprintf(fp, " (%s)", convertbytes((int)filesize));
+
+#ifdef HAS_CMARK
+ char newfpath[PATH_MAX];
+ char newfilename[PATH_MAX];
+ if (strcmp(get_ext(filename), "md") == 0) {
+ fprintf(fp, " View raw", filename);
+ strcpy(newfpath, fpath);
+ strcat(newfpath, "-raw");
+
+ strcpy(newfilename, filename);
+ strcat(newfilename, "-raw");
+ strcpy(oldfilename, filename);
+
+ /* NOTE: recurses */
+ writeblob(obj, newfpath, newfilename, filesize);
+ } else if (strcmp(get_ext(filename), "md-raw" ) == 0) {
+ fprintf(fp, " View rendered", oldfilename);
+ }
+#endif
+
+ fputs(".
Binary file.
\n", fp); } else { - lc = writeblobhtml(filename, fp, (git_blob *)obj); + writeblobhtml(filename, fp, (git_blob *)obj); if (ferror(fp)) err(1, "fwrite"); } + writefooter(fp); fclose(fp); relpath = ""; - - return lc; } const char * @@ -872,7 +957,7 @@ writefilestree(FILE *fp, git_tree *tree, const char *path) const char *entryname; char filepath[PATH_MAX], entrypath[PATH_MAX]; size_t count, i; - int lc, r, ret; + int r, ret; count = git_tree_entrycount(tree); for (i = 0; i < count; i++) { @@ -904,7 +989,7 @@ writefilestree(FILE *fp, git_tree *tree, const char *path) } filesize = git_blob_rawsize((git_blob *)obj); - lc = writeblob(obj, filepath, entryname, filesize); + writeblob(obj, filepath, entryname, filesize); fputs("