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
a6f6a9f4
Unverified
Commit
a6f6a9f4
authored
Sep 26, 2021
by
Edward Thomson
Committed by
GitHub
Sep 26, 2021
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #6077 from libgit2/ethomson/strarray
buf: common_prefix takes a string array
parents
13690108
7e7cfe8a
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
16 additions
and
30 deletions
+16
-30
src/buffer.c
+7
-6
src/buffer.h
+1
-1
src/pathspec.c
+1
-1
tests/core/buffer.c
+7
-22
No files found.
src/buffer.c
View file @
a6f6a9f4
...
...
@@ -1201,25 +1201,26 @@ int git_buf_lf_to_crlf(git_buf *tgt, const git_buf *src)
return
git_buf_put
(
tgt
,
scan
,
end
-
scan
);
}
int
git_buf_common_prefix
(
git_buf
*
buf
,
c
onst
git_strarray
*
strings
)
int
git_buf_common_prefix
(
git_buf
*
buf
,
c
har
*
const
*
const
strings
,
size_t
count
)
{
size_t
i
;
const
char
*
str
,
*
pfx
;
git_buf_clear
(
buf
);
if
(
!
strings
||
!
strings
->
count
)
if
(
!
strings
||
!
count
)
return
0
;
/* initialize common prefix to first string */
if
(
git_buf_sets
(
buf
,
strings
->
strings
[
0
])
<
0
)
if
(
git_buf_sets
(
buf
,
strings
[
0
])
<
0
)
return
-
1
;
/* go through the rest of the strings, truncating to shared prefix */
for
(
i
=
1
;
i
<
strings
->
count
;
++
i
)
{
for
(
i
=
1
;
i
<
count
;
++
i
)
{
for
(
str
=
strings
->
strings
[
i
],
pfx
=
buf
->
ptr
;
*
str
&&
*
str
==
*
pfx
;
str
++
,
pfx
++
)
for
(
str
=
strings
[
i
],
pfx
=
buf
->
ptr
;
*
str
&&
*
str
==
*
pfx
;
str
++
,
pfx
++
)
/* scanning */
;
git_buf_truncate
(
buf
,
pfx
-
buf
->
ptr
);
...
...
src/buffer.h
View file @
a6f6a9f4
...
...
@@ -324,7 +324,7 @@ extern int git_buf_lf_to_crlf(git_buf *tgt, const git_buf *src);
*
* Buffer will be set to empty if there is no common prefix
*/
extern
int
git_buf_common_prefix
(
git_buf
*
buf
,
c
onst
git_strarray
*
strs
);
extern
int
git_buf_common_prefix
(
git_buf
*
buf
,
c
har
*
const
*
const
strings
,
size_t
count
);
/**
* Check if a buffer begins with a UTF BOM
...
...
src/pathspec.c
View file @
a6f6a9f4
...
...
@@ -24,7 +24,7 @@ char *git_pathspec_prefix(const git_strarray *pathspec)
const
char
*
scan
;
if
(
!
pathspec
||
!
pathspec
->
count
||
git_buf_common_prefix
(
&
prefix
,
pathspec
)
<
0
)
git_buf_common_prefix
(
&
prefix
,
pathspec
->
strings
,
pathspec
->
count
)
<
0
)
return
NULL
;
/* diff prefix will only be leading non-wildcards */
...
...
tests/core/buffer.c
View file @
a6f6a9f4
...
...
@@ -632,7 +632,6 @@ void test_core_buffer__join3(void)
void
test_core_buffer__11
(
void
)
{
git_buf
a
=
GIT_BUF_INIT
;
git_strarray
t
;
char
*
t1
[]
=
{
"nothing"
,
"in"
,
"common"
};
char
*
t2
[]
=
{
"something"
,
"something else"
,
"some other"
};
char
*
t3
[]
=
{
"something"
,
"some fun"
,
"no fun"
};
...
...
@@ -641,39 +640,25 @@ void test_core_buffer__11(void)
char
*
t6
[]
=
{
"no"
,
"nope"
,
""
};
char
*
t7
[]
=
{
""
,
"doesn't matter"
};
t
.
strings
=
t1
;
t
.
count
=
3
;
cl_git_pass
(
git_buf_common_prefix
(
&
a
,
&
t
));
cl_git_pass
(
git_buf_common_prefix
(
&
a
,
t1
,
3
));
cl_assert_equal_s
(
a
.
ptr
,
""
);
t
.
strings
=
t2
;
t
.
count
=
3
;
cl_git_pass
(
git_buf_common_prefix
(
&
a
,
&
t
));
cl_git_pass
(
git_buf_common_prefix
(
&
a
,
t2
,
3
));
cl_assert_equal_s
(
a
.
ptr
,
"some"
);
t
.
strings
=
t3
;
t
.
count
=
3
;
cl_git_pass
(
git_buf_common_prefix
(
&
a
,
&
t
));
cl_git_pass
(
git_buf_common_prefix
(
&
a
,
t3
,
3
));
cl_assert_equal_s
(
a
.
ptr
,
""
);
t
.
strings
=
t4
;
t
.
count
=
3
;
cl_git_pass
(
git_buf_common_prefix
(
&
a
,
&
t
));
cl_git_pass
(
git_buf_common_prefix
(
&
a
,
t4
,
3
));
cl_assert_equal_s
(
a
.
ptr
,
"happ"
);
t
.
strings
=
t5
;
t
.
count
=
3
;
cl_git_pass
(
git_buf_common_prefix
(
&
a
,
&
t
));
cl_git_pass
(
git_buf_common_prefix
(
&
a
,
t5
,
3
));
cl_assert_equal_s
(
a
.
ptr
,
"happ"
);
t
.
strings
=
t6
;
t
.
count
=
3
;
cl_git_pass
(
git_buf_common_prefix
(
&
a
,
&
t
));
cl_git_pass
(
git_buf_common_prefix
(
&
a
,
t6
,
3
));
cl_assert_equal_s
(
a
.
ptr
,
""
);
t
.
strings
=
t7
;
t
.
count
=
3
;
cl_git_pass
(
git_buf_common_prefix
(
&
a
,
&
t
));
cl_git_pass
(
git_buf_common_prefix
(
&
a
,
t7
,
3
));
cl_assert_equal_s
(
a
.
ptr
,
""
);
git_buf_dispose
(
&
a
);
...
...
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