threads / patch / 17674

patchAdd the signed-off in the commit text dialog

Subject: [PATCH JGIT] Add the signed-off in the commit text dialog

## tl;dr

4 messages between Feb 9, 2009 and Feb 9, 2009. Diffs are folded; open one to read it.

replies: 3people: 2as markdown or json

Yann Simon· Feb 9, 2009, 15:17 UTC · lore

The user can see and edit the signed-off in the commit dialog before committing.

For new lines in the commit dialog, use Text.DELIMITER for plateform neutrality.

Signed-off-by: Yann Simon <yann.simon.fr@gmail.com>
---
This patch only applies after the 2 previous patches.
If you want to, I could probably modify this patch so that it would
apply on the current origin.
 .../egit/ui/internal/actions/CommitAction.java     |   10 +-----
 .../egit/ui/internal/dialogs/CommitDialog.java     |   29 +++++++++++++++++++-
 2 files changed, 30 insertions(+), 9 deletions(-)
Show changes to 2 files +30 −9

org.spearce.egit.ui/src/org/spearce/egit/ui/internal/actions/CommitAction.java, org.spearce.egit.ui/src/org/spearce/egit/ui/internal/dialogs/CommitDialog.java

diff --git a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/actions/CommitAction.java b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/actions/CommitAction.java
index 97aa60f..6aff07e 100644
--- a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/actions/CommitAction.java
+++ b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/actions/CommitAction.java
@@ -172,7 +172,7 @@ private void performCommit(CommitDialog commitDialog, String commitMessage)
 		}
 
 		try {
-			commitMessage = doCommits(commitDialog, commitMessage, treeMap);
+			doCommits(commitDialog, commitMessage, treeMap);
 		} catch (IOException e) {
 			throw new TeamException("Committing changes", e);
 		}
@@ -181,7 +181,7 @@ private void performCommit(CommitDialog commitDialog, String commitMessage)
 		}
 	}
 
-	private String doCommits(CommitDialog commitDialog, String commitMessage,
+	private void doCommits(CommitDialog commitDialog, String commitMessage,
 			HashMap<Repository, Tree> treeMap) throws IOException, TeamException {
 
 		String author = commitDialog.getAuthor();
@@ -209,11 +209,6 @@ private String doCommits(CommitDialog commitDialog, String commitMessage,
 			}
 			Commit commit = new Commit(repo, parentIds);
 			commit.setTree(tree);
-			commitMessage = commitMessage.replaceAll("\r", "\n");
-			if (commitDialog.isSignedOff())
-				commitMessage += "\n\nSigned-off-by: " + committerIdent.getName() + " <"
-								+ committerIdent.getEmailAddress() + ">";
-
 			commit.setMessage(commitMessage);
 			commit.setAuthor(new PersonIdent(authorIdent, commitDate, timeZone));
 			commit.setCommitter(new PersonIdent(committerIdent, commitDate, timeZone));
@@ -229,7 +224,6 @@ private String doCommits(CommitDialog commitDialog, String commitMessage,
 						+ " to commit " + commit.getCommitId() + ".");
 			}
 		}
