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
1d68fcd0
Commit
1d68fcd0
authored
Jul 16, 2012
by
Ben Straub
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Checkout: handle symlinks.
Includes unfinished win32 implementation.
parent
9587895f
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
57 additions
and
8 deletions
+57
-8
src/checkout.c
+33
-7
src/unix/posix.h
+1
-0
src/win32/posix.h
+1
-0
src/win32/posix_w32.c
+6
-0
tests-clar/checkout/checkout.c
+13
-0
tests-clar/resources/testrepo/.gitted/objects/09/9fabac3a9ea935598528c27f866e34089c2eff
+2
-0
tests-clar/resources/testrepo/.gitted/objects/45/dd856fdd4d89b884c340ba0e047752d9b085d6
+0
-0
tests-clar/resources/testrepo/.gitted/objects/87/380ae84009e9c503506c2f6143a4fc6c60bf80
+0
-0
tests-clar/resources/testrepo/.gitted/objects/c0/528fd6cc988c0a40ce0be11bc192fc8dc5346e
+0
-0
tests-clar/resources/testrepo/.gitted/refs/heads/master
+1
-1
No files found.
src/checkout.c
View file @
1d68fcd0
...
...
@@ -32,7 +32,30 @@ typedef struct tree_walk_data
}
tree_walk_data
;
static
int
blob_contents_to_file
(
git_repository
*
repo
,
git_buf
*
fnbuf
,
const
git_oid
*
id
,
int
mode
)
static
int
blob_contents_to_link
(
git_repository
*
repo
,
git_buf
*
fnbuf
,
const
git_oid
*
id
)
{
int
retcode
=
GIT_ERROR
;
git_blob
*
blob
;
/* Get the link target */
if
(
!
(
retcode
=
git_blob_lookup
(
&
blob
,
repo
,
id
)))
{
git_buf
linktarget
=
GIT_BUF_INIT
;
if
(
!
(
retcode
=
git_blob__getbuf
(
&
linktarget
,
blob
)))
{
/* Create the link */
retcode
=
p_symlink
(
git_buf_cstr
(
&
linktarget
),
git_buf_cstr
(
fnbuf
));
}
git_buf_free
(
&
linktarget
);
git_blob_free
(
blob
);
}
return
retcode
;
}
static
int
blob_contents_to_file
(
git_repository
*
repo
,
git_buf
*
fnbuf
,
const
git_oid
*
id
,
int
mode
)
{
int
retcode
=
GIT_ERROR
;
...
...
@@ -62,10 +85,8 @@ static int checkout_walker(const char *path, git_tree_entry *entry, void *payloa
/* TODO: handle submodules */
if
(
S_ISLNK
(
attr
))
{
printf
(
"It's a link!
\n
'"
);
}
else
{
switch
(
git_tree_entry_type
(
entry
))
{
switch
(
git_tree_entry_type
(
entry
))
{
case
GIT_OBJ_TREE
:
/* Nothing to do; the blob handling creates necessary directories. */
break
;
...
...
@@ -77,7 +98,13 @@ static int checkout_walker(const char *path, git_tree_entry *entry, void *payloa
git_repository_workdir
(
data
->
repo
),
path
,
git_tree_entry_name
(
entry
));
retcode
=
blob_contents_to_file
(
data
->
repo
,
&
fnbuf
,
git_tree_entry_id
(
entry
),
attr
);
if
(
S_ISLNK
(
attr
))
{
retcode
=
blob_contents_to_link
(
data
->
repo
,
&
fnbuf
,
git_tree_entry_id
(
entry
));
}
else
{
retcode
=
blob_contents_to_file
(
data
->
repo
,
&
fnbuf
,
git_tree_entry_id
(
entry
),
attr
);
}
git_buf_free
(
&
fnbuf
);
}
break
;
...
...
@@ -86,7 +113,6 @@ static int checkout_walker(const char *path, git_tree_entry *entry, void *payloa
retcode
=
-
1
;
break
;
}
}
data
->
stats
->
processed
++
;
return
retcode
;
...
...
src/unix/posix.h
View file @
1d68fcd0
...
...
@@ -19,6 +19,7 @@
#define p_lstat(p,b) lstat(p,b)
#define p_readlink(a, b, c) readlink(a, b, c)
#define p_link(o,n) link(o, n)
#define p_symlink(o,n) symlink(o,n)
#define p_unlink(p) unlink(p)
#define p_mkdir(p,m) mkdir(p, m)
#define p_fsync(fd) fsync(fd)
...
...
src/win32/posix.h
View file @
1d68fcd0
...
...
@@ -33,6 +33,7 @@ GIT_INLINE(int) p_mkdir(const char *path, mode_t mode)
extern
int
p_unlink
(
const
char
*
path
);
extern
int
p_lstat
(
const
char
*
file_name
,
struct
stat
*
buf
);
extern
int
p_readlink
(
const
char
*
link
,
char
*
target
,
size_t
target_len
);
extern
int
p_symlink
(
const
char
*
old
,
const
char
*
new
);
extern
int
p_hide_directory__w32
(
const
char
*
path
);
extern
char
*
p_realpath
(
const
char
*
orig_path
,
char
*
buffer
);
extern
int
p_vsnprintf
(
char
*
buffer
,
size_t
count
,
const
char
*
format
,
va_list
argptr
);
...
...
src/win32/posix_w32.c
View file @
1d68fcd0
...
...
@@ -217,6 +217,12 @@ int p_readlink(const char *link, char *target, size_t target_len)
return
dwRet
;
}
int
p_symlink
(
const
char
*
old
,
const
char
*
new
)
{
/* TODO */
return
-
1
;
}
int
p_open
(
const
char
*
path
,
int
flags
,
...)
{
int
fd
;
...
...
tests-clar/checkout/checkout.c
View file @
1d68fcd0
...
...
@@ -66,3 +66,16 @@ void test_checkout_checkout__stats(void)
{
/* TODO */
}
void
test_checkout_checkout__links
(
void
)
{
char
link_data
[
1024
];
size_t
link_size
=
1024
;
cl_git_pass
(
git_checkout_force
(
g_repo
,
NULL
));
link_size
=
p_readlink
(
"./testrepo/link_to_new.txt"
,
link_data
,
link_size
);
cl_assert_equal_i
(
link_size
,
strlen
(
"new.txt"
));
link_data
[
link_size
]
=
'\0'
;
cl_assert_equal_s
(
link_data
,
"new.txt"
);
test_file_contents
(
"./testrepo/link_to_new.txt"
,
"my new file
\n
"
);
}
tests-clar/resources/testrepo/.gitted/objects/09/9fabac3a9ea935598528c27f866e34089c2eff
0 → 100644
View file @
1d68fcd0
File added
tests-clar/resources/testrepo/.gitted/objects/45/dd856fdd4d89b884c340ba0e047752d9b085d6
0 → 100644
View file @
1d68fcd0
File added
tests-clar/resources/testrepo/.gitted/objects/87/380ae84009e9c503506c2f6143a4fc6c60bf80
0 → 100644
View file @
1d68fcd0
File added
tests-clar/resources/testrepo/.gitted/objects/c0/528fd6cc988c0a40ce0be11bc192fc8dc5346e
0 → 100644
View file @
1d68fcd0
File added
tests-clar/resources/testrepo/.gitted/refs/heads/master
View file @
1d68fcd0
a65fedf39aefe402d3bb6e24df4d4f5fe4547750
099fabac3a9ea935598528c27f866e34089c2eff
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