{"thread":{"id":"17895","subject":"[PATCH JGIT] In the commit dialog, deal with Signed-off-by not on the last line","startedAt":"2009-02-19T09:20:56Z","lastAt":"2009-02-20T07:48:08Z","messageCount":4,"participants":["Yann Simon","Robin Rosenberg","Sverre Rabbelier"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"105415","messageId":"499D2478.6080501@gmail.com","threadId":"17895","inReplyTo":null,"subject":"[PATCH JGIT] In the commit dialog, deal with Signed-off-by not on the last line","fromName":"Yann Simon","fromEmail":"yann.simon.fr@gmail.com","sentAt":"2009-02-19T09:20:56Z","receivedAt":"2009-02-19T09:20:56Z","isPatch":true,"sender":{"key":"yann.simon.fr@gmail.com","avatar":"https://gravatar.com/avatar/2d926895d27ac988c5c8e591887e5a6a4c7036390403c74fce92519119b887a0?d=mp&s=160"},"body":"The previous implementation made the assumption that\nthe Signed-off-by is always on the last line.\n\nCorrect this assumption and deal with Signed-off-by everywhere in\nthe commit message.\n\nSigned-off-by: Yann Simon <yann.simon.fr@gmail.com>\n---\nI hope this send will not be whitespace damaged.\n\n--\nyann\n\n .../egit/ui/internal/dialogs/CommitDialog.java     |   65\n++++++++++++--------\n 1 files changed, 40 insertions(+), 25 deletions(-)\n\ndiff --git\na/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/dialogs/CommitDialog.java\nb/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/dialogs/CommitDialog.java\nindex bbe7193..403d69d 100644\n---\na/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/dialogs/CommitDialog.java\n+++\nb/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/dialogs/CommitDialog.java\n@@ -179,14 +179,16 @@ public void keyPressed(KeyEvent arg0) {\n         if (committer != null)\n             committerText.setText(committer);\n         committerText.addModifyListener(new ModifyListener() {\n+            String oldCommitter = committerText.getText();\n             public void modifyText(ModifyEvent e) {\n                 if (signedOffButton.getSelection()) {\n                     // the commit message is signed\n                     // the signature must be updated\n-                    String oldCommitText = commitText.getText();\n-                    oldCommitText = removeLastLine(oldCommitText);\n-                    oldCommitText = signOff(oldCommitText);\n-                    commitText.setText(oldCommitText);\n+                    String neuCommitter = committerText.getText();\n+                    String oldSignOff = getSignedOff(oldCommitter);\n+                    String neuSignOff = getSignedOff(neuCommitter);\n+                  \n commitText.setText(replaceSignOff(commitText.getText(), oldSignOff,\nneuSignOff));\n+                    oldCommitter = neuCommitter;\n                 }\n             }\n         });\n@@ -230,12 +232,16 @@ public void widgetDefaultSelected(SelectionEvent\narg0) {\n \n         signedOffButton.addSelectionListener(new SelectionListener() {\n             public void widgetSelected(SelectionEvent arg0) {\n+                String curText = commitText.getText();\n                 if (signedOffButton.getSelection()) {\n                     // add signed off line\n-                    commitText.setText(signOff(commitText.getText()));\n+                    commitText.setText(signOff(curText));\n                 } else {\n                     // remove signed off line\n-                  \n commitText.setText(removeLastLine(commitText.getText()));\n+                    curText = replaceSignOff(curText, getSignedOff(), \"\");\n+                    if (curText.endsWith(Text.DELIMITER + Text.DELIMITER))\n+                        curText = curText.substring(0, curText.length()\n- Text.DELIMITER.length());\n+                    commitText.setText(curText);\n                 }\n             }\n \n@@ -279,11 +285,19 @@ public void modifyText(ModifyEvent e) {\n     }\n \n     private void updateSignedOffButton() {\n-      \n signedOffButton.setSelection(getLastLine(commitText.getText()).equals(getSignedOff()));\n+        String curText = commitText.getText();\n+        if (!curText.endsWith(Text.DELIMITER))\n+            curText += Text.DELIMITER;\n+\n+        signedOffButton.setSelection(curText.indexOf(getSignedOff() +\nText.DELIMITER) != -1);\n     }\n \n     private String getSignedOff() {\n-        return Constants.SIGNED_OFF_BY_TAG + committerText.getText();\n+        return getSignedOff(committerText.getText());\n+    }\n+\n+    private String getSignedOff(String signer) {\n+        return Constants.SIGNED_OFF_BY_TAG + signer;\n     }\n \n     private String signOff(String input) {\n@@ -299,32 +313,33 @@ private String signOff(String input) {\n     }\n \n     private String getLastLine(String input) {\n-        String output = removeLastLineBreak(input);\n+        String output = input;\n         int breakLength = Text.DELIMITER.length();\n \n-        // get the last line\n+        // remove last line break if exist\n         int lastIndexOfLineBreak = output.lastIndexOf(Text.DELIMITER);\n+        if (lastIndexOfLineBreak != -1 && lastIndexOfLineBreak ==\noutput.length() - breakLength)\n+            output = output.substring(0, output.length() - breakLength);\n+\n+        // get the last line\n+        lastIndexOfLineBreak = output.lastIndexOf(Text.DELIMITER);\n         return lastIndexOfLineBreak == -1 ? output :\noutput.substring(lastIndexOfLineBreak + breakLength, output.length());\n     }\n \n-    private String removeLastLine(String input) {\n-        String output = removeLastLineBreak(input);\n+    private String replaceSignOff(String input, String oldSignOff,\nString newSignOff) {\n+        assert input != null;\n+        assert oldSignOff != null;\n+        assert newSignOff != null;\n \n-        // remove the last line if possible\n-        int lastIndexOfLineBreak = output.lastIndexOf(Text.DELIMITER);\n-        return lastIndexOfLineBreak == -1 ? \"\" : output.substring(0,\nlastIndexOfLineBreak); //$NON-NLS-1$\n-    }\n-\n-    private String removeLastLineBreak(String input) {\n-        String output = input;\n-        int breakLength = Text.DELIMITER.length();\n+        String curText = input;\n+        if (!curText.endsWith(Text.DELIMITER))\n+            curText += Text.DELIMITER;\n \n-        // remove last line break if exist\n-        int lastIndexOfLineBreak = output.lastIndexOf(Text.DELIMITER);\n-        if (lastIndexOfLineBreak != -1 && lastIndexOfLineBreak ==\noutput.length() - breakLength)\n-            output = output.substring(0, output.length() - breakLength);\n+        int indexOfSignOff = curText.indexOf(oldSignOff + Text.DELIMITER);\n+        if (indexOfSignOff == -1)\n+            return input;\n \n-        return output;\n+        return input.substring(0, indexOfSignOff) + newSignOff +\ninput.substring(indexOfSignOff + oldSignOff.length(), input.length());\n     }\n \n     private Menu getContextMenu() {\n-- \n1.6.1.2\n"},{"id":"105484","messageId":"200902191828.25587.robin.rosenberg@dewire.com","threadId":"17895","inReplyTo":"499D2478.6080501@gmail.com","subject":"Re: [PATCH JGIT] In the commit dialog, deal with Signed-off-by not on the last line","fromName":"Robin Rosenberg","fromEmail":"robin.rosenberg@dewire.com","sentAt":"2009-02-19T17:28:25Z","receivedAt":"2009-02-19T17:28:25Z","isPatch":true,"sender":{"key":"robin.rosenberg@dewire.com","avatar":"https://avatars.githubusercontent.com/u/46357?v=4"},"body":"Yann Simon <yann.simon.fr@gmail.com>writes:\n> The previous implementation made the assumption that\n> the Signed-off-by is always on the last line.\n> \n> Correct this assumption and deal with Signed-off-by everywhere in\n> the commit message.\n> \n> Signed-off-by: Yann Simon <yann.simon.fr@gmail.com>\n> ---\n> I hope this send will not be whitespace damaged.\n\nSorry, It suffers from severe whitespace burns. \n\n-- robin\n"},{"id":"105485","messageId":"bd6139dc0902190953m195a56ey47aa9bf535c4d77c@mail.gmail.com","threadId":"17895","inReplyTo":"499D2478.6080501@gmail.com","subject":"Re: [PATCH JGIT] In the commit dialog, deal with Signed-off-by not on the last line","fromName":"Sverre Rabbelier","fromEmail":"srabbelier@gmail.com","sentAt":"2009-02-19T17:53:36Z","receivedAt":"2009-02-19T17:53:36Z","isPatch":true,"sender":{"key":"srabbelier@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3098?v=4"},"body":"On Thu, Feb 19, 2009 at 10:20, Yann Simon <yann.simon.fr@gmail.com> wrote:\n> I hope this send will not be whitespace damaged.\n\nYou could of course send your patch inlined, but attach the patch as\nwell if you fear your MUA will damage the patch. That way the patch\ncan still be easily reviewed, and can be applied just as well.\n\n-- \nCheers,\n\nSverre Rabbelier\n"},{"id":"105574","messageId":"551f769b0902192348k7b1a2444n4c882cc198c79723@mail.gmail.com","threadId":"17895","inReplyTo":"bd6139dc0902190953m195a56ey47aa9bf535c4d77c@mail.gmail.com","subject":"Re: [PATCH JGIT] In the commit dialog, deal with Signed-off-by not on the last line","fromName":"Yann Simon","fromEmail":"yann.simon.fr@gmail.com","sentAt":"2009-02-20T07:48:08Z","receivedAt":"2009-02-20T07:48:08Z","isPatch":true,"sender":{"key":"yann.simon.fr@gmail.com","avatar":"https://gravatar.com/avatar/2d926895d27ac988c5c8e591887e5a6a4c7036390403c74fce92519119b887a0?d=mp&s=160"},"body":"2009/2/19 Sverre Rabbelier <srabbelier@gmail.com>:\n> On Thu, Feb 19, 2009 at 10:20, Yann Simon <yann.simon.fr@gmail.com> wrote:\n>> I hope this send will not be whitespace damaged.\n>\n> You could of course send your patch inlined, but attach the patch as\n> well if you fear your MUA will damage the patch. That way the patch\n> can still be easily reviewed, and can be applied just as well.\n>\n> --\n> Cheers,\n>\n> Sverre Rabbelier\n>\n\nI switched from STMP to IMAP.\nMaybe it is the problem.\nI will revert to SMTP and re-test the send.\n\nSorry for the trouble\n\nYann\n"}]}