Skip to content

Commit 761f4f6

Browse files
committed
Merge remote-tracking branch 'origin/v2.16.9-based' into v3.0-based
Change-Id: I97acd00f65032d263529c3344595434c4f38e9d1
2 parents beb4572 + 143f1d3 commit 761f4f6

20 files changed

+612
-428
lines changed

qt-gerrit-ui-plugin/qt-gerrit-ui-plugin.html

Lines changed: 37 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,16 @@
88
<script>
99
'use strict';
1010

11-
var BUTTONS = {
12-
'gerrit-plugin-qt-workflow~abandon' : {
13-
header: 'Abandon the change?',
14-
action_name: 'abandon'
15-
},
16-
'gerrit-plugin-qt-workflow~defer' : {
17-
header: 'Defer the change?',
18-
action_name: 'defer'
19-
},
20-
'gerrit-plugin-qt-workflow~reopen' : {
21-
header: 'Reopen the change?',
22-
action_name: 'reopen'
23-
},
24-
'gerrit-plugin-qt-workflow~stage' : {
25-
header: 'Submit to staging?',
26-
action_name: 'stage'
27-
},
28-
'gerrit-plugin-qt-workflow~unstage' : {
29-
header: 'Unstage the change?',
30-
action_name: 'unstage'
31-
}
32-
};
11+
var BUTTONS = [
12+
'gerrit-plugin-qt-workflow~abandon',
13+
'gerrit-plugin-qt-workflow~defer',
14+
'gerrit-plugin-qt-workflow~reopen',
15+
'gerrit-plugin-qt-workflow~stage',
16+
'gerrit-plugin-qt-workflow~unstage'
17+
];
3318

