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
d0323a5f
Commit
d0323a5f
authored
Jun 01, 2011
by
Vicent Marti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
short-oid: Cleanup
parent
aea8a638
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
69 additions
and
46 deletions
+69
-46
include/git2/object.h
+11
-3
include/git2/odb.h
+1
-1
include/git2/odb_backend.h
+2
-2
src/backends/hiredis.c
+2
-2
src/backends/sqlite.c
+2
-2
src/object.c
+8
-9
src/odb.c
+7
-7
src/odb_loose.c
+15
-9
src/odb_pack.c
+21
-11
No files found.
include/git2/object.h
View file @
d0323a5f
...
...
@@ -56,7 +56,11 @@ GIT_BEGIN_DECL
* @param type the type of the object
* @return a reference to the object
*/
GIT_EXTERN
(
int
)
git_object_lookup
(
git_object
**
object
,
git_repository
*
repo
,
const
git_oid
*
id
,
git_otype
type
);
GIT_EXTERN
(
int
)
git_object_lookup
(
git_object
**
object
,
git_repository
*
repo
,
const
git_oid
*
id
,
git_otype
type
);
/**
* Lookup a reference to one of the objects in a repostory,
...
...
@@ -85,8 +89,12 @@ GIT_EXTERN(int) git_object_lookup(git_object **object, git_repository *repo, con
* @param type the type of the object
* @return a reference to the object
*/
GIT_EXTERN
(
int
)
git_object_lookup_short_oid
(
git_object
**
object_out
,
git_repository
*
repo
,
const
git_oid
*
id
,
unsigned
int
len
,
git_otype
type
);
GIT_EXTERN
(
int
)
git_object_lookup_prefix
(
git_object
**
object_out
,
git_repository
*
repo
,
const
git_oid
*
id
,
unsigned
int
len
,
git_otype
type
);
/**
* Get the id (SHA1) of a repository object
...
...
include/git2/odb.h
View file @
d0323a5f
...
...
@@ -154,7 +154,7 @@ GIT_EXTERN(int) git_odb_read(git_odb_object **out, git_odb *db, const git_oid *i
* - GIT_ENOTFOUND if the object is not in the database.
* - GIT_EAMBIGUOUS if the prefix is ambiguous (several objects match the prefix)
*/
GIT_EXTERN
(
int
)
git_odb_read_
unique_short_oid
(
git_oid
*
out_oid
,
git_odb_object
**
out
,
git_odb
*
db
,
const
git_oid
*
short_id
,
unsigned
int
len
);
GIT_EXTERN
(
int
)
git_odb_read_
prefix
(
git_odb_object
**
out
,
git_odb
*
db
,
const
git_oid
*
short_id
,
unsigned
int
len
);
/**
* Read the header of an object from the database, without
...
...
include/git2/odb_backend.h
View file @
d0323a5f
...
...
@@ -55,12 +55,12 @@ struct git_odb_backend {
* remaining (GIT_OID_HEXSZ - len)*4 bits
* are 0s.
*/
int
(
*
read_
unique_short_oid
)(
int
(
*
read_
prefix
)(
git_oid
*
,
void
**
,
size_t
*
,
git_otype
*
,
struct
git_odb_backend
*
,
const
git_oid
*
,
unsigned
int
len
);
unsigned
int
);
int
(
*
read_header
)(
size_t
*
,
git_otype
*
,
...
...
src/backends/hiredis.c
View file @
d0323a5f
...
...
@@ -107,7 +107,7 @@ int hiredis_backend__read(void **data_p, size_t *len_p, git_otype *type_p, git_o
return
error
==
GIT_SUCCESS
?
GIT_SUCCESS
:
git__rethrow
(
error
,
"Failed to read backend"
);
}
int
hiredis_backend__read_
unique_short_oid
(
git_oid
*
out_oid
,
void
**
data_p
,
size_t
*
len_p
,
git_otype
*
type_p
,
git_odb_backend
*
_backend
,
int
hiredis_backend__read_
prefix
(
git_oid
*
out_oid
,
void
**
data_p
,
size_t
*
len_p
,
git_otype
*
type_p
,
git_odb_backend
*
_backend
,
const
git_oid
*
short_oid
,
unsigned
int
len
)
{
if
(
len
>=
GIT_OID_HEXSZ
)
{
/* Just match the full identifier */
...
...
@@ -189,7 +189,7 @@ int git_odb_backend_hiredis(git_odb_backend **backend_out, const char *host, int
goto
cleanup
;
backend
->
parent
.
read
=
&
hiredis_backend__read
;
backend
->
parent
.
read_
unique_short_oid
=
&
hiredis_backend__read_unique_short_oid
;
backend
->
parent
.
read_
prefix
=
&
hiredis_backend__read_prefix
;
backend
->
parent
.
read_header
=
&
hiredis_backend__read_header
;
backend
->
parent
.
write
=
&
hiredis_backend__write
;
backend
->
parent
.
exists
=
&
hiredis_backend__exists
;
...
...
src/backends/sqlite.c
View file @
d0323a5f
...
...
@@ -103,7 +103,7 @@ int sqlite_backend__read(void **data_p, size_t *len_p, git_otype *type_p, git_od
return
error
==
GIT_SUCCESS
?
GIT_SUCCESS
:
git__rethrow
(
error
,
"SQLite backend: Failed to read"
);
}
int
sqlite_backend__read_
unique_short_oid
(
git_oid
*
out_oid
,
void
**
data_p
,
size_t
*
len_p
,
git_otype
*
type_p
,
git_odb_backend
*
_backend
,
int
sqlite_backend__read_
prefix
(
git_oid
*
out_oid
,
void
**
data_p
,
size_t
*
len_p
,
git_otype
*
type_p
,
git_odb_backend
*
_backend
,
const
git_oid
*
short_oid
,
unsigned
int
len
)
{
if
(
len
>=
GIT_OID_HEXSZ
)
{
/* Just match the full identifier */
...
...
@@ -270,7 +270,7 @@ int git_odb_backend_sqlite(git_odb_backend **backend_out, const char *sqlite_db)
goto
cleanup
;
backend
->
parent
.
read
=
&
sqlite_backend__read
;
backend
->
parent
.
read_
unique_short_oid
=
&
sqlite_backend__read_unique_short_oid
;
backend
->
parent
.
read_
prefix
=
&
sqlite_backend__read_prefix
;
backend
->
parent
.
read_header
=
&
sqlite_backend__read_header
;
backend
->
parent
.
write
=
&
sqlite_backend__write
;
backend
->
parent
.
exists
=
&
sqlite_backend__exists
;
...
...
src/object.c
View file @
d0323a5f
...
...
@@ -95,20 +95,20 @@ static int create_object(git_object **object_out, git_otype type)
return
GIT_SUCCESS
;
}
int
git_object_lookup_
short_oid
(
git_object
**
object_out
,
git_repository
*
repo
,
const
git_oid
*
id
,
unsigned
int
len
,
git_otype
type
)
int
git_object_lookup_
prefix
(
git_object
**
object_out
,
git_repository
*
repo
,
const
git_oid
*
id
,
unsigned
int
len
,
git_otype
type
)
{
git_object
*
object
=
NULL
;
git_odb_object
*
odb_obj
;
int
error
=
GIT_SUCCESS
;
git_oid
out_oid
;
assert
(
repo
&&
object_out
&&
id
);
if
(
len
<
GIT_OID_MINPREFIXLEN
)
return
git__throw
(
GIT_EAMBIGUOUSOIDPREFIX
,
"Failed to lookup object. Prefix length is lower than %d."
,
GIT_OID_MINPREFIXLEN
);
if
(
len
>
GIT_OID_HEXSZ
)
{
return
git__throw
(
GIT_EAMBIGUOUSOIDPREFIX
,
"Failed to lookup object. Prefix length is lower than %d."
,
GIT_OID_MINPREFIXLEN
);
if
(
len
>
GIT_OID_HEXSZ
)
len
=
GIT_OID_HEXSZ
;
}
if
(
len
==
GIT_OID_HEXSZ
)
{
/* We want to match the full id : we can first look up in the cache,
...
...
@@ -129,7 +129,6 @@ int git_object_lookup_short_oid(git_object **object_out, git_repository *repo, c
* but it may be much more costly for sqlite and hiredis.
*/
error
=
git_odb_read
(
&
odb_obj
,
repo
->
db
,
id
);
git_oid_cpy
(
&
out_oid
,
id
);
}
else
{
git_oid
short_oid
;
...
...
@@ -149,7 +148,7 @@ int git_object_lookup_short_oid(git_object **object_out, git_repository *repo, c
* - We never explore the cache, go right to exploring the backends
* We chose the latter : we explore directly the backends.
*/
error
=
git_odb_read_
unique_short_oid
(
&
out_oid
,
&
odb_obj
,
repo
->
db
,
&
short_oid
,
len
);
error
=
git_odb_read_
prefix
(
&
odb_obj
,
repo
->
db
,
&
short_oid
,
len
);
}
if
(
error
<
GIT_SUCCESS
)
...
...
@@ -166,7 +165,7 @@ int git_object_lookup_short_oid(git_object **object_out, git_repository *repo, c
return
git__rethrow
(
error
,
"Failed to lookup object"
);
/* Initialize parent object */
git_oid_cpy
(
&
object
->
cached
.
oid
,
&
o
ut_
oid
);
git_oid_cpy
(
&
object
->
cached
.
oid
,
&
o
db_obj
->
cached
.
oid
);
object
->
repo
=
repo
;
switch
(
type
)
{
...
...
@@ -202,7 +201,7 @@ int git_object_lookup_short_oid(git_object **object_out, git_repository *repo, c
}
int
git_object_lookup
(
git_object
**
object_out
,
git_repository
*
repo
,
const
git_oid
*
id
,
git_otype
type
)
{
return
git_object_lookup_
short_oid
(
object_out
,
repo
,
id
,
GIT_OID_HEXSZ
,
type
);
return
git_object_lookup_
prefix
(
object_out
,
repo
,
id
,
GIT_OID_HEXSZ
,
type
);
}
void
git_object__free
(
void
*
_obj
)
...
...
src/odb.c
View file @
d0323a5f
...
...
@@ -488,34 +488,34 @@ int git_odb_read(git_odb_object **out, git_odb *db, const git_oid *id)
return
error
;
}
int
git_odb_read_
unique_short_oid
(
git_oid
*
out_oid
,
git_odb_object
**
out
,
git_odb
*
db
,
const
git_oid
*
short_id
,
unsigned
int
len
)
int
git_odb_read_
prefix
(
git_odb_object
**
out
,
git_odb
*
db
,
const
git_oid
*
short_id
,
unsigned
int
len
)
{
unsigned
int
i
;
int
error
=
GIT_ENOTFOUND
;
git_oid
full_oid
;
git_rawobj
raw
;
int
found
=
0
;
assert
(
out
&&
db
&&
id
);
assert
(
out
&&
db
);
if
(
len
<
GIT_OID_MINPREFIXLEN
)
return
git__throw
(
GIT_EAMBIGUOUSOIDPREFIX
,
"Failed to lookup object. Prefix length is lower than %d."
,
GIT_OID_MINPREFIXLEN
);
if
(
len
>
GIT_OID_HEXSZ
)
len
=
GIT_OID_HEXSZ
;
if
(
len
==
GIT_OID_HEXSZ
)
{
*
out
=
git_cache_get
(
&
db
->
cache
,
short_id
);
if
(
*
out
!=
NULL
)
{
git_oid_cpy
(
out_oid
,
short_id
);
if
(
*
out
!=
NULL
)
return
GIT_SUCCESS
;
}
}
for
(
i
=
0
;
i
<
db
->
backends
.
length
&&
found
<
2
;
++
i
)
{
backend_internal
*
internal
=
git_vector_get
(
&
db
->
backends
,
i
);
git_odb_backend
*
b
=
internal
->
backend
;
if
(
b
->
read
!=
NULL
)
{
error
=
b
->
read_
unique_short_oid
(
out
_oid
,
&
raw
.
data
,
&
raw
.
len
,
&
raw
.
type
,
b
,
short_id
,
len
);
error
=
b
->
read_
prefix
(
&
full
_oid
,
&
raw
.
data
,
&
raw
.
len
,
&
raw
.
type
,
b
,
short_id
,
len
);
switch
(
error
)
{
case
GIT_SUCCESS
:
found
++
;
...
...
@@ -531,7 +531,7 @@ int git_odb_read_unique_short_oid(git_oid *out_oid, git_odb_object **out, git_od
}
if
(
found
==
1
)
{
*
out
=
git_cache_try_store
(
&
db
->
cache
,
new_odb_object
(
out
_oid
,
&
raw
));
*
out
=
git_cache_try_store
(
&
db
->
cache
,
new_odb_object
(
&
full
_oid
,
&
raw
));
}
else
if
(
found
>
1
)
{
return
git__throw
(
GIT_EAMBIGUOUSOIDPREFIX
,
"Failed to read object. Ambiguous sha1 prefix"
);
}
else
{
...
...
src/odb_loose.c
View file @
d0323a5f
...
...
@@ -29,6 +29,7 @@
#include "fileops.h"
#include "hash.h"
#include "odb.h"
#include "oid.h"
#include "delta-apply.h"
#include "filebuf.h"
...
...
@@ -491,7 +492,7 @@ int fn_locate_object_short_oid(void *state, char *pathbuf) {
if
(
!
gitfo_exists
(
pathbuf
)
&&
gitfo_isdir
(
pathbuf
))
{
/* We are already in the directory matching the 2 first hex characters */
if
(
!
git_oid_match_hex
(
sstate
->
short_oid_len
-
2
,
sstate
->
short_oid
+
2
,
pathbuf
+
sstate
->
dir_len
))
{
if
(
!
git_oid_match_hex
(
sstate
->
short_oid_len
-
2
,
sstate
->
short_oid
+
2
,
(
unsigned
char
*
)
pathbuf
+
sstate
->
dir_len
))
{
if
(
!
sstate
->
found
)
{
sstate
->
res_oid
[
0
]
=
sstate
->
short_oid
[
0
];
sstate
->
res_oid
[
1
]
=
sstate
->
short_oid
[
1
];
...
...
@@ -500,11 +501,10 @@ int fn_locate_object_short_oid(void *state, char *pathbuf) {
sstate
->
found
++
;
}
}
if
(
sstate
->
found
>
1
)
{
if
(
sstate
->
found
>
1
)
return
git__throw
(
GIT_EAMBIGUOUSOIDPREFIX
,
"Ambiguous sha1 prefix within loose objects"
);
}
else
{
return
GIT_SUCCESS
;
}
}
/* Locate an object matching a given short oid */
...
...
@@ -525,7 +525,7 @@ static int locate_object_short_oid(char *object_location, git_oid *res_oid, loos
object_location
[
dir_len
++
]
=
'/'
;
/* Convert raw oid to hex formatted oid */
git_oid_fmt
(
state
.
short_oid
,
short_oid
);
git_oid_fmt
(
(
char
*
)
state
.
short_oid
,
short_oid
);
/* Explore OBJ_DIR/xx/ where xx is the beginning of hex formatted short oid */
sprintf
(
object_location
+
dir_len
,
"%.2s/"
,
state
.
short_oid
);
...
...
@@ -546,7 +546,7 @@ static int locate_object_short_oid(char *object_location, git_oid *res_oid, loos
}
/* Convert obtained hex formatted oid to raw */
error
=
git_oid_mkstr
(
res_oid
,
state
.
res_oid
);
error
=
git_oid_mkstr
(
res_oid
,
(
char
*
)
state
.
res_oid
);
if
(
error
)
{
return
git__rethrow
(
error
,
"Failed to locate object from short oid"
);
}
...
...
@@ -616,8 +616,14 @@ int loose_backend__read(void **buffer_p, size_t *len_p, git_otype *type_p, git_o
return
GIT_SUCCESS
;
}
int
loose_backend__read_unique_short_oid
(
git_oid
*
out_oid
,
void
**
buffer_p
,
size_t
*
len_p
,
git_otype
*
type_p
,
git_odb_backend
*
backend
,
const
git_oid
*
short_oid
,
unsigned
int
len
)
int
loose_backend__read_prefix
(
git_oid
*
out_oid
,
void
**
buffer_p
,
size_t
*
len_p
,
git_otype
*
type_p
,
git_odb_backend
*
backend
,
const
git_oid
*
short_oid
,
unsigned
int
len
)
{
if
(
len
<
GIT_OID_MINPREFIXLEN
)
return
git__throw
(
GIT_EAMBIGUOUSOIDPREFIX
,
"Failed to read loose backend. Prefix length is lower than %d."
,
GIT_OID_MINPREFIXLEN
);
...
...
@@ -790,7 +796,7 @@ int git_odb_backend_loose(git_odb_backend **backend_out, const char *objects_dir
backend
->
fsync_object_files
=
0
;
backend
->
parent
.
read
=
&
loose_backend__read
;
backend
->
parent
.
read_
unique_short_oid
=
&
loose_backend__read_unique_short_oid
;
backend
->
parent
.
read_
prefix
=
&
loose_backend__read_prefix
;
backend
->
parent
.
read_header
=
&
loose_backend__read_header
;
backend
->
parent
.
writestream
=
&
loose_backend__stream
;
backend
->
parent
.
exists
=
&
loose_backend__exists
;
...
...
src/odb_pack.c
View file @
d0323a5f
...
...
@@ -294,7 +294,7 @@ static int pack_entry_find(struct pack_entry *e,
* This method assumes that len is between
* GIT_OID_MINPREFIXLEN and GIT_OID_HEXSZ.
*/
static
int
pack_entry_find_
unique_short_oid
(
struct
pack_entry
*
e
,
static
int
pack_entry_find_
prefix
(
struct
pack_entry
*
e
,
struct
pack_backend
*
backend
,
const
git_oid
*
short_oid
,
unsigned
int
len
);
...
...
@@ -1006,9 +1006,9 @@ static int pack_entry_find_offset(
current
=
index
+
pos
*
stride
;
}
else
{
/* No object was found */
pos
=
-
1
-
pos
;
/* pos refers to the object with the "closest" oid to short_oid */
if
(
pos
<
p
->
num_objects
)
{
pos
=
-
1
-
pos
;
if
(
pos
<
(
int
)
p
->
num_objects
)
{
current
=
index
+
pos
*
stride
;
if
(
!
git_oid_match_raw
(
len
,
short_oid
->
id
,
current
))
{
...
...
@@ -1016,7 +1016,8 @@ static int pack_entry_find_offset(
}
}
}
if
(
found
&&
pos
+
1
<
p
->
num_objects
)
{
if
(
found
&&
pos
+
1
<
(
int
)
p
->
num_objects
)
{
/* Check for ambiguousity */
const
unsigned
char
*
next
=
current
+
stride
;
...
...
@@ -1106,8 +1107,11 @@ static int pack_entry_find(struct pack_entry *e, struct pack_backend *backend, c
return
git__throw
(
GIT_ENOTFOUND
,
"Failed to find pack entry"
);
}
static
int
pack_entry_find_unique_short_oid
(
struct
pack_entry
*
e
,
struct
pack_backend
*
backend
,
const
git_oid
*
short_oid
,
unsigned
int
len
)
static
int
pack_entry_find_prefix
(
struct
pack_entry
*
e
,
struct
pack_backend
*
backend
,
const
git_oid
*
short_oid
,
unsigned
int
len
)
{
int
error
;
size_t
i
;
...
...
@@ -1137,7 +1141,7 @@ static int pack_entry_find_unique_short_oid(struct pack_entry *e, struct pack_ba
return
git__rethrow
(
error
,
"Failed to find pack entry. Ambiguous sha1 prefix"
);
}
else
if
(
error
==
GIT_SUCCESS
)
{
found
++
;
if
(
found
>
1
)
;
if
(
found
>
1
)
break
;
backend
->
last_found
=
p
;
}
...
...
@@ -1462,8 +1466,14 @@ int pack_backend__read(void **buffer_p, size_t *len_p, git_otype *type_p, git_od
return
GIT_SUCCESS
;
}
int
pack_backend__read_unique_short_oid
(
git_oid
*
out_oid
,
void
**
buffer_p
,
size_t
*
len_p
,
git_otype
*
type_p
,
git_odb_backend
*
backend
,
const
git_oid
*
short_oid
,
unsigned
int
len
)
int
pack_backend__read_prefix
(
git_oid
*
out_oid
,
void
**
buffer_p
,
size_t
*
len_p
,
git_otype
*
type_p
,
git_odb_backend
*
backend
,
const
git_oid
*
short_oid
,
unsigned
int
len
)
{
if
(
len
<
GIT_OID_MINPREFIXLEN
)
return
git__throw
(
GIT_EAMBIGUOUSOIDPREFIX
,
"Failed to read pack backend. Prefix length is lower than %d."
,
GIT_OID_MINPREFIXLEN
);
...
...
@@ -1480,7 +1490,7 @@ int pack_backend__read_unique_short_oid(git_oid *out_oid, void **buffer_p, size_
git_rawobj
raw
;
int
error
;
if
((
error
=
pack_entry_find_
unique_short_oid
(
&
e
,
(
struct
pack_backend
*
)
backend
,
short_oid
,
len
))
<
GIT_SUCCESS
)
if
((
error
=
pack_entry_find_
prefix
(
&
e
,
(
struct
pack_backend
*
)
backend
,
short_oid
,
len
))
<
GIT_SUCCESS
)
return
git__rethrow
(
error
,
"Failed to read pack backend"
);
if
((
error
=
packfile_unpack
(
&
raw
,
(
struct
pack_backend
*
)
backend
,
e
.
p
,
e
.
offset
))
<
GIT_SUCCESS
)
...
...
@@ -1549,7 +1559,7 @@ int git_odb_backend_pack(git_odb_backend **backend_out, const char *objects_dir)
}
backend
->
parent
.
read
=
&
pack_backend__read
;
backend
->
parent
.
read_
unique_short_oid
=
&
pack_backend__read_unique_short_oid
;
backend
->
parent
.
read_
prefix
=
&
pack_backend__read_prefix
;
backend
->
parent
.
read_header
=
NULL
;
backend
->
parent
.
exists
=
&
pack_backend__exists
;
backend
->
parent
.
free
=
&
pack_backend__free
;
...
...
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