1 /*******************************************************************************
2 * Copyright (C) 2007, Dave Watson <dwatson@mimvista.com>
3 * Copyright (C) 2007, Robin Rosenberg <me@lathund.dewire.com.dewire.com>
4 * Copyright (C) 2007, Robin Rosenberg <me@lathund.dewire.com>
5 * Copyright (C) 2008, Robin Rosenberg <robin.rosenberg@dewire.com>
6 * Copyright (C) 2007, Shawn O. Pearce <spearce@spearce.org>
8 * All rights reserved. This program and the accompanying materials
9 * are made available under the terms of the Eclipse Public License v1.0
10 * which accompanies this distribution, and is available at
11 * http://www.eclipse.org/legal/epl-v10.html
12 *******************************************************************************/
13 package org
.eclipse
.egit
.ui
.internal
.dialogs
;
16 import java
.io
.IOException
;
17 import java
.util
.ArrayList
;
18 import java
.util
.Collections
;
19 import java
.util
.Comparator
;
20 import java
.util
.Iterator
;
22 import org
.eclipse
.compare
.CompareUI
;
23 import org
.eclipse
.compare
.ITypedElement
;
24 import org
.eclipse
.core
.resources
.IFile
;
25 import org
.eclipse
.core
.resources
.IProject
;
26 import org
.eclipse
.egit
.core
.Activator
;
27 import org
.eclipse
.egit
.core
.GitProvider
;
28 import org
.eclipse
.egit
.core
.internal
.storage
.GitFileHistoryProvider
;
29 import org
.eclipse
.egit
.core
.internal
.trace
.GitTraceLocation
;
30 import org
.eclipse
.egit
.core
.project
.RepositoryMapping
;
31 import org
.eclipse
.egit
.ui
.UIText
;
32 import org
.eclipse
.egit
.ui
.internal
.GitCompareFileRevisionEditorInput
;
33 import org
.eclipse
.jface
.dialogs
.Dialog
;
34 import org
.eclipse
.jface
.dialogs
.IDialogConstants
;
35 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
36 import org
.eclipse
.jface
.layout
.GridDataFactory
;
37 import org
.eclipse
.jface
.viewers
.CheckboxTableViewer
;
38 import org
.eclipse
.jface
.viewers
.IStructuredContentProvider
;
39 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
40 import org
.eclipse
.jface
.viewers
.ITableLabelProvider
;
41 import org
.eclipse
.jface
.viewers
.Viewer
;
42 import org
.eclipse
.jface
.viewers
.ViewerComparator
;
43 import org
.eclipse
.swt
.SWT
;
44 import org
.eclipse
.swt
.events
.KeyAdapter
;
45 import org
.eclipse
.swt
.events
.KeyEvent
;
46 import org
.eclipse
.swt
.events
.ModifyEvent
;
47 import org
.eclipse
.swt
.events
.ModifyListener
;
48 import org
.eclipse
.swt
.events
.SelectionAdapter
;
49 import org
.eclipse
.swt
.events
.SelectionEvent
;
50 import org
.eclipse
.swt
.events
.SelectionListener
;
51 import org
.eclipse
.swt
.graphics
.Image
;
52 import org
.eclipse
.swt
.layout
.GridLayout
;
53 import org
.eclipse
.swt
.widgets
.Button
;
54 import org
.eclipse
.swt
.widgets
.Composite
;
55 import org
.eclipse
.swt
.widgets
.Control
;
56 import org
.eclipse
.swt
.widgets
.Event
;
57 import org
.eclipse
.swt
.widgets
.Label
;
58 import org
.eclipse
.swt
.widgets
.Listener
;
59 import org
.eclipse
.swt
.widgets
.Menu
;
60 import org
.eclipse
.swt
.widgets
.MenuItem
;
61 import org
.eclipse
.swt
.widgets
.Shell
;
62 import org
.eclipse
.swt
.widgets
.Table
;
63 import org
.eclipse
.swt
.widgets
.TableColumn
;
64 import org
.eclipse
.swt
.widgets
.Text
;
65 import org
.eclipse
.team
.core
.RepositoryProvider
;
66 import org
.eclipse
.team
.core
.history
.IFileHistory
;
67 import org
.eclipse
.team
.core
.history
.IFileHistoryProvider
;
68 import org
.eclipse
.team
.core
.history
.IFileRevision
;
69 import org
.eclipse
.team
.internal
.ui
.history
.FileRevisionTypedElement
;
70 import org
.eclipse
.ui
.model
.WorkbenchLabelProvider
;
71 import org
.eclipse
.jgit
.lib
.Commit
;
72 import org
.eclipse
.jgit
.lib
.Constants
;
73 import org
.eclipse
.jgit
.lib
.GitIndex
;
74 import org
.eclipse
.jgit
.lib
.PersonIdent
;
75 import org
.eclipse
.jgit
.lib
.Repository
;
76 import org
.eclipse
.jgit
.lib
.Tree
;
77 import org
.eclipse
.jgit
.lib
.TreeEntry
;
78 import org
.eclipse
.jgit
.lib
.GitIndex
.Entry
;
81 * Dialog is shown to user when they request to commit files. Changes in the
82 * selected portion of the tree are shown.
84 public class CommitDialog
extends Dialog
{
86 class CommitContentProvider
implements IStructuredContentProvider
{
88 public void inputChanged(Viewer viewer
, Object oldInput
, Object newInput
) {
92 public void dispose() {
96 public Object
[] getElements(Object inputElement
) {
97 return items
.toArray();
102 class CommitLabelProvider
extends WorkbenchLabelProvider
implements
103 ITableLabelProvider
{
104 public String
getColumnText(Object obj
, int columnIndex
) {
105 CommitItem item
= (CommitItem
) obj
;
107 switch (columnIndex
) {
112 return item
.file
.getProject().getName() + ": " //$NON-NLS-1$
113 + item
.file
.getProjectRelativePath();
120 public Image
getColumnImage(Object element
, int columnIndex
) {
121 if (columnIndex
== 0)
122 return getImage(element
);
127 ArrayList
<CommitItem
> items
= new ArrayList
<CommitItem
>();
132 public CommitDialog(Shell parentShell
) {
137 protected void createButtonsForButtonBar(Composite parent
) {
138 createButton(parent
, IDialogConstants
.SELECT_ALL_ID
, UIText
.CommitDialog_SelectAll
, false);
139 createButton(parent
, IDialogConstants
.DESELECT_ALL_ID
, UIText
.CommitDialog_DeselectAll
, false);
141 createButton(parent
, IDialogConstants
.OK_ID
, UIText
.CommitDialog_Commit
, true);
142 createButton(parent
, IDialogConstants
.CANCEL_ID
,
143 IDialogConstants
.CANCEL_LABEL
, false);
149 Button amendingButton
;
150 Button signedOffButton
;
152 CheckboxTableViewer filesViewer
;
155 protected Control
createDialogArea(Composite parent
) {
156 Composite container
= (Composite
) super.createDialogArea(parent
);
157 parent
.getShell().setText(UIText
.CommitDialog_CommitChanges
);
159 GridLayout layout
= new GridLayout(2, false);
160 container
.setLayout(layout
);
162 Label label
= new Label(container
, SWT
.LEFT
);
163 label
.setText(UIText
.CommitDialog_CommitMessage
);
164 label
.setLayoutData(GridDataFactory
.fillDefaults().span(2, 1).grab(true, false).create());
166 commitText
= new Text(container
, SWT
.MULTI
| SWT
.BORDER
| SWT
.V_SCROLL
);
167 commitText
.setLayoutData(GridDataFactory
.fillDefaults().span(2, 1).grab(true, true)
168 .hint(600, 200).create());
170 // allow to commit with ctrl-enter
171 commitText
.addKeyListener(new KeyAdapter() {
172 public void keyPressed(KeyEvent arg0
) {
173 if (arg0
.keyCode
== SWT
.CR
174 && (arg0
.stateMask
& SWT
.CONTROL
) > 0) {
176 } else if (arg0
.keyCode
== SWT
.TAB
177 && (arg0
.stateMask
& SWT
.SHIFT
) == 0) {
179 commitText
.traverse(SWT
.TRAVERSE_TAB_NEXT
);
184 new Label(container
, SWT
.LEFT
).setText(UIText
.CommitDialog_Author
);
185 authorText
= new Text(container
, SWT
.BORDER
);
186 authorText
.setLayoutData(GridDataFactory
.fillDefaults().grab(true, false).create());
188 authorText
.setText(author
);
190 new Label(container
, SWT
.LEFT
).setText(UIText
.CommitDialog_Committer
);
191 committerText
= new Text(container
, SWT
.BORDER
);
192 committerText
.setLayoutData(GridDataFactory
.fillDefaults().grab(true, false).create());
193 if (committer
!= null)
194 committerText
.setText(committer
);
195 committerText
.addModifyListener(new ModifyListener() {
196 String oldCommitter
= committerText
.getText();
197 public void modifyText(ModifyEvent e
) {
198 if (signedOffButton
.getSelection()) {
199 // the commit message is signed
200 // the signature must be updated
201 String newCommitter
= committerText
.getText();
202 String oldSignOff
= getSignedOff(oldCommitter
);
203 String newSignOff
= getSignedOff(newCommitter
);
204 commitText
.setText(replaceSignOff(commitText
.getText(), oldSignOff
, newSignOff
));
205 oldCommitter
= newCommitter
;
210 amendingButton
= new Button(container
, SWT
.CHECK
);
212 amendingButton
.setSelection(amending
);
213 amendingButton
.setEnabled(false); // if already set, don't allow any changes
214 commitText
.setText(previousCommitMessage
);
215 authorText
.setText(previousAuthor
);
216 } else if (!amendAllowed
) {
217 amendingButton
.setEnabled(false);
219 amendingButton
.addSelectionListener(new SelectionListener() {
220 boolean alreadyAdded
= false;
221 public void widgetSelected(SelectionEvent arg0
) {
224 if (amendingButton
.getSelection()) {
226 String curText
= commitText
.getText();
227 if (curText
.length() > 0)
228 curText
+= "\n"; //$NON-NLS-1$
229 commitText
.setText(curText
+ previousCommitMessage
);
230 authorText
.setText(previousAuthor
);
234 public void widgetDefaultSelected(SelectionEvent arg0
) {
239 amendingButton
.setText(UIText
.CommitDialog_AmendPreviousCommit
);
240 amendingButton
.setLayoutData(GridDataFactory
.fillDefaults().grab(true, false).span(2, 1).create());
242 signedOffButton
= new Button(container
, SWT
.CHECK
);
243 signedOffButton
.setSelection(signedOff
);
244 signedOffButton
.setText(UIText
.CommitDialog_AddSOB
);
245 signedOffButton
.setLayoutData(GridDataFactory
.fillDefaults().grab(true, false).span(2, 1).create());
247 signedOffButton
.addSelectionListener(new SelectionListener() {
248 public void widgetSelected(SelectionEvent arg0
) {
249 String curText
= commitText
.getText();
250 if (signedOffButton
.getSelection()) {
251 // add signed off line
252 commitText
.setText(signOff(curText
));
254 // remove signed off line
255 curText
= replaceSignOff(curText
, getSignedOff(), ""); //$NON-NLS-1$
256 if (curText
.endsWith(Text
.DELIMITER
+ Text
.DELIMITER
))
257 curText
= curText
.substring(0, curText
.length() - Text
.DELIMITER
.length());
258 commitText
.setText(curText
);
262 public void widgetDefaultSelected(SelectionEvent arg0
) {
267 commitText
.addModifyListener(new ModifyListener() {
268 public void modifyText(ModifyEvent e
) {
269 updateSignedOffButton();
272 updateSignedOffButton();
274 Table resourcesTable
= new Table(container
, SWT
.H_SCROLL
| SWT
.V_SCROLL
275 | SWT
.FULL_SELECTION
| SWT
.MULTI
| SWT
.CHECK
| SWT
.BORDER
);
276 resourcesTable
.setLayoutData(GridDataFactory
.fillDefaults().hint(600,
277 200).span(2,1).grab(true, true).create());
279 resourcesTable
.addSelectionListener(new CommitItemSelectionListener());
281 resourcesTable
.setHeaderVisible(true);
282 TableColumn statCol
= new TableColumn(resourcesTable
, SWT
.LEFT
);
283 statCol
.setText(UIText
.CommitDialog_Status
);
284 statCol
.setWidth(150);
285 statCol
.addSelectionListener(new HeaderSelectionListener(CommitItem
.Order
.ByStatus
));
287 TableColumn resourceCol
= new TableColumn(resourcesTable
, SWT
.LEFT
);
288 resourceCol
.setText(UIText
.CommitDialog_File
);
289 resourceCol
.setWidth(415);
290 resourceCol
.addSelectionListener(new HeaderSelectionListener(CommitItem
.Order
.ByFile
));
292 filesViewer
= new CheckboxTableViewer(resourcesTable
);
293 filesViewer
.setContentProvider(new CommitContentProvider());
294 filesViewer
.setLabelProvider(new CommitLabelProvider());
295 filesViewer
.setInput(items
);
296 filesViewer
.setAllChecked(true);
297 filesViewer
.getTable().setMenu(getContextMenu());
303 private void updateSignedOffButton() {
304 String curText
= commitText
.getText();
305 if (!curText
.endsWith(Text
.DELIMITER
))
306 curText
+= Text
.DELIMITER
;
308 signedOffButton
.setSelection(curText
.indexOf(getSignedOff() + Text
.DELIMITER
) != -1);
311 private String
getSignedOff() {
312 return getSignedOff(committerText
.getText());
315 private String
getSignedOff(String signer
) {
316 return Constants
.SIGNED_OFF_BY_TAG
+ signer
;
319 private String
signOff(String input
) {
320 String output
= input
;
321 if (!output
.endsWith(Text
.DELIMITER
))
322 output
+= Text
.DELIMITER
;
324 // if the last line is not a signed off (amend a commit), had a line break
325 if (!getLastLine(output
).startsWith(Constants
.SIGNED_OFF_BY_TAG
))
326 output
+= Text
.DELIMITER
;
327 output
+= getSignedOff();
331 private String
getLastLine(String input
) {
332 String output
= input
;
333 int breakLength
= Text
.DELIMITER
.length();
335 // remove last line break if exist
336 int lastIndexOfLineBreak
= output
.lastIndexOf(Text
.DELIMITER
);
337 if (lastIndexOfLineBreak
!= -1 && lastIndexOfLineBreak
== output
.length() - breakLength
)
338 output
= output
.substring(0, output
.length() - breakLength
);
341 lastIndexOfLineBreak
= output
.lastIndexOf(Text
.DELIMITER
);
342 return lastIndexOfLineBreak
== -1 ? output
: output
.substring(lastIndexOfLineBreak
+ breakLength
, output
.length());
345 private String
replaceSignOff(String input
, String oldSignOff
, String newSignOff
) {
346 assert input
!= null;
347 assert oldSignOff
!= null;
348 assert newSignOff
!= null;
350 String curText
= input
;
351 if (!curText
.endsWith(Text
.DELIMITER
))
352 curText
+= Text
.DELIMITER
;
354 int indexOfSignOff
= curText
.indexOf(oldSignOff
+ Text
.DELIMITER
);
355 if (indexOfSignOff
== -1)
358 return input
.substring(0, indexOfSignOff
) + newSignOff
+ input
.substring(indexOfSignOff
+ oldSignOff
.length(), input
.length());
361 private Menu
getContextMenu() {
362 Menu menu
= new Menu(filesViewer
.getTable());
363 MenuItem item
= new MenuItem(menu
, SWT
.PUSH
);
364 item
.setText(UIText
.CommitDialog_AddFileOnDiskToIndex
);
365 item
.addListener(SWT
.Selection
, new Listener() {
366 public void handleEvent(Event arg0
) {
367 IStructuredSelection sel
= (IStructuredSelection
) filesViewer
.getSelection();
372 ArrayList
<GitIndex
> changedIndexes
= new ArrayList
<GitIndex
>();
373 for (Iterator
<?
> it
= sel
.iterator(); it
.hasNext();) {
374 CommitItem commitItem
= (CommitItem
) it
.next();
376 IProject project
= commitItem
.file
.getProject();
377 RepositoryMapping map
= RepositoryMapping
.getMapping(project
);
379 Repository repo
= map
.getRepository();
380 GitIndex index
= null;
381 index
= repo
.getIndex();
382 Entry entry
= index
.getEntry(map
.getRepoRelativePath(commitItem
.file
));
383 if (entry
!= null && entry
.isModified(map
.getWorkDir())) {
384 entry
.update(new File(map
.getWorkDir(), entry
.getName()));
385 if (!changedIndexes
.contains(index
))
386 changedIndexes
.add(index
);
389 if (!changedIndexes
.isEmpty()) {
390 for (GitIndex idx
: changedIndexes
) {
393 filesViewer
.refresh(true);
395 } catch (IOException e
) {
396 if (GitTraceLocation
.CORE
.isActive())
397 GitTraceLocation
.getTrace().trace(GitTraceLocation
.CORE
.getLocation(), e
.getMessage(), e
);
406 private static String
getFileStatus(IFile file
) {
407 String prefix
= UIText
.CommitDialog_StatusUnknown
;
410 RepositoryMapping repositoryMapping
= RepositoryMapping
411 .getMapping(file
.getProject());
413 Repository repo
= repositoryMapping
.getRepository();
414 GitIndex index
= repo
.getIndex();
415 Tree headTree
= repo
.mapTree(Constants
.HEAD
);
417 String repoPath
= repositoryMapping
.getRepoRelativePath(file
);
418 TreeEntry headEntry
= (headTree
== null ?
null : headTree
.findBlobMember(repoPath
));
419 boolean headExists
= (headTree
== null ?
false : headTree
.existsBlob(repoPath
));
421 Entry indexEntry
= index
.getEntry(repoPath
);
422 if (headEntry
== null) {
423 prefix
= UIText
.CommitDialog_StatusAdded
;
424 if (indexEntry
.isModified(repositoryMapping
.getWorkDir()))
425 prefix
= UIText
.CommitDialog_StatusAddedIndexDiff
;
426 } else if (indexEntry
== null) {
427 prefix
= UIText
.CommitDialog_StatusRemoved
;
428 } else if (headExists
429 && !headEntry
.getId().equals(indexEntry
.getObjectId())) {
430 prefix
= UIText
.CommitDialog_StatusModified
;
432 if (indexEntry
.isModified(repositoryMapping
.getWorkDir()))
433 prefix
= UIText
.CommitDialog_StatusModifiedIndexDiff
;
434 } else if (!new File(repositoryMapping
.getWorkDir(), indexEntry
435 .getName()).isFile()) {
436 prefix
= UIText
.CommitDialog_StatusRemovedNotStaged
;
437 } else if (indexEntry
.isModified(repositoryMapping
.getWorkDir())) {
438 prefix
= UIText
.CommitDialog_StatusModifiedNotStaged
;
441 } catch (Exception e
) {
442 Activator
.logError("Problem in finding file status", e
);
443 prefix
= e
.getMessage();
450 * @return The message the user entered
452 public String
getCommitMessage() {
453 return commitMessage
.replaceAll(Text
.DELIMITER
, "\n"); //$NON-NLS-1$;
457 * Preset a commit message. This might be for amending a commit.
458 * @param s the commit message
460 public void setCommitMessage(String s
) {
461 this.commitMessage
= s
;
464 private String commitMessage
= ""; //$NON-NLS-1$
465 private String author
= null;
466 private String committer
= null;
467 private String previousAuthor
= null;
468 private boolean signedOff
= false;
469 private boolean amending
= false;
470 private boolean amendAllowed
= true;
472 private ArrayList
<IFile
> selectedFiles
= new ArrayList
<IFile
>();
473 private String previousCommitMessage
= ""; //$NON-NLS-1$
476 * Pre-select suggested set of resources to commit
480 public void setSelectedFiles(IFile
[] items
) {
481 Collections
.addAll(selectedFiles
, items
);
485 * @return the resources selected by the user to commit.
487 public IFile
[] getSelectedFiles() {
488 return selectedFiles
.toArray(new IFile
[0]);
491 class HeaderSelectionListener
extends SelectionAdapter
{
493 private CommitItem
.Order order
;
495 private boolean reversed
;
497 public HeaderSelectionListener(CommitItem
.Order order
) {
502 public void widgetSelected(SelectionEvent e
) {
503 TableColumn column
= (TableColumn
)e
.widget
;
504 Table table
= column
.getParent();
506 if (column
== table
.getSortColumn()) {
507 reversed
= !reversed
;
511 table
.setSortColumn(column
);
513 Comparator
<CommitItem
> comparator
;
515 comparator
= order
.descending();
516 table
.setSortDirection(SWT
.DOWN
);
519 table
.setSortDirection(SWT
.UP
);
522 filesViewer
.setComparator(new CommitViewerComparator(comparator
));
527 class CommitItemSelectionListener
extends SelectionAdapter
{
529 public void widgetDefaultSelected(SelectionEvent e
) {
530 IStructuredSelection selection
= (IStructuredSelection
) filesViewer
.getSelection();
532 CommitItem commitItem
= (CommitItem
) selection
.getFirstElement();
533 if (commitItem
== null) {
537 IProject project
= commitItem
.file
.getProject();
538 RepositoryMapping mapping
= RepositoryMapping
.getMapping(project
);
539 if (mapping
== null) {
542 Repository repository
= mapping
.getRepository();
546 headCommit
= repository
.mapCommit(Constants
.HEAD
);
547 } catch (IOException e1
) {
550 if (headCommit
== null) {
554 GitProvider provider
= (GitProvider
) RepositoryProvider
.getProvider(project
);
555 GitFileHistoryProvider fileHistoryProvider
= (GitFileHistoryProvider
) provider
.getFileHistoryProvider();
557 IFileHistory fileHistory
= fileHistoryProvider
.getFileHistoryFor(commitItem
.file
, IFileHistoryProvider
.SINGLE_REVISION
, null);
559 IFileRevision baseFile
= fileHistory
.getFileRevisions()[0];
560 IFileRevision nextFile
= fileHistoryProvider
.getWorkspaceFileRevision(commitItem
.file
);
562 ITypedElement base
= new FileRevisionTypedElement(baseFile
);
563 ITypedElement next
= new FileRevisionTypedElement(nextFile
);
565 GitCompareFileRevisionEditorInput input
= new GitCompareFileRevisionEditorInput(base
, next
, null);
566 CompareUI
.openCompareDialog(input
);
572 protected void okPressed() {
573 commitMessage
= commitText
.getText();
574 author
= authorText
.getText().trim();
575 committer
= committerText
.getText().trim();
576 signedOff
= signedOffButton
.getSelection();
577 amending
= amendingButton
.getSelection();
579 Object
[] checkedElements
= filesViewer
.getCheckedElements();
580 selectedFiles
.clear();
581 for (Object obj
: checkedElements
)
582 selectedFiles
.add(((CommitItem
) obj
).file
);
584 if (commitMessage
.trim().length() == 0) {
585 MessageDialog
.openWarning(getShell(), UIText
.CommitDialog_ErrorNoMessage
, UIText
.CommitDialog_ErrorMustEnterCommitMessage
);
589 boolean authorValid
= false;
590 if (author
.length() > 0) {
592 new PersonIdent(author
);
594 } catch (IllegalArgumentException e
) {
599 MessageDialog
.openWarning(getShell(), UIText
.CommitDialog_ErrorInvalidAuthor
, UIText
.CommitDialog_ErrorInvalidAuthorSpecified
);
603 boolean committerValid
= false;
604 if (committer
.length() > 0) {
606 new PersonIdent(committer
);
607 committerValid
= true;
608 } catch (IllegalArgumentException e
) {
609 committerValid
= false;
612 if (!committerValid
) {
613 MessageDialog
.openWarning(getShell(), UIText
.CommitDialog_ErrorInvalidAuthor
, UIText
.CommitDialog_ErrorInvalidCommitterSpecified
);
617 if (selectedFiles
.isEmpty() && !amending
) {
618 MessageDialog
.openWarning(getShell(), UIText
.CommitDialog_ErrorNoItemsSelected
, UIText
.CommitDialog_ErrorNoItemsSelectedToBeCommitted
);
625 * Set the total list of changed resources, including additions and
628 * @param files potentially affected by a new commit
630 public void setFileList(ArrayList
<IFile
> files
) {
632 for (IFile file
: files
) {
633 CommitItem item
= new CommitItem();
634 item
.status
= getFileStatus(file
);
641 protected void buttonPressed(int buttonId
) {
642 if (IDialogConstants
.SELECT_ALL_ID
== buttonId
) {
643 filesViewer
.setAllChecked(true);
645 if (IDialogConstants
.DESELECT_ALL_ID
== buttonId
) {
646 filesViewer
.setAllChecked(false);
648 super.buttonPressed(buttonId
);
652 * @return The author to set for the commit
654 public String
getAuthor() {
659 * Pre-set author for the commit
663 public void setAuthor(String author
) {
664 this.author
= author
;
668 * @return The committer to set for the commit
670 public String
getCommitter() {
675 * Pre-set committer for the commit
679 public void setCommitter(String committer
) {
680 this.committer
= committer
;
684 * Pre-set the previous author if amending the commit
686 * @param previousAuthor
688 public void setPreviousAuthor(String previousAuthor
) {
689 this.previousAuthor
= previousAuthor
;
693 * @return whether to auto-add a signed-off line to the message
695 public boolean isSignedOff() {
700 * Pre-set whether a signed-off line should be included in the commit
705 public void setSignedOff(boolean signedOff
) {
706 this.signedOff
= signedOff
;
710 * @return whether the last commit is to be amended
712 public boolean isAmending() {
717 * Pre-set whether the last commit is going to be amended
721 public void setAmending(boolean amending
) {
722 this.amending
= amending
;
726 * Set the message from the previous commit for amending.
730 public void setPreviousCommitMessage(String string
) {
731 this.previousCommitMessage
= string
;
735 * Set whether the previous commit may be amended
737 * @param amendAllowed
739 public void setAmendAllowed(boolean amendAllowed
) {
740 this.amendAllowed
= amendAllowed
;
744 protected int getShellStyle() {
745 return super.getShellStyle() | SWT
.RESIZE
;
754 public static enum Order
implements Comparator
<CommitItem
> {
757 public int compare(CommitItem o1
, CommitItem o2
) {
758 return o1
.status
.compareTo(o2
.status
);
765 public int compare(CommitItem o1
, CommitItem o2
) {
766 return o1
.file
.getProjectRelativePath().toString().
767 compareTo(o2
.file
.getProjectRelativePath().toString());
772 public Comparator
<CommitItem
> ascending() {
776 public Comparator
<CommitItem
> descending() {
777 return Collections
.reverseOrder(this);
782 class CommitViewerComparator
extends ViewerComparator
{
784 public CommitViewerComparator(Comparator comparator
){
788 @SuppressWarnings("unchecked")
790 public int compare(Viewer viewer
, Object e1
, Object e2
) {
791 return getComparator().compare(e1
, e2
);