summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 242abf1)
raw | patch | inline | side by side (parent: 242abf1)
author | Rene Scharfe <rene.scharfe@lsrfire.ath.cx> | |
Thu, 10 Aug 2006 15:02:30 +0000 (17:02 +0200) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Thu, 10 Aug 2006 21:13:53 +0000 (14:13 -0700) |
The little helper has_extension() documents through its name what we are
trying to do and makes sure we don't forget the underrun check.
Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <junkio@cox.net>
trying to do and makes sure we don't forget the underrun check.
Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <junkio@cox.net>
builtin-help.c | patch | blob | history | |
git-compat-util.h | patch | blob | history | |
http-fetch.c | patch | blob | history | |
index-pack.c | patch | blob | history | |
local-fetch.c | patch | blob | history | |
refs.c | patch | blob | history | |
sha1_file.c | patch | blob | history | |
verify-pack.c | patch | blob | history |
diff --git a/builtin-help.c b/builtin-help.c
index fb731cc9345e197e710aea611e9519f1e04e0ab8..7a7f7759e592208b4604b6987bce8be46c936882 100644 (file)
--- a/builtin-help.c
+++ b/builtin-help.c
continue;
entlen = strlen(de->d_name);
- if (4 < entlen && !strcmp(de->d_name + entlen - 4, ".exe"))
+ if (has_extension(de->d_name, entlen, ".exe"))
entlen -= 4;
if (longest < entlen)
diff --git a/git-compat-util.h b/git-compat-util.h
index 3bcf5b13f2c7bab387b02bd3075629a9d14c5feb..dd9209365253971c70db772929fb4541f1c609b2 100644 (file)
--- a/git-compat-util.h
+++ b/git-compat-util.h
}
}
+static inline int has_extension(const char *filename, int len, const char *ext)
+{
+ int extlen = strlen(ext);
+ return len > extlen && !memcmp(filename + len - extlen, ext, extlen);
+}
+
/* Sane ctype - no locale, and works with signed chars */
#undef isspace
#undef isdigit
diff --git a/http-fetch.c b/http-fetch.c
index 36af3e5b94bb87f8d452aac99c27cba0097abf13..6ea39f0589e74767be31eed87d2248370108b5f7 100644 (file)
--- a/http-fetch.c
+++ b/http-fetch.c
if (strlen(ls->dentry_name) == 63 &&
!strncmp(ls->dentry_name, "objects/pack/pack-", 18) &&
- !strncmp(ls->dentry_name+58, ".pack", 5)) {
+ has_extension(ls->dentry_name, 63, ".pack")) {
get_sha1_hex(ls->dentry_name + 18, sha1);
setup_index(ls->repo, sha1);
}
diff --git a/index-pack.c b/index-pack.c
index b39953dc698aae25f79caa9553e13bca6cd4e986..a91e39ecd6469c04da92391bdb24e5a05691b617 100644 (file)
--- a/index-pack.c
+++ b/index-pack.c
usage(index_pack_usage);
if (!index_name) {
int len = strlen(pack_name);
- if (len < 5 || strcmp(pack_name + len - 5, ".pack"))
+ if (!has_extension(pack_name, len, ".pack"))
die("packfile name '%s' does not end with '.pack'",
pack_name);
index_name_buf = xmalloc(len);
diff --git a/local-fetch.c b/local-fetch.c
index 4bf86fbbe2703514cd3ab39fd9c81accac662aaf..b6ec170c015661ec602a6c2bd2b2f10754dbbd9c 100644 (file)
--- a/local-fetch.c
+++ b/local-fetch.c
return -1;
while ((de = readdir(dir)) != NULL) {
int namelen = strlen(de->d_name);
- if (namelen != 50 ||
- strcmp(de->d_name + namelen - 5, ".pack"))
+ if (namelen != 50 ||
+ !has_extension(de->d_name, namelen, ".pack"))
continue;
get_sha1_hex(de->d_name + 5, sha1);
setup_index(sha1);
index 02850b69083f793becacc59a0da97a8f69367e4e..b01835f634603f2f89c188bd56aae6fb45983ba3 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -147,7 +147,7 @@ static int do_for_each_ref(const char *base, int (*fn)(const char *path, const u
namelen = strlen(de->d_name);
if (namelen > 255)
continue;
- if (namelen>5 && !strcmp(de->d_name+namelen-5,".lock"))
+ if (has_extension(de->d_name, namelen, ".lock"))
continue;
memcpy(path + baselen, de->d_name, namelen+1);
if (stat(git_path("%s", path), &st) < 0)
diff --git a/sha1_file.c b/sha1_file.c
index 43bc2ea0cf039bb9fd02c8313981e85bd7398d33..a1bb01ca3569279318333f8088ade35614167612 100644 (file)
--- a/sha1_file.c
+++ b/sha1_file.c
int namelen = strlen(de->d_name);
struct packed_git *p;
- if (strcmp(de->d_name + namelen - 4, ".idx"))
+ if (!has_extension(de->d_name, namelen, ".idx"))
continue;
/* we have .idx. Is it a file we can map? */
diff --git a/verify-pack.c b/verify-pack.c
index c99db9dd79315dff4ac19c79b35275cd02397e60..ef00204ad471820498ebb622a6b9424c295aab0e 100644 (file)
--- a/verify-pack.c
+++ b/verify-pack.c
/* Should name foo.idx, but foo.pack may be named;
* convert it to foo.idx
*/
- if (!strcmp(arg + len - 5, ".pack")) {
+ if (has_extension(arg, len, ".pack")) {
strcpy(arg + len - 5, ".idx");
len--;
}