From 3e255c257f3a07f1515e20a4f45a6505eec49d40 Mon Sep 17 00:00:00 2001
From: Wynn Wolf Arbor
Date: Wed, 10 Jun 2020 19:29:53 +0200
Subject: www-apps/cgit: Update to second version of git-http-backend(1) patch

The previous patch did not account for caching support, breaking clones
with git-http-backend(1) if enabled. Include a version that contains a
workaround.

Package-Manager: Portage-2.3.99, Repoman-2.3.22
---
 www-apps/cgit/Manifest                             |  2 +-
 .../cgit/files/cgit-1.2.3-git-http-backend.patch   | 45 +++++++++++++++++++++-
 2 files changed, 44 insertions(+), 3 deletions(-)

diff --git a/www-apps/cgit/Manifest b/www-apps/cgit/Manifest
index d602954..50f975f 100644
--- a/www-apps/cgit/Manifest
+++ b/www-apps/cgit/Manifest
@@ -1,4 +1,4 @@
-AUX cgit-1.2.3-git-http-backend.patch 6644 BLAKE2B d82af5f99768494d33b938a3f77d74d3cbf794fc25b1b8c87c9df408e163f8df2707e4eee26523ed3177f8e0e2998f689922750ce2a051654db8ade220b85df4 SHA512 13f0218dca8d9c83f17b20f0844397006667e8339bce07ab7c8f65ad738d6ddda3240d3fd1f3d11bf29e137b4c278c0f750c0a7a1d44c967cf96807631d8bd54
+AUX cgit-1.2.3-git-http-backend.patch 7727 BLAKE2B a79f9f187f4b4a3b924f9aef3d1f478e3c1ee79677378458e769dc29ad5e0f6353addf8a2ae1a1db41a2ea99f484f82b31fa38cad8b54a2c7bddbb25a3023aec SHA512 7f96b37ecc0ce7842fcb4bfa05ffc6134769bd01e5660a5fd53ef664dc9a44ca49df9d01b9d94c3859057bb3364602de4eedc0db55459dc418451c5c1f45d384
 DIST cgit-1.2.3.tar.xz 90632 BLAKE2B 594a9b2ae0b449e0ef090f428f955cc02833f5f5b1e4d6dc8c737daa565d01ba6840933c0bdc53d4eb683b2f44e2fae885ddd020cfb2de38141a870a6eae2380 SHA512 58f9bb644b07be49dc51f3ef30a3d0e53699cede3c06b1d6920f3874fe846c83dd2589632aa84357b70ea2d60272448409aa1b892f405d14dd6745f5559b4504
 DIST git-2.25.1.tar.xz 5875548 BLAKE2B 582da3d4ac996d7b9ce6cf505661496ab1a2cd061f058745350498121956b33d79739b567fb5fea0b4e298303261256034aa0b8da0b842feab04ae67a7d5b142 SHA512 15241143acfd8542d85d2709ac3c80dbd6e8d5234438f70c4f33cc71a2bdec3e32938df7f6351e2746d570b021d3bd0b70474ea4beec0c51d1fc45f9c287b344
 EBUILD cgit-1.2.3-r4.ebuild 2393 BLAKE2B 5b3f54b347ea51c6ee9682a7099058d12a6757762b24f4e463b5b3ddd7f1a359fed51a018044d84020235e2c5601a68215657677f5066136ee3a2c0fbd4100c0 SHA512 4d67e9db74b9d792ae9821eb2de81f2d5b5c9d6a93017899ffe0adda5da7ead4c383d2319ed657eb96f7368ced06eea75dba11196be1111cf4223147985f95d1
diff --git a/www-apps/cgit/files/cgit-1.2.3-git-http-backend.patch b/www-apps/cgit/files/cgit-1.2.3-git-http-backend.patch
index 4331629..93bd4eb 100644
--- a/www-apps/cgit/files/cgit-1.2.3-git-http-backend.patch
+++ b/www-apps/cgit/files/cgit-1.2.3-git-http-backend.patch
@@ -1,4 +1,4 @@
-From d90a0186d519bae5dddb25830eb07b6d8d2287ec Mon Sep 17 00:00:00 2001
+From 6c9eb981818260af3b7f4235185ab8b0f94c4f5e Mon Sep 17 00:00:00 2001
 From: Wynn Wolf Arbor <wolf@oriole.systems>
 Date: Sat, 30 May 2020 21:51:39 +0200
 Subject: [PATCH] Support Git over HTTP by proxying git-http-backend(1)
@@ -34,18 +34,59 @@ Notable changes to the original patch:
    def_cmd() macro directly, as the endpoints "git-upload-pack" and
    "git-receive-pack" contain dashes.
 
+ * The original patch did not account for caching support, which will
+   break the whole clone process if enabled. Work around this by
+   disabling the cache for commands that have is_clone set to true.
+
 [1] https://lists.zx2c4.com/pipermail/cgit/2014-December/002312.html
 [2] https://lists.zx2c4.com/pipermail/cgit/2016-February/002907.html
 [3] https://lists.zx2c4.com/pipermail/cgit/2016-February/002926.html
 ---
+ cache.c      | 11 +++++++++++
  cgit.c       |  3 +++
  cgit.h       |  1 +
  cgitrc.5.txt |  8 ++++++++
  cmd.c        | 13 +++++++++++++
  ui-clone.c   | 42 ++++++++++++++++++++++++++++++++++++++++++
  ui-clone.h   |  2 ++
- 6 files changed, 69 insertions(+)
+ 7 files changed, 80 insertions(+)
 
+diff --git a/cache.c b/cache.c
+index 2c70be7..bb4fc47 100644
+--- a/cache.c
++++ b/cache.c
+@@ -15,6 +15,7 @@
+ 
+ #include "cgit.h"
+ #include "cache.h"
++#include "cmd.h"
+ #include "html.h"
+ #ifdef HAVE_LINUX_SENDFILE
+ #include <sys/sendfile.h>
+@@ -356,6 +357,7 @@ int cache_process(int size, const char *path, const char *key, int ttl,
+ 	struct strbuf filename = STRBUF_INIT;
+ 	struct strbuf lockname = STRBUF_INIT;
+ 	struct cache_slot slot;
++	struct cgit_cmd *cmd;
+ 	int result;
+ 
+ 	/* If the cache is disabled, just generate the content */
+@@ -370,6 +372,15 @@ int cache_process(int size, const char *path, const char *key, int ttl,
+ 		fn();
+ 		return 0;
+ 	}
++
++	cmd = cgit_get_cmd();
++
++	/* Do not cache files that are being cloned */
++	if (cmd && cmd->is_clone) {
++		fn();
++		return 0;
++	}
++
+ 	if (!key)
+ 		key = "";
+ 	hash = hash_str(key) % size;
 diff --git a/cgit.c b/cgit.c
 index c4320f0..fc85c18 100644
 --- a/cgit.c
-- 
cgit v1.2.3-2-gb3c3