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
a79e8e63
Commit
a79e8e63
authored
Feb 05, 2011
by
nulltoken
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed a small issue in git__join_path(). Added tests to exercise git__join_path().
parent
ca0fb40a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
1 deletions
+32
-1
src/util.c
+3
-1
tests/t00-core.c
+29
-0
No files found.
src/util.c
View file @
a79e8e63
...
@@ -207,6 +207,8 @@ char *git__joinpath(const char *path_a, const char *path_b)
...
@@ -207,6 +207,8 @@ char *git__joinpath(const char *path_a, const char *path_b)
int
len_a
,
len_b
;
int
len_a
,
len_b
;
char
*
path_new
;
char
*
path_new
;
assert
(
path_a
&&
path_b
);
len_a
=
strlen
(
path_a
);
len_a
=
strlen
(
path_a
);
len_b
=
strlen
(
path_b
);
len_b
=
strlen
(
path_b
);
...
@@ -216,7 +218,7 @@ char *git__joinpath(const char *path_a, const char *path_b)
...
@@ -216,7 +218,7 @@ char *git__joinpath(const char *path_a, const char *path_b)
strcpy
(
path_new
,
path_a
);
strcpy
(
path_new
,
path_a
);
if
(
path_new
[
len_a
-
1
]
!=
'/'
)
if
(
len_a
>
0
&&
len_b
>
0
&&
path_new
[
len_a
-
1
]
!=
'/'
)
path_new
[
len_a
++
]
=
'/'
;
path_new
[
len_a
++
]
=
'/'
;
if
(
path_b
[
0
]
==
'/'
)
if
(
path_b
[
0
]
==
'/'
)
...
...
tests/t00-core.c
View file @
a79e8e63
...
@@ -342,6 +342,34 @@ BEGIN_TEST("path", dir_path_prettifying)
...
@@ -342,6 +342,34 @@ BEGIN_TEST("path", dir_path_prettifying)
must_fail
(
ensure_dir_path_normalized
(
"/d1/.../d2"
,
NULL
));
must_fail
(
ensure_dir_path_normalized
(
"/d1/.../d2"
,
NULL
));
END_TEST
END_TEST
static
int
ensure_joinpath
(
const
char
*
path_a
,
const
char
*
path_b
,
const
char
*
expected_path
)
{
int
error
=
GIT_SUCCESS
;
char
*
joined_path
;
joined_path
=
git__joinpath
(
path_a
,
path_b
);
if
(
joined_path
==
NULL
)
return
GIT_ERROR
;
if
(
strcmp
(
joined_path
,
expected_path
))
error
=
GIT_ERROR
;
return
error
;
}
BEGIN_TEST
(
"path"
,
joinpath
)
must_pass
(
ensure_joinpath
(
""
,
""
,
""
));
must_pass
(
ensure_joinpath
(
""
,
"a"
,
"a"
));
must_pass
(
ensure_joinpath
(
"a"
,
""
,
"a"
));
must_pass
(
ensure_joinpath
(
"a"
,
"b"
,
"a/b"
));
must_pass
(
ensure_joinpath
(
"/"
,
"a"
,
"/a"
));
must_pass
(
ensure_joinpath
(
"/"
,
""
,
"/"
));
must_pass
(
ensure_joinpath
(
"/a"
,
"/b"
,
"/a/b"
));
must_pass
(
ensure_joinpath
(
"/a"
,
"/b/"
,
"/a/b/"
));
must_pass
(
ensure_joinpath
(
"/a/"
,
"b/"
,
"/a/b/"
));
must_pass
(
ensure_joinpath
(
"/a/"
,
"/b/"
,
"/a/b/"
));
END_TEST
typedef
struct
name_data
{
typedef
struct
name_data
{
int
count
;
/* return count */
int
count
;
/* return count */
char
*
name
;
/* filename */
char
*
name
;
/* filename */
...
@@ -601,6 +629,7 @@ git_testsuite *libgit2_suite_core(void)
...
@@ -601,6 +629,7 @@ git_testsuite *libgit2_suite_core(void)
ADD_TEST
(
suite
,
"path"
,
file_path_prettifying
);
ADD_TEST
(
suite
,
"path"
,
file_path_prettifying
);
ADD_TEST
(
suite
,
"path"
,
dir_path_prettifying
);
ADD_TEST
(
suite
,
"path"
,
dir_path_prettifying
);
ADD_TEST
(
suite
,
"path"
,
joinpath
);
ADD_TEST
(
suite
,
"dirent"
,
dot
);
ADD_TEST
(
suite
,
"dirent"
,
dot
);
ADD_TEST
(
suite
,
"dirent"
,
sub
);
ADD_TEST
(
suite
,
"dirent"
,
sub
);
...
...
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