-		return commitMessage;
 	}
 
 	private void prepareTrees(IFile[] selectedItems,
diff --git a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/dialogs/CommitDialog.java b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/dialogs/CommitDialog.java
index 9d062cc..8f85c08 100644
--- a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/dialogs/CommitDialog.java
+++ b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/dialogs/CommitDialog.java
@@ -17,6 +17,7 @@
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.Iterator;
+import java.util.regex.Pattern;
 
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IProject;
@@ -67,6 +68,8 @@
  */
 public class CommitDialog extends Dialog {
 
+	private static Pattern signedOffPattern = Pattern.compile("(.|\r|\n)*Signed-off-by: .*(\r|\n)*"); //$NON-NLS-1$
+
 	class CommitContentProvider implements IStructuredContentProvider {
 
 		public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
@@ -214,6 +217,30 @@ public void widgetDefaultSelected(SelectionEvent arg0) {
 		signedOffButton.setText(UIText.CommitDialog_AddSOB);
 		signedOffButton.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).span(2, 1).create());
 
+		signedOffButton.addSelectionListener(new SelectionListener() {
+			boolean alreadySigned = false;
+			public void widgetSelected(SelectionEvent arg0) {
+				if (alreadySigned)
+					return;
+				if (signedOffButton.getSelection()) {
+					alreadySigned = true;
+					String curText = commitText.getText();
+
+					// add new lines if necessary
+					if (!curText.endsWith(Text.DELIMITER))
+						curText += Text.DELIMITER;
+
+					// if the last line is not a signed off (amend a commit), add a line break
+					if (!signedOffPattern.matcher(new StringBuilder(curText)).matches())
+						curText += Text.DELIMITER;
+					commitText.setText(curText + "Signed-off-by: " + committerText.getText()); //$NON-NLS-1$
+				}
+			}
+
+			public void widgetDefaultSelected(SelectionEvent arg0) {
+				// Empty
+			}
+		});
 		Table resourcesTable = new Table(container, SWT.H_SCROLL | SWT.V_SCROLL
 				| SWT.FULL_SELECTION | SWT.MULTI | SWT.CHECK | SWT.BORDER);
 		resourcesTable.setLayoutData(GridDataFactory.fillDefaults().hint(600,
@@ -330,7 +357,7 @@ private static String getFileStatus(IFile file) {
 	 * @return The message the user entered
 	 */
 	public String getCommitMessage() {
-		return commitMessage;
+		return commitMessage.replaceAll(Text.DELIMITER, "\n"); //$NON-NLS-1$;
 	}
 
 	/**
-- 
1.6.0.4
Shawn O. Pearce· Feb 9, 2009, 15:46 UTC · re: Yann Simon · lore

Re: [PATCH JGIT] Add the signed-off in the commit text dialog

Yann Simon <yann.simon.fr@gmail.com> wrote:
Show 11 quoted lines
> The user can see and edit the signed-off in the commit dialog
> before committing.
> 
> For new lines in the commit dialog, use Text.DELIMITER for
> plateform neutrality.
> 
> Signed-off-by: Yann Simon <yann.simon.fr@gmail.com>
> ---
> This patch only applies after the 2 previous patches.
> If you want to, I could probably modify this patch so that it would
> apply on the current origin.
The other two have been applied so no need to rebase.
 
Show 9 quoted lines
> diff --git a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/dialogs/CommitDialog.java b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/dialogs/CommitDialog.java
> index 9d062cc..8f85c08 100644
> --- a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/dialogs/CommitDialog.java
> +++ b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/dialogs/CommitDialog.java
> @@ -67,6 +68,8 @@
>   */
>  public class CommitDialog extends Dialog {
>  
> +	private static Pattern signedOffPattern = Pattern.compile("(.|\r|\n)*Signed-off-by: .*(\r|\n)*"); //$NON-NLS-1$
Wouldn't "[.\r\n]" be easier to use here than "(.|\r|\n)"?
Show 11 quoted lines
> @@ -214,6 +217,30 @@ public void widgetDefaultSelected(SelectionEvent arg0) {
>  		signedOffButton.setText(UIText.CommitDialog_AddSOB);
>  		signedOffButton.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).span(2, 1).create());
>  
> +		signedOffButton.addSelectionListener(new SelectionListener() {
> +			boolean alreadySigned = false;
> +			public void widgetSelected(SelectionEvent arg0) {
> +				if (alreadySigned)
> +					return;
> +				if (signedOffButton.getSelection()) {
> +					alreadySigned = true;

Huh. So I can only push the checkbox once, and that after that its just an idiot switch?

If that's really going to be how it is, maybe we should disable the checkbox?

FWIW, git-gui actually looks for the user's Signed-off-by line in the text buffer. If it can't find it, then it appends it onto the end. That way the user can delete the line and do the sign off again if they messed up somehow.

And actually, given that this is a checkbox and not a button, maybe we should be able to *delete* the SBO line when the user tries to uncheck the checkbox. Which then gets into, what if the user made an edit to the text and changed the SBO line, should this box get unchecked automatically by some form a listener on the text box?

Food for thought. I'm not sure what it should be. But if it were a checkbox, as a user I'd like it to be bi-directional (both add and remove my SBO) and also uncheck when I edit or delete the SBO line in the message box.

-- 
Shawn.
Yann Simon· Feb 9, 2009, 15:50 UTC · re: Shawn O. Pearce · lore

Re: [PATCH JGIT] Add the signed-off in the commit text dialog

2009/2/9 Shawn O. Pearce <spearce@spearce.org>:
Show 60 quoted lines
> Yann Simon <yann.simon.fr@gmail.com> wrote:
>> The user can see and edit the signed-off in the commit dialog
>> before committing.
>>
>> For new lines in the commit dialog, use Text.DELIMITER for
>> plateform neutrality.
>>
>> Signed-off-by: Yann Simon <yann.simon.fr@gmail.com>
>> ---
>> This patch only applies after the 2 previous patches.
>> If you want to, I could probably modify this patch so that it would
>> apply on the current origin.
>
> The other two have been applied so no need to rebase.
>
>> diff --git a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/dialogs/CommitDialog.java b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/dialogs/CommitDialog.java
>> index 9d062cc..8f85c08 100644
>> --- a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/dialogs/CommitDialog.java
>> +++ b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/dialogs/CommitDialog.java
>> @@ -67,6 +68,8 @@
>>   */
>>  public class CommitDialog extends Dialog {
>>
>> +     private static Pattern signedOffPattern = Pattern.compile("(.|\r|\n)*Signed-off-by: .*(\r|\n)*"); //$NON-NLS-1$
>
> Wouldn't "[.\r\n]" be easier to use here than "(.|\r|\n)"?
>
>> @@ -214,6 +217,30 @@ public void widgetDefaultSelected(SelectionEvent arg0) {
>>               signedOffButton.setText(UIText.CommitDialog_AddSOB);
>>               signedOffButton.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).span(2, 1).create());
>>
>> +             signedOffButton.addSelectionListener(new SelectionListener() {
>> +                     boolean alreadySigned = false;
>> +                     public void widgetSelected(SelectionEvent arg0) {
>> +                             if (alreadySigned)
>> +                                     return;
>> +                             if (signedOffButton.getSelection()) {
>> +                                     alreadySigned = true;
>
> Huh.  So I can only push the checkbox once, and that after that
> its just an idiot switch?
>
> If that's really going to be how it is, maybe we should disable
> the checkbox?
>
> FWIW, git-gui actually looks for the user's Signed-off-by line in the
> text buffer.  If it can't find it, then it appends it onto the end.
> That way the user can delete the line and do the sign off again if
> they messed up somehow.
>
> And actually, given that this is a checkbox and not a button, maybe
> we should be able to *delete* the SBO line when the user tries to
> uncheck the checkbox.  Which then gets into, what if the user made
> an edit to the text and changed the SBO line, should this box get
> unchecked automatically by some form a listener on the text box?
>
> Food for thought.  I'm not sure what it should be.  But if it were
> a checkbox, as a user I'd like it to be bi-directional (both add
> and remove my SBO) and also uncheck when I edit or delete the SBO
> line in the message box.

He he, more challenging but it would be much better too! I try to implement this when I have time.

And what should we do, when we commit a change from somebody else? Sould we be able to modify the signed-off of the author?

Yann
Shawn O. Pearce· Feb 9, 2009, 15:58 UTC · re: Yann Simon · lore

Re: [PATCH JGIT] Add the signed-off in the commit text dialog

Yann Simon <yann.simon.fr@gmail.com> wrote:
> 
> And what should we do, when we commit a change from somebody else?
> Sould we be able to modify the signed-off of the author?

Well, not by a fancy UI widget and automated tools. But editing the SBO line in the message buffer is fine, just like any other part of the message.

IMHO, the SBO checkbox/button in the UI is only for *your* SBO, as the committer. That's how git-gui behaves and it seems to work out nicely.

-- 
Shawn.

← back to recent threads