]> git.armaanb.net Git - stagit.git/blobdiff - src/stagit.c
stagit: generate tar archive for each repo
[stagit.git] / src / stagit.c
index aa99c7767eff014f68b0ec0477f6e1ac94b83a4c..cd18b03fd48522bb8f435de1571d97662db37df8 100644 (file)
@@ -357,14 +357,14 @@ writeheader(FILE *fp, const char *title)
        fprintf(fp, "</title>\n<link rel=\"icon\" type=\"image/png\" href=\"%sfavicon.png\" />\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=\"stylesheet\" type=\"text/css\" href=\"%sstyle.min.css\" />\n", relpath);
+       fprintf(fp, "<link rel=\"stylesheet\" type=\"text/css\" href=\"%sstyle.css\" />\n", relpath);
        fprintf(fp, "<link rel=\"stylesheet\" type=\"text/css\" href=\"%ssyntax.css\" />\n", relpath);
        fputs("</head>\n<body>\n<table><tr><td>", fp);
        fprintf(fp, "<a href=\"../%s\"><img src=\"%slogo.png\" alt=\"\" width=\"32\" height=\"32\" /></a>",
                relpath, relpath);
        fputs("</td><td><h1>", fp);
        xmlencode(fp, strippedname, strlen(strippedname));
-       fputs("</h1><span class=\"desc\">", fp);
+       fputs("</h1></td></tr><tr><td></td><td><span class=\"desc\">", fp);
        xmlencode(fp, description, strlen(description));
        fputs("</span></td></tr>", fp);
        if (cloneurl[0]) {
@@ -387,6 +387,8 @@ writeheader(FILE *fp, const char *title)
        if (license)
                fprintf(fp, " | <a href=\"%sfile/%s.html\">LICENSE</a>",
                        relpath, license);
+       fprintf(fp, " | <a href=\"%s%s.tar.gz\">Download</a>",
+                                       relpath, strippedname);
        fputs("</td></tr></table>\n<hr/>\n<div id=\"content\">\n", fp);
 }
 
@@ -397,7 +399,7 @@ writefooter(FILE *fp)
 }
 
 int
-call_py(const char *filename, FILE *fp, const char *s, size_t len)
+call_chroma(const char *filename, FILE *fp, const char *s, size_t len)
 {
        // Flush HTML-file
        fflush(fp);
@@ -406,8 +408,10 @@ call_py(const char *filename, FILE *fp, const char *s, size_t len)
        // Redirect STDOUT
        dup2(fileno(fp), 1);
 
-       // Python Pygments script for syntax highlighting.
-       FILE *child = popen("/usr/local/share/stagit/highlight.py", "w");
+       char cmd[] = "chroma --html --html-only --html-lines --html-lines-table --filename ";
+       strcat(cmd, filename);
+
+       FILE *child = popen(cmd, "w");
        if (child == NULL) {
                printf("child is null: %s", strerror(errno));
                exit(1);
@@ -437,7 +441,7 @@ writeblobhtml(const char *filename, FILE *fp, const git_blob *blob)
        git_off_t len = git_blob_rawsize(blob);
 
        if (len > 0) {
-               lc = call_py(filename, fp, s, len);
+               lc = call_chroma(filename, fp, s, len);
        }
 
        return lc;
@@ -447,11 +451,11 @@ void
 printcommit(FILE *fp, struct commitinfo *ci)
 {
        fprintf(fp, "<b>commit</b> <a href=\"%scommit/%s.html\">%s</a>\n",
-               relpath, ci->oid, ci->oid);
+                       relpath, ci->oid, ci->oid);
 
        if (ci->parentoid[0])
                fprintf(fp, "<b>parent</b> <a href=\"%scommit/%s.html\">%s</a>\n",
-                       relpath, ci->parentoid, ci->parentoid);
+                               relpath, ci->parentoid, ci->parentoid);
 
        if (ci->author) {
                fputs("<b>Author:</b> ", fp);
@@ -1152,7 +1156,7 @@ main(int argc, char *argv[])
        strcpy(cwd, getcwd(cwd, sizeof(cwd)));
        cp("/usr/local/share/stagit/syntax.css", strcat(cwd, "/syntax.css"));
        strcpy(cwd, getcwd(cwd, sizeof(cwd)));
-       cp("/usr/local/share/stagit/style.min.css", strcat(cwd, "/style.min.css"));
+       cp("/usr/local/share/stagit/style.css", strcat(cwd, "/style.css"));
 
        /* strip .git suffix */
        if (!(strippedname = strdup(name)))
@@ -1207,6 +1211,12 @@ main(int argc, char *argv[])
                submodules = ".gitmodules";
        git_object_free(obj);
 
+       /* Generate tarball */
+       char tarball[255];
+       sprintf(tarball, "tar -zcf %s.tar.gz --ignore-failed-read --exclude='.git' %s",
+                           strippedname, repodir);
+       system(tarball);
+
        /* log for HEAD */
        fp = efopen("log.html", "w");
        relpath = "";