]> gitweb.ps.run Git - ps-cgit/blobdiff - ui-snapshot.c
authors: specify maintainers
[ps-cgit] / ui-snapshot.c
index 8a720801004cca005287c2f9457340da8703ef81..5136c49d84b8fb9307c592892f246fb605a89a69 100644 (file)
@@ -1,7 +1,6 @@
 /* ui-snapshot.c: generate snapshot of a commit
  *
- * Copyright (C) 2006 Lars Hjemli
- * Copyright (C) 2012 Jason A. Donenfeld <Jason@zx2c4.com>
+ * Copyright (C) 2006-2014 cgit Development Team <cgit@lists.zx2c4.com>
  *
  * Licensed under GNU General Public License v2
  *   (see COPYING for full license text)
@@ -16,7 +15,6 @@ static int write_archive_type(const char *format, const char *hex, const char *p
 {
        struct argv_array argv = ARGV_ARRAY_INIT;
        const char **nargv;
-       char *user_home, *xdg_home;
        int result;
        argv_array_push(&argv, "snapshot");
        argv_array_push(&argv, format);
@@ -39,15 +37,7 @@ static int write_archive_type(const char *format, const char *hex, const char *p
        /* argv_array guarantees a trailing NULL entry. */
        memcpy(nargv, argv.argv, sizeof(char *) * (argv.argc + 1));
 
-       user_home = getenv("HOME");
-       xdg_home = getenv("XDG_CONFIG_HOME");
-       unsetenv("HOME");
-       unsetenv("XDG_CONFIG_HOME");
        result = write_archive(argv.argc, nargv, NULL, 1, NULL, 0);
-       if (user_home)
-               setenv("HOME", user_home, 1);
-       if (xdg_home)
-               setenv("XDG_CONFIG_HOME", xdg_home, 1);
        argv_array_clear(&argv);
        free(nargv);
        return result;
@@ -68,10 +58,10 @@ static int write_compressed_tar_archive(const char *hex,
                                        char *filter_argv[])
 {
        int rv;
-       struct cgit_filter f;
-
-       f.cmd = filter_argv[0];
-       f.argv = filter_argv;
+       struct cgit_filter f = {
+               .cmd = filter_argv[0],
+               .argv = filter_argv,
+       };
        cgit_open_filter(&f);
        rv = write_tar_archive(hex, prefix);
        cgit_close_filter(&f);
@@ -108,14 +98,9 @@ const struct cgit_snapshot_format cgit_snapshot_formats[] = {
 static const struct cgit_snapshot_format *get_format(const char *filename)
 {
        const struct cgit_snapshot_format *fmt;
-       int fl, sl;
 
-       fl = strlen(filename);
        for (fmt = cgit_snapshot_formats; fmt->suffix; fmt++) {
-               sl = strlen(fmt->suffix);
-               if (sl >= fl)
-                       continue;
-               if (!strcmp(fmt->suffix, filename + fl - sl))
+               if (!suffixcmp(filename, fmt->suffix))
                        return fmt;
        }
        return NULL;