about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLukas Fleischer <cgit@cryptocrack.de>2014-01-10 12:44:35 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2014-01-10 17:01:29 +0100
commit36bdb2171f7154fcdf1a24d38c8ce3bd7e448cb1 (patch)
tree06a5bc8163bde09074e18ad5e66deb35ebb136c6
parentREADME: Fix dependencies (diff)
downloadcgit-pink-36bdb2171f7154fcdf1a24d38c8ce3bd7e448cb1.tar.gz
cgit-pink-36bdb2171f7154fcdf1a24d38c8ce3bd7e448cb1.zip
Replace most uses of strncmp() with prefixcmp()
This is a preparation for replacing all prefix checks with either
strip_prefix() or starts_with() when Git 1.8.6 is released.

Signed-off-by: Lukas Fleischer <cgit@cryptocrack.de>
Diffstat (limited to '')
-rw-r--r--cgit.c18
-rw-r--r--parsing.c12
-rw-r--r--scan-tree.c2
-rw-r--r--ui-refs.c4
-rw-r--r--ui-shared.c2
-rw-r--r--ui-summary.c2
6 files changed, 20 insertions, 20 deletions
diff --git a/cgit.c b/cgit.c
index 1f84da8..e31962d 100644
--- a/cgit.c
+++ b/cgit.c
@@ -863,7 +863,7 @@ static void cgit_parse_args(int argc, const char **argv)
 	int scan = 0;
 
 	for (i = 1; i < argc; i++) {
-		if (!strncmp(argv[i], "--cache=", 8)) {
+		if (!prefixcmp(argv[i], "--cache=")) {
 			ctx.cfg.cache_root = xstrdup(argv[i] + 8);
 		}
 		if (!strcmp(argv[i], "--nocache")) {
@@ -872,28 +872,28 @@ static void cgit_parse_args(int argc, const char **argv)
 		if (!strcmp(argv[i], "--nohttp")) {
 			ctx.env.no_http = "1";
 		}
-		if (!strncmp(argv[i], "--query=", 8)) {
+		if (!prefixcmp(argv[i], "--query=")) {
 			ctx.qry.raw = xstrdup(argv[i] + 8);
 		}
-		if (!strncmp(argv[i], "--repo=", 7)) {
+		if (!prefixcmp(argv[i], "--repo=")) {
 			ctx.qry.repo = xstrdup(argv[i] + 7);
 		}
-		if (!strncmp(argv[i], "--page=", 7)) {
+		if (!prefixcmp(argv[i], "--page=")) {
 			ctx.qry.page = xstrdup(argv[i] + 7);
 		}
-		if (!strncmp(argv[i], "--head=", 7)) {
+		if (!prefixcmp(argv[i], "--head=")) {
 			ctx.qry.head = xstrdup(argv[i] + 7);
 			ctx.qry.has_symref = 1;
 		}
-		if (!strncmp(argv[i], "--sha1=", 7)) {
+		if (!prefixcmp(argv[i], "--sha1=")) {
 			ctx.qry.sha1 = xstrdup(argv[i] + 7);
 			ctx.qry.has_sha1 = 1;
 		}
-		if (!strncmp(argv[i], "--ofs=", 6)) {
+		if (!prefixcmp(argv[i], "--ofs=")) {
 			ctx.qry.ofs = atoi(argv[i] + 6);
 		}
-		if (!strncmp(argv[i], "--scan-tree=", 12) ||
-		    !strncmp(argv[i], "--scan-path=", 12)) {
+		if (!prefixcmp(argv[i], "--scan-tree=") ||
+		    !prefixcmp(argv[i], "--scan-path=")) {
 			/* HACK: the global snapshot bitmask defines the
 			 * set of allowed snapshot formats, but the config
 			 * file hasn't been parsed yet so the mask is
diff --git a/parsing.c b/parsing.c
index 248b6ee..d740d38 100644
--- a/parsing.c
+++ b/parsing.c
@@ -142,25 +142,25 @@ struct commitinfo *cgit_parse_commit(struct commit *commit)
 	if (p == NULL)
 		return ret;
 
-	if (strncmp(p, "tree ", 5))
+	if (prefixcmp(p, "tree "))
 		die("Bad commit: %s", sha1_to_hex(commit->object.sha1));
 	else
 		p += 46; // "tree " + hex[40] + "\n"
 
-	while (!strncmp(p, "parent ", 7))
+	while (!prefixcmp(p, "parent "))
 		p += 48; // "parent " + hex[40] + "\n"
 
-	if (p && !strncmp(p, "author ", 7)) {
+	if (p && !prefixcmp(p, "author ")) {
 		p = parse_user(p + 7, &ret->author, &ret->author_email,
 			&ret->author_date);
 	}
 
-	if (p && !strncmp(p, "committer ", 9)) {
+	if (p && !prefixcmp(p, "committer ")) {
 		p = parse_user(p + 9, &ret->committer, &ret->committer_email,
 			&ret->committer_date);
 	}
 
-	if (p && !strncmp(p, "encoding ", 9)) {
+	if (p && !prefixcmp(p, "encoding ")) {
 		p += 9;
 		t = strchr(p, '\n');
 		if (t) {
@@ -239,7 +239,7 @@ struct taginfo *cgit_parse_tag(struct tag *tag)
 		if (*p == '\n')
 			break;
 
-		if (!strncmp(p, "tagger ", 7)) {
+		if (!prefixcmp(p, "tagger ")) {
 			p = parse_user(p + 7, &ret->tagger, &ret->tagger_email,
 				&ret->tagger_date);
 		} else {
diff --git a/scan-tree.c b/scan-tree.c
index 1a2ea87..49de658 100644
--- a/scan-tree.c
+++ b/scan-tree.c
@@ -105,7 +105,7 @@ static void add_repo(const char *base, struct strbuf *path, repo_config_fn fn)
 		return;
 	strbuf_setlen(path, pathlen);
 
-	if (strncmp(base, path->buf, strlen(base)))
+	if (prefixcmp(path->buf, base))
 		strbuf_addbuf(&rel, path);
 	else
 		strbuf_addstr(&rel, path->buf + strlen(base) + 1);
diff --git a/ui-refs.c b/ui-refs.c
index 7af6fed..20c91e3 100644
--- a/ui-refs.c
+++ b/ui-refs.c
@@ -240,9 +240,9 @@ void cgit_print_refs()
 
 	html("<table class='list nowrap'>");
 
-	if (ctx.qry.path && !strncmp(ctx.qry.path, "heads", 5))
+	if (ctx.qry.path && !prefixcmp(ctx.qry.path, "heads"))
 		cgit_print_branches(0);
-	else if (ctx.qry.path && !strncmp(ctx.qry.path, "tags", 4))
+	else if (ctx.qry.path && !prefixcmp(ctx.qry.path, "tags"))
 		cgit_print_tags(0);
 	else {
 		cgit_print_branches(0);
diff --git a/ui-shared.c b/ui-shared.c
index d32852f..2c12de7 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -120,7 +120,7 @@ const char *cgit_repobasename(const char *reponame)
 	/* strip trailing slashes */
 	while (p && rvbuf[p] == '/') rvbuf[p--] = 0;
 	/* strip trailing .git */
-	if (p >= 3 && !strncmp(&rvbuf[p-3], ".git", 4)) {
+	if (p >= 3 && !prefixcmp(&rvbuf[p-3], ".git")) {
 		p -= 3; rvbuf[p--] = 0;
 	}
 	/* strip more trailing slashes if any */
diff --git a/ui-summary.c b/ui-summary.c
index 3a7c7a7..63a5a75 100644
--- a/ui-summary.c
+++ b/ui-summary.c
@@ -116,7 +116,7 @@ static char* append_readme_path(const char *filename, const char *ref, const cha
 	if (!ref) {
 		resolved_base = realpath(base_dir, NULL);
 		resolved_full = realpath(full_path, NULL);
-		if (!resolved_base || !resolved_full || strncmp(resolved_base, resolved_full, strlen(resolved_base))) {
+		if (!resolved_base || !resolved_full || prefixcmp(resolved_full, resolved_base)) {
 			free(full_path);
 			full_path = NULL;
 		}
git: update to v2.20.0Christian Hesse Update to git version v2.20.0. Required changes follow upstream commits: * 00436bf1b1c2a8fe6cf5d2c2457d419d683042f4 (archive: initialize archivers earlier) * 611e42a5980a3a9f8bb3b1b49c1abde63c7a191e (xdiff: provide a separate emit callback for hunks) Signed-off-by: Christian Hesse <mail@eworm.de> 2018-11-25ui-blame: set repo for sbJason A. Donenfeld Otherwise recent git complains and crashes with: "BUG: blame.c:1787: repo is NULL". Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> 2018-11-25auth-filter: pass url with query string attachedJason A. Donenfeld Otherwise redirections come out wrong. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> 2018-11-21git: use xz compressed archive for downloadChristian Hesse Upstream will stop providing gz compressed source tarballs [0], so stop using them. [0] https://lists.zx2c4.com/pipermail/cgit/2018-November/004254.html Signed-off-by: Christian Hesse <mail@eworm.de> 2018-10-12git: update to v2.19.1Christian Hesse Update to git version v2.19.1. Required changes follow upstream commits: * commit: add repository argument to get_cached_commit_buffer (3ce85f7e5a41116145179f0fae2ce6d86558d099) * commit: add repository argument to lookup_commit_reference (2122f6754c93be8f02bfb5704ed96c88fc9837a8) * object: add repository argument to parse_object (109cd76dd3467bd05f8d2145b857006649741d5c) * tag: add repository argument to deref_tag (a74093da5ed601a09fa158e5ba6f6f14c1142a3e) * tag: add repository argument to lookup_tag (ce71efb713f97f476a2d2ab541a0c73f684a5db3) * tree: add repository argument to lookup_tree (f86bcc7b2ce6cad68ba1a48a528e380c6126705e) * archive.c: avoid access to the_index (b612ee202a48f129f81f8f6a5af6cf71d1a9caef) * for_each_*_object: move declarations to object-store.h (0889aae1cd18c1804ba01c1a4229e516dfb9fe9b) Signed-off-by: Christian Hesse <mail@eworm.de> 2018-09-11ui-ssdiff: ban strcat()Christian Hesse Git upstream bans strcat() with commit: banned.h: mark strcat() as banned 1b11b64b815db62f93a04242e4aed5687a448748 Signed-off-by: Christian Hesse <mail@eworm.de> 2018-09-11ui-ssdiff: ban strncpy()Christian Hesse Git upstream bans strncpy() with commit: banned.h: mark strncpy() as banned e488b7aba743d23b830d239dcc33d9ca0745a9ad Signed-off-by: Christian Hesse <mail@eworm.de> 2018-09-11ui-shared: ban strcat()Christian Hesse Git upstream bans strcat() with commit: banned.h: mark strcat() as banned 1b11b64b815db62f93a04242e4aed5687a448748 To avoid compiler warnings from gcc 8.1.x we get the hard way. Signed-off-by: Christian Hesse <mail@eworm.de> 2018-09-11ui-patch: ban sprintf()Christian Hesse Git upstream bans sprintf() with commit: banned.h: mark sprintf() as banned cc8fdaee1eeaf05d8dd55ff11f111b815f673c58 Signed-off-by: Christian Hesse <mail@eworm.de> 2018-09-11ui-log: ban strncpy()Christian Hesse Git upstream bans strncpy() with commit: banned.h: mark strncpy() as banned e488b7aba743d23b830d239dcc33d9ca0745a9ad Signed-off-by: Christian Hesse <mail@eworm.de> 2018-09-11ui-log: ban strcpy()Christian Hesse Git upstream bans strcpy() with commit: automatically ban strcpy() c8af66ab8ad7cd78557f0f9f5ef6a52fd46ee6dd Signed-off-by: Christian Hesse <mail@eworm.de> 2018-09-11parsing: ban sprintf()Christian Hesse Git upstream bans sprintf() with commit: banned.h: mark sprintf() as banned cc8fdaee1eeaf05d8dd55ff11f111b815f673c58 Signed-off-by: Christian Hesse <mail@eworm.de> 2018-09-11parsing: ban strncpy()Christian Hesse Git upstream bans strncpy() with commit: banned.h: mark strncpy() as banned e488b7aba743d23b830d239dcc33d9ca0745a9ad Signed-off-by: Christian Hesse <mail@eworm.de> 2018-08-28filters: generate anchor links from markdownChristian Hesse This makes the markdown filter generate anchor links for headings. Signed-off-by: Christian Hesse <mail@eworm.de> Tested-by: jean-christophe manciot <actionmystique@gmail.com> 2018-08-03Bump version.Jason A. Donenfeld Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> 2018-08-03clone: fix directory traversalJason A. Donenfeld This was introduced in the initial version of this code, way back when in 2008. $ curl http://127.0.0.1/cgit/repo/objects/?path=../../../../../../../../../etc/passwd root:x:0:0:root:/root:/bin/sh ... Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> Reported-by: Jann Horn <jannh@google.com> 2018-08-03config: record repo.snapshot-prefix in the per-repo configKonstantin Ryabitsev