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
3fbcac89
Commit
3fbcac89
authored
May 02, 2012
by
Vicent Martí
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove old and unused error codes
parent
b02bcd97
Show whitespace changes
Inline
Side-by-side
Showing
24 changed files
with
92 additions
and
355 deletions
+92
-355
include/git2/errors.h
+4
-104
include/git2/refspec.h
+4
-4
src/config.c
+2
-3
src/crlf.c
+1
-2
src/delta-apply.c
+3
-2
src/diff.c
+2
-5
src/errors.c
+1
-105
src/fetch.c
+1
-9
src/filter.c
+4
-4
src/object.c
+1
-2
src/refspec.c
+6
-2
src/revwalk.c
+1
-1
src/tag.c
+1
-1
src/transport.c
+4
-2
src/transports/git.c
+1
-1
src/transports/http.c
+3
-3
src/tree-cache.c
+30
-47
src/tree.c
+1
-1
src/util.c
+0
-16
src/util.h
+0
-2
tests-clar/clar_libgit2.h
+3
-3
tests-clar/core/errors.c
+16
-33
tests-clar/network/remotes.c
+2
-2
tests-clar/object/tree/frompath.c
+1
-1
No files found.
include/git2/errors.h
View file @
3fbcac89
...
...
@@ -21,98 +21,25 @@ typedef enum {
GIT_SUCCESS
=
0
,
GIT_ERROR
=
-
1
,
/** Input was not a properly formatted Git object id. */
GIT_ENOTOID
=
-
2
,
/** Input does not exist in the scope searched. */
GIT_ENOTFOUND
=
-
3
,
/** Not enough space available. */
GIT_ENOMEM
=
-
4
,
/** Consult the OS error information. */
GIT_EOSERR
=
-
5
,
/** The specified object is of invalid type */
GIT_EOBJTYPE
=
-
6
,
/** The specified repository is invalid */
GIT_ENOTAREPO
=
-
7
,
/** The object type is invalid or doesn't match */
GIT_EINVALIDTYPE
=
-
8
,
/** The object cannot be written because it's missing internal data */
GIT_EMISSINGOBJDATA
=
-
9
,
/** The packfile for the ODB is corrupted */
GIT_EPACKCORRUPTED
=
-
10
,
/** Failed to acquire or release a file lock */
GIT_EFLOCKFAIL
=
-
11
,
/** The Z library failed to inflate/deflate an object's data */
GIT_EZLIB
=
-
12
,
/** The queried object is currently busy */
GIT_EBUSY
=
-
13
,
/** The index file is not backed up by an existing repository */
GIT_EBAREINDEX
=
-
14
,
/** The name of the reference is not valid */
GIT_EINVALIDREFNAME
=
-
15
,
/** The specified reference has its data corrupted */
GIT_EREFCORRUPTED
=
-
16
,
/** The specified symbolic reference is too deeply nested */
GIT_ETOONESTEDSYMREF
=
-
17
,
/** The pack-refs file is either corrupted or its format is not currently supported */
GIT_EPACKEDREFSCORRUPTED
=
-
18
,
/** The path is invalid */
GIT_EINVALIDPATH
=
-
19
,
/** The revision walker is empty; there are no more commits left to iterate */
GIT_EREVWALKOVER
=
-
20
,
/** The state of the reference is not valid */
GIT_EINVALIDREFSTATE
=
-
21
,
/** This feature has not been implemented yet */
GIT_ENOTIMPLEMENTED
=
-
22
,
/** A reference with this name already exists */
GIT_EEXISTS
=
-
23
,
/** The given integer literal is too large to be parsed */
GIT_EOVERFLOW
=
-
24
,
/** The given literal is not a valid number */
GIT_ENOTNUM
=
-
25
,
/** Streaming error */
GIT_ESTREAM
=
-
26
,
/** invalid arguments to function */
GIT_EINVALIDARGS
=
-
27
,
/** The specified object has its data corrupted */
GIT_EOBJCORRUPTED
=
-
28
,
/** The given short oid is ambiguous */
GIT_EAMBIGUOUS
=
-
29
,
/** Skip and passthrough the given ODB backend */
GIT_EPASSTHROUGH
=
-
30
,
/** The path pattern and string did not match */
GIT_ENOMATCH
=
-
31
,
/** The buffer is too short to satisfy the request */
GIT_ESHORTBUFFER
=
-
32
,
GIT_EREVWALKOVER
=
-
33
,
}
git_error_t
;
typedef
struct
{
...
...
@@ -138,44 +65,17 @@ typedef enum {
}
git_error_class
;
/**
* Return a detailed error string with the latest error
* that occurred in the library.
* @deprecated This will be replaced in the new error handling
* @return a string explaining the error
*/
GIT_EXTERN
(
const
char
*
)
git_lasterror
(
void
);
/**
* strerror() for the Git library
*
* Get a string description for a given error code.
* NOTE: This method will be eventually deprecated in favor
* of the new `git_lasterror`.
*
* @deprecated This will be replaced in the new error handling
* @param num The error code to explain
* @return a string explaining the error code
*/
GIT_EXTERN
(
const
char
*
)
git_strerror
(
int
num
);
/**
* Clear the latest library error
* @deprecated This will be replaced in the new error handling
*/
GIT_EXTERN
(
void
)
git_clearerror
(
void
);
/**
* Return the last `git_error` object that was generated for the
* current thread or NULL if no error has occurred.
*
* @return A git_error object.
*/
GIT_EXTERN
(
const
git_error
*
)
git
_erro
r_last
(
void
);
GIT_EXTERN
(
const
git_error
*
)
git
er
r_last
(
void
);
/**
* Clear the last library error that occurred for this thread.
*/
GIT_EXTERN
(
void
)
git
_erro
r_clear
(
void
);
GIT_EXTERN
(
void
)
git
er
r_clear
(
void
);
/** @} */
GIT_END_DECL
...
...
include/git2/refspec.h
View file @
3fbcac89
...
...
@@ -7,6 +7,7 @@
#ifndef INCLUDE_git_refspec_h__
#define INCLUDE_git_refspec_h__
#include "common.h"
#include "types.h"
/**
...
...
@@ -35,14 +36,13 @@ const char *git_refspec_src(const git_refspec *refspec);
const
char
*
git_refspec_dst
(
const
git_refspec
*
refspec
);
/**
*
Match a refspec's source descriptor with a reference name
*
Check if a refspec's source descriptor matches a reference
*
* @param refspec the refspec
* @param refname the name of the reference to check
* @return GIT_SUCCESS on successful match; GIT_ENOMACH on match
* failure or an error code on other failure
* @return 1 if the refspec matches, 0 otherwise
*/
int
git_refspec_src_match
(
const
git_refspec
*
refspec
,
const
char
*
refname
);
int
git_refspec_src_match
es
(
const
git_refspec
*
refspec
,
const
char
*
refname
);
/**
* Transform a reference to its target following the refspec's rules
...
...
src/config.c
View file @
3fbcac89
...
...
@@ -59,8 +59,7 @@ int git_config_new(git_config **out)
git_config
*
cfg
;
cfg
=
git__malloc
(
sizeof
(
git_config
));
if
(
cfg
==
NULL
)
return
GIT_ENOMEM
;
GITERR_CHECK_ALLOC
(
cfg
);
memset
(
cfg
,
0x0
,
sizeof
(
git_config
));
...
...
@@ -221,7 +220,7 @@ int git_config_parse_bool(int *out, const char *value)
return
0
;
}
return
GIT_EINVALIDTYPE
;
return
-
1
;
}
static
int
parse_int64
(
int64_t
*
out
,
const
char
*
value
)
...
...
src/crlf.c
View file @
3fbcac89
...
...
@@ -216,8 +216,7 @@ int git_filter_add__crlf_to_odb(git_vector *filters, git_repository *repo, const
/* If we're good, we create a new filter object and push it
* into the filters array */
filter
=
git__malloc
(
sizeof
(
struct
crlf_filter
));
if
(
filter
==
NULL
)
return
GIT_ENOMEM
;
GITERR_CHECK_ALLOC
(
filter
);
filter
->
f
.
apply
=
&
crlf_apply_to_odb
;
filter
->
f
.
do_free
=
NULL
;
...
...
src/delta-apply.c
View file @
3fbcac89
...
...
@@ -61,8 +61,9 @@ int git__delta_apply(
return
-
1
;
}
if
((
res_dp
=
git__malloc
(
res_sz
+
1
))
==
NULL
)
return
GIT_ENOMEM
;
res_dp
=
git__malloc
(
res_sz
+
1
);
GITERR_CHECK_ALLOC
(
res_dp
);
res_dp
[
res_sz
]
=
'\0'
;
out
->
data
=
res_dp
;
out
->
len
=
res_sz
;
...
...
src/diff.c
View file @
3fbcac89
...
...
@@ -35,10 +35,10 @@ static bool diff_path_matches_pathspec(git_diff_list *diff, const char *path)
return
true
;
git_vector_foreach
(
&
diff
->
pathspec
,
i
,
match
)
{
int
result
=
git_
_fnmatch
(
match
->
pattern
,
path
,
0
);
int
result
=
p
_fnmatch
(
match
->
pattern
,
path
,
0
);
/* if we didn't match, look for exact dirname prefix match */
if
(
result
==
GIT_E
NOMATCH
&&
if
(
result
==
FNM_
NOMATCH
&&
(
match
->
flags
&
GIT_ATTR_FNMATCH_HASWILD
)
==
0
&&
strncmp
(
path
,
match
->
pattern
,
match
->
length
)
==
0
&&
path
[
match
->
length
]
==
'/'
)
...
...
@@ -46,9 +46,6 @@ static bool diff_path_matches_pathspec(git_diff_list *diff, const char *path)
if
(
result
==
0
)
return
(
match
->
flags
&
GIT_ATTR_FNMATCH_NEGATIVE
)
?
false
:
true
;
if
(
result
!=
GIT_ENOMATCH
)
giterr_clear
();
}
return
false
;
...
...
src/errors.c
View file @
3fbcac89
...
...
@@ -9,105 +9,6 @@
#include "posix.h"
#include <stdarg.h>
static
struct
{
int
num
;
const
char
*
str
;
}
error_codes
[]
=
{
{
GIT_ERROR
,
"Unspecified error"
},
{
GIT_ENOTOID
,
"Input was not a properly formatted Git object id."
},
{
GIT_ENOTFOUND
,
"Object does not exist in the scope searched."
},
{
GIT_ENOMEM
,
"Not enough space available."
},
{
GIT_EOSERR
,
"Consult the OS error information."
},
{
GIT_EOBJTYPE
,
"The specified object is of invalid type"
},
{
GIT_EOBJCORRUPTED
,
"The specified object has its data corrupted"
},
{
GIT_ENOTAREPO
,
"The specified repository is invalid"
},
{
GIT_EINVALIDTYPE
,
"The object or config variable type is invalid or doesn't match"
},
{
GIT_EMISSINGOBJDATA
,
"The object cannot be written that because it's missing internal data"
},
{
GIT_EPACKCORRUPTED
,
"The packfile for the ODB is corrupted"
},
{
GIT_EFLOCKFAIL
,
"Failed to adquire or release a file lock"
},
{
GIT_EZLIB
,
"The Z library failed to inflate/deflate an object's data"
},
{
GIT_EBUSY
,
"The queried object is currently busy"
},
{
GIT_EINVALIDPATH
,
"The path is invalid"
},
{
GIT_EBAREINDEX
,
"The index file is not backed up by an existing repository"
},
{
GIT_EINVALIDREFNAME
,
"The name of the reference is not valid"
},
{
GIT_EREFCORRUPTED
,
"The specified reference has its data corrupted"
},
{
GIT_ETOONESTEDSYMREF
,
"The specified symbolic reference is too deeply nested"
},
{
GIT_EPACKEDREFSCORRUPTED
,
"The pack-refs file is either corrupted of its format is not currently supported"
},
{
GIT_EINVALIDPATH
,
"The path is invalid"
},
{
GIT_EREVWALKOVER
,
"The revision walker is empty; there are no more commits left to iterate"
},
{
GIT_EINVALIDREFSTATE
,
"The state of the reference is not valid"
},
{
GIT_ENOTIMPLEMENTED
,
"This feature has not been implemented yet"
},
{
GIT_EEXISTS
,
"A reference with this name already exists"
},
{
GIT_EOVERFLOW
,
"The given integer literal is too large to be parsed"
},
{
GIT_ENOTNUM
,
"The given literal is not a valid number"
},
{
GIT_EAMBIGUOUS
,
"The given oid prefix is ambiguous"
},
};
const
char
*
git_strerror
(
int
num
)
{
size_t
i
;
if
(
num
==
GIT_EOSERR
)
return
strerror
(
errno
);
for
(
i
=
0
;
i
<
ARRAY_SIZE
(
error_codes
);
i
++
)
if
(
num
==
error_codes
[
i
].
num
)
return
error_codes
[
i
].
str
;
return
"Unknown error"
;
}
#define ERROR_MAX_LEN 1024
void
git___rethrow
(
const
char
*
msg
,
...)
{
char
new_error
[
ERROR_MAX_LEN
];
char
*
last_error
;
char
*
old_error
=
NULL
;
va_list
va
;
last_error
=
GIT_GLOBAL
->
error
.
last
;
va_start
(
va
,
msg
);
vsnprintf
(
new_error
,
ERROR_MAX_LEN
,
msg
,
va
);
va_end
(
va
);
old_error
=
git__strdup
(
last_error
);
snprintf
(
last_error
,
ERROR_MAX_LEN
,
"%s
\n
- %s"
,
new_error
,
old_error
);
git__free
(
old_error
);
}
void
git___throw
(
const
char
*
msg
,
...)
{
va_list
va
;
va_start
(
va
,
msg
);
vsnprintf
(
GIT_GLOBAL
->
error
.
last
,
ERROR_MAX_LEN
,
msg
,
va
);
va_end
(
va
);
}
const
char
*
git_lasterror
(
void
)
{
char
*
last_error
=
GIT_GLOBAL
->
error
.
last
;
if
(
!
last_error
[
0
])
{
const
git_error
*
err
=
git_error_last
();
if
(
err
!=
NULL
)
return
err
->
message
;
return
NULL
;
}
return
last_error
;
}
void
git_clearerror
(
void
)
{
char
*
last_error
=
GIT_GLOBAL
->
error
.
last
;
last_error
[
0
]
=
'\0'
;
}
/********************************************
* New error handling
********************************************/
...
...
@@ -198,13 +99,8 @@ void giterr_clear(void)
GIT_GLOBAL
->
last_error
=
NULL
;
}
const
git_error
*
git
_erro
r_last
(
void
)
const
git_error
*
git
er
r_last
(
void
)
{
return
GIT_GLOBAL
->
last_error
;
}
void
git_error_clear
(
void
)
{
giterr_clear
();
}
src/fetch.c
View file @
3fbcac89
...
...
@@ -29,21 +29,13 @@ struct filter_payload {
static
int
filter_ref__cb
(
git_remote_head
*
head
,
void
*
payload
)
{
struct
filter_payload
*
p
=
payload
;
int
ret
;
if
(
!
p
->
found_head
&&
strcmp
(
head
->
name
,
GIT_HEAD_FILE
)
==
0
)
{
p
->
found_head
=
1
;
}
else
{
/* If it doesn't match the refpec, we don't want it */
ret
=
git_refspec_src_match
(
p
->
spec
,
head
->
name
);
if
(
ret
==
GIT_ENOMATCH
)
if
(
!
git_refspec_src_matches
(
p
->
spec
,
head
->
name
))
return
0
;
if
(
ret
<
GIT_SUCCESS
)
{
giterr_set
(
GITERR_NET
,
"Error matching remote ref name"
);
return
-
1
;
}
}
/* If we have the object, mark it so we don't ask for it */
...
...
src/filter.c
View file @
3fbcac89
...
...
@@ -92,11 +92,11 @@ int git_filters_load(git_vector *filters, git_repository *repo, const char *path
if
(
mode
==
GIT_FILTER_TO_ODB
)
{
/* Load the CRLF cleanup filter when writing to the ODB */
error
=
git_filter_add__crlf_to_odb
(
filters
,
repo
,
path
);
if
(
error
<
GIT_SUCCESS
)
if
(
error
<
0
)
return
error
;
}
else
{
giterr_set
(
GITERR_INVALID
,
"Worktree filters are not implemented yet"
);
return
GIT_ENOTIMPLEMENTED
;
return
-
1
;
}
return
(
int
)
filters
->
length
;
...
...
@@ -135,7 +135,7 @@ int git_filters_apply(git_buf *dest, git_buf *source, git_vector *filters)
/* Pre-grow the destination buffer to more or less the size
* we expect it to have */
if
(
git_buf_grow
(
dest
,
git_buf_len
(
source
))
<
0
)
return
GIT_ENOMEM
;
return
-
1
;
for
(
i
=
0
;
i
<
filters
->
length
;
++
i
)
{
git_filter
*
filter
=
git_vector_get
(
filters
,
i
);
...
...
@@ -153,7 +153,7 @@ int git_filters_apply(git_buf *dest, git_buf *source, git_vector *filters)
src
=
dst
;
if
(
git_buf_oom
(
dbuffer
[
dst
]))
return
GIT_ENOMEM
;
return
-
1
;
}
/* Ensure that the output ends up in dbuffer[1] (i.e. the dest) */
...
...
src/object.c
View file @
3fbcac89
...
...
@@ -62,8 +62,7 @@ static int create_object(git_object **object_out, git_otype type)
case
GIT_OBJ_BLOB
:
case
GIT_OBJ_TREE
:
object
=
git__malloc
(
git_object__size
(
type
));
if
(
object
==
NULL
)
return
GIT_ENOMEM
;
GITERR_CHECK_ALLOC
(
object
);
memset
(
object
,
0x0
,
git_object__size
(
type
));
break
;
...
...
src/refspec.c
View file @
3fbcac89
...
...
@@ -10,6 +10,7 @@
#include "common.h"
#include "refspec.h"
#include "util.h"
#include "posix.h"
int
git_refspec_parse
(
git_refspec
*
refspec
,
const
char
*
str
)
{
...
...
@@ -52,9 +53,12 @@ const char *git_refspec_dst(const git_refspec *refspec)
return
refspec
==
NULL
?
NULL
:
refspec
->
dst
;
}
int
git_refspec_src_match
(
const
git_refspec
*
refspec
,
const
char
*
refname
)
int
git_refspec_src_match
es
(
const
git_refspec
*
refspec
,
const
char
*
refname
)
{
return
(
refspec
==
NULL
||
refspec
->
src
==
NULL
)
?
GIT_ENOMATCH
:
git__fnmatch
(
refspec
->
src
,
refname
,
0
);
if
(
refspec
==
NULL
||
refspec
->
src
==
NULL
)
return
false
;
return
(
p_fnmatch
(
refspec
->
src
,
refname
,
0
)
==
0
);
}
int
git_refspec_transform
(
char
*
out
,
size_t
outlen
,
const
git_refspec
*
spec
,
const
char
*
name
)
...
...
src/revwalk.c
View file @
3fbcac89
...
...
@@ -486,7 +486,7 @@ static int push_glob_cb(const char *refname, void *data_)
{
struct
push_cb_data
*
data
=
(
struct
push_cb_data
*
)
data_
;
if
(
!
git_
_fnmatch
(
data
->
glob
,
refname
,
0
))
if
(
!
p
_fnmatch
(
data
->
glob
,
refname
,
0
))
return
push_ref
(
data
->
walk
,
refname
,
data
->
hide
);
return
0
;
...
...
src/tag.c
View file @
3fbcac89
...
...
@@ -420,7 +420,7 @@ int git_tag_list_match(git_strarray *tag_names, const char *pattern, git_reposit
assert
(
tag_names
&&
repo
&&
pattern
);
if
(
git_vector_init
(
&
taglist
,
8
,
NULL
)
<
GIT_SUCCESS
)
return
GIT_ENOMEM
;
return
-
1
;
filter
.
taglist
=
&
taglist
;
filter
.
pattern
=
pattern
;
...
...
src/transport.c
View file @
3fbcac89
...
...
@@ -66,8 +66,10 @@ int git_transport_new(git_transport **out, const char *url)
fn
=
transport_find_fn
(
url
);
if
(
fn
==
NULL
)
return
git__throw
(
GIT_EINVALIDARGS
,
"Unsupported URL or non-existent path"
);
if
(
fn
==
NULL
)
{
giterr_set
(
GITERR_NET
,
"Unsupported URL protocol"
);
return
-
1
;
}
error
=
fn
(
&
transport
);
if
(
error
<
GIT_SUCCESS
)
...
...
src/transports/git.c
View file @
3fbcac89
...
...
@@ -72,7 +72,7 @@ static int gen_proto(git_buf *request, const char *cmd, const char *url)
git_buf_putc
(
request
,
'\0'
);
if
(
git_buf_oom
(
request
))
return
GIT_ENOMEM
;
return
-
1
;
return
0
;
}
...
...
src/transports/http.c
View file @
3fbcac89
...
...
@@ -78,7 +78,7 @@ static int gen_request(git_buf *buf, const char *url, const char *host, const ch
git_buf_puts
(
buf
,
"
\r\n
"
);
if
(
git_buf_oom
(
buf
))
return
GIT_ENOMEM
;
return
-
1
;
return
0
;
}
...
...
@@ -174,13 +174,13 @@ static int on_headers_complete(http_parser *parser)
if
(
t
->
content_type
==
NULL
)
{
t
->
content_type
=
git__strdup
(
git_buf_cstr
(
buf
));
if
(
t
->
content_type
==
NULL
)
return
t
->
error
=
GIT_ENOMEM
;
return
t
->
error
=
-
1
;
}
git_buf_clear
(
buf
);
git_buf_printf
(
buf
,
"application/x-git-%s-advertisement"
,
t
->
service
);
if
(
git_buf_oom
(
buf
))
return
t
->
error
=
GIT_ENOMEM
;
return
t
->
error
=
-
1
;
if
(
strcmp
(
t
->
content_type
,
git_buf_cstr
(
buf
)))
return
t
->
error
=
-
1
;
...
...
src/tree-cache.c
View file @
3fbcac89
...
...
@@ -82,24 +82,19 @@ static int read_tree_internal(git_tree_cache **out,
git_tree_cache
*
tree
=
NULL
;
const
char
*
name_start
,
*
buffer
;
int
count
;
int
error
=
GIT_SUCCESS
;
size_t
name_len
;
buffer
=
name_start
=
*
buffer_in
;
if
((
buffer
=
memchr
(
buffer
,
'\0'
,
buffer_end
-
buffer
))
==
NULL
)
{
error
=
GIT_EOBJCORRUPTED
;
goto
cleanup
;
}
if
((
buffer
=
memchr
(
buffer
,
'\0'
,
buffer_end
-
buffer
))
==
NULL
)
goto
corrupted
;
if
(
++
buffer
>=
buffer_end
)
{
error
=
GIT_EOBJCORRUPTED
;
goto
cleanup
;
}
if
(
++
buffer
>=
buffer_end
)
goto
corrupted
;
name_len
=
strlen
(
name_start
);
if
((
tree
=
git__malloc
(
sizeof
(
git_tree_cache
)
+
name_len
+
1
))
==
NULL
)
return
GIT_ENOMEM
;
tree
=
git__malloc
(
sizeof
(
git_tree_cache
)
+
name_len
+
1
);
GITERR_CHECK_ALLOC
(
tree
)
;
memset
(
tree
,
0x0
,
sizeof
(
git_tree_cache
));
tree
->
parent
=
parent
;
...
...
@@ -109,39 +104,28 @@ static int read_tree_internal(git_tree_cache **out,
tree
->
name
[
name_len
]
=
'\0'
;
/* Blank-terminated ASCII decimal number of entries in this tree */
if
(
git__strtol32
(
&
count
,
buffer
,
&
buffer
,
10
)
<
GIT_SUCCESS
||
count
<
-
1
)
{
error
=
GIT_EOBJCORRUPTED
;
goto
cleanup
;
}
if
(
git__strtol32
(
&
count
,
buffer
,
&
buffer
,
10
)
<
0
||
count
<
-
1
)
goto
corrupted
;
tree
->
entries
=
count
;
if
(
*
buffer
!=
' '
||
++
buffer
>=
buffer_end
)
{
error
=
GIT_EOBJCORRUPTED
;
goto
cleanup
;
}
if
(
*
buffer
!=
' '
||
++
buffer
>=
buffer_end
)
goto
corrupted
;
/* Number of children of the tree, newline-terminated */
if
(
git__strtol32
(
&
count
,
buffer
,
&
buffer
,
10
)
<
GIT_SUCCESS
||
count
<
0
)
{
error
=
GIT_EOBJCORRUPTED
;
goto
cleanup
;
}
if
(
git__strtol32
(
&
count
,
buffer
,
&
buffer
,
10
)
<
0
||
count
<
0
)
goto
corrupted
;
tree
->
children_count
=
count
;
if
(
*
buffer
!=
'\n'
||
++
buffer
>
buffer_end
)
{
error
=
GIT_EOBJCORRUPTED
;
goto
cleanup
;
}
if
(
*
buffer
!=
'\n'
||
++
buffer
>
buffer_end
)
goto
corrupted
;
/* The SHA1 is only there if it's not invalidated */
if
(
tree
->
entries
>=
0
)
{
/* 160-bit SHA-1 for this tree and it's children */
if
(
buffer
+
GIT_OID_RAWSZ
>
buffer_end
)
{
error
=
GIT_EOBJCORRUPTED
;
goto
cleanup
;
}
if
(
buffer
+
GIT_OID_RAWSZ
>
buffer_end
)
goto
corrupted
;
git_oid_fromraw
(
&
tree
->
oid
,
(
const
unsigned
char
*
)
buffer
);
buffer
+=
GIT_OID_RAWSZ
;
...
...
@@ -150,40 +134,39 @@ static int read_tree_internal(git_tree_cache **out,
/* Parse children: */
if
(
tree
->
children_count
>
0
)
{
unsigned
int
i
;
int
err
;
tree
->
children
=
git__malloc
(
tree
->
children_count
*
sizeof
(
git_tree_cache
*
));
if
(
tree
->
children
==
NULL
)
goto
cleanup
;
GITERR_CHECK_ALLOC
(
tree
->
children
);
for
(
i
=
0
;
i
<
tree
->
children_count
;
++
i
)
{
err
=
read_tree_internal
(
&
tree
->
children
[
i
],
&
buffer
,
buffer_end
,
tree
);
if
(
err
<
GIT_SUCCESS
)
goto
cleanup
;
if
(
read_tree_internal
(
&
tree
->
children
[
i
],
&
buffer
,
buffer_end
,
tree
)
<
0
)
return
-
1
;
}
}
*
buffer_in
=
buffer
;
*
out
=
tree
;
return
GIT_SUCCESS
;
return
0
;
c
leanup
:
c
orrupted
:
git_tree_cache_free
(
tree
);
return
error
;
giterr_set
(
GITERR_INDEX
,
"Corruped TREE extension in index"
);
return
-
1
;
}
int
git_tree_cache_read
(
git_tree_cache
**
tree
,
const
char
*
buffer
,
size_t
buffer_size
)
{
const
char
*
buffer_end
=
buffer
+
buffer_size
;
int
error
;
error
=
read_tree_internal
(
tree
,
&
buffer
,
buffer_end
,
NULL
);
if
(
read_tree_internal
(
tree
,
&
buffer
,
buffer_end
,
NULL
)
<
0
)
return
-
1
;
if
(
buffer
<
buffer_end
)
return
GIT_EOBJCORRUPTED
;
if
(
buffer
<
buffer_end
)
{
giterr_set
(
GITERR_INDEX
,
"Corruped TREE extension in index (unexpected trailing data)"
);
return
-
1
;
}
return
error
;
return
0
;
}
void
git_tree_cache_free
(
git_tree_cache
*
tree
)
...
...
src/tree.c
View file @
3fbcac89
...
...
@@ -741,7 +741,7 @@ int git_tree_walk(git_tree *tree, git_treewalk_cb callback, int mode, void *payl
case
GIT_TREEWALK_PRE
:
tree_error
(
"Preorder tree walking is still not implemented"
);
return
GIT_ENOTIMPLEMENTED
;
return
-
1
;
default:
giterr_set
(
GITERR_INVALID
,
"Invalid walking mode for tree walk"
);
...
...
src/util.c
View file @
3fbcac89
...
...
@@ -60,22 +60,6 @@ int git_strarray_copy(git_strarray *tgt, const git_strarray *src)
return
0
;
}
int
git__fnmatch
(
const
char
*
pattern
,
const
char
*
name
,
int
flags
)
{
int
ret
;
ret
=
p_fnmatch
(
pattern
,
name
,
flags
);
switch
(
ret
)
{
case
0
:
return
0
;
case
FNM_NOMATCH
:
return
GIT_ENOMATCH
;
default:
giterr_set
(
GITERR_OS
,
"Error trying to match path"
);
return
-
1
;
}
}
int
git__strtol64
(
int64_t
*
result
,
const
char
*
nptr
,
const
char
**
endptr
,
int
base
)
{
const
char
*
p
;
...
...
src/util.h
View file @
3fbcac89
...
...
@@ -105,8 +105,6 @@ GIT_INLINE(const char *) git__next_line(const char *s)
return
s
;
}
extern
int
git__fnmatch
(
const
char
*
pattern
,
const
char
*
name
,
int
flags
);
extern
void
git__tsort
(
void
**
dst
,
size_t
size
,
int
(
*
cmp
)(
const
void
*
,
const
void
*
));
/**
...
...
tests-clar/clar_libgit2.h
View file @
3fbcac89
...
...
@@ -13,9 +13,9 @@
* return error codes!
*/
#define cl_git_pass(expr) do { \
git
_clearerro
r(); \
if ((expr) !=
GIT_SUCCESS
) \
clar__assert(0, __FILE__, __LINE__, "Function call failed: " #expr, git
_lasterror()
, 1); \
git
err_clea
r(); \
if ((expr) !=
0
) \
clar__assert(0, __FILE__, __LINE__, "Function call failed: " #expr, git
err_last()->message
, 1); \
} while(0)
/**
...
...
tests-clar/core/errors.c
View file @
3fbcac89
...
...
@@ -3,46 +3,30 @@
#include "util.h"
#include "posix.h"
#ifdef git__throw
void
test_core_errors__old_school
(
void
)
{
git_clearerror
();
cl_assert
(
git_lasterror
()
==
NULL
);
cl_assert
(
git_strerror
(
GIT_ENOTFOUND
)
!=
NULL
);
git__throw
(
GIT_ENOTFOUND
,
"My Message"
);
cl_assert
(
git_lasterror
()
!=
NULL
);
cl_assert
(
git__prefixcmp
(
git_lasterror
(),
"My Message"
)
==
0
);
git_clearerror
();
}
#endif
#ifdef GITERR_CHECK_ALLOC
void
test_core_errors__new_school
(
void
)
{
char
*
str_in_error
;
git
_erro
r_clear
();
cl_assert
(
git
_erro
r_last
()
==
NULL
);
git
er
r_clear
();
cl_assert
(
git
er
r_last
()
==
NULL
);
giterr_set_oom
();
/* internal fn */
cl_assert
(
git
_erro
r_last
()
!=
NULL
);
cl_assert
(
git
_erro
r_last
()
->
klass
==
GITERR_NOMEMORY
);
str_in_error
=
strstr
(
git
_erro
r_last
()
->
message
,
"memory"
);
cl_assert
(
git
er
r_last
()
!=
NULL
);
cl_assert
(
git
er
r_last
()
->
klass
==
GITERR_NOMEMORY
);
str_in_error
=
strstr
(
git
er
r_last
()
->
message
,
"memory"
);
cl_assert
(
str_in_error
!=
NULL
);
git
_erro
r_clear
();
git
er
r_clear
();
giterr_set
(
GITERR_REPOSITORY
,
"This is a test"
);
/* internal fn */
cl_assert
(
git
_erro
r_last
()
!=
NULL
);
str_in_error
=
strstr
(
git
_erro
r_last
()
->
message
,
"This is a test"
);
cl_assert
(
git
er
r_last
()
!=
NULL
);
str_in_error
=
strstr
(
git
er
r_last
()
->
message
,
"This is a test"
);
cl_assert
(
str_in_error
!=
NULL
);
git
_erro
r_clear
();
cl_assert
(
git
_erro
r_last
()
==
NULL
);
git
er
r_clear
();
cl_assert
(
git
er
r_last
()
==
NULL
);
do
{
struct
stat
st
;
...
...
@@ -52,26 +36,25 @@ void test_core_errors__new_school(void)
}
while
(
false
);
giterr_set
(
GITERR_OS
,
"stat failed"
);
/* internal fn */
cl_assert
(
git
_erro
r_last
()
!=
NULL
);
str_in_error
=
strstr
(
git
_erro
r_last
()
->
message
,
"stat failed"
);
cl_assert
(
git
er
r_last
()
!=
NULL
);
str_in_error
=
strstr
(
git
er
r_last
()
->
message
,
"stat failed"
);
cl_assert
(
str_in_error
!=
NULL
);
cl_assert
(
git__prefixcmp
(
str_in_error
,
"stat failed: "
)
==
0
);
cl_assert
(
strlen
(
str_in_error
)
>
strlen
(
"stat failed: "
));
#ifdef GIT_WIN32
git
_erro
r_clear
();
git
er
r_clear
();
/* The MSDN docs use this to generate a sample error */
cl_assert
(
GetProcessId
(
NULL
)
==
0
);
giterr_set
(
GITERR_OS
,
"GetProcessId failed"
);
/* internal fn */
cl_assert
(
git
_erro
r_last
()
!=
NULL
);
str_in_error
=
strstr
(
git
_erro
r_last
()
->
message
,
"GetProcessId failed"
);
cl_assert
(
git
er
r_last
()
!=
NULL
);
str_in_error
=
strstr
(
git
er
r_last
()
->
message
,
"GetProcessId failed"
);
cl_assert
(
str_in_error
!=
NULL
);
cl_assert
(
git__prefixcmp
(
str_in_error
,
"GetProcessId failed: "
)
==
0
);
cl_assert
(
strlen
(
str_in_error
)
>
strlen
(
"GetProcessId failed: "
));
#endif
git
_erro
r_clear
();
git
er
r_clear
();
}
#endif
tests-clar/network/remotes.c
View file @
3fbcac89
...
...
@@ -101,8 +101,8 @@ void test_network_remotes__save(void)
void
test_network_remotes__fnmatch
(
void
)
{
cl_
git_pass
(
git_refspec_src_match
(
_refspec
,
"refs/heads/master"
));
cl_
git_pass
(
git_refspec_src_match
(
_refspec
,
"refs/heads/multi/level/branch"
));
cl_
assert
(
git_refspec_src_matches
(
_refspec
,
"refs/heads/master"
));
cl_
assert
(
git_refspec_src_matches
(
_refspec
,
"refs/heads/multi/level/branch"
));
}
void
test_network_remotes__transform
(
void
)
...
...
tests-clar/object/tree/frompath.c
View file @
3fbcac89
...
...
@@ -43,7 +43,7 @@ static void assert_tree_from_path(git_tree *root, const char *path, int expected
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
_erro
r_last
()
->
klass
==
expected_result
);
cl_assert
(
git
er
r_last
()
->
klass
==
expected_result
);
}
void
test_object_tree_frompath__retrieve_tree_from_path_to_treeentry
(
void
)
...
...
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