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
3a12891f
Commit
3a12891f
authored
Jun 07, 2011
by
Vicent Martí
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #243 from jpfender/symlinks2
Symlinks NEW
parents
a5aa5bd1
27a1b382
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
48 additions
and
13 deletions
+48
-13
src/blob.c
+26
-10
src/fileops.c
+8
-0
src/fileops.h
+2
-0
src/index.c
+12
-3
No files found.
src/blob.c
View file @
3a12891f
...
...
@@ -80,37 +80,52 @@ int git_blob_create_frombuffer(git_oid *oid, git_repository *repo, const void *b
int
git_blob_create_fromfile
(
git_oid
*
oid
,
git_repository
*
repo
,
const
char
*
path
)
{
int
error
,
fd
;
int
error
,
islnk
;
int
fd
=
0
;
char
full_path
[
GIT_PATH_MAX
];
char
buffer
[
2048
];
git_off_t
size
;
git_odb_stream
*
stream
;
struct
stat
st
;
gitfo_lstat
(
path
,
&
st
);
islnk
=
S_ISLNK
(
st
.
st_mode
);
if
(
repo
->
path_workdir
==
NULL
)
return
git__throw
(
GIT_ENOTFOUND
,
"Failed to create blob. (No working directory found)"
);
git__joinpath
(
full_path
,
repo
->
path_workdir
,
path
);
if
((
fd
=
gitfo_open
(
full_path
,
O_RDONLY
))
<
0
)
return
git__throw
(
GIT_ENOTFOUND
,
"Failed to create blob. Could not open '%s'"
,
full_path
);
if
(
!
islnk
)
{
if
((
fd
=
gitfo_open
(
full_path
,
O_RDONLY
))
<
0
)
return
git__throw
(
GIT_ENOTFOUND
,
"Failed to create blob. Could not open '%s'"
,
full_path
);
if
((
size
=
gitfo_size
(
fd
))
<
0
||
!
git__is_sizet
(
size
))
{
gitfo_close
(
fd
);
return
git__throw
(
GIT_EOSERR
,
"Failed to create blob. '%s' appears to be corrupted"
,
full_path
);
if
((
size
=
gitfo_size
(
fd
))
<
0
||
!
git__is_sizet
(
size
))
{
gitfo_close
(
fd
);
return
git__throw
(
GIT_EOSERR
,
"Failed to create blob. '%s' appears to be corrupted"
,
full_path
);
}
}
else
{
size
=
st
.
st_size
;
}
if
((
error
=
git_odb_open_wstream
(
&
stream
,
repo
->
db
,
(
size_t
)
size
,
GIT_OBJ_BLOB
))
<
GIT_SUCCESS
)
{
gitfo_close
(
fd
);
if
(
!
islnk
)
gitfo_close
(
fd
);
return
git__rethrow
(
error
,
"Failed to create blob"
);
}
while
(
size
>
0
)
{
ssize_t
read_len
;
read_len
=
read
(
fd
,
buffer
,
sizeof
(
buffer
));
if
(
!
islnk
)
read_len
=
read
(
fd
,
buffer
,
sizeof
(
buffer
));
else
read_len
=
readlink
(
full_path
,
buffer
,
sizeof
(
buffer
));
if
(
read_len
<
0
)
{
gitfo_close
(
fd
);
if
(
!
islnk
)
gitfo_close
(
fd
);
stream
->
free
(
stream
);
return
git__throw
(
GIT_EOSERR
,
"Failed to create blob. Can't read full file"
);
}
...
...
@@ -121,7 +136,8 @@ int git_blob_create_fromfile(git_oid *oid, git_repository *repo, const char *pat
error
=
stream
->
finalize_write
(
oid
,
stream
);
stream
->
free
(
stream
);
gitfo_close
(
fd
);
if
(
!
islnk
)
gitfo_close
(
fd
);
if
(
error
<
GIT_SUCCESS
)
return
git__rethrow
(
error
,
"Failed to create blob"
);
...
...
src/fileops.c
View file @
3a12891f
...
...
@@ -175,6 +175,14 @@ int gitfo_exists(const char *path)
return
access
(
path
,
F_OK
);
}
int
gitfo_shallow_exists
(
const
char
*
path
)
{
assert
(
path
);
struct
stat
st
;
return
gitfo_lstat
(
path
,
&
st
);
}
git_off_t
gitfo_size
(
git_file
fd
)
{
struct
stat
sb
;
...
...
src/fileops.h
View file @
3a12891f
...
...
@@ -65,6 +65,7 @@ typedef struct { /* file io buffer */
}
gitfo_buf
;
extern
int
gitfo_exists
(
const
char
*
path
);
extern
int
gitfo_shallow_exists
(
const
char
*
path
);
extern
int
gitfo_open
(
const
char
*
path
,
int
flags
);
extern
int
gitfo_creat
(
const
char
*
path
,
int
mode
);
extern
int
gitfo_creat_force
(
const
char
*
path
,
int
mode
);
...
...
@@ -94,6 +95,7 @@ extern int gitfo_mv_force(const char *from, const char *to);
#define gitfo_stat(p,b) stat(p, b)
#define gitfo_fstat(f,b) fstat(f, b)
#define gitfo_lstat(p,b) lstat(p,b)
#define gitfo_unlink(p) unlink(p)
#define gitfo_rmdir(p) rmdir(p)
...
...
src/index.c
View file @
3a12891f
...
...
@@ -138,6 +138,15 @@ int unmerged_cmp(const void *a, const void *b)
return
strcmp
(
info_a
->
path
,
info_b
->
path
);
}
unsigned
int
index_create_mode
(
unsigned
int
mode
)
{
if
(
S_ISLNK
(
mode
))
return
S_IFLNK
;
if
(
S_ISDIR
(
mode
)
||
(
mode
&
S_IFMT
)
==
0160000
)
return
0160000
;
return
S_IFREG
|
((
mode
&
0100
)
?
0755
:
0644
);
}
static
int
index_initialize
(
git_index
**
index_out
,
git_repository
*
owner
,
const
char
*
index_path
)
{
git_index
*
index
;
...
...
@@ -402,10 +411,10 @@ static int index_init_entry(git_index_entry *entry, git_index *index, const char
git__joinpath
(
full_path
,
index
->
repository
->
path_workdir
,
rel_path
);
if
(
gitfo_exists
(
full_path
)
<
0
)
if
(
gitfo_
shallow_
exists
(
full_path
)
<
0
)
return
git__throw
(
GIT_ENOTFOUND
,
"Failed to initialize entry. %s does not exist"
,
full_path
);
if
(
gitfo_stat
(
full_path
,
&
st
)
<
0
)
if
(
gitfo_
l
stat
(
full_path
,
&
st
)
<
0
)
return
git__throw
(
GIT_EOSERR
,
"Failed to initialize entry. %s appears to be corrupted"
,
full_path
);
if
(
stage
<
0
||
stage
>
3
)
...
...
@@ -419,7 +428,7 @@ static int index_init_entry(git_index_entry *entry, git_index *index, const char
/* entry.ctime.nanoseconds = st.st_ctimensec; */
entry
->
dev
=
st
.
st_rdev
;
entry
->
ino
=
st
.
st_ino
;
entry
->
mode
=
st
.
st_mode
;
entry
->
mode
=
index_create_mode
(
st
.
st_mode
)
;
entry
->
uid
=
st
.
st_uid
;
entry
->
gid
=
st
.
st_gid
;
entry
->
file_size
=
st
.
st_size
;
...
...
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