Commit 61a7d79fef51b4bf48411fcd4542401f10acc626

Stefan Sperling 2020-02-29T08:05:11

remove GOT_ERR_NOT_ABSPATH and fix existing users to deal with absolute paths

diff --git a/include/got_error.h b/include/got_error.h
index ae6efb2..cd15a3a 100644
--- a/include/got_error.h
+++ b/include/got_error.h
@@ -18,7 +18,7 @@
 #define GOT_ERR_OK		0
 #define GOT_ERR_ERRNO		1
 #define GOT_ERR_NOT_GIT_REPO	2
-#define GOT_ERR_NOT_ABSPATH	3
+/* 3 is currently unused */
 #define GOT_ERR_BAD_PATH	4
 #define GOT_ERR_NOT_REF		5
 #define GOT_ERR_IO		6
@@ -139,7 +139,7 @@ static const struct got_error {
 	{ GOT_ERR_OK,		"no error occured?!?" },
 	{ GOT_ERR_ERRNO,	"see errno" },
 	{ GOT_ERR_NOT_GIT_REPO, "no git repository found" },
-	{ GOT_ERR_NOT_ABSPATH,	"absolute path expected" },
+	{ 3,			"unused error code" },
 	{ GOT_ERR_BAD_PATH,	"bad path" },
 	{ GOT_ERR_NOT_REF,	"no such reference found" },
 	{ GOT_ERR_IO,		"input/output error" },
diff --git a/lib/object.c b/lib/object.c
index f8ccc9e..ea5232a 100644
--- a/lib/object.c
+++ b/lib/object.c
@@ -1637,18 +1637,15 @@ got_object_tree_path_changed(int *changed,
 
 	*changed = 0;
 
-	/* We are expecting an absolute in-repository path. */
-	if (path[0] != '/')
-		return got_error(GOT_ERR_NOT_ABSPATH);
-
 	/* We not do support comparing the root path. */
-	if (path[1] == '\0')
+	if (got_path_is_root_dir(path))
 		return got_error_path(path, GOT_ERR_BAD_PATH);
 
 	tree1 = tree01;
 	tree2 = tree02;
 	s = path;
-	s++; /* skip leading '/' */
+	while (*s == '/')
+		s++;
 	seg = s;
 	seglen = 0;
 	while (*s) {
diff --git a/libexec/got-read-pack/got-read-pack.c b/libexec/got-read-pack/got-read-pack.c
index 37bda9d..d690ffc 100644
--- a/libexec/got-read-pack/got-read-pack.c
+++ b/libexec/got-read-pack/got-read-pack.c
@@ -446,16 +446,13 @@ tree_path_changed(int *changed, uint8_t **buf1, uint8_t **buf2,
 
 	*changed = 0;
 
-	/* We are expecting an absolute in-repository path. */
-	if (path[0] != '/')
-		return got_error(GOT_ERR_NOT_ABSPATH);
-
 	/* We not do support comparing the root path. */
-	if (path[1] == '\0')
+	if (got_path_is_root_dir(path))
 		return got_error_path(path, GOT_ERR_BAD_PATH);
 
 	s = path;
-	s++; /* skip leading '/' */
+	while (*s == '/')
+		s++;
 	seg = s;
 	seglen = 0;
 	while (*s) {