Commit Graph

95 Commits

Author SHA1 Message Date
Pavel Shutsin 5b70ffcf14 Add MergeRequestDiff#lines_count convenience method 2019-08-06 11:38:50 +03:00
Thong Kuah a2cfc150ce Add # frozen_string_literal to spec/models
Adds `# frozen_string_literal: true` to spec/models ruby files
2019-04-01 14:37:54 +13:00
Nick Thomas 0e831b0b69
Allow external diffs to be used conditionally
Since external diffs are likely to be a bit slower than in-database
ones, add a mode that makes diffs external after they've been obsoleted
by events. This should strike a balance between performance and disk
space.

A background cron drives the majority of migrations, since diffs become
outdated through user actions.
2019-03-27 16:51:33 +00:00
Stan Hu 6552197eec Fix error creating a merge request when diff includes a null byte
If a diff happened to include a single null byte anywhere, insertion
into the database would fail with an Error 500 since the column is text
and not a byte array. To fix this, we mark the diff as binary if we
detect a single null byte and Base64-encode it.

Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/57710
2019-03-14 12:55:45 -07:00
Francisco Javier López ebf16ada85 Arbitrary file read via MergeRequestDiff 2019-03-04 18:36:34 +00:00
Nick Thomas f9e41d0d85
Allow MR diffs to be placed into an object store 2019-02-05 14:12:48 +00:00
Jasper Maes 921bc753bf Fix deprecation: Passing conditions to delete_all is deprecated 2018-12-13 21:38:51 +01:00
Mark Chao 67b579c54e Allow getting all paths (old & new) involved in MR
Fetch database columns directly if available
2018-11-07 11:28:43 +08:00
Stan Hu dbc03ce3a9 Optimize merge request refresh by using the database to check commit SHAs
Previously for a given merge request, we would:

1. Create the array of commit SHAs involved in the push (A)
2. Request all merge request commits and map the SHA (B)
3. Reload the diff if there were any common commits between A and B

We can avoid additional database querying and overhead by
checking with the database whether the merge request contains any
of the commit SHAs.

Relates to https://gitlab.com/gitlab-org/gitlab-ce/issues/53213
2018-11-02 12:11:30 -07:00
Stan Hu 9338c11f61 Fix merge request specs that expect diff_files to be called 2018-11-01 09:51:42 -07:00
Oswaldo Ferreira fc4a0cd055 Only serializes diff files found by paths query 2018-08-01 10:26:38 -03:00
Oswaldo Ferreira 3ecc2b04a3 Render MR page when no persisted diff_refs or diffs size 2018-07-18 10:53:19 +01:00
Sean McGivern 2c2422d54e Fix MR diffs created with gitaly_diff_between enabled
When we save merge request diffs to the database, we need to expand the diff
before doing so. That's so that we can expand diffs (within the normal limits)
without hitting the repository, but just by going to the database.

This is done implicitly - diffs are expanded unless we say otherwise. However,
we have another option we can pass, that lets us enforce diff size limits, that
defaults to true.

Prior to this commit:

- The Rugged code path defaulted to setting `expanded: true` and
  `enforce_limits: true`.
- The Gitaly code path defaulted to setting `expanded: false` and
  `enforce_limits: true`.

This was introduced by eb36fa17a6, which
implemented the initial feature. Since then, if the `gitaly_diff_between`
feature flag was enabled, MRs would have diffs that could not be expanded in
some cases, with no fix other than to disable the feature flag and force push to
the MR to refresh the diff in the database.
2018-06-29 14:25:35 +01:00
Oswaldo Ferreira f5ed18e1e3 Delete non-latest merge request diff files upon diffs reload 2018-06-24 18:01:37 -03:00
Hiroyuki Sato a7d26f00c3 Display related merge requests in commit detail page 2018-01-12 20:38:36 +00:00
Sean McGivern 4ebbfe5d3e Remove serialised diff and commit columns
The st_commits and st_diffs columns on merge_request_diffs historically held the
YAML-serialised data for a merge request diff, in a variety of formats.

