Commit d14519756a20c300e9189d2db6b7477b7adfe312

Stefan Sperling 2018-11-11T13:52:20

add custom error code for 'no such tree entry' errors

diff --git a/include/got_error.h b/include/got_error.h
index 5e8cb64..143e83f 100644
--- a/include/got_error.h
+++ b/include/got_error.h
@@ -63,6 +63,7 @@
 #define GOT_ERR_RANGE		47
 #define GOT_ERR_EXPECTED	48 /* for use in regress tests only */
 #define GOT_ERR_CANCELLED	49
+#define GOT_ERR_NO_TREE_ENTRY	50
 
 static const struct got_error {
 	int code;
@@ -114,6 +115,7 @@ static const struct got_error {
 	{ GOT_ERR_RANGE,	"value out of range" },
 	{ GOT_ERR_EXPECTED,	"expected an error but have no error" },
 	{ GOT_ERR_CANCELLED,	"operation in progress has been cancelled" },
+	{ GOT_ERR_NO_TREE_ENTRY,"no such entry found in tree" },
 };
 
 /*
diff --git a/lib/blame.c b/lib/blame.c
index e933e16..3bb1f98 100644
--- a/lib/blame.c
+++ b/lib/blame.c
@@ -206,7 +206,7 @@ blame_commit(struct got_blame *blame, struct got_object_id *id,
 
 	err = got_object_id_by_path(&pobj_id, repo, pid, path);
 	if (err) {
-		if (err->code == GOT_ERR_NO_OBJ) {
+		if (err->code == GOT_ERR_NO_TREE_ENTRY) {
 			/* Blob's history began in previous commit. */
 			err = got_error(GOT_ERR_ITER_COMPLETED);
 		}
diff --git a/lib/commit_graph.c b/lib/commit_graph.c
index e91da57..7ca2aa5 100644
--- a/lib/commit_graph.c
+++ b/lib/commit_graph.c
@@ -190,7 +190,7 @@ detect_changed_path(int *changed, struct got_commit_object *commit,
 		struct got_object_id *obj_id;
 		err = got_object_id_by_path(&obj_id, repo, commit_id, path);
 		if (err) {
-			if (err->code == GOT_ERR_NO_OBJ)
+			if (err->code == GOT_ERR_NO_TREE_ENTRY)
 				err = NULL;
 		} else
 			*changed = 1; /* The path was created in this commit. */
@@ -309,7 +309,7 @@ advance_branch(struct got_commit_graph *graph,
 			err = got_object_id_by_path(&id, repo, qid->id,
 			    graph->path);
 			if (err) {
-				if (err->code == GOT_ERR_NO_OBJ) {
+				if (err->code == GOT_ERR_NO_TREE_ENTRY) {
 					branches_differ = 1;
 					continue;
 				}
diff --git a/lib/object.c b/lib/object.c
index 97f5a2e..6bb2eb4 100644
--- a/lib/object.c
+++ b/lib/object.c
@@ -771,7 +771,7 @@ got_object_id_by_path(struct got_object_id **id, struct got_repository *repo,
 
 		te = find_entry_by_name(tree, seg, seglen);
 		if (te == NULL) {
-			err = got_error(GOT_ERR_NO_OBJ);
+			err = got_error(GOT_ERR_NO_TREE_ENTRY);
 			goto done;
 		}
 
@@ -798,7 +798,7 @@ got_object_id_by_path(struct got_object_id **id, struct got_repository *repo,
 		if (*id == NULL)
 			return got_error_from_errno();
 	} else
-		err = got_error(GOT_ERR_NO_OBJ);
+		err = got_error(GOT_ERR_NO_TREE_ENTRY);
 done:
 	if (commit)
 		got_object_commit_close(commit);