Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2014-07-16 22:25:59 +0400
committerJunio C Hamano <gitster@pobox.com>2014-07-16 22:26:00 +0400
commit6e4094731acee5207595a8416d19508107ea475d (patch)
treea04d3fe754e34c91216f3a5e2f5450a705fd969d /git-compat-util.h
parentd518cc0a56b8b22a5d085be8710f082dbabfe1b3 (diff)
parent47bf4b0fc52f3ad5823185a85f5f82325787c84b (diff)
Merge branch 'jk/strip-suffix'
* jk/strip-suffix: prepare_packed_git_one: refactor duplicate-pack check verify-pack: use strbuf_strip_suffix strbuf: implement strbuf_strip_suffix index-pack: use strip_suffix to avoid magic numbers use strip_suffix instead of ends_with in simple cases replace has_extension with ends_with implement ends_with via strip_suffix add strip_suffix function sha1_file: replace PATH_MAX buffer with strbuf in prepare_packed_git_one()
Diffstat (limited to 'git-compat-util.h')
-rw-r--r--git-compat-util.h41
1 files changed, 33 insertions, 8 deletions
diff --git a/git-compat-util.h b/git-compat-util.h
index 9de3180710..0b53c9a4af 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -347,7 +347,6 @@ extern void set_error_routine(void (*routine)(const char *err, va_list params));
extern void set_die_is_recursing_routine(int (*routine)(void));
extern int starts_with(const char *str, const char *prefix);
-extern int ends_with(const char *str, const char *suffix);
/*
* If the string "str" begins with the string found in "prefix", return 1.
@@ -377,6 +376,39 @@ static inline int skip_prefix(const char *str, const char *prefix,
return 0;
}
+/*
+ * If buf ends with suffix, return 1 and subtract the length of the suffix
+ * from *len. Otherwise, return 0 and leave *len untouched.
+ */
+static inline int strip_suffix_mem(const char *buf, size_t *len,
+ const char *suffix)
+{
+ size_t suflen = strlen(suffix);
+ if (*len < suflen || memcmp(buf + (*len - suflen), suffix, suflen))
+ return 0;
+ *len -= suflen;
+ return 1;
+}
+
+/*
+ * If str ends with suffix, return 1 and set *len to the size of the string
+ * without the suffix. Otherwise, return 0 and set *len to the size of the
+ * string.
+ *
+ * Note that we do _not_ NUL-terminate str to the new length.
+ */
+static inline int strip_suffix(const char *str, const char *suffix, size_t *len)
+{
+ *len = strlen(str);
+ return strip_suffix_mem(str, len, suffix);
+}
+
+static inline int ends_with(const char *str, const char *suffix)
+{
+ size_t len;
+ return strip_suffix(str, suffix, &len);
+}
+
#if defined(NO_MMAP) || defined(USE_WIN32_MMAP)
#ifndef PROT_READ
@@ -581,13 +613,6 @@ static inline size_t xsize_t(off_t len)
return (size_t)len;
}
-static inline int has_extension(const char *filename, const char *ext)
-{
- size_t len = strlen(filename);
- size_t extlen = strlen(ext);
- return len > extlen && !memcmp(filename + len - extlen, ext, extlen);
-}
-
/* in ctype.c, for kwset users */
extern const char tolower_trans_tbl[256];