Skip to content
Snippets Groups Projects

repositoryService: implement GetRawChanges

Open Sushil Khanchi requested to merge topic/default/repository-GetRawChanges into branch/default
1 unresolved thread
1 file
+ 83
0
Compare changes
  • Side-by-side
  • Inline
@@ -17,6 +17,8 @@
CreateRepositoryRequest,
FindMergeBaseRequest,
SetFullPathRequest,
GetRawChangesRequest,
GetRawChangesResponse,
)
from hgitaly.stub.repository_service_pb2_grpc import RepositoryServiceStub
@@ -24,6 +26,9 @@
if skip_comparison_tests(): # pragma no cover
pytestmark = pytest.mark.skip
OPERATION_TYPES = dict(GetRawChangesResponse.RawChange.Operation.items())
NULLHEX = node_mod.nullhex
def test_compare_find_merge_base(gitaly_comparison):
fixture = gitaly_comparison
@@ -189,3 +194,81 @@
grpc_repo=Repository(
relative_path=fixture.gitaly_repo.relative_path,
storage_name='unknown'))
def test_get_raw_changes(gitaly_comparison):
fixture = gitaly_comparison
wrapper = fixture.hg_repo_wrapper
# Repo structure:
#
# @ 4 Rename barcopy to foobar
# |
# o 3 Removed bar
# |
# o 2 Copy bar to barcopy
# |
# o 1 Modified bar
# |
# o 0 Add bar
#
ctx0 = wrapper.commit_file('bar', message=b'add bar')
ctx1 = wrapper.commit_file('bar', content=b'modified bar')
wrapper.command(b'cp', wrapper.repo.root + b'/bar',
wrapper.repo.root + b'/barcopy')
ctx2 = wrapper.commit(rel_paths=['barcopy'], add_remove=True,
message=b'copy bar to barcopy')
wrapper.command(b'mv', wrapper.repo.root + b'/barcopy',
wrapper.repo.root + b'/foobar')
ctx3 = wrapper.commit([b'foobar', b'barcopy'],
message=b'Rename barcopy to foobar')
wrapper.command(b'rm', wrapper.repo.root + b'/bar')
ctx4 = wrapper.commit(rel_paths=['bar'], add_remove=True,
message=b'remove bar')
def normalizer(rpc_helper, resp, **kw):
for chunked_resp in resp:
for chg in chunked_resp.raw_changes:
# blob_id differs between hgitaly and gitaly
chg.blob_id = b''
# XXX:COPIED case, looks like Gitaly implementation is not
# detecting Copies, which is probably because of default
# behavior of `git diff` which can be fixed by either passing
# -C flag to detect copies or setting `diff.renames=copies`.
# Until it's fixed, we are hacking around and modifying
# few fields.
if (chg.operation == OPERATION_TYPES['COPIED']
and kw['vcs'] == 'hg'):
chg.old_path = ''
chg.old_mode = 0
chg.old_path_bytes = b''
chg.operation = OPERATION_TYPES['ADDED']
rpc_helper = fixture.rpc_helper(
stub_cls=RepositoryServiceStub,
method_name='GetRawChanges',
request_cls=GetRawChangesRequest,
request_sha_attrs=['from_revision', 'to_revision'],
normalizer=normalizer,
streaming=True,
)
# all revs except ctx4 ,it will be tested separately becuase Git fails
# to detect copies/renames for "cumulative diff" of multiple revisions.
all_revs = [NULLHEX, ctx0.hex(), ctx1.hex(), ctx2.hex(), ctx3.hex()]
for to_idx, to_rev in enumerate(all_revs):
for from_rev in all_revs[:to_idx]:
rpc_helper.assert_compare(
from_revision=from_rev,
to_revision=to_rev,
)
# testing ctx4's raw changes
rpc_helper.assert_compare(from_revision=ctx4.hex(), to_revision=ctx3.hex())
# Error case: when commit_id does not correspond to a commit
sha_not_exists = b'deadnode' * 5
rpc_helper.assert_compare_errors(
from_revision=sha_not_exists, to_revision=ctx3.hex())
# corner case: when to_revision is NULLHEX, empty response is returned
rpc_helper.assert_compare(from_revision=ctx4.hex(), to_revision=NULLHEX)
Loading