]> git.armaanb.net Git - stagit.git/blobdiff - stagit.c
atom.xml: add newline before EOF
[stagit.git] / stagit.c
index f97ade984f8a08cbd370f4d39e878f999e0e9d56..d3753eb7a4ebc667133ab1e804a12e87d163b639 100644 (file)
--- a/stagit.c
+++ b/stagit.c
@@ -57,7 +57,7 @@ static const char *relpath = "";
 static const char *repodir;
 
 static char *name = "";
-static char *strippedname;
+static char *strippedname = "";
 static char description[255];
 static char cloneurl[1024];
 static int haslicense, hasreadme, hassubmodules;
@@ -69,11 +69,7 @@ static FILE *rcachefp, *wcachefp;
 static const char *cachefile;
 
 #ifndef USE_PLEDGE
-int
-pledge(const char *promises, const char *paths[])
-{
-       return 0;
-}
+#define pledge(p1,p2) 0
 #endif
 
 void
@@ -181,6 +177,7 @@ commitinfo_free(struct commitinfo *ci)
        git_tree_free(ci->commit_tree);
        git_tree_free(ci->parent_tree);
        git_commit_free(ci->commit);
+       git_commit_free(ci->parent);
 }
 
 struct commitinfo *
@@ -329,9 +326,9 @@ void
 writeheader(FILE *fp, const char *title)
 {
        fputs("<!DOCTYPE html>\n"
-               "<html dir=\"ltr\" lang=\"en\">\n<head>\n"
+               "<html>\n<head>\n"
                "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\n"
-               "<meta http-equiv=\"Content-Language\" content=\"en\" />\n<title>", fp);
+               "<title>", fp);
        xmlencode(fp, title, strlen(title));
        if (title[0] && strippedname[0])
                fputs(" - ", fp);
@@ -699,7 +696,7 @@ writeatom(FILE *fp)
        }
        git_revwalk_free(w);
 
-       fputs("</feed>", fp);
+       fputs("</feed>\n", fp);
 
        return 0;
 }
@@ -790,7 +787,7 @@ filemode(git_filemode_t m)
 }
 
 int
-writefilestree(FILE *fp, git_tree *tree, const char *branch, const char *path)
+writefilestree(FILE *fp, git_tree *tree, const char *path)
 {
        const git_tree_entry *entry = NULL;
        git_submodule *module = NULL;
@@ -819,7 +816,7 @@ writefilestree(FILE *fp, git_tree *tree, const char *branch, const char *path)
                                break;
                        case GIT_OBJ_TREE:
                                /* NOTE: recurses */
-                               ret = writefilestree(fp, (git_tree *)obj, branch,
+                               ret = writefilestree(fp, (git_tree *)obj,
                                                     entrypath);
                                git_object_free(obj);
                                if (ret)
@@ -843,6 +840,7 @@ writefilestree(FILE *fp, git_tree *tree, const char *branch, const char *path)
                        else
                                fprintf(fp, "%juB", (uintmax_t)filesize);
                        fputs("</td></tr>\n", fp);
+                       git_object_free(obj);
                } else if (!git_submodule_lookup(&module, repo, entryname)) {
                        fprintf(fp, "<tr><td>m---------</td><td><a href=\"%sfile/.gitmodules.html\">",
                                relpath);
@@ -856,7 +854,7 @@ writefilestree(FILE *fp, git_tree *tree, const char *branch, const char *path)
 }
 
 int
-writefiles(FILE *fp, const git_oid *id, const char *branch)
+writefiles(FILE *fp, const git_oid *id)
 {
        git_tree *tree = NULL;
        git_commit *commit = NULL;
@@ -868,7 +866,7 @@ writefiles(FILE *fp, const git_oid *id, const char *branch)
 
        if (!git_commit_lookup(&commit, repo, id) &&
            !git_commit_tree(&tree, commit))
-               ret = writefilestree(fp, tree, branch, "");
+               ret = writefilestree(fp, tree, "");
 
        fputs("</tbody></table>", fp);
 
@@ -883,13 +881,10 @@ refs_cmp(const void *v1, const void *v2)
 {
        git_reference *r1 = (*(git_reference **)v1);
        git_reference *r2 = (*(git_reference **)v2);
-       int t1, t2;
-
-       t1 = git_reference_is_branch(r1);
-       t2 = git_reference_is_branch(r2);
+       int r;
 
-       if (t1 != t2)
-               return t1 - t2;
+       if ((r = git_reference_is_branch(r1) - git_reference_is_branch(r2)))
+               return r;
 
        return strcmp(git_reference_shorthand(r1),
                      git_reference_shorthand(r2));
@@ -1041,11 +1036,14 @@ main(int argc, char *argv[])
        }
 
        /* find HEAD */
-       if (git_revparse_single(&obj, repo, "HEAD"))
-               return 1;
-       head = git_object_id(obj);
+       if (!git_revparse_single(&obj, repo, "HEAD"))
+               head = git_object_id(obj);
        git_object_free(obj);
 
+       /* don't cache if there is no HEAD */
+       if (!head)
+               cachefile = NULL;
+
        /* use directory name as name */
        if ((name = strrchr(repodirabs, '/')))
                name++;
@@ -1141,7 +1139,8 @@ main(int argc, char *argv[])
                }
                fclose(wcachefp);
        } else {
-               writelog(fp, head);
+               if (head)
+                       writelog(fp, head);
        }
 
        fputs("</tbody></table>", fp);
@@ -1151,7 +1150,8 @@ main(int argc, char *argv[])
        /* files for HEAD */
        fp = efopen("files.html", "w");
        writeheader(fp, "Files");
-       writefiles(fp, head, "HEAD");
+       if (head)
+               writefiles(fp, head);
        writefooter(fp);
        fclose(fp);