Since 9.5, these have been migrated in the background to two new tables:
merge_request_diff_commits and merge_request_diff_files. That has the advantage
that we can actually query the data (for instance, to find out how many commits
we've stored), and that it can't be in a variety of formats, but must match the
new schema.

This is the final step of that journey, where we drop those columns and remove
all references to them. This is a breaking change to the importer, because we
can no longer import diffs created in the old format, and we cannot guarantee
the export will be in the new format unless it was generated after this commit.
2017-11-28 16:13:40 +00:00
Sean McGivern 991bf24ec8 Use latest_merge_request_diff association
Compared to the merge_request_diff association:

1. It's simpler to query. The query uses a foreign key to the
   merge_request_diffs table, so no ordering is necessary.
2. It's faster for preloading. The merge_request_diff association has to load
   every diff for the MRs in the set, then discard all but the most recent for
   each. This association means that Rails can just query for N diffs from N
   MRs.
3. It's more complicated to update. This is a bidirectional foreign key, so we
   need to update two tables when adding a diff record. This also means we need
   to handle this as a special case when importing a GitLab project.

There is some juggling with this association in the merge request model:

* `MergeRequest#latest_merge_request_diff` is _always_ the latest diff.
* `MergeRequest#merge_request_diff` reuses
  `MergeRequest#latest_merge_request_diff` unless:
    * Arguments are passed. These are typically to force-reload the association.
    * It doesn't exist. That means we might be trying to implicitly create a
      diff. This only seems to happen in specs.
    * The association is already loaded. This is important for the reasons
      explained in the comment, which I'll reiterate here: if we a) load a
      non-latest diff, then b) get its `merge_request`, then c) get that MR's
      `merge_request_diff`, we should get the diff we loaded in c), even though
      that's not the latest diff.

Basically, `MergeRequest#merge_request_diff` is the latest diff in most cases,
but not quite all.
2017-11-23 12:14:56 +00:00
Rémy Coutable cddc5cacfb Use described_class when possible
Signed-off-by: Rémy Coutable <remy@rymai.me>
2017-07-27 14:31:53 +02:00
Rémy Coutable ddccd24c13 Remove superfluous lib: true, type: redis, service: true, models: true, services: true, no_db: true, api: true
Signed-off-by: Rémy Coutable <remy@rymai.me>
2017-07-27 14:31:53 +02:00
Sean McGivern 396b8f91ec Fix saving diffs that are not valid UTF-8
Previously, we used Psych, which would:

1. Check if a string was encoded as binary, and not ASCII-compatible.
2. Add the !binary tag in that case.
3. Convert to base64.

We need to do the same thing, using a new column in place of the tag.
2017-07-26 15:34:57 +01:00
Sean McGivern aff5c9f3e5 Add table for merge request commits
This is an ID-less table with just three columns: an association to the merge
request diff the commit belongs to, the relative order of the commit within the
merge request diff, and the commit SHA itself.

Previously we stored much more information about the commits, so that we could
display them even when they were deleted from the repo. Since 8.0, we ensure
that those commits are kept around for as long as the target repo itself is, so
we don't need to duplicate that data in the database.
2017-07-06 17:36:10 +01:00
Sean McGivern 9a73b634ab Add table for files in merge request diffs
This adds an ID-less table containing one row per file, per merge request
diff. It has a column for each attribute on Gitlab::Git::Diff that is serialised
currently, with the advantage that we can easily query the attributes of this
new table.

It does not migrate existing data, so we have fallback code when the legacy
st_diffs column is present instead. For a merge request diff to be valid, it
should have at most one of:

* Rows in this new table, with the correct merge_request_diff_id.
* A non-NULL st_diffs column.

It may have neither, if the diff is empty.
2017-06-16 18:30:01 +01:00
Robert Speicher a6ec5121f0 Correct RSpec/SingleLineHook cop offenses 2017-06-14 13:18:56 -05:00
James Lopez 6b53add3f9 Fix binary encoding error on MR diffs 2017-06-06 16:40:07 +00:00
Douwe Maan 56de781a2c Revert "Enable Style/DotPosition"
This reverts commit e00fb2bdc2090e9cabeb1eb35a2672a882cc96e9.

