Compare should diff commits, not the merge base
Summary
The diff output of the Compare feature does not show all differing lines.
Steps to reproduce
- Clone https://gitlab.com/jssfr/diffsample
git diff bob..alice
- Compare the
git diff
output with the GitLab compare output when usingalice
as source andbob
as target.
Example Project
What is the current bug behavior?
Some content from the diff is missing. Specifically, the copy the bytes
comment is not found in the GitLab compare view, while git diff
shows it.
What is the expected correct behavior?
GitLab should not omit changed lines from a diff.
Relevant logs and/or screenshots
With git diff:
diff --git a/code.c b/code.c
index 37ea888..cfe8f2e 100644
--- a/code.c
+++ b/code.c
@@ -1,15 +1,14 @@
-void Chunk_copy(Chunk *src, size_t src_start, Chunk *dst, size_t dst_start, size_t n)
+int Chunk_bounds_check(Chunk *chunk, size_t start, size_t n)
{
- if (!Chunk_bounds_check(src, src_start, n)) return;
- if (!Chunk_bounds_check(dst, dst_start, n)) return;
+ if (chunk == NULL) return 0;
- // copy the bytes
- memcpy(dst->data + dst_start, src->data + src_start, n);
+ return start <= chunk->length && n <= chunk->length - start;
}
-int Chunk_bounds_check(Chunk *chunk, size_t start, size_t n)
+void Chunk_copy(Chunk *src, size_t src_start, Chunk *dst, size_t dst_start, size_t n)
{
- if (chunk == NULL) return 0;
+ if (!Chunk_bounds_check(src, src_start, n)) return;
+ if (!Chunk_bounds_check(dst, dst_start, n)) return;
- return start <= chunk->length && n <= chunk->length - start;
+ memcpy(dst->data + dst_start, src->data + src_start, n);
}
With GitLab compare (click on the screenshot to get to the Compare page of the example project right away):
(jssfr/diffsample@bob...alice)
Output of checks
This bug happens on GitLab.com (in addition to our self-hosted GitLab CE 11.x).
Acknowledgements and notes
- The code and diff examples were taken from https://blog.jcoglan.com/2017/06/19/why-merges-fail-and-what-can-be-done-about-it/
- While the example is rather pathological, we have seen this type of issues from time to time in our self-hosted instance, but never were able to find a proper (shareable and humanly understandable) reproducer until now..