[PATCH v2 1/2] ui-snapshot: use named constants for snapshot formats

Christian Hesse list at eworm.de
Thu Jun 7 17:14:51 CEST 2018


From: Christian Hesse <mail at eworm.de>

Instead of using bitmasks directly we use named constants for snapshot
formats. This makes thing more comprehensible.

We also change the element order and move tar to the top. Note this
change is visible in UI for the user!

Signed-off-by: Christian Hesse <mail at eworm.de>
---
 cgit.h        | 10 ++++++++++
 ui-snapshot.c | 16 +++++++++++-----
 2 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/cgit.h b/cgit.h
index a686390..02d63ca 100644
--- a/cgit.h
+++ b/cgit.h
@@ -310,10 +310,20 @@ struct cgit_context {
 
 typedef int (*write_archive_fn_t)(const char *, const char *);
 
+enum cgit_snapshot_type {
+	CGIT_SNAPSHOT_NONE	= 0x00,
+	CGIT_SNAPSHOT_TAR	= 0x01,
+	CGIT_SNAPSHOT_TAR_GZ	= 0x02,
+	CGIT_SNAPSHOT_TAR_BZ2	= 0x04,
+	CGIT_SNAPSHOT_TAR_XZ	= 0x08,
+	CGIT_SNAPSHOT_ZIP	= 0x10
+};
+
 struct cgit_snapshot_format {
 	const char *suffix;
 	const char *mimetype;
 	write_archive_fn_t write_func;
+	int base;
 	int bit;
 };
 
diff --git a/ui-snapshot.c b/ui-snapshot.c
index c7611e8..c9ec1f3 100644
--- a/ui-snapshot.c
+++ b/ui-snapshot.c
@@ -86,11 +86,17 @@ static int write_tar_xz_archive(const char *hex, const char *prefix)
 }
 
 const struct cgit_snapshot_format cgit_snapshot_formats[] = {
-	{ ".zip", "application/x-zip", write_zip_archive, 0x01 },
-	{ ".tar.gz", "application/x-gzip", write_tar_gzip_archive, 0x02 },
-	{ ".tar.bz2", "application/x-bzip2", write_tar_bzip2_archive, 0x04 },
-	{ ".tar", "application/x-tar", write_tar_archive, 0x08 },
-	{ ".tar.xz", "application/x-xz", write_tar_xz_archive, 0x10 },
+	/* Keep tar the first! */
+	{ ".tar",	"application/x-tar",	write_tar_archive,
+		CGIT_SNAPSHOT_NONE,	CGIT_SNAPSHOT_TAR	},
+	{ ".tar.gz",	"application/x-gzip",	write_tar_gzip_archive,
+		CGIT_SNAPSHOT_TAR,	CGIT_SNAPSHOT_TAR_GZ	},
+	{ ".tar.bz2",	"application/x-bzip2",	write_tar_bzip2_archive,
+		CGIT_SNAPSHOT_TAR,	CGIT_SNAPSHOT_TAR_BZ2	},
+	{ ".tar.xz",	"application/x-xz",	write_tar_xz_archive,
+		CGIT_SNAPSHOT_TAR,	CGIT_SNAPSHOT_TAR_XZ	},
+	{ ".zip",	"application/x-zip",	write_zip_archive,
+		CGIT_SNAPSHOT_NONE,	CGIT_SNAPSHOT_ZIP	},
 	{ NULL }
 };
 


More information about the CGit mailing list