diff options
Diffstat (limited to 'ui-snapshot.c')
-rw-r--r-- | ui-snapshot.c | 48 |
1 files changed, 24 insertions, 24 deletions
diff --git a/ui-snapshot.c b/ui-snapshot.c index f9879ed..bd34a28 100644 --- a/ui-snapshot.c +++ b/ui-snapshot.c | |||
@@ -30,7 +30,7 @@ static int write_compressed_tar_archive(struct archiver_args *args,const char *f | |||
30 | /* parent */ | 30 | /* parent */ |
31 | chk_zero(close(rw[0]), "Closing read end of pipe"); | 31 | chk_zero(close(rw[0]), "Closing read end of pipe"); |
32 | chk_non_negative(dup2(rw[1],STDOUT_FILENO), "Redirecting output to compressor"); | 32 | chk_non_negative(dup2(rw[1],STDOUT_FILENO), "Redirecting output to compressor"); |
33 | 33 | ||
34 | rv = write_tar_archive(args); | 34 | rv = write_tar_archive(args); |
35 | 35 | ||
36 | chk_zero(close(STDOUT_FILENO), "Closing STDOUT redirected to compressor"); | 36 | chk_zero(close(STDOUT_FILENO), "Closing STDOUT redirected to compressor"); |
@@ -48,6 +48,7 @@ static int write_tar_gzip_archive(struct archiver_args *args) | |||
48 | { | 48 | { |
49 | return write_compressed_tar_archive(args,"gzip"); | 49 | return write_compressed_tar_archive(args,"gzip"); |
50 | } | 50 | } |
51 | |||
51 | static int write_tar_bzip2_archive(struct archiver_args *args) | 52 | static int write_tar_bzip2_archive(struct archiver_args *args) |
52 | { | 53 | { |
53 | return write_compressed_tar_archive(args,"bzip2"); | 54 | return write_compressed_tar_archive(args,"bzip2"); |
@@ -65,27 +66,25 @@ static const struct snapshot_archive_t { | |||
65 | { ".tar", "application/x-tar", write_tar_archive, 0x8 } | 66 | { ".tar", "application/x-tar", write_tar_archive, 0x8 } |
66 | }; | 67 | }; |
67 | 68 | ||
69 | #define snapshot_archives_len (sizeof(snapshot_archives) / sizeof(*snapshot_archives)) | ||
70 | |||
68 | void cgit_print_snapshot(struct cacheitem *item, const char *head, | 71 | void cgit_print_snapshot(struct cacheitem *item, const char *head, |
69 | const char *hex, const char *prefix, | 72 | const char *hex, const char *prefix, |
70 | const char *filename, int snapshots) | 73 | const char *filename, int snapshots) |
71 | { | 74 | { |
72 | int fnl = strlen(filename); | 75 | const struct snapshot_archive_t* sat; |
73 | int f, n; | 76 | struct archiver_args args; |
74 | 77 | struct commit *commit; | |
75 | n = sizeof(snapshot_archives) / sizeof(*snapshot_archives); | 78 | unsigned char sha1[20]; |
76 | for(f=0; f<n; f++) { | 79 | int f, sl, fnl = strlen(filename); |
77 | const struct snapshot_archive_t* sat = &snapshot_archives[f]; | 80 | |
78 | int sl; | 81 | for(f=0; f<snapshot_archives_len; f++) { |
82 | sat = &snapshot_archives[f]; | ||
79 | if(!(snapshots & sat->bit)) | 83 | if(!(snapshots & sat->bit)) |
80 | continue; | 84 | continue; |
81 | sl = strlen(sat->suffix); | 85 | sl = strlen(sat->suffix); |
82 | if(fnl<sl || strcmp(&filename[fnl-sl],sat->suffix)) | 86 | if(fnl<sl || strcmp(&filename[fnl-sl],sat->suffix)) |
83 | continue; | 87 | continue; |
84 | |||
85 | struct archiver_args args; | ||
86 | struct commit *commit; | ||
87 | unsigned char sha1[20]; | ||
88 | |||
89 | if (!hex) | 88 | if (!hex) |
90 | hex = head; | 89 | hex = head; |
91 | if(get_sha1(hex, sha1)) { | 90 | if(get_sha1(hex, sha1)) { |
@@ -93,16 +92,13 @@ void cgit_print_snapshot(struct cacheitem *item, const char *head, | |||
93 | return; | 92 | return; |
94 | } | 93 | } |
95 | commit = lookup_commit_reference(sha1); | 94 | commit = lookup_commit_reference(sha1); |
96 | |||
97 | if(!commit) { | 95 | if(!commit) { |
98 | cgit_print_error(fmt("Not a commit reference: %s", hex)); | 96 | cgit_print_error(fmt("Not a commit reference: %s", hex)); |
99 | return;; | 97 | return;; |
100 | } | 98 | } |
101 | |||
102 | memset(&args,0,sizeof(args)); | 99 | memset(&args,0,sizeof(args)); |
103 | args.base = fmt("%s/", prefix); | 100 | args.base = fmt("%s/", prefix); |
104 | args.tree = commit->tree; | 101 | args.tree = commit->tree; |
105 | |||
106 | cgit_print_snapshot_start(sat->mimetype, filename, item); | 102 | cgit_print_snapshot_start(sat->mimetype, filename, item); |
107 | (*sat->write_func)(&args); | 103 | (*sat->write_func)(&args); |
108 | return; | 104 | return; |
@@ -113,12 +109,12 @@ void cgit_print_snapshot(struct cacheitem *item, const char *head, | |||
113 | void cgit_print_snapshot_links(const char *repo, const char *head, | 109 | void cgit_print_snapshot_links(const char *repo, const char *head, |
114 | const char *hex, int snapshots) | 110 | const char *hex, int snapshots) |
115 | { | 111 | { |
112 | const struct snapshot_archive_t* sat; | ||
116 | char *filename; | 113 | char *filename; |
117 | int f, n; | 114 | int f; |
118 | 115 | ||
119 | n = sizeof(snapshot_archives) / sizeof(*snapshot_archives); | 116 | for(f=0; f<snapshot_archives_len; f++) { |
120 | for(f=0; f<n ;f++) { | 117 | sat = &snapshot_archives[f]; |
121 | const struct snapshot_archive_t* sat = &snapshot_archives[f]; | ||
122 | if(!(snapshots & sat->bit)) | 118 | if(!(snapshots & sat->bit)) |
123 | continue; | 119 | continue; |
124 | filename = fmt("%s-%s%s", cgit_repobasename(repo), hex, | 120 | filename = fmt("%s-%s%s", cgit_repobasename(repo), hex, |
@@ -131,18 +127,22 @@ void cgit_print_snapshot_links(const char *repo, const char *head, | |||
131 | 127 | ||
132 | int cgit_parse_snapshots_mask(const char *str) | 128 | int cgit_parse_snapshots_mask(const char *str) |
133 | { | 129 | { |
130 | const struct snapshot_archive_t* sat; | ||
134 | static const char *delim = " \t,:/|;"; | 131 | static const char *delim = " \t,:/|;"; |
135 | int f, tl, rv = 0; | 132 | int f, tl, rv = 0; |
133 | |||
136 | /* favor legacy setting */ | 134 | /* favor legacy setting */ |
137 | if(atoi(str)) return 1; | 135 | if(atoi(str)) |
136 | return 1; | ||
138 | for(;;) { | 137 | for(;;) { |
139 | str += strspn(str,delim); | 138 | str += strspn(str,delim); |
140 | tl = strcspn(str,delim); | 139 | tl = strcspn(str,delim); |
141 | if(!tl) | 140 | if(!tl) |
142 | break; | 141 | break; |
143 | for(f=0;f<(sizeof(snapshot_archives)/sizeof(*snapshot_archives));++f) { | 142 | for(f=0; f<snapshot_archives_len; f++) { |
144 | const struct snapshot_archive_t* sat = &snapshot_archives[f]; | 143 | sat = &snapshot_archives[f]; |
145 | if(! ( strncmp(sat->suffix,str,tl) && strncmp(sat->suffix+1,str,tl-1) ) ) { | 144 | if(!(strncmp(sat->suffix, str, tl) && |
145 | strncmp(sat->suffix+1, str, tl-1))) { | ||
146 | rv |= sat->bit; | 146 | rv |= sat->bit; |
147 | break; | 147 | break; |
148 | } | 148 | } |