3419
Gerrit.install(plugin => {
3520

36-
plugin.custom_popup = null;
37-
plugin.custom_popup_promise = null;
3821
plugin.buttons = null;
3922

4023
function htmlToElement(html) {
@@ -126,32 +109,28 @@
126109

127110
// Remove any existing buttons
128111
if (plugin.buttons) {
129-
for (var key in BUTTONS) {
130-
if (BUTTONS.hasOwnProperty(key)) {
131-
if(typeof plugin.buttons[key] !== 'undefined' && plugin.buttons[key] !== null) {
132-
plugin.ca.removeTapListener(plugin.buttons[key], (param) => {} );
133-
plugin.ca.remove(plugin.buttons[key]);
134-
plugin.buttons[key] = null;
135-
}
112+
BUTTONS.forEach((key) => {
113+
if(typeof plugin.buttons[key] !== 'undefined' && plugin.buttons[key] !== null) {
114+
plugin.ca.removeTapListener(plugin.buttons[key], (param) => {} );
115+
plugin.ca.remove(plugin.buttons[key]);
116+
plugin.buttons[key] = null;
136117
}
137-
}
118+
});
138119
} else plugin.buttons = [];
139120

140121
// Add buttons based on server response
141-
for (var key in BUTTONS) {
142-
if (BUTTONS.hasOwnProperty(key)) {
143-
var action = plugin.ca.getActionDetails(key);
144-
if (action) {
145-
// hide dropdown action
146-
plugin.ca.setActionHidden(action.__type, action.__key, true);
147-
148-
// add button
149-
plugin.buttons[key] = plugin.ca.add(action.__type, action.label);
150-
plugin.ca.setTitle(plugin.buttons[key], action.title);
151-
plugin.ca.addTapListener(plugin.buttons[key], buttonEventCallback);
152-
}
122+
BUTTONS.forEach((key) => {
123+
var action = plugin.ca.getActionDetails(key);
124+
if (action) {
125+
// hide dropdown action
126+
plugin.ca.setActionHidden(action.__type, action.__key, true);
127+
128+
// add button
129+
plugin.buttons[key] = plugin.ca.add(action.__type, action.label);
130+
plugin.ca.setTitle(plugin.buttons[key], action.title);
131+
plugin.ca.addTapListener(plugin.buttons[key], buttonEventCallback);
153132
}
154-
}
133+
});
155134

156135
function buttonEventCallback(event) {
157136
var button_key = event.type.substring(0, event.type.indexOf('-tap'));
@@ -165,106 +144,22 @@
165144
}
166145
}
167146
if (button_action) {
168-
plugin.popup('qt-gerrit-ui-confirm-dialog').then( (param) => {
169-
plugin.custom_popup_promise = param;
170-
plugin.custom_popup.set('header', BUTTONS[button_index].header);
171-
plugin.custom_popup.set('subject', changeInfo.subject);
172-
plugin.custom_popup.set('action_name', BUTTONS[button_index].action_name);
173-
plugin.custom_popup.set('api_url', button_action.__url);
174-
}).catch( (param) => { console.log('unexpected error: promise failed');});
147+
const buttonEl = this.$$(`[data-action-key="${button_key}"]`);
148+
buttonEl.setAttribute('loading', true);
149+
buttonEl.disabled = true;
150+
plugin.restApi().post(button_action.__url, {})
151+
.then((ok_resp) => {
152+
buttonEl.removeAttribute('loading');
153+
buttonEl.disabled = false;
154+
window.location.reload(true);
155+
}).catch((failed_resp) => {
156+
buttonEl.removeAttribute('loading');
157+
buttonEl.disabled = false;
158+
this.fire('show-alert', {message: 'FAILED: ' + failed_resp});
159+
});
175160
} else console.log('unexpected error: no action');
176161
}
177162
});
178163
});
179164
</script>
180165
</dom-module>
181-
182-
<dom-module id="qt-gerrit-ui-confirm-dialog">
183-
<template>
184-
<style include="shared-styles">
185-
#dialog {
186-
min-width: 40em;
187-
}
188-
p {
189-
margin-bottom: 1em;
190-
}
191-
@media screen and (max-width: 50em) {
192-
#dialog {
193-
min-width: inherit;
194-
width: 100%;
195-
}
196-
}
197-
</style>
198-
<gr-dialog
199-
id="dialog"
200-
confirm-label="Continue"
201-
confirm-on-enter
202-
on-cancel="_handleCancelTap"
203-
on-confirm="_handleConfirmTap">
204-
<div class="header" slot="header">[[header]]</div>
205-
<div class="main" slot="main">
206-
<p>Ready to [[action_name]] &ldquo;<strong>[[subject]]</strong>&rdquo;?</p>
207-
<p class="main" style="color: red;font-weight: bold;">[[errorMessage]]</p>
208-
</div>
209-
</gr-dialog>
210-
</template>
211-
<script>
212-
'use strict';
213-
214-
var qtgerrituiconfirmdialog = Polymer({
215-
is: 'qt-gerrit-ui-confirm-dialog',
216-
217-
properties: {
218-
header: {
219-
type: String,
220-
value: '...wait...'
221-
},
222-
action_name: {
223-
type: String,
224-
value: ''
225-
},
226-
api_url: {
227-
type: String,
228-
value: ''
229-
},
230-
subject: {
231-
type: String,
232-
value: ''
233-
},
234-
errorMessage: {
235-
type: String,
236-
value: ''
237-
}
238-
},
239-
240-
attached: function() {
241-
this.plugin.custom_popup = this;
242-
},
243-
244-
resetFocus(e) {
245-
this.$.dialog.resetFocus();
246-
},
247-
248-
_handleConfirmTap(e) {
249-
this.$.dialog.disabled = true;
250-
e.preventDefault();
251-
this.plugin.restApi().post(this.get('api_url'), {})
252-
.then((ok_resp) => {
253-
this.$.dialog.disabled = false;
254-
this.plugin.custom_popup_promise.close();
255-
this.plugin.custom_popup_promise = null;
256-
window.location.reload(true);
257-
}).catch((failed_resp) => {
258-
this.$.dialog.disabled = false;
259-
this.set('errorMessage', 'FAILED: ' + failed_resp);
260-
});
261-
},
262-
263-
_handleCancelTap(e) {
264-
e.preventDefault();
265-
this.plugin.custom_popup_promise.close();
266-
this.plugin.custom_popup_promise = null;
267-
},
268-
});
269-
</script>
270-
</dom-module>

src/main/java/com/googlesource/gerrit/plugins/qtcodereview/QtCherryPickPatch.java

