Skip to content

Commit

Permalink
Task #1178 move the implementation to the AVersionControlCommitHandler
Browse files Browse the repository at this point in the history
for more generality.
  • Loading branch information
ngat_di authored and ngat_di committed Apr 16, 2024
1 parent 3658d6f commit bea3bfa
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
*/
public abstract class AVersionControlCommitHandler extends AVersionControlHandler {

public static final int NUMBEROFWORK = 3;
/**
* Override this method to provide some default proposed comment in the commit message dialog.
* The default implementation just gives the empty string.
Expand All @@ -52,9 +53,6 @@ protected void doCommit(IProject project, String message, IProgressMonitor monit
backend.commit(project, message, monitor);
}

protected void doUpdate(IProject project, IProgressMonitor monitor) throws Exception {
backend.update(project, monitor);
}

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
Expand All @@ -71,9 +69,11 @@ public Object execute(ExecutionEvent event) throws ExecutionException {

@Override
protected void executeBackendOperation(IProject project, IProgressMonitor monitor) throws Exception {
SubMonitor subMonitor = SubMonitor.convert(monitor, 2);
doCommit(project, commitMessageDialog.getCommitMessage(), subMonitor.split(1));
project.refreshLocal(IResource.DEPTH_INFINITE, subMonitor.split(1));
SubMonitor subMonitor = SubMonitor.convert(monitor, NUMBEROFWORK);

doUpdate(project, subMonitor.split(1));
doCommit(project, commitMessageDialog.getCommitMessage(), subMonitor.split(1));
project.refreshLocal(IResource.DEPTH_INFINITE, subMonitor.split(1));
}
};

Expand All @@ -82,4 +82,8 @@ protected void executeBackendOperation(IProject project, IProgressMonitor monito
return null;
}

protected void doUpdate(IProject project, IProgressMonitor monitor) throws Exception {
backend.update(project, monitor);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@
import org.eclipse.egit.core.internal.credentials.EGitCredentialsProvider;
import org.eclipse.egit.core.op.PushOperationResult;
import org.eclipse.egit.core.project.RepositoryMapping;
import org.eclipse.egit.ui.internal.pull.PullResultDialog;
import org.eclipse.egit.ui.internal.push.PushMode;
import org.eclipse.egit.ui.internal.push.ShowPushResultAction;
import org.eclipse.jgit.api.PullResult;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.transport.PushResult;
import org.eclipse.swt.widgets.Display;
Expand All @@ -29,58 +27,35 @@
/**
* This class performs a git commit
*/

@SuppressWarnings("restriction")
public class GitCommitHandler extends AVersionControlCommitHandler {

@Override
protected IVirSatVersionControlBackend createVersionControlBackend() {
return new VirSatGitVersionControlBackend(new EGitCredentialsProvider());
}

@Override
protected void doUpdate(IProject project, IProgressMonitor monitor) throws Exception {
super.doUpdate(project, monitor);

VirSatGitVersionControlBackend gitBackend = (VirSatGitVersionControlBackend) backend;
PullResult pullResult = gitBackend.getLastPullResult();

Repository gitRepository = RepositoryMapping.getMapping(project).getRepository();
@Override
protected IVirSatVersionControlBackend createVersionControlBackend() {
return new VirSatGitVersionControlBackend(new EGitCredentialsProvider());
}

@Override
protected void doCommit(IProject project, String message, IProgressMonitor monitor) throws Exception {
super.doCommit(project, message, monitor);

VirSatGitVersionControlBackend gitBackend = (VirSatGitVersionControlBackend) backend;

// Build the dialog in the UI threads
Display.getDefault().asyncExec(() -> {
PullResultDialog pullResultDialog =
new PullResultDialog(Display.getDefault().getActiveShell(), gitRepository, pullResult);
pullResultDialog.open();
});
}

@Override
protected void doCommit(IProject project, String message, IProgressMonitor monitor) throws Exception {

// Update before committing
updateBeforeCommit(project, monitor);
super.doCommit(project, message, monitor);

VirSatGitVersionControlBackend gitBackend = (VirSatGitVersionControlBackend) backend;

// Create an interim push operation result object for passing on to egit
PushOperationResult pushOperationResult = new PushOperationResult();
Iterable<PushResult> lastPushResults = gitBackend.getLastPushResults();
for (PushResult pushResult : lastPushResults) {
pushOperationResult.addOperationResult(pushResult.getURI(), pushResult);
}

// Create the actual egit dialog for showing push results
Repository gitRepository = RepositoryMapping.getMapping(project).getRepository();
String destination = lastPushResults.iterator().next().getURI().toString();
ShowPushResultAction showPushResultAction =
new ShowPushResultAction(gitRepository, pushOperationResult, destination, false, PushMode.UPSTREAM);

// Run it in the display thread since we will be showing UI
Display.getDefault().asyncExec(() -> showPushResultAction.run());
}

private void updateBeforeCommit(IProject project, IProgressMonitor monitor) throws Exception {
doUpdate(project, monitor);
// Create an interim push operation result object for passing on to egit
PushOperationResult pushOperationResult = new PushOperationResult();
Iterable<PushResult> lastPushResults = gitBackend.getLastPushResults();
for (PushResult pushResult : lastPushResults) {
pushOperationResult.addOperationResult(pushResult.getURI(), pushResult);
}

// Create the actual egit dialog for showing push results
Repository gitRepository = RepositoryMapping.getMapping(project).getRepository();
String destination = lastPushResults.iterator().next().getURI().toString();
ShowPushResultAction showPushResultAction =
new ShowPushResultAction(gitRepository, pushOperationResult, destination, false, PushMode.UPSTREAM);

// Run it in the display thread since we will be showing UI
Display.getDefault().asyncExec(() -> showPushResultAction.run());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected void doUpdate(IProject project, IProgressMonitor monitor) throws Excep

Repository gitRepository = RepositoryMapping.getMapping(project).getRepository();

// Build the dialog in the UI threads
// Build the dialog in the UI thread
Display.getDefault().asyncExec(() -> {
PullResultDialog pullResultDialog =
new PullResultDialog(Display.getDefault().getActiveShell(), gitRepository, pullResult);
Expand Down

0 comments on commit bea3bfa

Please sign in to comment.