diff options
author | Sean McGivern <sean@gitlab.com> | 2017-08-18 13:02:30 +0100 |
---|---|---|
committer | Sean McGivern <sean@gitlab.com> | 2017-08-18 13:02:30 +0100 |
commit | 34a859ee2aace209a4331f277ff03d50de3e64be (patch) | |
tree | 236dc109029ea45858483107f06e1e9321308126 /lib | |
parent | 133c72ae421b97f483417d5c427721336719b5da (diff) | |
download | gitlab-ce-34a859ee2aace209a4331f277ff03d50de3e64be.tar.gz |
Fix MR diffs background migration when file modes are missing36630-activerecord-statementinvalid-pg-notnullviolation-error-null-value-in-column-a_mode-violates-not-null-constraint
Guess the modes based on the following:
1. If the file didn't exist, it's zero.
2. If the diff contains 'Subproject commit', it might be a submodule, so 0600.
3. Otherwise, it's 0644.
This isn't perfect, but it doesn't have to be - it won't change file modes in
the repository.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/background_migration/deserialize_merge_request_diffs_and_commits.rb | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/lib/gitlab/background_migration/deserialize_merge_request_diffs_and_commits.rb b/lib/gitlab/background_migration/deserialize_merge_request_diffs_and_commits.rb index 310a69a4bd4..3fde1b09efb 100644 --- a/lib/gitlab/background_migration/deserialize_merge_request_diffs_and_commits.rb +++ b/lib/gitlab/background_migration/deserialize_merge_request_diffs_and_commits.rb @@ -81,12 +81,15 @@ module Gitlab relative_order: index ) - # Compatibility with old diffs created with Psych. diff_hash.tap do |hash| diff_text = hash[:diff] hash[:too_large] = !!hash[:too_large] + hash[:a_mode] ||= guess_mode(hash[:new_file], hash[:diff]) + hash[:b_mode] ||= guess_mode(hash[:deleted_file], hash[:diff]) + + # Compatibility with old diffs created with Psych. if diff_text.encoding == Encoding::BINARY && !diff_text.ascii_only? hash[:binary] = true hash[:diff] = [diff_text].pack('m0') @@ -97,6 +100,15 @@ module Gitlab [commit_rows, file_rows] end + # This doesn't have to be 100% accurate, because it's only used for + # display - it won't change file modes in the repository. Submodules are + # created as 600, regular files as 644. + def guess_mode(file_missing, diff) + return '0' if file_missing + + diff.include?('Subproject commit') ? '160000' : '100644' + end + # Unlike MergeRequestDiff#valid_raw_diff?, don't count Rugged objects as # valid, because we don't render them usefully anyway. def valid_raw_diffs?(diffs) |