Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
MMCV
Commits
22ba143d
Commit
22ba143d
authored
Sep 07, 2019
by
Zhipeng Han
Committed by
Kai Chen
Sep 07, 2019
Browse files
[feat]: find root of Version Control Systems (#129)
Signed-off-by:
Zhipeng Han
<
hanzhipeng9@gmail.com
>
parent
5b10dcd7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
0 deletions
+21
-0
mmcv/utils/path.py
mmcv/utils/path.py
+21
-0
No files found.
mmcv/utils/path.py
View file @
22ba143d
...
...
@@ -77,3 +77,24 @@ def scandir(dir_path, suffix=None):
return
_scandir_py35
(
dir_path
,
suffix
)
else
:
return
_scandir_py
(
dir_path
,
suffix
)
def
find_vcs_root
(
path
,
markers
=
(
'.git'
,
)):
"""Finds the root directory (including itself) of specified markers.
Args:
path (str): Path of directory or file.
markers (list[str], optional): List of file or directory names.
Returns:
The directory contained one of the markers or None if not found.
"""
if
osp
.
isfile
(
path
):
path
=
osp
.
dirname
(
path
)
prev
,
cur
=
None
,
osp
.
abspath
(
osp
.
expanduser
(
path
))
while
cur
!=
prev
:
if
any
(
osp
.
exists
(
osp
.
join
(
cur
,
marker
))
for
marker
in
markers
):
return
cur
prev
,
cur
=
cur
,
osp
.
split
(
cur
)[
0
]
return
None
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