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
1eab9f0e
Commit
1eab9f0e
authored
Nov 05, 2013
by
Vicent Marti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
error: Simplify giterr_detach
parent
3b259cbd
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
25 deletions
+18
-25
include/git2/errors.h
+6
-9
src/errors.c
+6
-11
src/iterator.c
+6
-5
No files found.
include/git2/errors.h
View file @
1eab9f0e
...
@@ -89,17 +89,14 @@ GIT_EXTERN(void) giterr_clear(void);
...
@@ -89,17 +89,14 @@ GIT_EXTERN(void) giterr_clear(void);
/**
/**
* Get the last error data and clear it.
* Get the last error data and clear it.
*
*
* This copies the last error message into the given `git_buf` and returns
* This copies the last error into the given `git_error` struct
* the associated `git_error_t`, leaving the error cleared as if
* and returns 0 if the copy was successful, leaving the error
* `giterr_clear` had been called. You must call `git_buf_free` on the
* cleared as if `giterr_clear` had been called.
* message to release the memory.
*
*
* Note: it is possible that this will return `GITERR_NONE` and set the
* If there was no existing error in the library, -1 will be returned
* buffer to NULL, so be prepared for that condition. Also, if the last
* and the contents of `cpy` will be left unmodified.
* error was an out-of-memory error, this will return `GITERR_NOMEMORY`
* but also leave the buffer set to NULL (to avoid allocation).
*/
*/
GIT_EXTERN
(
git_error_t
)
giterr_detach
(
git_buf
*
message
);
GIT_EXTERN
(
int
)
giterr_detach
(
git_error
*
cpy
);
/**
/**
* Set the error message string for this thread.
* Set the error message string for this thread.
...
...
src/errors.c
View file @
1eab9f0e
...
@@ -112,27 +112,22 @@ void giterr_clear(void)
...
@@ -112,27 +112,22 @@ void giterr_clear(void)
#endif
#endif
}
}
git_error_t
giterr_detach
(
git_buf
*
message
)
int
giterr_detach
(
git_error
*
cpy
)
{
{
git_error_t
rval
;
git_error
*
error
=
GIT_GLOBAL
->
last_error
;
git_error
*
error
=
GIT_GLOBAL
->
last_error
;
assert
(
message
);
assert
(
cpy
);
git_buf_free
(
message
);
if
(
!
error
)
if
(
!
error
)
return
GITERR_NONE
;
return
-
1
;
rval
=
error
->
klass
;
if
(
error
!=
&
g_git_oom_error
)
cpy
->
message
=
error
->
message
;
git_buf_attach
(
message
,
error
->
message
,
0
)
;
cpy
->
klass
=
error
->
klass
;
error
->
message
=
NULL
;
error
->
message
=
NULL
;
giterr_clear
();
giterr_clear
();
return
rval
;
return
0
;
}
}
const
git_error
*
giterr_last
(
void
)
const
git_error
*
giterr_last
(
void
)
...
...
src/iterator.c
View file @
1eab9f0e
...
@@ -991,8 +991,9 @@ static int fs_iterator__expand_dir(fs_iterator *fi)
...
@@ -991,8 +991,9 @@ static int fs_iterator__expand_dir(fs_iterator *fi)
fi
->
base
.
start
,
fi
->
base
.
end
,
&
ff
->
entries
);
fi
->
base
.
start
,
fi
->
base
.
end
,
&
ff
->
entries
);
if
(
error
<
0
)
{
if
(
error
<
0
)
{
git_buf
msg
=
GIT_BUF_INIT
;
git_error
last_error
=
{
0
};
git_error_t
errt
=
giterr_detach
(
&
msg
);
giterr_detach
(
&
last_error
);
/* these callbacks may clear the error message */
/* these callbacks may clear the error message */
fs_iterator__free_frame
(
ff
);
fs_iterator__free_frame
(
ff
);
...
@@ -1000,9 +1001,9 @@ static int fs_iterator__expand_dir(fs_iterator *fi)
...
@@ -1000,9 +1001,9 @@ static int fs_iterator__expand_dir(fs_iterator *fi)
/* next time return value we skipped to */
/* next time return value we skipped to */
fi
->
base
.
flags
&=
~
GIT_ITERATOR_FIRST_ACCESS
;
fi
->
base
.
flags
&=
~
GIT_ITERATOR_FIRST_ACCESS
;
if
(
msg
.
ptr
)
{
if
(
last_error
.
message
)
{
giterr_set_str
(
errt
,
msg
.
ptr
);
giterr_set_str
(
last_error
.
klass
,
last_error
.
message
);
git_buf_free
(
&
msg
);
free
(
last_error
.
message
);
}
}
return
error
;
return
error
;
...
...
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