diff --git a/java/com/google/gerrit/acceptance/LogThreshold.java b/java/com/google/gerrit/acceptance/LogThreshold.java index da1fcc5c41..36831f3f1a 100644 --- a/java/com/google/gerrit/acceptance/LogThreshold.java +++ b/java/com/google/gerrit/acceptance/LogThreshold.java @@ -17,11 +17,13 @@ import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.ElementType.TYPE; import static java.lang.annotation.RetentionPolicy.RUNTIME; +import java.lang.annotation.Inherited; import java.lang.annotation.Retention; import java.lang.annotation.Target; @Target({TYPE, METHOD}) @Retention(RUNTIME) +@Inherited public @interface LogThreshold { String level() default "DEBUG"; } diff --git a/polygerrit-ui/app/elements/admin/gr-create-change-dialog/gr-create-change-dialog.html b/polygerrit-ui/app/elements/admin/gr-create-change-dialog/gr-create-change-dialog.html index 987b63dab6..da1c871a9f 100644 --- a/polygerrit-ui/app/elements/admin/gr-create-change-dialog/gr-create-change-dialog.html +++ b/polygerrit-ui/app/elements/admin/gr-create-change-dialog/gr-create-change-dialog.html @@ -32,9 +32,6 @@ limitations under the License. diff --git a/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view.html b/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view.html index 730f5270d4..32b11528fb 100644 --- a/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view.html +++ b/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view.html @@ -24,7 +24,6 @@ limitations under the License. - @@ -40,6 +39,7 @@ limitations under the License. + @@ -545,6 +545,7 @@ limitations under the License. all-patch-sets="[[_allPatchSets]]" change="[[_change]]" change-num="[[_changeNum]]" + revision-info="[[_revisionInfo]]" change-comments="[[_changeComments]]" commit-info="[[_commitInfo]]" change-url="[[_computeChangeUrl(_change)]]" diff --git a/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view.js b/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view.js index defbcdc4eb..123a7b5923 100644 --- a/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view.js +++ b/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view.js @@ -132,6 +132,7 @@ type: Object, value: {}, }, + _prefs: Object, /** @type {?} */ _changeComments: Object, _canStartReview: { @@ -144,6 +145,10 @@ type: Object, observer: '_changeChanged', }, + _revisionInfo: { + type: Object, + computed: '_getRevisionInfo(_change)', + }, /** @type {?} */ _commitInfo: Object, _currentRevision: { @@ -291,6 +296,7 @@ 'fullscreen-overlay-closed': '_handleShowBackgroundContent', 'diff-comments-modified': '_handleReloadCommentThreads', }, + observers: [ '_labelsChanged(_change.labels.*)', '_paramsAndChangeChanged(params, _change)', @@ -375,7 +381,7 @@ _setDiffViewMode(opt_reset) { if (!opt_reset && this.viewState.diffViewMode) { return; } - return this.$.restAPI.getPreferences().then( prefs => { + return this._getPreferences().then( prefs => { if (!this.viewState.diffMode) { this.set('viewState.diffMode', prefs.default_diff_view); } @@ -847,10 +853,11 @@ _changeChanged(change) { if (!change || !this._patchRange || !this._allPatchSets) { return; } - this.set('_patchRange.basePatchNum', - this._patchRange.basePatchNum || 'PARENT'); - this.set('_patchRange.patchNum', - this._patchRange.patchNum || + + const parent = this._getBasePatchNum(change, this._patchRange); + + this.set('_patchRange.basePatchNum', parent); + this.set('_patchRange.patchNum', this._patchRange.patchNum || this.computeLatestPatchNum(this._allPatchSets)); // Reset the related changes toggle in the event it was previously @@ -861,6 +868,35 @@ this.fire('title-change', {title}); }, + /** + * Gets base patch number, if is a parent try and + * decide from preference weather to default to `auto merge` + * or `Parent 1`. + * @param {Object} change + * @param {Object} patchRange + * @return {number|string} + */ + _getBasePatchNum(change, patchRange) { + if (patchRange.basePatchNum && + patchRange.basePatchNum !== 'PARENT') { + return patchRange.basePatchNum; + } + + const revisionInfo = this._getRevisionInfo(change); + if (!revisionInfo) return 'PARENT'; + + const parentCounts = revisionInfo.getParentCountMap(); + // check that there is at least 2 parents otherwise fall back to 1, + // which means there is only one parent. + const parentCount = parentCounts.hasOwnProperty(1) ? + parentCounts[1] : 1; + + const preferFirst = this._prefs && + this._prefs.default_base_for_merges === 'FIRST_PARENT'; + + return parentCount > 1 && preferFirst ? -1 : 'PARENT'; + }, + _computeShowPrimaryTabs(dynamicTabContentEndpoints) { return dynamicTabContentEndpoints.length > 0; }, @@ -1120,6 +1156,10 @@ }); }, + _getPreferences() { + return this.$.restAPI.getPreferences(); + }, + _updateRebaseAction(revisionActions) { if (revisionActions && revisionActions.rebase) { revisionActions.rebase.rebaseOnCurrent = @@ -1173,9 +1213,12 @@ const detailCompletes = this.$.restAPI.getChangeDetail( this._changeNum, this._handleGetChangeDetailError.bind(this)); const editCompletes = this._getEdit(); + const prefCompletes = this._getPreferences(); + + return Promise.all([detailCompletes, editCompletes, prefCompletes]) + .then(([change, edit, prefs]) => { + this._prefs = prefs; - return Promise.all([detailCompletes, editCompletes]) - .then(([change, edit]) => { if (!change) { return ''; } @@ -1724,6 +1767,10 @@ e.detail.starred); }, + _getRevisionInfo(change) { + return new Gerrit.RevisionInfo(change); + }, + _computeCurrentRevision(currentRevision, revisions) { return revisions && revisions[currentRevision]; }, diff --git a/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view_test.html b/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view_test.html index a88142e705..b8b48e7c3f 100644 --- a/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view_test.html +++ b/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view_test.html @@ -297,7 +297,8 @@ limitations under the License. }); test(', should open diff preferences', () => { - const stub = sandbox.stub(element.$.fileList.$.diffPreferences, 'open'); + const stub = sandbox.stub( + element.$.fileList.$.diffPreferencesDialog, 'open'); element._loggedIn = false; element.disableDiffPrefs = true; MockInteractions.pressAndReleaseKeyOn(element, 188, null, ','); @@ -1604,8 +1605,8 @@ limitations under the License. }); test('_selectedRevision updates when patchNum is changed', () => { - const revision1 = {_number: 1, commit: {}}; - const revision2 = {_number: 2, commit: {}}; + const revision1 = {_number: 1, commit: {parents: []}}; + const revision2 = {_number: 2, commit: {parents: []}}; sandbox.stub(element.$.restAPI, 'getChangeDetail').returns( Promise.resolve({ revisions: { @@ -1618,6 +1619,7 @@ limitations under the License. change_id: 'loremipsumdolorsitamet', })); sandbox.stub(element, '_getEdit').returns(Promise.resolve()); + sandbox.stub(element, '_getPreferences').returns(Promise.resolve({})); element._patchRange = {patchNum: '2'}; return element._getChangeDetail().then(() => { assert.strictEqual(element._selectedRevision, revision2); diff --git a/polygerrit-ui/app/elements/change/gr-download-dialog/gr-download-dialog.html b/polygerrit-ui/app/elements/change/gr-download-dialog/gr-download-dialog.html index 5e82cda980..28d25d27da 100644 --- a/polygerrit-ui/app/elements/change/gr-download-dialog/gr-download-dialog.html +++ b/polygerrit-ui/app/elements/change/gr-download-dialog/gr-download-dialog.html @@ -19,8 +19,8 @@ limitations under the License. - +