Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
heptapod
hgitaly
Commits
e985245bdaa0
Commit
e985245b
authored
Feb 28, 2021
by
Sushil Khanchi
🐨
Browse files
CommitDelta: yield response data in batches
parent
435c18365c19
Changes
1
Hide whitespace changes
Inline
Side-by-side
hgitaly/service/diff.py
View file @
e985245b
...
...
@@ -47,6 +47,7 @@
from
..servicer
import
HGitalyServicer
from
..revision
import
gitlab_revision_changeset
from
..stream
import
(
aggregate_flush_batch
,
concat_resplit
,
iter_boolean_lookahead
,
split_batches
,
...
...
@@ -334,24 +335,25 @@
match
=
m
,
opts
=
diffopts
)
batch
=
[]
for
header
in
patchmod
.
parsepatch
(
diffchunks
):
from_path
,
to_path
=
old_new_file_path
(
header
)
from_id
,
to_id
=
old_new_blob_oids
(
header
,
ctx_from
,
ctx_to
)
old_mode
,
new_mode
=
old_new_file_mode
(
header
,
ctx_from
,
ctx_to
)
# For CommitDeltaResponse, modes are returned in decimal form
old_mode
,
new_mode
=
int
(
old_mode
,
8
),
int
(
new_mode
,
8
)
# As per Gitaly/Git behavior, if current Delta is a Rename and
# if `from_path` is missing in `request.paths`, the other file
# should be considered as Added instead of a Rename
if
(
request
.
paths
and
from_path
!=
to_path
and
from_path
not
in
request
.
paths
):
# considering `to_path` as added
from_path
=
to_path
from_id
=
nullhex
old_mode
=
0
batch
.
append
(
MsgCommitDelta
(
def
in_deltas
():
for
header
in
patchmod
.
parsepatch
(
diffchunks
):
from_path
,
to_path
=
old_new_file_path
(
header
)
from_id
,
to_id
=
old_new_blob_oids
(
header
,
ctx_from
,
ctx_to
)
old_mode
,
new_mode
=
old_new_file_mode
(
header
,
ctx_from
,
ctx_to
)
# For CommitDeltaResponse, modes are returned in decimal form
old_mode
,
new_mode
=
int
(
old_mode
,
8
),
int
(
new_mode
,
8
)
# As per Gitaly/Git behavior, if current Delta is a Rename and
# if `from_path` is missing in `request.paths`, the other file
# should be considered as Added instead of a Rename
if
(
request
.
paths
and
from_path
!=
to_path
and
from_path
not
in
request
.
paths
):
# considering `to_path` as added
from_path
=
to_path
from_id
=
nullhex
old_mode
=
0
delta
=
MsgCommitDelta
(
from_path
=
from_path
,
to_path
=
to_path
,
from_id
=
from_id
,
...
...
@@ -359,8 +361,10 @@
old_mode
=
old_mode
,
new_mode
=
new_mode
,
)
)
yield
CommitDeltaResponse
(
deltas
=
batch
)
yield
delta
for
batch
in
aggregate_flush_batch
(
in_deltas
(),
commit_delta_size
,
DIFF_MSG_SIZE_THRESHOLD
):
yield
CommitDeltaResponse
(
deltas
=
batch
)
def
RawDiff
(
self
,
request
:
RawDiffRequest
,
context
)
->
RawDiffResponse
:
...
...
@@ -548,3 +552,12 @@
chunkiter
=
patchmod
.
diff
(
repo
,
p1
,
node
,
opts
=
diffopts
)
for
chunk
in
chunkiter
:
yield
chunk
def
commit_delta_size
(
delta
):
size
=
(
len
(
delta
.
from_id
)
+
len
(
delta
.
to_id
)
+
4
+
4
# old_mode and new_mode are int, each 4 bytes
+
len
(
delta
.
from_path
)
+
len
(
delta
.
to_path
)
)
return
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