summaryrefslogtreecommitdiffstats
path: root/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view.js
diff options
context:
space:
mode:
Diffstat (limited to 'polygerrit-ui/app/elements/change/gr-change-view/gr-change-view.js')
-rw-r--r--polygerrit-ui/app/elements/change/gr-change-view/gr-change-view.js61
1 files changed, 54 insertions, 7 deletions
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 909a1ee0ec..470f8596c1 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
@@ -122,6 +122,7 @@
type: Object,
value: {},
},
+ _prefs: Object,
/** @type {?} */
_changeComments: Object,
_canStartReview: {
@@ -134,6 +135,10 @@
type: Object,
observer: '_changeChanged',
},
+ _revisionInfo: {
+ type: Object,
+ computed: '_getRevisionInfo(_change)',
+ },
/** @type {?} */
_commitInfo: Object,
_currentRevision: {
@@ -262,6 +267,7 @@
'fullscreen-overlay-closed': '_handleShowBackgroundContent',
'diff-comments-modified': '_handleReloadCommentThreads',
},
+
observers: [
'_labelsChanged(_change.labels.*)',
'_paramsAndChangeChanged(params, _change)',
@@ -335,7 +341,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);
}
@@ -790,10 +796,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
@@ -804,6 +811,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';
+ },
+
_computeChangeUrl(change) {
return Gerrit.Nav.getUrlForChange(change);
},
@@ -1057,6 +1093,10 @@
});
},
+ _getPreferences() {
+ return this.$.restAPI.getPreferences();
+ },
+
_updateRebaseAction(revisionActions) {
if (revisionActions && revisionActions.rebase) {
revisionActions.rebase.rebaseOnCurrent =
@@ -1110,9 +1150,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 '';
}
@@ -1661,6 +1704,10 @@
e.detail.starred);
},
+ _getRevisionInfo(change) {
+ return new Gerrit.RevisionInfo(change);
+ },
+
_computeCurrentRevision(currentRevision, revisions) {
return revisions && revisions[currentRevision];
},