[PATCH gcli] gitconfig: Fix {html,ssh}_extractor for nested projects on Gitlab
Export this patch
This fixes a bug where the review action for pulls would display
bad defaults leading to a miserable UX where the user must correct
the remote and the owner and target branch of the MR.
Fix by scanning the remote-url backwards for slashes thus extracting
the correct owner and repo paths.
Signed-off-by: Nico Sonack <nsonack@herrhotzenplotz.de>
---
src/cmd/gitconfig.c | 4 ++--
thirdparty/sn/sn.c | 16 ++++++++++++++++
thirdparty/sn/sn.h | 1 +
3 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/src/cmd/gitconfig.c b/src/cmd/gitconfig.c
index a03f373a..9e5b9795 100644
--- a/src/cmd/gitconfig.c
+++ b/src/cmd/gitconfig.c
@@ -303,7 +303,7 @@ http_extractor(struct gcli_gitremote *const remote, char const *prefix)
pair.length -= prefix_size;
pair.data += prefix_size;
- remote->owner = sn_sv_chop_until(&pair, '/');
+ remote->owner = sn_sv_chop_to_last(&pair, '/');
pair.data += 1;
pair.length -= 1;
@@ -341,7 +341,7 @@ ssh_extractor(struct gcli_gitremote *const remote, char const *prefix)
pair.length -= 1;
}
- remote->owner = sn_sv_chop_until(&pair, '/');
+ remote->owner = sn_sv_chop_to_last(&pair, '/');
pair.data += 1;
pair.length -= 1;
diff --git a/thirdparty/sn/sn.c b/thirdparty/sn/sn.c
index 66b6e4d6..72c02a2a 100644
--- a/thirdparty/sn/sn.c
+++ b/thirdparty/sn/sn.c
@@ -281,6 +281,22 @@ sn_sv_chop_until(sn_sv *it, char c)
return result;
}
+sn_sv
+sn_sv_chop_to_last(sn_sv *it, char sep)
+{
+ sn_sv result = *it;
+
+ while (result.length) {
+ if (result.data[--result.length] == sep)
+ break;
+ }
+
+ it->length -= result.length;
+ it->data += result.length;
+
+ return result;
+}
+
bool
sn_sv_has_prefix(sn_sv it, const char *prefix)
{
diff --git a/thirdparty/sn/sn.h b/thirdparty/sn/sn.h
index 7dc1631c..9e6c4a4b 100644
--- a/thirdparty/sn/sn.h
+++ b/thirdparty/sn/sn.h
@@ -131,6 +131,7 @@ sn_sv_from_parts(char *buf, size_t len)
sn_sv sn_sv_trim_front(sn_sv);
sn_sv sn_sv_trim(sn_sv);
sn_sv sn_sv_chop_until(sn_sv *, char);
+sn_sv sn_sv_chop_to_last(sn_sv *, char);
bool sn_sv_has_prefix(sn_sv, const char *);
bool sn_sv_eq(const sn_sv, const sn_sv);
bool sn_sv_eq_to(const sn_sv, const char *);
--
2.45.2