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
691aa968
Commit
691aa968
authored
Dec 02, 2010
by
Vicent Marti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add 'git_repository_open2' to customize repo folders
Signed-off-by: Vicent Marti <tanoku@gmail.com>
parent
eec95235
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
144 additions
and
7 deletions
+144
-7
src/git/repository.h
+34
-1
src/repository.c
+110
-6
No files found.
src/git/repository.h
View file @
691aa968
...
@@ -36,12 +36,45 @@ GIT_BEGIN_DECL
...
@@ -36,12 +36,45 @@ GIT_BEGIN_DECL
*
*
* @param repository pointer to the repo which will be opened
* @param repository pointer to the repo which will be opened
* @param path the path to the repository
* @param path the path to the repository
* @return
the new repository handle; NULL on error
* @return
0 on sucess; error code otherwise
*/
*/
GIT_EXTERN
(
int
)
git_repository_open
(
git_repository
**
repository
,
const
char
*
path
);
GIT_EXTERN
(
int
)
git_repository_open
(
git_repository
**
repository
,
const
char
*
path
);
/**
/**
* Open a git repository by manually specifying all its paths
*
* @param repository pointer to the repo which will be opened
*
* @param git_dir The full path to the repository folder
* e.g. a '.git' folder for live repos, any folder for bare
* Equivalent to $GIT_DIR.
* Cannot be NULL.
*
* @param git_object_directory The full path to the ODB folder.
* the folder where all the loose and packed objects are stored
* Equivalent to $GIT_OBJECT_DIRECTORY.
* If NULL, "$GIT_DIR/objects/" is assumed.
*
* @param git_index_file The full path to the index (dircache) file
* Equivalent to $GIT_INDEX_FILE.
* If NULL, "$GIT_DIR/index" is assumed.
*
* @param git_work_tree The full path to the working tree of the repository,
* if the repository is not bare.
* Equivalent to $GIT_WORK_TREE.
* If NULL, the repository is assumed to be bare.
*
* @return 0 on sucess; error code otherwise
*/
GIT_EXTERN
(
int
)
git_repository_open2
(
git_repository
**
repository
,
const
char
*
git_dir
,
const
char
*
git_object_directory
,
const
char
*
git_index_file
,
const
char
*
git_work_tree
);
/**
* Lookup a reference to one of the objects in the repostory.
* Lookup a reference to one of the objects in the repostory.
*
*
* The generated reference is owned by the repository and
* The generated reference is owned by the repository and
...
...
src/repository.c
View file @
691aa968
...
@@ -31,6 +31,11 @@
...
@@ -31,6 +31,11 @@
#include "blob.h"
#include "blob.h"
#include "fileops.h"
#include "fileops.h"
#define GIT_FOLDER "/.git/"
#define GIT_OBJECTS_FOLDER "objects/"
#define GIT_INDEX_FILE "index"
#define GIT_HEAD_FILE "HEAD"
static
const
int
default_table_size
=
32
;
static
const
int
default_table_size
=
32
;
static
const
double
max_load_factor
=
0
.
65
;
static
const
double
max_load_factor
=
0
.
65
;
...
@@ -66,7 +71,70 @@ int git__objtable_haskey(void *object, const void *key)
...
@@ -66,7 +71,70 @@ int git__objtable_haskey(void *object, const void *key)
return
(
git_oid_cmp
(
oid
,
&
obj
->
id
)
==
0
);
return
(
git_oid_cmp
(
oid
,
&
obj
->
id
)
==
0
);
}
}
static
int
parse_repository_folders
(
git_repository
*
repo
,
const
char
*
repository_path
)
static
int
assign_repository_folders
(
git_repository
*
repo
,
const
char
*
git_dir
,
const
char
*
git_object_directory
,
const
char
*
git_index_file
,
const
char
*
git_work_tree
)
{
char
path_aux
[
GIT_PATH_MAX
];
size_t
path_len
;
assert
(
repo
);
if
(
git_dir
==
NULL
||
gitfo_isdir
(
git_dir
)
<
0
)
return
GIT_ENOTFOUND
;
/* store GIT_DIR */
path_len
=
strlen
(
git_dir
);
strcpy
(
path_aux
,
git_dir
);
if
(
path_aux
[
path_len
-
1
]
!=
'/'
)
{
path_aux
[
path_len
]
=
'/'
;
path_aux
[
path_len
+
1
]
=
0
;
path_len
=
path_len
+
1
;
}
repo
->
path_repository
=
git__strdup
(
path_aux
);
/* store GIT_OBJECT_DIRECTORY */
if
(
git_object_directory
==
NULL
)
strcpy
(
path_aux
+
path_len
,
GIT_OBJECTS_FOLDER
);
else
strcpy
(
path_aux
,
git_object_directory
);
if
(
gitfo_isdir
(
path_aux
)
<
0
)
return
GIT_ENOTFOUND
;
repo
->
path_odb
=
git__strdup
(
path_aux
);
/* store GIT_INDEX_FILE */
if
(
git_index_file
==
NULL
)
strcpy
(
path_aux
+
path_len
,
GIT_INDEX_FILE
);
else
strcpy
(
path_aux
,
git_index_file
);
if
(
gitfo_exists
(
path_aux
)
<
0
)
return
GIT_ENOTFOUND
;
repo
->
path_index
=
git__strdup
(
path_aux
);
/* store GIT_WORK_TREE */
if
(
git_work_tree
==
NULL
)
repo
->
is_bare
=
1
;
else
repo
->
path_workdir
=
git__strdup
(
git_work_tree
);
return
GIT_SUCCESS
;
}
static
int
guess_repository_folders
(
git_repository
*
repo
,
const
char
*
repository_path
)
{
{
char
path_aux
[
GIT_PATH_MAX
],
*
last_folder
;
char
path_aux
[
GIT_PATH_MAX
],
*
last_folder
;
int
path_len
;
int
path_len
;
...
@@ -87,13 +155,13 @@ static int parse_repository_folders(git_repository *repo, const char *repository
...
@@ -87,13 +155,13 @@ static int parse_repository_folders(git_repository *repo, const char *repository
repo
->
path_repository
=
git__strdup
(
path_aux
);
repo
->
path_repository
=
git__strdup
(
path_aux
);
/* objects database */
/* objects database */
strcpy
(
path_aux
+
path_len
,
"objects/"
);
strcpy
(
path_aux
+
path_len
,
GIT_OBJECTS_FOLDER
);
if
(
gitfo_isdir
(
path_aux
)
<
0
)
if
(
gitfo_isdir
(
path_aux
)
<
0
)
return
GIT_ENOTAREPO
;
return
GIT_ENOTAREPO
;
repo
->
path_odb
=
git__strdup
(
path_aux
);
repo
->
path_odb
=
git__strdup
(
path_aux
);
/* HEAD file */
/* HEAD file */
strcpy
(
path_aux
+
path_len
,
"HEAD"
);
strcpy
(
path_aux
+
path_len
,
GIT_HEAD_FILE
);
if
(
gitfo_exists
(
path_aux
)
<
0
)
if
(
gitfo_exists
(
path_aux
)
<
0
)
return
GIT_ENOTAREPO
;
return
GIT_ENOTAREPO
;
...
@@ -104,11 +172,11 @@ static int parse_repository_folders(git_repository *repo, const char *repository
...
@@ -104,11 +172,11 @@ static int parse_repository_folders(git_repository *repo, const char *repository
while
(
*
last_folder
!=
'/'
)
while
(
*
last_folder
!=
'/'
)
last_folder
--
;
last_folder
--
;
if
(
strcmp
(
last_folder
,
"/.git/"
)
==
0
)
{
if
(
strcmp
(
last_folder
,
GIT_FOLDER
)
==
0
)
{
repo
->
is_bare
=
0
;
repo
->
is_bare
=
0
;
/* index file */
/* index file */
strcpy
(
path_aux
+
path_len
,
"index"
);
strcpy
(
path_aux
+
path_len
,
GIT_INDEX_FILE
);
repo
->
path_index
=
git__strdup
(
path_aux
);
repo
->
path_index
=
git__strdup
(
path_aux
);
/* working dir */
/* working dir */
...
@@ -144,6 +212,42 @@ git_repository *git_repository__alloc()
...
@@ -144,6 +212,42 @@ git_repository *git_repository__alloc()
return
repo
;
return
repo
;
}
}
int
git_repository_open2
(
git_repository
**
repo_out
,
const
char
*
git_dir
,
const
char
*
git_object_directory
,
const
char
*
git_index_file
,
const
char
*
git_work_tree
)
{
git_repository
*
repo
;
int
error
=
GIT_SUCCESS
;
assert
(
repo_out
);
repo
=
git_repository__alloc
();
if
(
repo
==
NULL
)
return
GIT_ENOMEM
;
error
=
assign_repository_folders
(
repo
,
git_dir
,
git_object_directory
,
git_index_file
,
git_work_tree
);
if
(
error
<
0
)
goto
cleanup
;
error
=
git_odb_open
(
&
repo
->
db
,
repo
->
path_odb
);
if
(
error
<
0
)
goto
cleanup
;
*
repo_out
=
repo
;
return
GIT_SUCCESS
;
cleanup:
git_repository_free
(
repo
);
return
error
;
}
int
git_repository_open
(
git_repository
**
repo_out
,
const
char
*
path
)
int
git_repository_open
(
git_repository
**
repo_out
,
const
char
*
path
)
{
{
git_repository
*
repo
;
git_repository
*
repo
;
...
@@ -155,7 +259,7 @@ int git_repository_open(git_repository **repo_out, const char *path)
...
@@ -155,7 +259,7 @@ int git_repository_open(git_repository **repo_out, const char *path)
if
(
repo
==
NULL
)
if
(
repo
==
NULL
)
return
GIT_ENOMEM
;
return
GIT_ENOMEM
;
error
=
parse
_repository_folders
(
repo
,
path
);
error
=
guess
_repository_folders
(
repo
,
path
);
if
(
error
<
0
)
if
(
error
<
0
)
goto
cleanup
;
goto
cleanup
;
...
...
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