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
ffd04053
Commit
ffd04053
authored
Nov 05, 2013
by
Vicent Martí
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1941 from libgit2/rb/preserve-iterator-error
Preserve error messages during file system iterator cleanup
parents
b7fbfbb2
1eab9f0e
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
79 additions
and
0 deletions
+79
-0
include/git2/errors.h
+14
-0
src/errors.c
+18
-0
src/iterator.c
+13
-0
tests-clar/repo/iterator.c
+34
-0
No files found.
include/git2/errors.h
View file @
ffd04053
...
@@ -8,6 +8,7 @@
...
@@ -8,6 +8,7 @@
#define INCLUDE_git_errors_h__
#define INCLUDE_git_errors_h__
#include "common.h"
#include "common.h"
#include "buffer.h"
/**
/**
* @file git2/errors.h
* @file git2/errors.h
...
@@ -45,6 +46,7 @@ typedef struct {
...
@@ -45,6 +46,7 @@ typedef struct {
/** Error classes */
/** Error classes */
typedef
enum
{
typedef
enum
{
GITERR_NONE
=
0
,
GITERR_NOMEMORY
,
GITERR_NOMEMORY
,
GITERR_OS
,
GITERR_OS
,
GITERR_INVALID
,
GITERR_INVALID
,
...
@@ -85,6 +87,18 @@ GIT_EXTERN(const git_error *) giterr_last(void);
...
@@ -85,6 +87,18 @@ GIT_EXTERN(const git_error *) giterr_last(void);
GIT_EXTERN
(
void
)
giterr_clear
(
void
);
GIT_EXTERN
(
void
)
giterr_clear
(
void
);
/**
/**
* Get the last error data and clear it.
*
* This copies the last error into the given `git_error` struct
* and returns 0 if the copy was successful, leaving the error
* cleared as if `giterr_clear` had been called.
*
* If there was no existing error in the library, -1 will be returned
* and the contents of `cpy` will be left unmodified.
*/
GIT_EXTERN
(
int
)
giterr_detach
(
git_error
*
cpy
);
/**
* Set the error message string for this thread.
* Set the error message string for this thread.
*
*
* This function is public so that custom ODB backends and the like can
* This function is public so that custom ODB backends and the like can
...
...
src/errors.c
View file @
ffd04053
...
@@ -112,6 +112,24 @@ void giterr_clear(void)
...
@@ -112,6 +112,24 @@ void giterr_clear(void)
#endif
#endif
}
}
int
giterr_detach
(
git_error
*
cpy
)
{
git_error
*
error
=
GIT_GLOBAL
->
last_error
;
assert
(
cpy
);
if
(
!
error
)
return
-
1
;
cpy
->
message
=
error
->
message
;
cpy
->
klass
=
error
->
klass
;
error
->
message
=
NULL
;
giterr_clear
();
return
0
;
}
const
git_error
*
giterr_last
(
void
)
const
git_error
*
giterr_last
(
void
)
{
{
return
GIT_GLOBAL
->
last_error
;
return
GIT_GLOBAL
->
last_error
;
...
...
src/iterator.c
View file @
ffd04053
...
@@ -991,8 +991,21 @@ static int fs_iterator__expand_dir(fs_iterator *fi)
...
@@ -991,8 +991,21 @@ 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_error
last_error
=
{
0
};
giterr_detach
(
&
last_error
);
/* these callbacks may clear the error message */
fs_iterator__free_frame
(
ff
);
fs_iterator__free_frame
(
ff
);
fs_iterator__advance_over
(
NULL
,
(
git_iterator
*
)
fi
);
fs_iterator__advance_over
(
NULL
,
(
git_iterator
*
)
fi
);
/* next time return value we skipped to */
fi
->
base
.
flags
&=
~
GIT_ITERATOR_FIRST_ACCESS
;
if
(
last_error
.
message
)
{
giterr_set_str
(
last_error
.
klass
,
last_error
.
message
);
free
(
last_error
.
message
);
}
return
error
;
return
error
;
}
}
...
...
tests-clar/repo/iterator.c
View file @
ffd04053
...
@@ -926,3 +926,37 @@ void test_repo_iterator__fs2(void)
...
@@ -926,3 +926,37 @@ void test_repo_iterator__fs2(void)
expect_iterator_items
(
i
,
12
,
expect_base
,
12
,
expect_base
);
expect_iterator_items
(
i
,
12
,
expect_base
,
12
,
expect_base
);
git_iterator_free
(
i
);
git_iterator_free
(
i
);
}
}
void
test_repo_iterator__fs_preserves_error
(
void
)
{
git_iterator
*
i
;
const
git_index_entry
*
e
;
if
(
!
cl_is_chmod_supported
())
return
;
g_repo
=
cl_git_sandbox_init
(
"empty_standard_repo"
);
cl_must_pass
(
p_mkdir
(
"empty_standard_repo/r"
,
0777
));
cl_git_mkfile
(
"empty_standard_repo/r/a"
,
"hello"
);
cl_must_pass
(
p_mkdir
(
"empty_standard_repo/r/b"
,
0777
));
cl_git_mkfile
(
"empty_standard_repo/r/b/problem"
,
"not me"
);
cl_must_pass
(
p_chmod
(
"empty_standard_repo/r/b"
,
0000
));
cl_must_pass
(
p_mkdir
(
"empty_standard_repo/r/c"
,
0777
));
cl_git_mkfile
(
"empty_standard_repo/r/d"
,
"final"
);
cl_git_pass
(
git_iterator_for_filesystem
(
&
i
,
"empty_standard_repo/r"
,
0
,
NULL
,
NULL
));
cl_git_pass
(
git_iterator_advance
(
&
e
,
i
));
/* a */
cl_git_fail
(
git_iterator_advance
(
&
e
,
i
));
/* b */
cl_assert
(
giterr_last
());
cl_assert
(
giterr_last
()
->
message
!=
NULL
);
/* skip 'c/' empty directory */
cl_git_pass
(
git_iterator_advance
(
&
e
,
i
));
/* d */
cl_assert_equal_i
(
GIT_ITEROVER
,
git_iterator_advance
(
&
e
,
i
));
cl_must_pass
(
p_chmod
(
"empty_standard_repo/r/b"
,
0777
));
git_iterator_free
(
i
);
}
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