URI: 
       detect more names for README and LICENSE - stagit-gopher - A git gopher frontend. (mirror)
  HTML git clone git://bitreich.org/stagit-gopher/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/stagit-gopher/
   DIR Log
   DIR Files
   DIR Refs
   DIR Tags
   DIR README
   DIR LICENSE
       ---
   DIR commit 4ae2a118c3f7dd0cc7e7b81289152afbada103bc
   DIR parent 3a00e5bb2bf0415338ff08d1a7bc9a47b4b751e2
  HTML Author: Hiltjo Posthuma <hiltjo@codemadness.org>
       Date:   Sun, 11 Nov 2018 19:07:24 +0100
       
       detect more names for README and LICENSE
       
       - for license: LICENSE, LICENSE.md, COPYING.
       - for readme: README, README.md.
       
       Diffstat:
         M stagit-gopher.c                     |      47 ++++++++++++++++++++-----------
       
       1 file changed, 31 insertions(+), 16 deletions(-)
       ---
   DIR diff --git a/stagit-gopher.c b/stagit-gopher.c
       @@ -58,12 +58,17 @@ static char *name = "";
        static char *strippedname = "";
        static char description[255];
        static char cloneurl[1024];
       -static int haslicense, hasreadme, hassubmodules, hastagsgph;
       +static int hastagsgph;
       +static char *submodules;
       +static char *licensefiles[] = { "HEAD:LICENSE", "HEAD:LICENSE.md", "HEAD:COPYING" };
       +static char *license;
       +static char *readmefiles[] = { "HEAD:README", "HEAD:README.md" };
       +static char *readme;
        static long long nlogcommits = -1; /* < 0 indicates not used */
        
        /* cache */
        static git_oid lastoid;
       -static char lastoidstr[GIT_OID_HEXSZ + 2]; /* id + newline + nul byte */
       +static char lastoidstr[GIT_OID_HEXSZ + 2]; /* id + newline + NUL byte */
        static FILE *rcachefp, *wcachefp;
        static const char *cachefile;
        
       @@ -465,12 +470,15 @@ writeheader(FILE *fp, const char *title)
                fprintf(fp, "[1|Refs|%s/refs.gph|server|port]\n", relpath);
                if (hastagsgph)
                        fprintf(fp, "[1|Tags|%s/tags.gph|server|port]\n", relpath);
       -        if (hassubmodules)
       -                fprintf(fp, "[1|Submodules|%s/file/.gitmodules.gph|server|port]\n", relpath);
       -        if (hasreadme)
       -                fprintf(fp, "[1|README|%s/file/README.gph|server|port]\n", relpath);
       -        if (haslicense)
       -                fprintf(fp, "[1|LICENSE|%s/file/LICENSE.gph|server|port]\n", relpath);
       +        if (submodules)
       +                fprintf(fp, "[1|Submodules|%s/file/%s.gph|server|port]\n",
       +                        relpath, submodules);
       +        if (readme)
       +                fprintf(fp, "[1|README|%s/file/%s.gph|server|port]\n",
       +                        relpath, readme);
       +        if (license)
       +                fprintf(fp, "[1|LICENSE|%s/file/%s.gph|server|port]\n",
       +                        relpath, license);
                fputs("---\n", fp);
        }
        
       @@ -1218,17 +1226,24 @@ main(int argc, char *argv[])
                hastagsgph = (access("tags.gph", F_OK) == 0);
        
                /* check LICENSE */
       -        haslicense = (!git_revparse_single(&obj, repo, "HEAD:LICENSE") &&
       -                git_object_type(obj) == GIT_OBJ_BLOB);
       -        git_object_free(obj);
       +        for (i = 0; i < sizeof(licensefiles) / sizeof(*licensefiles) && !license; i++) {
       +                if (!git_revparse_single(&obj, repo, licensefiles[i]) &&
       +                    git_object_type(obj) == GIT_OBJ_BLOB)
       +                        license = licensefiles[i] + strlen("HEAD:");
       +                git_object_free(obj);
       +        }
        
                /* check README */
       -        hasreadme = (!git_revparse_single(&obj, repo, "HEAD:README") &&
       -                git_object_type(obj) == GIT_OBJ_BLOB);
       -        git_object_free(obj);
       +        for (i = 0; i < sizeof(readmefiles) / sizeof(*readmefiles) && !readme; i++) {
       +                if (!git_revparse_single(&obj, repo, readmefiles[i]) &&
       +                    git_object_type(obj) == GIT_OBJ_BLOB)
       +                        readme = readmefiles[i] + strlen("HEAD:");
       +                git_object_free(obj);
       +        }
        
       -        hassubmodules = (!git_revparse_single(&obj, repo, "HEAD:.gitmodules") &&
       -                git_object_type(obj) == GIT_OBJ_BLOB);
       +        if (!git_revparse_single(&obj, repo, "HEAD:.gitmodules") &&
       +            git_object_type(obj) == GIT_OBJ_BLOB)
       +                submodules = ".gitmodules";
                git_object_free(obj);
        
                /* log for HEAD */