Lines changed: 22 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,18 @@
55
package com.googlesource.gerrit.plugins.qtcodereview;
66

77
import com.google.common.flogger.FluentLogger;
8-
import com.google.gerrit.extensions.api.changes.NotifyHandling;
98
import com.google.gerrit.extensions.restapi.BadRequestException;
109
import com.google.gerrit.extensions.restapi.MergeConflictException;
1110
import com.google.gerrit.extensions.restapi.MethodNotAllowedException;
1211
import com.google.gerrit.extensions.restapi.RestApiException;
1312
import com.google.gerrit.reviewdb.client.Change;
1413
import com.google.gerrit.reviewdb.client.PatchSet;
1514
import com.google.gerrit.reviewdb.client.Project;
16-
import com.google.gerrit.server.ChangeUtil;
1715
import com.google.gerrit.server.IdentifiedUser;
18-
import com.google.gerrit.server.change.NotifyResolver;
19-
import com.google.gerrit.server.change.PatchSetInserter;
2016
import com.google.gerrit.server.git.CodeReviewCommit;
2117
import com.google.gerrit.server.git.CodeReviewCommit.CodeReviewRevWalk;
2218
import com.google.gerrit.server.git.GitRepositoryManager;
2319
import com.google.gerrit.server.git.MergeUtil;
24-
import com.google.gerrit.server.notedb.ChangeNotes;
2520
import com.google.gerrit.server.project.NoSuchProjectException;
2621
import com.google.gerrit.server.project.NoSuchRefException;
2722
import com.google.gerrit.server.project.ProjectCache;
@@ -35,12 +30,10 @@
3530
import com.google.inject.Inject;
3631
import com.google.inject.Provider;
3732
import com.google.inject.Singleton;
38-
import java.io.IOException;
3933
import java.sql.Timestamp;
4034
import java.util.Arrays;
4135
import java.util.Date;
4236
import java.util.List;
43-
import org.eclipse.jgit.errors.ConfigInvalidException;
4437
import org.eclipse.jgit.lib.ObjectId;
4538
import org.eclipse.jgit.lib.ObjectInserter;
4639
import org.eclipse.jgit.lib.ObjectReader;
@@ -56,7 +49,6 @@ public class QtCherryPickPatch {
5649
private final BatchUpdate.Factory batchUpdateFactory;
5750
private final GitRepositoryManager gitManager;
5851
private final Provider<IdentifiedUser> user;
59-
private final PatchSetInserter.Factory patchSetInserterFactory;
6052
private final MergeUtil.Factory mergeUtilFactory;
6153
private final ProjectCache projectCache;
6254
private final QtChangeUpdateOp.Factory qtUpdateFactory;
@@ -65,14 +57,12 @@ public class QtCherryPickPatch {
6557
QtCherryPickPatch(BatchUpdate.Factory batchUpdateFactory,
6658
GitRepositoryManager gitManager,
6759
Provider<IdentifiedUser> user,
68-
PatchSetInserter.Factory patchSetInserterFactory,
6960
MergeUtil.Factory mergeUtilFactory,
7061
ProjectCache projectCache,
7162
QtChangeUpdateOp.Factory qtUpdateFactory) {
7263
this.batchUpdateFactory = batchUpdateFactory;
7364
this.gitManager = gitManager;
7465
this.user = user;
75-
this.patchSetInserterFactory = patchSetInserterFactory;
7666
this.mergeUtilFactory = mergeUtilFactory;
7767
this.projectCache = projectCache;
7868
this.qtUpdateFactory = qtUpdateFactory;
@@ -114,7 +104,6 @@ public CodeReviewCommit cherryPickPatch(ChangeData changeData,
114104
commitToCherryPick.setNotes(changeData.notes());
115105

116106
CodeReviewCommit cherryPickCommit;
117-
boolean mergeCommit = false;
118107

119108
ProjectState projectState = projectCache.checkedGet(project);
120109
if (projectState == null) throw new NoSuchProjectException(project);
@@ -123,14 +112,21 @@ public CodeReviewCommit cherryPickPatch(ChangeData changeData,
123112
if (commitToCherryPick.getParentCount() > 1) {
124113
// Merge commit cannot be cherrypicked
125114
logger.atInfo().log("qtcodereview: merge commit detected %s", commitToCherryPick);
126-
mergeCommit = true;
127-
RevCommit commit = QtUtil.merge(committerIdent,
128-
git, oi,
129-
revWalk,
130-
commitToCherryPick,
131-
baseCommit,
132-
true /* merge always */);
133-
cherryPickCommit = revWalk.parseCommit(commit);
115+
116+
if (commitToCherryPick.getParent(0).equals(baseCommit)) {
117+
// allow fast forward, when parent index 0 is correct
118+
logger.atInfo().log("qtcodereview: merge commit fast forwarded");
119+
cherryPickCommit = commitToCherryPick;
120+
} else {
121+
logger.atInfo().log("qtcodereview: merge of merge created");
122+
RevCommit commit = QtUtil.merge(committerIdent,
123+
git, oi,
124+
revWalk,
125+
commitToCherryPick,
126+
baseCommit,
127+
true);
128+
cherryPickCommit = revWalk.parseCommit(commit);
129+
}
134130
} else {
135131
String commitMessage = mergeUtil.createCommitMessageOnSubmit(commitToCherryPick, baseCommit);
136132
cherryPickCommit = mergeUtil.createCherryPickFromCommit(oi,
@@ -147,30 +143,17 @@ public CodeReviewCommit cherryPickPatch(ChangeData changeData,
147143

148144
boolean patchSetNotChanged = cherryPickCommit.equals(commitToCherryPick);
149145
if (!patchSetNotChanged) {
150-
logger.atInfo().log("qtcodereview: new patch %s -> %s", commitToCherryPick, cherryPickCommit);
146+
logger.atInfo().log("qtcodereview: %s cherrypicked as %s", commitToCherryPick, cherryPickCommit);
151147
oi.flush();
152148
}
153149
Timestamp commitTimestamp = new Timestamp(committerIdent.getWhen().getTime());
154150
BatchUpdate bu = batchUpdateFactory.create(project, identifiedUser, commitTimestamp);
155-
bu.setRepository(git, revWalk, oi);
156-
if (!patchSetNotChanged && !mergeCommit) {
157-
Change.Id changeId = insertPatchSet(bu, git, changeData.notes(), cherryPickCommit);
158-
bu.addOp(changeData.getId(), qtUpdateFactory.create(newStatus,
159-
null,
160-
defaultMessage,
161-
inputMessage,
162-
tag,
163-
commitToCherryPick));
164-
logger.atInfo().log("qtcodereview: cherrypick new patch %s for %s", cherryPickCommit.toObjectId(), changeId);
165-
} else {
166-
bu.addOp(changeData.getId(), qtUpdateFactory.create(newStatus,
167-
null,
168-
defaultMessage,
169-
inputMessage,
170-
tag,
171-
null));
172-
}
173-
151+
bu.addOp(changeData.getId(), qtUpdateFactory.create(newStatus,
152+
null,
153+
defaultMessage,
154+
inputMessage,
155+
tag,
156+
null));
174157
bu.execute();
175158
logger.atInfo().log("qtcodereview: cherrypick done %s", changeData.getId());
176159
return cherryPickCommit;
@@ -179,19 +162,4 @@ public CodeReviewCommit cherryPickPatch(ChangeData changeData,
179162
}
180163
}
181164

182-
private Change.Id insertPatchSet(BatchUpdate bu,
183-
Repository git,
184-
ChangeNotes destNotes,
185-
CodeReviewCommit cherryPickCommit)
186-
throws IOException, BadRequestException, ConfigInvalidException {
187-
Change destChange = destNotes.getChange();
188-
PatchSet.Id psId = ChangeUtil.nextPatchSetId(git, destChange.currentPatchSetId());
189-
PatchSetInserter inserter = patchSetInserterFactory.create(destNotes, psId, cherryPickCommit);
190-
inserter.setAllowClosed(true);
191-
// .setCopyApprovals(true) doesn't work, so copying done in QtChangeUpdateOp
192-
bu.setNotify(NotifyResolver.Result.none());
193-
bu.addOp(destChange.getId(), inserter);
194-
return destChange.getId();
195-
}
196-
197165
}

0 commit comments

Comments
 (0)