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
f02f4b53
Commit
f02f4b53
authored
May 13, 2011
by
Vicent Martí
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #183 from schu/errors
Replace errors
parents
098173c5
b51c9269
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
24 additions
and
27 deletions
+24
-27
src/blob.c
+3
-3
src/revwalk.c
+10
-10
src/tree.c
+7
-7
src/vector.c
+4
-7
No files found.
src/blob.c
View file @
f02f4b53
...
@@ -62,7 +62,7 @@ int git_blob_create_frombuffer(git_oid *oid, git_repository *repo, const void *b
...
@@ -62,7 +62,7 @@ int git_blob_create_frombuffer(git_oid *oid, git_repository *repo, const void *b
git_odb_stream
*
stream
;
git_odb_stream
*
stream
;
if
((
error
=
git_odb_open_wstream
(
&
stream
,
repo
->
db
,
len
,
GIT_OBJ_BLOB
))
<
GIT_SUCCESS
)
if
((
error
=
git_odb_open_wstream
(
&
stream
,
repo
->
db
,
len
,
GIT_OBJ_BLOB
))
<
GIT_SUCCESS
)
return
error
;
return
git__rethrow
(
error
,
"Failed to create blob. Can't open write stream"
)
;
stream
->
write
(
stream
,
buffer
,
len
);
stream
->
write
(
stream
,
buffer
,
len
);
...
@@ -81,7 +81,7 @@ int git_blob_create_fromfile(git_oid *oid, git_repository *repo, const char *pat
...
@@ -81,7 +81,7 @@ int git_blob_create_fromfile(git_oid *oid, git_repository *repo, const char *pat
git_odb_stream
*
stream
;
git_odb_stream
*
stream
;
if
(
repo
->
path_workdir
==
NULL
)
if
(
repo
->
path_workdir
==
NULL
)
return
GIT_ENOTFOUND
;
return
git__throw
(
GIT_ENOTFOUND
,
"Failed to create blob. No workdir given"
)
;
git__joinpath
(
full_path
,
repo
->
path_workdir
,
path
);
git__joinpath
(
full_path
,
repo
->
path_workdir
,
path
);
...
@@ -106,7 +106,7 @@ int git_blob_create_fromfile(git_oid *oid, git_repository *repo, const char *pat
...
@@ -106,7 +106,7 @@ int git_blob_create_fromfile(git_oid *oid, git_repository *repo, const char *pat
if
(
read_len
<
0
)
{
if
(
read_len
<
0
)
{
gitfo_close
(
fd
);
gitfo_close
(
fd
);
stream
->
free
(
stream
);
stream
->
free
(
stream
);
return
GIT_EOSERR
;
return
git__throw
(
GIT_EOSERR
,
"Failed to create blob. Can't read full file"
)
;
}
}
stream
->
write
(
stream
,
buffer
,
read_len
);
stream
->
write
(
stream
,
buffer
,
read_len
);
...
...
src/revwalk.c
View file @
f02f4b53
...
@@ -210,7 +210,7 @@ static int commit_quick_parse(git_revwalk *walk, commit_object *commit, git_rawo
...
@@ -210,7 +210,7 @@ static int commit_quick_parse(git_revwalk *walk, commit_object *commit, git_rawo
git_oid
oid
;
git_oid
oid
;
if
(
git_oid_mkstr
(
&
oid
,
(
char
*
)
buffer
+
STRLEN
(
"parent "
))
<
GIT_SUCCESS
)
if
(
git_oid_mkstr
(
&
oid
,
(
char
*
)
buffer
+
STRLEN
(
"parent "
))
<
GIT_SUCCESS
)
return
GIT_EOBJCORRUPTED
;
return
git__throw
(
GIT_EOBJCORRUPTED
,
"Failed to parse commit. Parent object is corrupted"
)
;
commit
->
parents
[
i
]
=
commit_lookup
(
walk
,
&
oid
);
commit
->
parents
[
i
]
=
commit_lookup
(
walk
,
&
oid
);
if
(
commit
->
parents
[
i
]
==
NULL
)
if
(
commit
->
parents
[
i
]
==
NULL
)
...
@@ -222,14 +222,14 @@ static int commit_quick_parse(git_revwalk *walk, commit_object *commit, git_rawo
...
@@ -222,14 +222,14 @@ static int commit_quick_parse(git_revwalk *walk, commit_object *commit, git_rawo
commit
->
out_degree
=
(
unsigned
short
)
parents
;
commit
->
out_degree
=
(
unsigned
short
)
parents
;
if
((
buffer
=
memchr
(
buffer
,
'\n'
,
buffer_end
-
buffer
))
==
NULL
)
if
((
buffer
=
memchr
(
buffer
,
'\n'
,
buffer_end
-
buffer
))
==
NULL
)
return
GIT_EOBJCORRUPTED
;
return
git__throw
(
GIT_EOBJCORRUPTED
,
"Failed to parse commit. Object is corrupted"
)
;
buffer
=
memchr
(
buffer
,
'>'
,
buffer_end
-
buffer
);
buffer
=
memchr
(
buffer
,
'>'
,
buffer_end
-
buffer
);
if
(
buffer
==
NULL
)
if
(
buffer
==
NULL
)
return
GIT_EOBJCORRUPTED
;
return
git__throw
(
GIT_EOBJCORRUPTED
,
"Failed to parse commit. Can't find author"
)
;
if
(
git__strtol32
(
&
commit_time
,
(
char
*
)
buffer
+
2
,
NULL
,
10
)
<
GIT_SUCCESS
)
if
(
git__strtol32
(
&
commit_time
,
(
char
*
)
buffer
+
2
,
NULL
,
10
)
<
GIT_SUCCESS
)
return
GIT_EOBJCORRUPTED
;
return
git__throw
(
GIT_EOBJCORRUPTED
,
"Failed to parse commit. Can't parse commit time"
)
;
commit
->
time
=
(
time_t
)
commit_time
;
commit
->
time
=
(
time_t
)
commit_time
;
commit
->
parsed
=
1
;
commit
->
parsed
=
1
;
...
@@ -245,11 +245,11 @@ static int commit_parse(git_revwalk *walk, commit_object *commit)
...
@@ -245,11 +245,11 @@ static int commit_parse(git_revwalk *walk, commit_object *commit)
return
GIT_SUCCESS
;
return
GIT_SUCCESS
;
if
((
error
=
git_odb_read
(
&
obj
,
walk
->
repo
->
db
,
&
commit
->
oid
))
<
GIT_SUCCESS
)
if
((
error
=
git_odb_read
(
&
obj
,
walk
->
repo
->
db
,
&
commit
->
oid
))
<
GIT_SUCCESS
)
return
error
;
return
git__rethrow
(
error
,
"Failed to parse commit. Can't read object"
)
;
if
(
obj
->
raw
.
type
!=
GIT_OBJ_COMMIT
)
{
if
(
obj
->
raw
.
type
!=
GIT_OBJ_COMMIT
)
{
git_odb_object_close
(
obj
);
git_odb_object_close
(
obj
);
return
GIT_EOBJTYPE
;
return
git__throw
(
GIT_EOBJTYPE
,
"Failed to parse commit. Object is no commit object"
)
;
}
}
error
=
commit_quick_parse
(
walk
,
commit
,
&
obj
->
raw
);
error
=
commit_quick_parse
(
walk
,
commit
,
&
obj
->
raw
);
...
@@ -305,7 +305,7 @@ static int push_commit(git_revwalk *walk, const git_oid *oid, int uninteresting)
...
@@ -305,7 +305,7 @@ static int push_commit(git_revwalk *walk, const git_oid *oid, int uninteresting)
commit
=
commit_lookup
(
walk
,
oid
);
commit
=
commit_lookup
(
walk
,
oid
);
if
(
commit
==
NULL
)
if
(
commit
==
NULL
)
return
GIT_ENOTFOUND
;
return
git__throw
(
GIT_ENOTFOUND
,
"Failed to push commit. Object not found"
)
;
commit
->
uninteresting
=
uninteresting
;
commit
->
uninteresting
=
uninteresting
;
...
@@ -349,7 +349,7 @@ static int revwalk_next_timesort(commit_object **object_out, git_revwalk *walk)
...
@@ -349,7 +349,7 @@ static int revwalk_next_timesort(commit_object **object_out, git_revwalk *walk)
}
}
}
}
return
GIT_EREVWALKOVER
;
return
git__throw
(
GIT_EREVWALKOVER
,
"No more commits left to iterate"
)
;
}
}
static
int
revwalk_next_unsorted
(
commit_object
**
object_out
,
git_revwalk
*
walk
)
static
int
revwalk_next_unsorted
(
commit_object
**
object_out
,
git_revwalk
*
walk
)
...
@@ -367,7 +367,7 @@ static int revwalk_next_unsorted(commit_object **object_out, git_revwalk *walk)
...
@@ -367,7 +367,7 @@ static int revwalk_next_unsorted(commit_object **object_out, git_revwalk *walk)
}
}
}
}
return
GIT_EREVWALKOVER
;
return
git__throw
(
GIT_EREVWALKOVER
,
"No more commits left to iterate"
)
;
}
}
static
int
revwalk_next_toposort
(
commit_object
**
object_out
,
git_revwalk
*
walk
)
static
int
revwalk_next_toposort
(
commit_object
**
object_out
,
git_revwalk
*
walk
)
...
@@ -378,7 +378,7 @@ static int revwalk_next_toposort(commit_object **object_out, git_revwalk *walk)
...
@@ -378,7 +378,7 @@ static int revwalk_next_toposort(commit_object **object_out, git_revwalk *walk)
for
(;;)
{
for
(;;)
{
next
=
commit_list_pop
(
&
walk
->
iterator_topo
);
next
=
commit_list_pop
(
&
walk
->
iterator_topo
);
if
(
next
==
NULL
)
if
(
next
==
NULL
)
return
GIT_EREVWALKOVER
;
return
git__throw
(
GIT_EREVWALKOVER
,
"No more commits left to iterate"
)
;
if
(
next
->
in_degree
>
0
)
{
if
(
next
->
in_degree
>
0
)
{
next
->
topo_delay
=
1
;
next
->
topo_delay
=
1
;
...
...
src/tree.c
View file @
f02f4b53
...
@@ -151,15 +151,15 @@ static int tree_parse_buffer(git_tree *tree, const char *buffer, const char *buf
...
@@ -151,15 +151,15 @@ static int tree_parse_buffer(git_tree *tree, const char *buffer, const char *buf
return
GIT_ENOMEM
;
return
GIT_ENOMEM
;
if
(
git__strtol32
((
long
*
)
&
entry
->
attr
,
buffer
,
&
buffer
,
8
)
<
GIT_SUCCESS
)
if
(
git__strtol32
((
long
*
)
&
entry
->
attr
,
buffer
,
&
buffer
,
8
)
<
GIT_SUCCESS
)
return
GIT_EOBJCORRUPTED
;
return
git__throw
(
GIT_EOBJCORRUPTED
,
"Failed to parse tree. Can't parse attributes"
)
;
if
(
*
buffer
++
!=
' '
)
{
if
(
*
buffer
++
!=
' '
)
{
error
=
GIT_EOBJCORRUPTED
;
error
=
git__throw
(
GIT_EOBJCORRUPTED
,
"Failed to parse tree. Object it corrupted"
)
;
break
;
break
;
}
}
if
(
memchr
(
buffer
,
0
,
buffer_end
-
buffer
)
==
NULL
)
{
if
(
memchr
(
buffer
,
0
,
buffer_end
-
buffer
)
==
NULL
)
{
error
=
GIT_EOBJCORRUPTED
;
error
=
git__throw
(
GIT_EOBJCORRUPTED
,
"Failed to parse tree. Object it corrupted"
)
;
break
;
break
;
}
}
...
@@ -274,7 +274,7 @@ int git_tree_create_fromindex(git_oid *oid, git_index *index)
...
@@ -274,7 +274,7 @@ int git_tree_create_fromindex(git_oid *oid, git_index *index)
int
error
;
int
error
;
if
(
index
->
repository
==
NULL
)
if
(
index
->
repository
==
NULL
)
return
GIT_EBAREINDEX
;
return
git__throw
(
GIT_EBAREINDEX
,
"Failed to create tree. The index file is not backed up by an existing repository"
)
;
error
=
write_index
(
oid
,
index
,
""
,
0
,
0
,
git_index_entrycount
(
index
));
error
=
write_index
(
oid
,
index
,
""
,
0
,
0
,
git_index_entrycount
(
index
));
return
(
error
<
GIT_SUCCESS
)
?
error
:
GIT_SUCCESS
;
return
(
error
<
GIT_SUCCESS
)
?
error
:
GIT_SUCCESS
;
...
@@ -343,7 +343,7 @@ int git_treebuilder_insert(git_tree_entry **entry_out, git_treebuilder *bld, con
...
@@ -343,7 +343,7 @@ int git_treebuilder_insert(git_tree_entry **entry_out, git_treebuilder *bld, con
assert
(
bld
&&
id
&&
filename
);
assert
(
bld
&&
id
&&
filename
);
if
(
!
valid_attributes
(
attributes
))
if
(
!
valid_attributes
(
attributes
))
return
GIT_ERROR
;
return
git__throw
(
GIT_ERROR
,
"Failed to insert entry. Invalid atrributes"
)
;
if
((
pos
=
git_vector_bsearch2
(
&
bld
->
entries
,
entry_search_cmp
,
filename
))
!=
GIT_ENOTFOUND
)
{
if
((
pos
=
git_vector_bsearch2
(
&
bld
->
entries
,
entry_search_cmp
,
filename
))
!=
GIT_ENOTFOUND
)
{
entry
=
git_vector_get
(
&
bld
->
entries
,
pos
);
entry
=
git_vector_get
(
&
bld
->
entries
,
pos
);
...
@@ -400,7 +400,7 @@ int git_treebuilder_remove(git_treebuilder *bld, const char *filename)
...
@@ -400,7 +400,7 @@ int git_treebuilder_remove(git_treebuilder *bld, const char *filename)
git_tree_entry
*
remove_ptr
=
(
git_tree_entry
*
)
git_treebuilder_get
(
bld
,
filename
);
git_tree_entry
*
remove_ptr
=
(
git_tree_entry
*
)
git_treebuilder_get
(
bld
,
filename
);
if
(
remove_ptr
==
NULL
||
remove_ptr
->
removed
)
if
(
remove_ptr
==
NULL
||
remove_ptr
->
removed
)
return
GIT_ENOTFOUND
;
return
git__throw
(
GIT_ENOTFOUND
,
"Failed to remove entry. File isn't in the tree"
)
;
remove_ptr
->
removed
=
1
;
remove_ptr
->
removed
=
1
;
bld
->
entry_count
--
;
bld
->
entry_count
--
;
...
@@ -431,7 +431,7 @@ int git_treebuilder_write(git_oid *oid, git_repository *repo, git_treebuilder *b
...
@@ -431,7 +431,7 @@ int git_treebuilder_write(git_oid *oid, git_repository *repo, git_treebuilder *b
}
}
if
((
error
=
git_odb_open_wstream
(
&
stream
,
git_repository_database
(
repo
),
size
,
GIT_OBJ_TREE
))
<
GIT_SUCCESS
)
if
((
error
=
git_odb_open_wstream
(
&
stream
,
git_repository_database
(
repo
),
size
,
GIT_OBJ_TREE
))
<
GIT_SUCCESS
)
return
error
;
return
git__rethrow
(
error
,
"Failed to write tree. Can't open write stream"
)
;
for
(
i
=
0
;
i
<
bld
->
entries
.
length
;
++
i
)
{
for
(
i
=
0
;
i
<
bld
->
entries
.
length
;
++
i
)
{
git_tree_entry
*
entry
=
bld
->
entries
.
contents
[
i
];
git_tree_entry
*
entry
=
bld
->
entries
.
contents
[
i
];
...
...
src/vector.c
View file @
f02f4b53
...
@@ -106,7 +106,7 @@ int git_vector_bsearch2(git_vector *v, git_vector_cmp key_lookup, const void *ke
...
@@ -106,7 +106,7 @@ int git_vector_bsearch2(git_vector *v, git_vector_cmp key_lookup, const void *ke
/* need comparison function to sort the vector */
/* need comparison function to sort the vector */
if
(
v
->
_cmp
==
NULL
)
if
(
v
->
_cmp
==
NULL
)
return
GIT_ENOTFOUND
;
return
git__throw
(
GIT_ENOTFOUND
,
"Can't sort vector. No comparison function set"
)
;
git_vector_sort
(
v
);
git_vector_sort
(
v
);
...
@@ -114,7 +114,7 @@ int git_vector_bsearch2(git_vector *v, git_vector_cmp key_lookup, const void *ke
...
@@ -114,7 +114,7 @@ int git_vector_bsearch2(git_vector *v, git_vector_cmp key_lookup, const void *ke
if
(
find
!=
NULL
)
if
(
find
!=
NULL
)
return
(
int
)(
find
-
v
->
contents
);
return
(
int
)(
find
-
v
->
contents
);
return
GIT_ENOTFOUND
;
return
git__throw
(
GIT_ENOTFOUND
,
"Can't find element"
)
;
}
}
int
git_vector_search2
(
git_vector
*
v
,
git_vector_cmp
key_lookup
,
const
void
*
key
)
int
git_vector_search2
(
git_vector
*
v
,
git_vector_cmp
key_lookup
,
const
void
*
key
)
...
@@ -128,7 +128,7 @@ int git_vector_search2(git_vector *v, git_vector_cmp key_lookup, const void *key
...
@@ -128,7 +128,7 @@ int git_vector_search2(git_vector *v, git_vector_cmp key_lookup, const void *key
return
i
;
return
i
;
}
}
return
GIT_ENOTFOUND
;
return
git__throw
(
GIT_ENOTFOUND
,
"Can't find element"
)
;
}
}
static
int
strict_comparison
(
const
void
*
a
,
const
void
*
b
)
static
int
strict_comparison
(
const
void
*
a
,
const
void
*
b
)
...
@@ -143,9 +143,6 @@ int git_vector_search(git_vector *v, const void *entry)
...
@@ -143,9 +143,6 @@ int git_vector_search(git_vector *v, const void *entry)
int
git_vector_bsearch
(
git_vector
*
v
,
const
void
*
key
)
int
git_vector_bsearch
(
git_vector
*
v
,
const
void
*
key
)
{
{
if
(
v
->
_cmp
==
NULL
)
return
GIT_ENOTFOUND
;
return
git_vector_bsearch2
(
v
,
v
->
_cmp
,
key
);
return
git_vector_bsearch2
(
v
,
v
->
_cmp
,
key
);
}
}
...
@@ -156,7 +153,7 @@ int git_vector_remove(git_vector *v, unsigned int idx)
...
@@ -156,7 +153,7 @@ int git_vector_remove(git_vector *v, unsigned int idx)
assert
(
v
);
assert
(
v
);
if
(
idx
>=
v
->
length
||
v
->
length
==
0
)
if
(
idx
>=
v
->
length
||
v
->
length
==
0
)
return
GIT_ENOTFOUND
;
return
git__throw
(
GIT_ENOTFOUND
,
"Can't remove element. Index out of bounds"
)
;
for
(
i
=
idx
;
i
<
v
->
length
-
1
;
++
i
)
for
(
i
=
idx
;
i
<
v
->
length
-
1
;
++
i
)
v
->
contents
[
i
]
=
v
->
contents
[
i
+
1
];
v
->
contents
[
i
]
=
v
->
contents
[
i
+
1
];
...
...
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