Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
3aa351ea
Commit
3aa351ea
authored
Apr 26, 2012
by
Carlos Martín Nieto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
error handling: move the missing parts over to the new error handling
parent
eb3d71a5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
64 additions
and
48 deletions
+64
-48
include/git2/errors.h
+2
-0
src/commit.c
+4
-2
src/delta-apply.c
+10
-5
src/filter.c
+2
-2
src/object.c
+15
-15
src/refspec.c
+19
-18
src/tag.c
+0
-0
src/tree.c
+0
-0
tests-clar/object/tree/frompath.c
+12
-6
No files found.
include/git2/errors.h
View file @
3aa351ea
...
...
@@ -133,6 +133,8 @@ typedef enum {
GITERR_INDEX
,
GITERR_OBJECT
,
GITERR_NET
,
GITERR_TAG
,
GITERR_TREE
,
}
git_error_class
;
/**
...
...
src/commit.c
View file @
3aa351ea
...
...
@@ -310,8 +310,10 @@ int git_commit_parent(git_commit **parent, git_commit *commit, unsigned int n)
assert
(
commit
);
parent_oid
=
git_vector_get
(
&
commit
->
parent_oids
,
n
);
if
(
parent_oid
==
NULL
)
return
git__throw
(
GIT_ENOTFOUND
,
"Parent %u does not exist"
,
n
);
if
(
parent_oid
==
NULL
)
{
giterr_set
(
GITERR_INVALID
,
"Parent %u does not exist"
,
n
);
return
GIT_ENOTFOUND
;
}
return
git_commit_lookup
(
parent
,
commit
->
object
.
repo
,
parent_oid
);
}
...
...
src/delta-apply.c
View file @
3aa351ea
...
...
@@ -51,11 +51,15 @@ int git__delta_apply(
* if not we would underflow while accessing data from the
* base object, resulting in data corruption or segfault.
*/
if
((
hdr_sz
(
&
base_sz
,
&
delta
,
delta_end
)
<
0
)
||
(
base_sz
!=
base_len
))
return
git__throw
(
GIT_ERROR
,
"Failed to apply delta. Base size does not match given data"
);
if
((
hdr_sz
(
&
base_sz
,
&
delta
,
delta_end
)
<
0
)
||
(
base_sz
!=
base_len
))
{
giterr_set
(
GITERR_INVALID
,
"Failed to apply delta. Base size does not match given data"
);
return
-
1
;
}
if
(
hdr_sz
(
&
res_sz
,
&
delta
,
delta_end
)
<
0
)
return
git__throw
(
GIT_ERROR
,
"Failed to apply delta. Base size does not match given data"
);
if
(
hdr_sz
(
&
res_sz
,
&
delta
,
delta_end
)
<
0
)
{
giterr_set
(
GITERR_INVALID
,
"Failed to apply delta. Base size does not match given data"
);
return
-
1
;
}
if
((
res_dp
=
git__malloc
(
res_sz
+
1
))
==
NULL
)
return
GIT_ENOMEM
;
...
...
@@ -111,5 +115,6 @@ int git__delta_apply(
fail:
git__free
(
out
->
data
);
out
->
data
=
NULL
;
return
git__throw
(
GIT_ERROR
,
"Failed to apply delta"
);
giterr_set
(
GITERR_INVALID
,
"Failed to apply delta"
);
return
-
1
;
}
src/filter.c
View file @
3aa351ea
...
...
@@ -95,8 +95,8 @@ int git_filters_load(git_vector *filters, git_repository *repo, const char *path
if
(
error
<
GIT_SUCCESS
)
return
error
;
}
else
{
return
git__throw
(
GIT_ENOTIMPLEMENTED
,
"Worktree filters are not implemented yet"
)
;
giterr_set
(
GITERR_INVALID
,
"Worktree filters are not implemented yet"
);
return
GIT_ENOTIMPLEMENTED
;
}
return
(
int
)
filters
->
length
;
...
...
src/object.c
View file @
3aa351ea
...
...
@@ -68,7 +68,8 @@ static int create_object(git_object **object_out, git_otype type)
break
;
default:
return
git__throw
(
GIT_EINVALIDTYPE
,
"The given type is invalid"
);
giterr_set
(
GITERR_INVALID
,
"The given type is invalid"
);
return
-
1
;
}
object
->
type
=
type
;
...
...
@@ -92,8 +93,7 @@ int git_object_lookup_prefix(
assert
(
repo
&&
object_out
&&
id
);
if
(
len
<
GIT_OID_MINPREFIXLEN
)
return
git__throw
(
GIT_EAMBIGUOUS
,
"Failed to lookup object. Prefix length is lower than %d."
,
GIT_OID_MINPREFIXLEN
);
return
GIT_EAMBIGUOUS
;
error
=
git_repository_odb__weakptr
(
&
odb
,
repo
);
if
(
error
<
GIT_SUCCESS
)
...
...
@@ -110,13 +110,12 @@ int git_object_lookup_prefix(
if
(
object
!=
NULL
)
{
if
(
type
!=
GIT_OBJ_ANY
&&
type
!=
object
->
type
)
{
git_object_free
(
object
);
return
git__throw
(
GIT_EINVALIDTYPE
,
"Failed to lookup object. "
"The given type does not match the type on the ODB"
);
giterr_set
(
GITERR_INVALID
,
"The given type does not match the type in ODB"
);
return
-
1
;
}
*
object_out
=
object
;
return
GIT_SUCCESS
;
return
0
;
}
/* Object was not found in the cache, let's explore the backends.
...
...
@@ -147,18 +146,19 @@ int git_object_lookup_prefix(
error
=
git_odb_read_prefix
(
&
odb_obj
,
odb
,
&
short_oid
,
len
);
}
if
(
error
<
GIT_SUCCESS
)
return
git__rethrow
(
error
,
"Failed to lookup object"
)
;
if
(
error
<
0
)
return
-
1
;
if
(
type
!=
GIT_OBJ_ANY
&&
type
!=
odb_obj
->
raw
.
type
)
{
git_odb_object_free
(
odb_obj
);
return
git__throw
(
GIT_EINVALIDTYPE
,
"Failed to lookup object. The given type does not match the type on the ODB"
);
giterr_set
(
GITERR_INVALID
,
"The given type does not match the type on the ODB"
);
return
-
1
;
}
type
=
odb_obj
->
raw
.
type
;
if
(
(
error
=
create_object
(
&
object
,
type
))
<
GIT_SUCCESS
)
return
git__rethrow
(
error
,
"Failed to lookup object"
)
;
if
(
create_object
(
&
object
,
type
)
<
0
)
return
-
1
;
/* Initialize parent object */
git_oid_cpy
(
&
object
->
cached
.
oid
,
&
odb_obj
->
cached
.
oid
);
...
...
@@ -187,13 +187,13 @@ int git_object_lookup_prefix(
git_odb_object_free
(
odb_obj
);
if
(
error
<
GIT_SUCCESS
)
{
if
(
error
<
0
)
{
git_object__free
(
object
);
return
git__rethrow
(
error
,
"Failed to lookup object"
)
;
return
-
1
;
}
*
object_out
=
git_cache_try_store
(
&
repo
->
objects
,
object
);
return
GIT_SUCCESS
;
return
0
;
}
int
git_object_lookup
(
git_object
**
object_out
,
git_repository
*
repo
,
const
git_oid
*
id
,
git_otype
type
)
{
...
...
src/refspec.c
View file @
3aa351ea
...
...
@@ -25,24 +25,21 @@ int git_refspec_parse(git_refspec *refspec, const char *str)
delim
=
strchr
(
str
,
':'
);
if
(
delim
==
NULL
)
{
refspec
->
src
=
git__strdup
(
str
);
if
(
refspec
->
src
==
NULL
)
return
GIT_ENOMEM
;
return
GIT_SUCCESS
;
GITERR_CHECK_ALLOC
(
refspec
->
src
);
return
0
;
}
refspec
->
src
=
git__strndup
(
str
,
delim
-
str
);
if
(
refspec
->
src
==
NULL
)
return
GIT_ENOMEM
;
GITERR_CHECK_ALLOC
(
refspec
->
src
);
refspec
->
dst
=
git__strdup
(
delim
+
1
);
if
(
refspec
->
dst
==
NULL
)
{
git__free
(
refspec
->
src
);
refspec
->
src
=
NULL
;
return
GIT_ENOMEM
;
return
-
1
;
}
return
GIT_SUCCESS
;
return
0
;
}
const
char
*
git_refspec_src
(
const
git_refspec
*
refspec
)
...
...
@@ -65,8 +62,10 @@ int git_refspec_transform(char *out, size_t outlen, const git_refspec *spec, con
size_t
baselen
,
namelen
;
baselen
=
strlen
(
spec
->
dst
);
if
(
outlen
<=
baselen
)
return
git__throw
(
GIT_EINVALIDREFNAME
,
"Reference name too long"
);
if
(
outlen
<=
baselen
)
{
giterr_set
(
GITERR_INVALID
,
"Reference name too long"
);
return
GIT_ESHORTBUFFER
;
}
/*
* No '*' at the end means that it's mapped to one specific local
...
...
@@ -74,7 +73,7 @@ int git_refspec_transform(char *out, size_t outlen, const git_refspec *spec, con
*/
if
(
spec
->
dst
[
baselen
-
1
]
!=
'*'
)
{
memcpy
(
out
,
spec
->
dst
,
baselen
+
1
);
/* include '\0' */
return
GIT_SUCCESS
;
return
0
;
}
/* There's a '*' at the end, so remove its length */
...
...
@@ -85,32 +84,34 @@ int git_refspec_transform(char *out, size_t outlen, const git_refspec *spec, con
namelen
=
strlen
(
name
);
if
(
outlen
<=
baselen
+
namelen
)
return
git__throw
(
GIT_EINVALIDREFNAME
,
"Reference name too long"
);
if
(
outlen
<=
baselen
+
namelen
)
{
giterr_set
(
GITERR_INVALID
,
"Reference name too long"
);
return
GIT_ESHORTBUFFER
;
}
memcpy
(
out
,
spec
->
dst
,
baselen
);
memcpy
(
out
+
baselen
,
name
,
namelen
+
1
);
return
GIT_SUCCESS
;
return
0
;
}
int
git_refspec_transform_r
(
git_buf
*
out
,
const
git_refspec
*
spec
,
const
char
*
name
)
{
if
(
git_buf_sets
(
out
,
spec
->
dst
)
<
GIT_SUCCESS
)
return
GIT_ENOMEM
;
if
(
git_buf_sets
(
out
,
spec
->
dst
)
<
0
)
return
-
1
;
/*
* No '*' at the end means that it's mapped to one specific local
* branch, so no actual transformation is needed.
*/
if
(
out
->
size
>
0
&&
out
->
ptr
[
out
->
size
-
1
]
!=
'*'
)
return
GIT_SUCCESS
;
return
0
;
git_buf_truncate
(
out
,
out
->
size
-
1
);
/* remove trailing '*' */
git_buf_puts
(
out
,
name
+
strlen
(
spec
->
src
)
-
1
);
if
(
git_buf_oom
(
out
))
return
GIT_ENOMEM
;
return
-
1
;
return
0
;
}
...
...
src/tag.c
View file @
3aa351ea
This diff is collapsed.
Click to expand it.
src/tree.c
View file @
3aa351ea
This diff is collapsed.
Click to expand it.
tests-clar/object/tree/frompath.c
View file @
3aa351ea
...
...
@@ -40,6 +40,12 @@ static void assert_tree_from_path(git_tree *root, const char *path, int expected
git_tree_free
(
containing_tree
);
}
static
void
assert_tree_from_path_klass
(
git_tree
*
root
,
const
char
*
path
,
int
expected_result
,
const
char
*
expected_raw_oid
)
{
assert_tree_from_path
(
root
,
path
,
GIT_ERROR
,
expected_raw_oid
);
cl_assert
(
git_error_last
()
->
klass
==
expected_result
);
}
void
test_object_tree_frompath__retrieve_tree_from_path_to_treeentry
(
void
)
{
/* Will return self if given a one path segment... */
...
...
@@ -66,10 +72,10 @@ void test_object_tree_frompath__fail_when_processing_an_unknown_tree_segment(voi
void
test_object_tree_frompath__fail_when_processing_an_invalid_path
(
void
)
{
assert_tree_from_path
(
tree
,
"/"
,
GIT_EINVALIDPATH
,
NULL
);
assert_tree_from_path
(
tree
,
"/ab"
,
GIT_EINVALIDPATH
,
NULL
);
assert_tree_from_path
(
tree
,
"/ab/de"
,
GIT_EINVALIDPATH
,
NULL
);
assert_tree_from_path
(
tree
,
"ab/"
,
GIT_EINVALIDPATH
,
NULL
);
assert_tree_from_path
(
tree
,
"ab//de"
,
GIT_EINVALIDPATH
,
NULL
);
assert_tree_from_path
(
tree
,
"ab/de/"
,
GIT_EINVALIDPATH
,
NULL
);
assert_tree_from_path
_klass
(
tree
,
"/"
,
GITERR_INVALID
,
NULL
);
assert_tree_from_path
_klass
(
tree
,
"/ab"
,
GITERR_INVALID
,
NULL
);
assert_tree_from_path
_klass
(
tree
,
"/ab/de"
,
GITERR_INVALID
,
NULL
);
assert_tree_from_path
_klass
(
tree
,
"ab/"
,
GITERR_INVALID
,
NULL
);
assert_tree_from_path
_klass
(
tree
,
"ab//de"
,
GITERR_INVALID
,
NULL
);
assert_tree_from_path
_klass
(
tree
,
"ab/de/"
,
GITERR_INVALID
,
NULL
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment