[PATCH 06/10] add ref_abbrev_matches_full_with_rev_parse_rules() comparing abbrev with full ref name
- From
Steffen Prohaska <prohaska@zib.de>
- Date
- Oct 28, 2007, 17:46 UTC
- Message-ID
- <11935935821136-git-send-email-prohaska@zib.de>
- In-Reply-To
- <11935935822846-git-send-email-prohaska@zib.de>
ref_abbrev_matches_full_with_rev_parse_rules(abbrev_name, full_name) expands abbrev_name according to the rules documented in git-rev-parse and compares the expanded name with full_name. It reports a match by returning 0.
This function makes the rules for resolving refs to sha1s available for string comparison. Before this change, the rules were buried in get_sha1*() and dwim_ref().
The function name is very long to make the rule set used explicit. We have a different set of rules for matching refspecs. It would be a good thing to unify all different rule sets. But this commit doesn't address this challenge. It only makes the git-rev-parse rules available for string comparison.
ref_abbrev_matches_full_with_rev_parse_rules() will be used for matching refspecs in git-send-pack.
Thanks to Daniel Barkalow <barkalow@iabervon.org> for pointing out that ref_matches_abbrev in remote.c solves a similar problem and care should be take to avoid confusion.
Signed-off-by: Steffen Prohaska <prohaska@zib.de> --- cache.h | 1 + sha1_name.c | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 0 deletions(-)
diff --git a/cache.h b/cache.h index 27485d3..bb10ade 100644 --- a/cache.h +++ b/cache.h @@ -405,6 +405,7 @@ extern int get_sha1_hex(const char *hex, unsigned char *sha1); extern char *sha1_to_hex(const unsigned char *sha1); /* static buffer result! */ extern int read_ref(const char *filename, unsigned char *sha1); extern const char *resolve_ref(const char *path, unsigned char *sha1, int, int *); +extern int ref_abbrev_matches_full_with_rev_parse_rules(const char *abbrev_name, const char *full_name); extern int dwim_ref(const char *str, int len, unsigned char *sha1, char **ref); extern int dwim_log(const char *str, int len, unsigned char *sha1, char **ref); diff --git a/sha1_name.c b/sha1_name.c index 2d727d5..944e318 100644 --- a/sha1_name.c +++ b/sha1_name.c @@ -249,6 +249,20 @@ static const char *ref_fmt[] = { NULL }; +int ref_abbrev_matches_full_with_rev_parse_rules(const char *abbrev_name, const char *full_name) +{ + const char **p; + const int abbrev_name_len = strlen(abbrev_name); + + for (p = ref_fmt; *p; p++) { + if (!strcmp(full_name, mkpath(*p, abbrev_name_len, abbrev_name))) { + return 0; + } + } + + return -1; +} + int dwim_ref(const char *str, int len, unsigned char *sha1, char **ref) { const char **p, *r;
-- 1.5.3.4.439.ge8b49