10 Commits

Author SHA1 Message Date
Alice Kober-Sotzek
2f62486149 Mark hunks which are present due to a rebase when diffing patch sets
The diff between two patch sets contains hunks which weren't
introduced by either patch set if a rebase occurred between those
patch sets. Previous optimizations for this case simply omitted all
files which aren't touched by either of the patch sets.

This change goes one step further: All hunks which can clearly be
identified as being introduced by a rebase are marked. In case of
doubt (e.g. they overlap with a regular hunk), they aren't marked.

To be consistent with the previous behavior, we exclude all files from
the result which only contain hunks due to rebase. In some cases (e.g.
a patch set touches 'fileA' but all identified hunks were introduced
by the rebase), this rule can be stricter than the previously mentioned
(as the previous rule would still show file 'fileA' but we exclude it
now).

Hunks which are introduced by a rebase are identified by computing
the diff between the parents of the two patch sets and transforming
the result to differences in terms of treeA of patch set A and treeB
of patch set B. This follows a suggestion which was posted as a comment
(https://gerrit-review.googlesource.com/c/33091/5//COMMIT_MSG#7) in
change I63d3a21ad4f.

As we always determine which hunks are introduced by a rebase when
two commits are explicitly specified which don't share a common
parent, we will determine those hunks even when we compute the
diff between the parents of the patch sets provided that those
parents fulfill the condition of being separated by a rebase. Those
situations should be rare and hence we refrain from adding
optimizations for this case for the moment.

Bug: Issue 217
Change-Id: If06381d506d360f0e3d24d078dcb54692698e766
2017-06-09 13:38:43 +02:00
Alice Kober-Sotzek
30d6c7d3da Add REST endpoint to apply a suggested fix of a robot comment
To apply a suggested fix, we manually compute the Git tree which
results from applying the described modifications to the patch set.
That Git tree is transformed into a change edit if none exists or
merged with an existing one.

Similar to change edits, fixes may only be applied for the current
patch set if no change edit exists. If one exists, fixes may only be
applied for the patch set on which the change edit is based on.

To fail as early as possible, we now reject suggested fixes which
include overlapping replacements when they are provided as review input.

Change-Id: Iabf0d0af025b0878e839956d16f29693b1e74eee
2017-03-23 09:49:46 +01:00
David Pursehouse
c75d2749dc SitePathsTest: Convert to use Google Truth
Convert the tests to use Google Truth instead of junit.Assert.

Add a new PathSubject to perform assertions about Path objects.

Change-Id: I8016daeebc6f8cb291f9a767441f5e1a52ea5097
2017-03-01 14:03:12 +09:00
Dave Borowitz
292fa154c1 Format all Java files with google-java-format
Having a standard tool for formatting saves reviewers' valuable time.
google-java-format is Google's standard formatter and is somewhat
inspired by gofmt[1]. This commit formats everything using
google-java-format version 1.2.

The downside of this one-off formatting is breaking blame. This can be
somewhat hacked around with a tool like git-hyper-blame[2], but it's
definitely not optimal until/unless this kind of feature makes its way
to git core.

Not in this change:
* Tool support, e.g. Eclipse. The command must be run manually [3].
* Documentation of best practice, e.g. new 100-column default.

[1] https://talks.golang.org/2015/gofmt-en.slide#3
[2] https://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_tools/docs/html/git-hyper-blame.html
[3] git ls-files | grep java$ | xargs google-java-format -i

Change-Id: Id5f3c6de95ce0b68b41f0a478b5c99a93675aaa3
Signed-off-by: David Pursehouse <dpursehouse@collab.net>
2017-02-07 10:04:39 +09:00
David Pursehouse
83bb19bd9a BinaryResultSubject: Remove unnecessary resource warning suppression
Change-Id: I5fbd7329aca2ebe6732ca5912861fdd061cb10ce
2017-01-28 15:41:25 +09:00
David Pursehouse
40ef1b6f37 Remove @SuppressWarnings annotations with non-standard values
Change-Id: I469f809fa3187577e460d692af260837d641a55a
2017-01-28 15:41:02 +09:00
Alice Kober-Sotzek
5dd17b647e Add Java API for change edits and use it in tests
For some reason, a Java API for change edits didn't exist previously
even though a detailed REST API has been available. Because of that,
tests needed to use internal classes when they interacted with change
edits. Using internal classes is fragile and impedes refactorings.
That's why we should avoid it.

If possible, the structure and behavior of the tests is kept. Some of
them might and should be improved but that's beyond the scope of this
change. Some of the tests are adapted a bit because the internal
classes allow change edits to be created for previous patch sets
which isn't possible when using the REST API (and hence the Java API).

As modifications to the mentioned internal classes are necessary to
properly implement the 'Apply fix' feature of robot comments, it is
crucial that none of the tests use the internal classes directly.
In addition, the tests which will be added for the 'Apply fix' feature
will also need to modify and query change edits, which will be much
easier with the Java API.

Change-Id: I6b455541d1bc1b7a05b5f0507911181b0451829a
2017-01-24 15:16:20 +01:00
Alice Kober-Sotzek
110f60f082 Make the file path for the replacement of a robot comment explicit
Up to now, the file path was implicitly limited to the file on which
the robot comment was placed. This restriction will be relaxed in the
future. In order to not break systems which use the fix suggestions at
that (later) point in time, the mandatory field 'path' is introduced
with this change.

Change-Id: I73875b97bf844dee927720765046161bbd888c02
2016-12-19 16:45:26 +01:00
Alice Kober-Sotzek
4f8edafb7c Move custom Truth subjects to gerrit-test-util
To simplify and encourage writing unit tests, the custom Truth subjects
are moved to a Bazel/Buck package which is available to the IT tests as
well as the unit tests.

Change-Id: I529bfa5e8b566a17a05a2ba33c884655bb454dcf
2016-12-08 13:26:38 +01:00
Alice Kober-Sotzek
bc8186ad79 Add unit tests for Comment.Range#isValid
In order to use the RangeSubject within gerrit-extension-api as well
as gerrit-acceptance-tests, a new Bazel/Buck package is introduced.
The purpose of this package is to bundle test helper classes which are
shared by different packages.

Change-Id: I59aa42d89c06f4de60a2a05d41a72653eba268de
2016-12-08 11:21:48 +01:00