diff --git a/hgitaly/message.py b/hgitaly/message.py index ff6feb0a8cef865e5578d61f8917c7ad0efe2794_aGdpdGFseS9tZXNzYWdlLnB5..286ac2f23b0e34d00e5aa36296726e92f7d5c2d4_aGdpdGFseS9tZXNzYWdlLnB5 100644 --- a/hgitaly/message.py +++ b/hgitaly/message.py @@ -107,6 +107,7 @@ return GitCommit(id=ctx.hex(), subject=descr.split(b'\n', 1)[0].rstrip(b'\r\n'), body=descr, + body_size=len(descr), parent_ids=[p.hex().decode() for p in ctx.parents() if p.rev() != node.nullrev], diff --git a/hgitaly/service/tests/test_commit.py b/hgitaly/service/tests/test_commit.py index ff6feb0a8cef865e5578d61f8917c7ad0efe2794_aGdpdGFseS9zZXJ2aWNlL3Rlc3RzL3Rlc3RfY29tbWl0LnB5..286ac2f23b0e34d00e5aa36296726e92f7d5c2d4_aGdpdGFseS9zZXJ2aWNlL3Rlc3RzL3Rlc3RfY29tbWl0LnB5 100644 --- a/hgitaly/service/tests/test_commit.py +++ b/hgitaly/service/tests/test_commit.py @@ -103,6 +103,7 @@ now = time.time() ctx = wrapper.write_commit('foo', utc_timestamp=now, + message="A single line", user="HGitaly Test <hgitaly@heptapod.test>") ctx2 = wrapper.write_commit('foo', tz_timestamp=(123456, -7200), # UTC+2 @@ -120,6 +121,9 @@ assert commit.author.email == b"hgitaly@heptapod.test" assert commit.author.date.seconds == int(now) assert commit.author.timezone == b'+0000' + assert commit.subject == b"A single line" + assert commit.body == commit.subject + assert commit.body_size == 13 request = FindCommitRequest(repository=grpc_repo, revision=ctx2.hex()) response = grpc_stub.FindCommit(request) @@ -128,6 +132,7 @@ assert commit2 is not None assert commit2.subject == b'Foo deux' assert commit2.body == b"Foo deux\n\nA very interesting bar" + assert commit2.body_size == 32 assert commit2.parent_ids == [ctx.hex().decode()] assert commit2.author.timezone == b'+0200' diff --git a/tests_with_gitaly/comparison.py b/tests_with_gitaly/comparison.py index ff6feb0a8cef865e5578d61f8917c7ad0efe2794_dGVzdHNfd2l0aF9naXRhbHkvY29tcGFyaXNvbi5weQ==..286ac2f23b0e34d00e5aa36296726e92f7d5c2d4_dGVzdHNfd2l0aF9naXRhbHkvY29tcGFyaXNvbi5weQ== 100644 --- a/tests_with_gitaly/comparison.py +++ b/tests_with_gitaly/comparison.py @@ -251,8 +251,17 @@ # TODO tree_id should be replaced by HGitaly standard value # once HGitaly2 is the norm commit.tree_id = '' - # TODO Git adds a line ending (can be a surprise not to have it to clients) - # hg-git adds a branch marker (this is just a test artifact) - commit.body = b'' - # TODO should be provided - commit.body_size = 0 + + # hg-git may add a branch marker (this is just a test artifact) + hg_marker = b'\n--HG--\n' + split = commit.body.split(hg_marker, 1) + if len(split) > 1: + commit.body = split[0] + commit.body_size = commit.body_size - len(split[1]) - len(hg_marker) + + # Either hg-git or Git itself adds a newline if there isn't one. + # TODO investigate and if it is Git, add the newline in Mercurial + # response. + if not commit.body.endswith(b'\n'): + commit.body = commit.body + b'\n' + commit.body_size = commit.body_size + 1 diff --git a/tests_with_gitaly/test_commit.py b/tests_with_gitaly/test_commit.py index ff6feb0a8cef865e5578d61f8917c7ad0efe2794_dGVzdHNfd2l0aF9naXRhbHkvdGVzdF9jb21taXQucHk=..286ac2f23b0e34d00e5aa36296726e92f7d5c2d4_dGVzdHNfd2l0aF9naXRhbHkvdGVzdF9jb21taXQucHk= 100644 --- a/tests_with_gitaly/test_commit.py +++ b/tests_with_gitaly/test_commit.py @@ -47,7 +47,7 @@ # use, e.g., check how to make it accept patterns) ctx1 = wrapper.commit(rel_paths=['sub/bar', 'sub/ba2', 'sub/dir/bar', 'sub/dir/ba2'], - message="zebar", add_remove=True) + message="ze\nbar", add_remove=True) git_shas[ctx1.hex()] = git_repo.branches()[b'branch/default']['sha'] ctx2 = wrapper.write_commit('sub/bar', message='default head') ctx3 = wrapper.write_commit('foo', parent=ctx1, branch='other',