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
83580562
Commit
83580562
authored
Mar 06, 2017
by
Edward Thomson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refdb_fs: honor the namespace
parent
d24ae06d
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
25 deletions
+34
-25
src/refdb_fs.c
+34
-25
No files found.
src/refdb_fs.c
View file @
83580562
...
@@ -1433,26 +1433,25 @@ static void refdb_fs_backend__free(git_refdb_backend *_backend)
...
@@ -1433,26 +1433,25 @@ static void refdb_fs_backend__free(git_refdb_backend *_backend)
git__free
(
backend
);
git__free
(
backend
);
}
}
static
int
setup_namespace
(
git_buf
*
gitpath
,
git_repository
*
repo
)
static
char
*
setup_namespace
(
git_repository
*
repo
,
const
char
*
in
)
{
{
char
*
parts
,
*
start
,
*
end
;
git_buf
path
=
GIT_BUF_INIT
;
char
*
parts
,
*
start
,
*
end
,
*
out
=
NULL
;
/* Not all repositories have a gitpath */
if
(
!
in
)
if
(
repo
->
gitdir
==
NULL
)
goto
done
;
return
0
;
if
(
repo
->
commondir
==
NULL
)
return
0
;
/* Load the path to the repo first */
git_buf_puts
(
&
path
,
in
);
git_buf_puts
(
gitpath
,
repo
->
gitdir
);
/* if the repo is not namespaced, nothing else to do */
/* if the repo is not namespaced, nothing else to do */
if
(
repo
->
namespace
==
NULL
)
if
(
repo
->
namespace
==
NULL
)
{
return
0
;
out
=
git_buf_detach
(
&
path
);
goto
done
;
}
parts
=
end
=
git__strdup
(
repo
->
namespace
);
parts
=
end
=
git__strdup
(
repo
->
namespace
);
if
(
parts
==
NULL
)
if
(
parts
==
NULL
)
return
-
1
;
goto
done
;
/*
/*
* From `man gitnamespaces`:
* From `man gitnamespaces`:
...
@@ -1460,21 +1459,24 @@ static int setup_namespace(git_buf *gitpath, git_repository *repo)
...
@@ -1460,21 +1459,24 @@ static int setup_namespace(git_buf *gitpath, git_repository *repo)
* of namespaces; for example, GIT_NAMESPACE=foo/bar will store
* of namespaces; for example, GIT_NAMESPACE=foo/bar will store
* refs under refs/namespaces/foo/refs/namespaces/bar/
* refs under refs/namespaces/foo/refs/namespaces/bar/
*/
*/
while
((
start
=
git__strsep
(
&
end
,
"/"
))
!=
NULL
)
{
while
((
start
=
git__strsep
(
&
end
,
"/"
))
!=
NULL
)
git_buf_printf
(
gitpath
,
"refs/namespaces/%s/"
,
start
);
git_buf_printf
(
&
path
,
"refs/namespaces/%s/"
,
start
);
}
git_buf_printf
(
git
path
,
"refs/namespaces/%s/refs"
,
end
);
git_buf_printf
(
&
path
,
"refs/namespaces/%s/refs"
,
end
);
git__free
(
parts
);
git__free
(
parts
);
/* Make sure that the folder with the namespace exists */
/* Make sure that the folder with the namespace exists */
if
(
git_futils_mkdir_relative
(
git_buf_cstr
(
gitpath
),
repo
->
commondir
,
if
(
git_futils_mkdir_relative
(
git_buf_cstr
(
&
path
),
in
,
0777
,
0777
,
GIT_MKDIR_PATH
,
NULL
)
<
0
)
GIT_MKDIR_PATH
,
NULL
)
<
0
)
return
-
1
;
goto
done
;
/* Return root of the namespaced gitpath, i.e. without the trailing '/refs' */
/* Return root of the namespaced gitpath, i.e. without the trailing '/refs' */
git_buf_rtruncate_at_char
(
gitpath
,
'/'
);
git_buf_rtruncate_at_char
(
&
path
,
'/'
);
return
0
;
out
=
git_buf_detach
(
&
path
);
done:
git_buf_free
(
&
path
);
return
out
;
}
}
static
int
reflog_alloc
(
git_reflog
**
reflog
,
const
char
*
name
)
static
int
reflog_alloc
(
git_reflog
**
reflog
,
const
char
*
name
)
...
@@ -1979,12 +1981,19 @@ int git_refdb_backend_fs(
...
@@ -1979,12 +1981,19 @@ int git_refdb_backend_fs(
backend
->
repo
=
repository
;
backend
->
repo
=
repository
;
if
(
setup_namespace
(
&
gitpath
,
repository
)
<
0
)
if
(
repository
->
gitdir
)
{
backend
->
gitpath
=
setup_namespace
(
repository
,
repository
->
gitdir
);
if
(
backend
->
gitpath
==
NULL
)
goto
fail
;
goto
fail
;
}
if
(
repository
->
commondir
)
{
backend
->
commonpath
=
setup_namespace
(
repository
,
repository
->
commondir
);
backend
->
gitpath
=
backend
->
commonpath
=
git_buf_detach
(
&
gitpath
);
if
(
backend
->
commonpath
==
NULL
)
if
(
repository
->
commondir
)
goto
fail
;
backend
->
commonpath
=
git__strdup
(
repository
->
commondir
);
}
if
(
git_buf_joinpath
(
&
gitpath
,
backend
->
commonpath
,
GIT_PACKEDREFS_FILE
)
<
0
||
if
(
git_buf_joinpath
(
&
gitpath
,
backend
->
commonpath
,
GIT_PACKEDREFS_FILE
)
<
0
||
git_sortedcache_new
(
git_sortedcache_new
(
...
...
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