List for cgit developers and users
 help / color / mirror / Atom feed
From: list at eworm.de (Christian Hesse)
Subject: [PATCH v2 1/2] ui-snapshot: use named constants for snapshot formats
Date: Thu,  7 Jun 2018 17:14:51 +0200	[thread overview]
Message-ID: <20180607151452.24300-1-list@eworm.de> (raw)
In-Reply-To: <20180607171302.5fedf42f@leda>

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 }
 };
 


  reply	other threads:[~2018-06-07 15:14 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-07 12:12 Custom snapshot prefix & Snapshot signatures list
2018-06-07 12:15 ` [PATCH 1/1] snapshot: support tar signature for compressed tar list
2018-06-07 13:17   ` john
2018-06-07 15:13     ` list
2018-06-07 15:14       ` list [this message]
2018-06-07 15:14         ` [PATCH v2 2/2] " list
2018-06-07 15:21           ` john
2018-06-07 19:36             ` list
2018-06-07 19:38               ` [PATCH v3 1/1] " list
2018-06-27 16:34                 ` Jason
2018-06-27 20:14                   ` john
2018-07-02  7:10                     ` list
2018-07-03 18:56                       ` Jason
2018-06-08 22:11             ` [PATCH 1/1] snapshot: strip bit from struct cgit_snapshot_format list
2018-06-09 11:16               ` john
2018-06-11  6:51                 ` list
2018-06-11  6:53                   ` [PATCH v2 " list
2018-06-07 13:10 ` Custom snapshot prefix & Snapshot signatures john

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180607151452.24300-1-list@eworm.de \
    --to=cgit@lists.zx2c4.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).