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
618818dc
Commit
618818dc
authored
Jan 23, 2011
by
nulltoken
Committed by
Vicent Marti
Jan 29, 2011
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added git_prettify_file_path().
parent
4581c22a
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
0 deletions
+49
-0
src/fileops.c
+27
-0
src/fileops.h
+22
-0
tests/t0005-path.c
+0
-0
No files found.
src/fileops.c
View file @
618818dc
...
...
@@ -456,3 +456,30 @@ int git_prettify_dir_path(char *buffer_out, const char *path)
return
GIT_SUCCESS
;
}
int
git_prettify_file_path
(
char
*
buffer_out
,
const
char
*
path
)
{
int
error
,
path_len
,
i
;
const
char
*
pattern
=
"/.."
;
path_len
=
strlen
(
path
);
/* Let's make sure the filename doesn't end with "/", "/." or "/.." */
for
(
i
=
1
;
path_len
>
i
&&
i
<
4
;
i
++
)
{
if
(
!
strncmp
(
path
+
path_len
-
i
,
pattern
,
i
))
return
GIT_ERROR
;
}
error
=
git_prettify_dir_path
(
buffer_out
,
path
);
if
(
error
<
GIT_SUCCESS
)
return
error
;
path_len
=
strlen
(
buffer_out
);
if
(
path_len
<
2
)
return
GIT_ERROR
;
/* Remove the trailing slash */
buffer_out
[
path_len
-
1
]
=
'\0'
;
return
GIT_SUCCESS
;
}
src/fileops.h
View file @
618818dc
...
...
@@ -155,4 +155,26 @@ extern int gitfo_close_cached(gitfo_cache *ioc);
*/
GIT_EXTERN
(
int
)
git_prettify_dir_path
(
char
*
buffer_out
,
const
char
*
path
);
/**
* Clean up a provided absolute or relative file path.
*
* This prettification relies on basic operations such as coalescing
* multiple forward slashes into a single slash, removing '.' and
* './' current directory segments, and removing parent directory
* whenever '..' is encountered.
*
* For instance, this will turn "d1/s1///s2/..//../s3" into "d1/s3".
*
* This only performs a string based analysis of the path.
* No checks are done to make sure the path actually makes sense from
* the file system perspective.
*
* @param buffer_out buffer to populate with the normalized path.
* @param path file path to clean up.
* @return
* - GIT_SUCCESS on success;
* - GIT_ERROR when the input path is invalid or escapes the current directory.
*/
GIT_EXTERN
(
int
)
git_prettify_file_path
(
char
*
buffer_out
,
const
char
*
path
);
#endif
/* INCLUDE_fileops_h__ */
tests/t0005-path.c
View file @
618818dc
This diff is collapsed.
Click to expand it.
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