Commit e985245b authored by Sushil Khanchi's avatar Sushil Khanchi 🐨
Browse files

CommitDelta: yield response data in batches

parent 435c18365c19
......@@ -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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment