[PATCH 1/7] sha1_name: abstract upstream_mark() logic
From: Ramkumar Ramachandra <hidden>
Date: 2016-06-15 22:57:25
Subsystem:
the rest · Maintainer:
Linus Torvalds
Currently, the only non-numerical @{...} expression we support is
@{u[pstream]}. Since we're slowly growing git to support triangular
workflows, it might make sense to have a @{p[ush]} and various other
special @{...} expressions in the future. To prepare for this, abstract
out the upstream_mark() logic to accept any suffix, while preserving the
upstream_mark() interface.
Signed-off-by: Ramkumar Ramachandra <redacted>
---
sha1_name.c | 40 +++++++++++++++++++++++++++++++---------
1 file changed, 31 insertions(+), 9 deletions(-)
diff --git a/sha1_name.c b/sha1_name.c
index 6928cc7..766e4e9 100644
--- a/sha1_name.c
+++ b/sha1_name.c@@ -23,6 +23,8 @@ struct disambiguate_state { unsigned always_call_fn:1; }; +#define AT_KIND_UPSTREAM 0 + static void update_candidates(struct disambiguate_state *ds, const unsigned char *current) { if (ds->always_call_fn) {
@@ -416,20 +418,40 @@ static int ambiguous_path(const char *path, int len) return slash; } -static inline int upstream_mark(const char *string, int len) +static inline int at_mark(const char *string, int len, int *kind) { - const char *suffix[] = { "@{upstream}", "@{u}" }; - int i; - - for (i = 0; i < ARRAY_SIZE(suffix); i++) { - int suffix_len = strlen(suffix[i]); - if (suffix_len <= len - && !memcmp(string, suffix[i], suffix_len)) - return suffix_len; + int i, j; + + static struct { + int kind; + const char *suffix[2]; + } at_form[] = { + { AT_KIND_UPSTREAM, { "@{upstream}", "@{u}" } } + }; + + for (j = 0; j < ARRAY_SIZE(at_form); j++) { + for (i = 0; i < ARRAY_SIZE(at_form[j].suffix); i++) { + int suffix_len = strlen(at_form[j].suffix[i]); + if (suffix_len <= len + && !memcmp(string, at_form[j].suffix[i], suffix_len)) { + if (kind) + *kind = at_form[j].kind; + return suffix_len; + } + } } return 0; } +static inline int upstream_mark(const char *string, int len) +{ + int suffix_len, kind; + suffix_len = at_mark(string, len, &kind); + if (suffix_len && kind == AT_KIND_UPSTREAM) + return suffix_len; + return 0; +} + static int get_sha1_1(const char *name, int len, unsigned char *sha1, unsigned lookup_flags); static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
--
1.8.3.rc3.17.gd95ec6c.dirty