summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--ui-snapshot.c48
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
@@ -21,135 +21,135 @@ static int write_compressed_tar_archive(struct archiver_args *args,const char *f
21 gzpid = chk_non_negative(fork(), "Forking compressor subprocess"); 21 gzpid = chk_non_negative(fork(), "Forking compressor subprocess");
22 if(gzpid==0) { 22 if(gzpid==0) {
23 /* child */ 23 /* child */
24 chk_zero(close(rw[1]), "Closing write end of pipe in child"); 24 chk_zero(close(rw[1]), "Closing write end of pipe in child");
25 chk_zero(close(STDIN_FILENO), "Closing STDIN"); 25 chk_zero(close(STDIN_FILENO), "Closing STDIN");
26 chk_non_negative(dup2(rw[0],STDIN_FILENO), "Redirecting compressor input to stdin"); 26 chk_non_negative(dup2(rw[0],STDIN_FILENO), "Redirecting compressor input to stdin");
27 execlp(filter,filter,NULL); 27 execlp(filter,filter,NULL);
28 _exit(-1); 28 _exit(-1);
29 } 29 }
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");
37 chk_non_negative(dup2(stdout2,STDOUT_FILENO), "Restoring uncompressed STDOUT"); 37 chk_non_negative(dup2(stdout2,STDOUT_FILENO), "Restoring uncompressed STDOUT");
38 chk_zero(close(stdout2), "Closing uncompressed STDOUT"); 38 chk_zero(close(stdout2), "Closing uncompressed STDOUT");
39 chk_zero(close(rw[1]), "Closing write end of pipe in parent"); 39 chk_zero(close(rw[1]), "Closing write end of pipe in parent");
40 chk_positive(waitpid(gzpid,&status,0), "Waiting on compressor process"); 40 chk_positive(waitpid(gzpid,&status,0), "Waiting on compressor process");
41 if(! ( WIFEXITED(status) && WEXITSTATUS(status)==0 ) ) 41 if(! ( WIFEXITED(status) && WEXITSTATUS(status)==0 ) )
42 cgit_print_error("Failed to compress archive"); 42 cgit_print_error("Failed to compress archive");
43 43
44 return rv; 44 return rv;
45} 45}
46 46
47static int write_tar_gzip_archive(struct archiver_args *args) 47static 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
51static int write_tar_bzip2_archive(struct archiver_args *args) 52static 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");
54} 55}
55 56
56static const struct snapshot_archive_t { 57static const struct snapshot_archive_t {
57 const char *suffix; 58 const char *suffix;
58 const char *mimetype; 59 const char *mimetype;
59 write_archive_fn_t write_func; 60 write_archive_fn_t write_func;
60 int bit; 61 int bit;
61 }snapshot_archives[] = { 62 }snapshot_archives[] = {
62 { ".zip", "application/x-zip", write_zip_archive, 0x1 }, 63 { ".zip", "application/x-zip", write_zip_archive, 0x1 },
63 { ".tar.gz", "application/x-tar", write_tar_gzip_archive, 0x2 }, 64 { ".tar.gz", "application/x-tar", write_tar_gzip_archive, 0x2 },
64 { ".tar.bz2", "application/x-tar", write_tar_bzip2_archive, 0x4 }, 65 { ".tar.bz2", "application/x-tar", write_tar_bzip2_archive, 0x4 },
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
68void cgit_print_snapshot(struct cacheitem *item, const char *head, 71void 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)) {
92 cgit_print_error(fmt("Bad object id: %s", hex)); 91 cgit_print_error(fmt("Bad object id: %s", hex));
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;
109 } 105 }
110 cgit_print_error(fmt("Unsupported snapshot format: %s", filename)); 106 cgit_print_error(fmt("Unsupported snapshot format: %s", filename));
111} 107}
112 108
113void cgit_print_snapshot_links(const char *repo, const char *head, 109void 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,
125 sat->suffix); 121 sat->suffix);
126 cgit_snapshot_link(filename, NULL, NULL, (char *)head, 122 cgit_snapshot_link(filename, NULL, NULL, (char *)head,
127 (char *)hex, filename); 123 (char *)hex, filename);
128 html("<br/>"); 124 html("<br/>");
129 } 125 }
130} 126}
131 127
132int cgit_parse_snapshots_mask(const char *str) 128int 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 }
149 } 149 }
150 str += tl; 150 str += tl;
151 } 151 }
152 return rv; 152 return rv;
153} 153}
154 154
155/* vim:set sw=8: */ 155/* vim:set sw=8: */