Loading
Commits on Source 5
-
GitLab Release Tools Bot authored
-
Mustafa Bayar authored
GetPatchID computes a patch ID by piping git-diff(1) into `git patch-id --verbatim`. We use `--verbatim` to keep whitespace, but it also turns on `--stable`, which hashes each file diff on its own and adds the hashes together. That sum only makes the ID independent of the order the files appear in, and we do not need it: Gitaly generates the diff itself, so the order is always the same. `--unstable` hashes the whole diff at once, which is what we want, but git will not combine it with `--verbatim`. So this adds a whole_diff_hash option that skips git-patch-id(1) altogether. When it is set, Gitaly normalizes the diff exactly as `git patch-id --verbatim` would and hashes it once with SHA256. Hunk headers and "index" lines are left out so that line numbers and blob IDs do not change the result, which is what lets a patch ID survive a rebase. Our normalization matches git's in every case but one: we also hash the file header that ends a binary diff, which git drops. This changes nothing that exists today, since whole_diff_hash is new, and it only matters in a rare case, a mode-only change right after a binary diff. There git hashes nothing that identifies the file, so two patches that change the same binary but chmod different files get the same ID. Hashing the header keeps them apart. Gitaly always passes --full-index, so a binary diff should always carry an "index" line. A missing one is treated as an error only as a safety check. The diff is read with ReadSlice(3) instead of ReadBytes(3) so we do not allocate a string for every line. On a ~40MB diff this roughly halves the time and cuts allocations from about 205k to 4. The normalization is tested against git itself, not against our reading of git. For a single-file patch git's per-file sum equals a single hash, so `git patch-id --verbatim` is an exact reference. Multi-file patches are checked by splitting the diff per file and reproducing git's sum. Fixes: https://gitlab.com/gitlab-org/gitaly/-/issues/7350 Changelog: added Co-Authored-By:
Claude Fable 5 <noreply@anthropic.com>
-
Olivier Campeau authored
Add whole-diff hash option to GetPatchID See merge request gitlab-org/gitaly!9170 Merged-by:
Olivier Campeau <ocampeau@gitlab.com>
Approved-by:
Olivier Campeau <ocampeau@gitlab.com>
Co-authored-by: Mustafa Bayar <mbayar@gitlab.com>
-
GitLab Release Tools Bot authored
[ci skip]
-
GitLab Release Tools Bot authored