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
5dc8513b
Commit
5dc8513b
authored
Sep 24, 2013
by
Vicent Martí
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1864 from libgit2/minimize-regex-usage
Minimize regex usage
parents
d89b8b60
106c12f1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
58 deletions
+29
-58
src/remote.c
+15
-29
src/revwalk.c
+14
-29
No files found.
src/remote.c
View file @
5dc8513b
...
...
@@ -18,8 +18,6 @@
#include "refspec.h"
#include "fetchhead.h"
#include <regex.h>
static
int
add_refspec
(
git_remote
*
remote
,
const
char
*
string
,
bool
is_fetch
)
{
git_refspec
*
spec
;
...
...
@@ -1075,35 +1073,28 @@ void git_remote_free(git_remote *remote)
git__free
(
remote
);
}
struct
cb_data
{
git_vector
*
list
;
regex_t
*
preg
;
};
static
int
remote_list_cb
(
const
git_config_entry
*
entry
,
void
*
data_
)
static
int
remote_list_cb
(
const
git_config_entry
*
entry
,
void
*
payload
)
{
struct
cb_data
*
data
=
(
struct
cb_data
*
)
data_
;
size_t
nmatch
=
2
;
regmatch_t
pmatch
[
2
]
;
c
onst
char
*
name
=
entry
->
name
;
git_vector
*
list
=
payload
;
const
char
*
name
=
entry
->
name
+
strlen
(
"remote."
)
;
size_t
namelen
=
strlen
(
name
)
;
c
har
*
remote_
name
;
if
(
!
regexec
(
data
->
preg
,
name
,
nmatch
,
pmatch
,
0
))
{
char
*
remote_name
=
git__strndup
(
&
name
[
pmatch
[
1
].
rm_so
],
pmatch
[
1
].
rm_eo
-
pmatch
[
1
].
rm_so
);
GITERR_CHECK_ALLOC
(
remote_name
);
/* we know name matches "remote.<stuff>.(push)?url" */
if
(
git_vector_insert
(
data
->
list
,
remote_name
)
<
0
)
return
-
1
;
}
if
(
!
strcmp
(
&
name
[
namelen
-
4
],
".url"
))
remote_name
=
git__strndup
(
name
,
namelen
-
4
);
/* strip ".url" */
else
remote_name
=
git__strndup
(
name
,
namelen
-
8
);
/* strip ".pushurl" */
GITERR_CHECK_ALLOC
(
remote_name
);
return
0
;
return
git_vector_insert
(
list
,
remote_name
)
;
}
int
git_remote_list
(
git_strarray
*
remotes_list
,
git_repository
*
repo
)
{
git_config
*
cfg
;
git_vector
list
;
regex_t
preg
;
struct
cb_data
data
;
int
error
;
if
(
git_repository_config__weakptr
(
&
cfg
,
repo
)
<
0
)
...
...
@@ -1112,18 +1103,13 @@ int git_remote_list(git_strarray *remotes_list, git_repository *repo)
if
(
git_vector_init
(
&
list
,
4
,
git__strcmp_cb
)
<
0
)
return
-
1
;
if
(
regcomp
(
&
preg
,
"^remote
\\
.(.*)
\\
.(push)?url$"
,
REG_EXTENDED
)
<
0
)
{
giterr_set
(
GITERR_OS
,
"Remote catch regex failed to compile"
);
return
-
1
;
}
error
=
git_config_foreach_match
(
cfg
,
"^remote
\\
..*
\\
.(push)?url$"
,
remote_list_cb
,
&
list
);
data
.
list
=
&
list
;
data
.
preg
=
&
preg
;
error
=
git_config_foreach
(
cfg
,
remote_list_cb
,
&
data
);
regfree
(
&
preg
);
if
(
error
<
0
)
{
size_t
i
;
char
*
elem
;
git_vector_foreach
(
&
list
,
i
,
elem
)
{
git__free
(
elem
);
}
...
...
src/revwalk.c
View file @
5dc8513b
...
...
@@ -14,8 +14,6 @@
#include "git2/revparse.h"
#include "merge.h"
#include <regex.h>
git_commit_list_node
*
git_revwalk__commit_lookup
(
git_revwalk
*
walk
,
const
git_oid
*
oid
)
{
...
...
@@ -181,48 +179,35 @@ static int push_glob_cb(const char *refname, void *data_)
static
int
push_glob
(
git_revwalk
*
walk
,
const
char
*
glob
,
int
hide
)
{
int
error
=
0
;
git_buf
buf
=
GIT_BUF_INIT
;
struct
push_cb_data
data
;
regex_t
preg
;
size_t
wildcard
;
assert
(
walk
&&
glob
);
/* refs/ is implied if not given in the glob */
if
(
strncmp
(
glob
,
GIT_REFS_DIR
,
strlen
(
GIT_REFS_DIR
)))
{
git_buf_
printf
(
&
buf
,
GIT_REFS_DIR
"%s"
,
glob
);
}
else
{
if
(
git__prefixcmp
(
glob
,
GIT_REFS_DIR
)
!=
0
)
git_buf_
joinpath
(
&
buf
,
GIT_REFS_DIR
,
glob
);
else
git_buf_puts
(
&
buf
,
glob
);
}
/* If no '?', '*' or '[' exist, we append '/ *' to the glob */
memset
(
&
preg
,
0x0
,
sizeof
(
regex_t
));
if
(
regcomp
(
&
preg
,
"[?*[]"
,
REG_EXTENDED
))
{
giterr_set
(
GITERR_OS
,
"Regex failed to compile"
);
git_buf_free
(
&
buf
);
return
-
1
;
}
if
(
regexec
(
&
preg
,
glob
,
0
,
NULL
,
0
))
git_buf_puts
(
&
buf
,
"/*"
);
if
(
git_buf_oom
(
&
buf
))
goto
on_error
;
wildcard
=
strcspn
(
glob
,
"?*["
);
if
(
!
glob
[
wildcard
])
git_buf_put
(
&
buf
,
"/*"
,
2
);
data
.
walk
=
walk
;
data
.
hide
=
hide
;
if
(
git_reference_foreach_glob
(
walk
->
repo
,
git_buf_cstr
(
&
buf
),
push_glob_cb
,
&
data
)
<
0
)
goto
on_error
;
regfree
(
&
preg
);
git_buf_free
(
&
buf
);
return
0
;
if
(
git_buf_oom
(
&
buf
))
error
=
-
1
;
else
error
=
git_reference_foreach_glob
(
walk
->
repo
,
git_buf_cstr
(
&
buf
),
push_glob_cb
,
&
data
);
on_error:
regfree
(
&
preg
);
git_buf_free
(
&
buf
);
return
-
1
;
return
error
;
}
int
git_revwalk_push_glob
(
git_revwalk
*
walk
,
const
char
*
glob
)
...
...
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