# Conflicts:
#	.rubocop.yml
#	.rubocop_todo.yml
#	lib/gitlab/ci/config/entry/global.rb
#	lib/gitlab/ci/config/entry/jobs.rb
#	spec/lib/gitlab/ci/config/entry/factory_spec.rb
#	spec/lib/gitlab/ci/config/entry/global_spec.rb
#	spec/lib/gitlab/ci/config/entry/job_spec.rb
#	spec/lib/gitlab/ci/status/build/factory_spec.rb
#	spec/lib/gitlab/incoming_email_spec.rb
2017-02-23 09:33:19 -06:00
Douwe Maan 1fe7501b49 Revert "Prefer leading style for Style/DotPosition"
This reverts commit cb10b725c8929b8b4460f89c9d96c773af39ba6b.
2017-02-23 09:33:05 -06:00
Douwe Maan 7d4b52b27d Enable Style/WordArray 2017-02-23 09:32:41 -06:00
Douwe Maan 206953a430 Prefer leading style for Style/DotPosition 2017-02-23 09:32:22 -06:00
Douwe Maan 3dadf306dd Enable Style/DotPosition 2017-02-23 09:31:56 -06:00
Felipe Artur ca0cf5a3cd Show 'too many changes' message for merge request 2017-01-12 13:41:29 -02:00
Adam Niedzielski cb6f8cdfc2 Replace references to MergeRequestDiff#commits with st_commits
when we care only about the number of commits

We do not have to instantiate all objects in this case.
2016-12-01 12:17:30 +01:00
Dmitriy Zaporozhets 7421c08ace Better tests for MergeRequestDiff#compare_with method
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
2016-10-12 16:32:57 +03:00
Dmitriy Zaporozhets cdcc11d48f Improve tests for merge request diff model
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
2016-10-12 16:32:57 +03:00
Douwe Maan d1eab555b6 Merge branch '20708-new-branch-is-immediatelly-tagged-as-merged' into 'master'
Removes inconsistency regarding tagging immediately as merged once you create a …

- [x] [CHANGELOG](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CHANGELOG) entry added
- [x] [Documentation created/updated](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/development/doc_styleguide.md)
- [x] API support added
- Tests
  - [x] Added for this feature/bug
  - [x] All builds are passing
- [x] Conform by the [merge request performance guides](http://docs.gitlab.com/ce/development/merge_request_performance_guidelines.html)
- [x] Conform by the [style guides](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CONTRIBUTING.md#style-guides)
- [x] Branch has no merge conflicts with `master` (if you do - rebase it please)
- [x] [Squashed related commits together](https://git-scm.com/book/en/Git-Tools-Rewriting-History#Squashing-Commits)

## What are the relevant issue numbers?


Closes #20708

See merge request !6408
2016-10-12 10:17:35 +00:00
tiagonbotelho c90483406e refactors tests because of gitlab-test repository changes 2016-10-11 16:33:06 +01:00
Stan Hu d4fab17d7c Fix Error 500 when viewing old merge requests with bad diff data
Customers running old versions of GitLab may have MergeRequestDiffs with
the text ["--broken diff"] due to text generated by gitlab_git 1.0.3.
To avoid the Error 500, verify that each element is a type that gitlab_git
will accept before attempting to create a DiffCollection.

Closes #20776
2016-10-10 13:05:09 -07:00
Lin Jen-Shin b0ce4ca110 Add test for MergeRequestDiff#commits_sha, feedback:
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/6470#note_15856755
2016-09-22 17:36:43 +08:00
Dmitriy Zaporozhets d64c15c5c3
Add code improvements to merge request version feature
* Add MergeRequestDiff#latest?
* Remove unnecessary variable assignment

Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
2016-08-25 10:59:30 +03:00
Dmitriy Zaporozhets 5e95c0b8d2
Merge branch 'master' into dz-merge-request-version
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
2016-08-15 17:27:22 +03:00
Paco Guzman 631f59d4e7 change the API on the merge_request_diff model from diffs -> raw_diffs 2016-08-03 23:32:12 +02:00
Dmitriy Zaporozhets 6515ec09bb
Chnage the way how merge request diff is initialized and saved
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
2016-08-02 15:38:03 +03:00
Dmitriy Zaporozhets f8aeb8cdac Change merge request diff creation from callback to part of the service
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
2016-08-02 13:31:19 +03:00
Dmitriy Zaporozhets 3c1dca0301 Add more tests to merge_request_diff and improve initialize
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
2016-08-02 13:31:19 +03:00
Sean McGivern 5266ae87c4 Support renames in diff_for_path actions 2016-07-11 09:31:34 +01:00
Sean McGivern b6b26692ea Collapse large diffs by default
When rendering a list of diff files, skip those where the diff is over
10 KB and provide an endpoint to render individually instead.
2016-07-08 10:56:55 +01:00