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
72139ef2
Commit
72139ef2
authored
Apr 23, 2023
by
Edward Thomson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
shallow: don't assume SHA1
parent
3853ba8d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
26 deletions
+46
-26
src/libgit2/repository.c
+4
-2
src/libgit2/transports/smart_pkt.c
+42
-24
No files found.
src/libgit2/repository.c
View file @
72139ef2
...
...
@@ -3670,13 +3670,14 @@ int git_repository__shallow_roots_write(git_repository *repo, git_array_oid_t ro
{
git_filebuf
file
=
GIT_FILEBUF_INIT
;
git_str
path
=
GIT_STR_INIT
;
char
oid_str
[
GIT_OID_MAX_HEXSIZE
+
1
];
size_t
idx
;
git_oid
*
oid
;
int
filebuf_hash
,
error
=
0
;
GIT_ASSERT_ARG
(
repo
);
filebuf_hash
=
git_filebuf_hash_flags
(
git_oid_algorithm
(
GIT_OID_SHA1
));
filebuf_hash
=
git_filebuf_hash_flags
(
git_oid_algorithm
(
repo
->
oid_type
));
GIT_ASSERT
(
filebuf_hash
);
if
((
error
=
git_str_joinpath
(
&
path
,
repo
->
gitdir
,
"shallow"
))
<
0
)
...
...
@@ -3686,7 +3687,8 @@ int git_repository__shallow_roots_write(git_repository *repo, git_array_oid_t ro
goto
on_error
;
git_array_foreach
(
roots
,
idx
,
oid
)
{
git_filebuf_write
(
&
file
,
git_oid_tostr_s
(
oid
),
GIT_OID_SHA1_HEXSIZE
);
git_oid_tostr
(
oid_str
,
sizeof
(
oid_str
),
oid
);
git_filebuf_write
(
&
file
,
oid_str
,
git_oid_hexsize
(
repo
->
oid_type
));
git_filebuf_write
(
&
file
,
"
\n
"
,
1
);
}
...
...
src/libgit2/transports/smart_pkt.c
View file @
72139ef2
...
...
@@ -44,9 +44,14 @@ static int flush_pkt(git_pkt **out)
}
/* the rest of the line will be useful for multi_ack and multi_ack_detailed */
static
int
ack_pkt
(
git_pkt
**
out
,
const
char
*
line
,
size_t
len
)
static
int
ack_pkt
(
git_pkt
**
out
,
const
char
*
line
,
size_t
len
,
git_pkt_parse_data
*
data
)
{
git_pkt_ack
*
pkt
;
size_t
oid_hexsize
=
git_oid_hexsize
(
data
->
oid_type
);
pkt
=
git__calloc
(
1
,
sizeof
(
git_pkt_ack
));
GIT_ERROR_CHECK_ALLOC
(
pkt
);
...
...
@@ -57,11 +62,11 @@ static int ack_pkt(git_pkt **out, const char *line, size_t len)
line
+=
4
;
len
-=
4
;
if
(
len
<
GIT_OID_SHA1_HEXSIZE
||
git_oid__fromstr
(
&
pkt
->
oid
,
line
,
GIT_OID_SHA1
)
<
0
)
if
(
len
<
oid_hexsize
||
git_oid__fromstr
(
&
pkt
->
oid
,
line
,
data
->
oid_type
)
<
0
)
goto
out_err
;
line
+=
GIT_OID_SHA1_HEXSIZE
;
len
-=
GIT_OID_SHA1_HEXSIZE
;
line
+=
oid_hexsize
;
len
-=
oid_hexsize
;
if
(
len
&&
line
[
0
]
==
' '
)
{
line
++
;
...
...
@@ -436,9 +441,14 @@ static int unpack_pkt(git_pkt **out, const char *line, size_t len)
return
0
;
}
static
int
shallow_pkt
(
git_pkt
**
out
,
const
char
*
line
,
size_t
len
)
static
int
shallow_pkt
(
git_pkt
**
out
,
const
char
*
line
,
size_t
len
,
git_pkt_parse_data
*
data
)
{
git_pkt_shallow
*
pkt
;
size_t
oid_hexsize
=
git_oid_hexsize
(
data
->
oid_type
);
pkt
=
git__calloc
(
1
,
sizeof
(
git_pkt_shallow
));
GIT_ERROR_CHECK_ALLOC
(
pkt
);
...
...
@@ -451,13 +461,14 @@ static int shallow_pkt(git_pkt **out, const char *line, size_t len)
line
+=
8
;
len
-=
8
;
if
(
len
>=
GIT_OID_SHA1_HEXSIZE
)
{
git_oid__fromstr
(
&
pkt
->
oid
,
line
,
GIT_OID_SHA1
);
line
+=
GIT_OID_SHA1_HEXSIZE
+
1
;
len
-=
GIT_OID_SHA1_HEXSIZE
+
1
;
}
if
(
len
!=
oid_hexsize
)
goto
out_err
;
*
out
=
(
git_pkt
*
)
pkt
;
git_oid__fromstr
(
&
pkt
->
oid
,
line
,
data
->
oid_type
);
line
+=
oid_hexsize
+
1
;
len
-=
oid_hexsize
+
1
;
*
out
=
(
git_pkt
*
)
pkt
;
return
0
;
...
...
@@ -467,9 +478,14 @@ out_err:
return
-
1
;
}
static
int
unshallow_pkt
(
git_pkt
**
out
,
const
char
*
line
,
size_t
len
)
static
int
unshallow_pkt
(
git_pkt
**
out
,
const
char
*
line
,
size_t
len
,
git_pkt_parse_data
*
data
)
{
git_pkt_shallow
*
pkt
;
size_t
oid_hexsize
=
git_oid_hexsize
(
data
->
oid_type
);
pkt
=
git__calloc
(
1
,
sizeof
(
git_pkt_shallow
));
GIT_ERROR_CHECK_ALLOC
(
pkt
);
...
...
@@ -482,11 +498,12 @@ static int unshallow_pkt(git_pkt **out, const char *line, size_t len)
line
+=
10
;
len
-=
10
;
if
(
len
>=
GIT_OID_SHA1_HEXSIZE
)
{
git_oid__fromstr
(
&
pkt
->
oid
,
line
,
GIT_OID_SHA1
);
line
+=
GIT_OID_SHA1_HEXSIZE
+
1
;
len
-=
GIT_OID_SHA1_HEXSIZE
+
1
;
}
if
(
len
!=
oid_hexsize
)
goto
out_err
;
git_oid__fromstr
(
&
pkt
->
oid
,
line
,
data
->
oid_type
);
line
+=
oid_hexsize
+
1
;
len
-=
oid_hexsize
+
1
;
*
out
=
(
git_pkt
*
)
pkt
;
...
...
@@ -615,7 +632,7 @@ int git_pkt_parse_line(
else
if
(
*
line
==
GIT_SIDE_BAND_ERROR
)
error
=
sideband_error_pkt
(
pkt
,
line
,
len
);
else
if
(
!
git__prefixncmp
(
line
,
len
,
"ACK"
))
error
=
ack_pkt
(
pkt
,
line
,
len
);
error
=
ack_pkt
(
pkt
,
line
,
len
,
data
);
else
if
(
!
git__prefixncmp
(
line
,
len
,
"NAK"
))
error
=
nak_pkt
(
pkt
);
else
if
(
!
git__prefixncmp
(
line
,
len
,
"ERR"
))
...
...
@@ -629,9 +646,9 @@ int git_pkt_parse_line(
else
if
(
!
git__prefixncmp
(
line
,
len
,
"unpack"
))
error
=
unpack_pkt
(
pkt
,
line
,
len
);
else
if
(
!
git__prefixcmp
(
line
,
"shallow"
))
error
=
shallow_pkt
(
pkt
,
line
,
len
);
error
=
shallow_pkt
(
pkt
,
line
,
len
,
data
);
else
if
(
!
git__prefixcmp
(
line
,
"unshallow"
))
error
=
unshallow_pkt
(
pkt
,
line
,
len
);
error
=
unshallow_pkt
(
pkt
,
line
,
len
,
data
);
else
error
=
ref_pkt
(
pkt
,
line
,
len
,
data
);
...
...
@@ -788,12 +805,13 @@ int git_pkt_buffer_wants(
/* Tell the server about our shallow objects */
for
(
i
=
0
;
i
<
git_shallowarray_count
(
wants
->
shallow_roots
);
i
++
)
{
char
oid
[
GIT_OID_
SHA1_HEXSIZE
];
char
oid
[
GIT_OID_
MAX_HEXSIZE
+
1
];
git_str
shallow_buf
=
GIT_STR_INIT
;
git_oid_fmt
(
oid
,
git_shallowarray_get
(
wants
->
shallow_roots
,
i
));
git_oid_tostr
(
oid
,
GIT_OID_MAX_HEXSIZE
+
1
,
git_shallowarray_get
(
wants
->
shallow_roots
,
i
));
git_str_puts
(
&
shallow_buf
,
"shallow "
);
git_str_put
(
&
shallow_buf
,
oid
,
GIT_OID_SHA1_HEXSIZE
);
git_str_put
s
(
&
shallow_buf
,
oid
);
git_str_putc
(
&
shallow_buf
,
'\n'
);
git_str_printf
(
buf
,
"%04x%s"
,
(
unsigned
int
)
git_str_len
(
&
shallow_buf
)
+
4
,
git_str_cstr
(
&
shallow_buf
));
...
...
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