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
18e5b854
Commit
18e5b854
authored
Feb 10, 2012
by
Vicent Martí
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
odb: Add internal `git_odb__hashfd`
parent
9b8d5608
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
24 deletions
+32
-24
src/indexer.c
+1
-1
src/odb.c
+28
-22
src/odb.h
+3
-1
No files found.
src/indexer.c
View file @
18e5b854
...
...
@@ -345,7 +345,7 @@ int git_indexer_run(git_indexer *idx, git_indexer_stats *stats)
}
/* FIXME: Parse the object instead of hashing it */
error
=
git_odb__hash
_
obj
(
&
oid
,
&
obj
);
error
=
git_odb__hashobj
(
&
oid
,
&
obj
);
if
(
error
<
GIT_SUCCESS
)
{
error
=
git__rethrow
(
error
,
"Failed to hash object"
);
goto
cleanup
;
...
...
src/odb.c
View file @
18e5b854
...
...
@@ -33,13 +33,13 @@ static int format_object_header(char *hdr, size_t n, size_t obj_len, git_otype o
const
char
*
type_str
=
git_object_type2string
(
obj_type
);
int
len
=
p_snprintf
(
hdr
,
n
,
"%s %"
PRIuZ
,
type_str
,
obj_len
);
if
(
len
<
0
||
((
size_t
)
len
)
>=
n
)
if
(
len
<
0
||
len
>=
(
int
)
n
)
return
git__throw
(
GIT_ERROR
,
"Cannot format object header. Length is out of bounds"
);
return
len
+
1
;
}
int
git_odb__hash
_
obj
(
git_oid
*
id
,
git_rawobj
*
obj
)
int
git_odb__hashobj
(
git_oid
*
id
,
git_rawobj
*
obj
)
{
git_buf_vec
vec
[
2
];
char
header
[
64
];
...
...
@@ -113,22 +113,13 @@ void git_odb_object_free(git_odb_object *object)
git_cached_obj_decref
((
git_cached_obj
*
)
object
,
&
free_odb_object
);
}
int
git_odb_
hashfile
(
git_oid
*
out
,
const
char
*
path
,
git_otype
type
)
int
git_odb_
_hashfd
(
git_oid
*
out
,
git_file
fd
,
size_t
size
,
git_otype
type
)
{
int
fd
,
hdr_len
;
int
hdr_len
;
char
hdr
[
64
],
buffer
[
2048
];
git_off_t
size
;
git_hash_ctx
*
ctx
;
if
((
fd
=
p_open
(
path
,
O_RDONLY
))
<
0
)
return
git__throw
(
GIT_ENOTFOUND
,
"Could not open '%s'"
,
path
);
if
((
size
=
git_futils_filesize
(
fd
))
<
0
||
!
git__is_sizet
(
size
))
{
p_close
(
fd
);
return
git__throw
(
GIT_EOSERR
,
"'%s' appears to be corrupted"
,
path
);
}
hdr_len
=
format_object_header
(
hdr
,
sizeof
(
hdr
),
(
size_t
)
size
,
type
);
hdr_len
=
format_object_header
(
hdr
,
sizeof
(
hdr
),
size
,
type
);
if
(
hdr_len
<
0
)
return
git__throw
(
GIT_ERROR
,
"Failed to format blob header. Length is out of bounds"
);
...
...
@@ -137,28 +128,43 @@ int git_odb_hashfile(git_oid *out, const char *path, git_otype type)
git_hash_update
(
ctx
,
hdr
,
hdr_len
);
while
(
size
>
0
)
{
ssize_t
read_len
;
read_len
=
read
(
fd
,
buffer
,
sizeof
(
buffer
));
ssize_t
read_len
=
read
(
fd
,
buffer
,
sizeof
(
buffer
));
if
(
read_len
<
0
)
{
p_close
(
fd
);
git_hash_free_ctx
(
ctx
);
return
git__throw
(
GIT_EOSERR
,
"
Can't read full file '%s'"
,
path
);
return
git__throw
(
GIT_EOSERR
,
"
Error when reading file: %s"
,
strerror
(
errno
)
);
}
git_hash_update
(
ctx
,
buffer
,
read_len
);
size
-=
read_len
;
}
p_close
(
fd
);
git_hash_final
(
out
,
ctx
);
git_hash_free_ctx
(
ctx
);
return
GIT_SUCCESS
;
}
int
git_odb_hashfile
(
git_oid
*
out
,
const
char
*
path
,
git_otype
type
)
{
int
fd
,
error
;
git_off_t
size
;
if
((
fd
=
p_open
(
path
,
O_RDONLY
))
<
0
)
return
git__throw
(
GIT_ENOTFOUND
,
"Could not open '%s'"
,
path
);
if
((
size
=
git_futils_filesize
(
fd
))
<
0
||
!
git__is_sizet
(
size
))
{
p_close
(
fd
);
return
git__throw
(
GIT_EOSERR
,
"File size overflow. The object is too big to fit in 32-bit mode"
);
}
error
=
git_odb__hashfd
(
out
,
fd
,
(
size_t
)
size
,
type
);
p_close
(
fd
);
return
error
;
}
int
git_odb_hash
(
git_oid
*
id
,
const
void
*
data
,
size_t
len
,
git_otype
type
)
{
git_rawobj
raw
;
...
...
@@ -169,7 +175,7 @@ int git_odb_hash(git_oid *id, const void *data, size_t len, git_otype type)
raw
.
len
=
len
;
raw
.
type
=
type
;
return
git_odb__hash
_
obj
(
id
,
&
raw
);
return
git_odb__hashobj
(
id
,
&
raw
);
}
/**
...
...
src/odb.h
View file @
18e5b854
...
...
@@ -13,6 +13,7 @@
#include "vector.h"
#include "cache.h"
#include "posix.h"
#define GIT_OBJECTS_DIR "objects/"
#define GIT_OBJECT_DIR_MODE 0777
...
...
@@ -38,6 +39,7 @@ struct git_odb {
git_cache
cache
;
};
int
git_odb__hash_obj
(
git_oid
*
id
,
git_rawobj
*
obj
);
int
git_odb__hashobj
(
git_oid
*
id
,
git_rawobj
*
obj
);
int
git_odb__hashfd
(
git_oid
*
out
,
git_file
fd
,
size_t
size
,
git_otype
type
);
#endif
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