Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSeverin Gehwolf2010-12-10 23:03:21 +0000
committerSeverin Gehwolf2010-12-10 23:03:21 +0000
commiteb9f79f25ab09bc3f28eeeeebddd64e713445241 (patch)
tree7ee023782d4c87dabe25b6955c39bf84324f8e5d /changelog/org.eclipse.linuxtools.changelog.core
parent551898d0b84c8c32c49d530c2dbd22ef4991c2c3 (diff)
downloadorg.eclipse.linuxtools-eb9f79f25ab09bc3f28eeeeebddd64e713445241.tar.gz
org.eclipse.linuxtools-eb9f79f25ab09bc3f28eeeeebddd64e713445241.tar.xz
org.eclipse.linuxtools-eb9f79f25ab09bc3f28eeeeebddd64e713445241.zip
2010-12-10 Severin Gehwolf <sgehwolf@redhat.com>
Commit for Eclipse BZ #331688. * src/org/eclipse/linuxtools/changelog/core/formatters/GNUFormat.java (mergeChangelog): Added call to removeWhitespaceOnlyLines. (removeWhitespaceOnlyLines): New method. Implements whitespace removal. * src/org/eclipse/linuxtools/changelog/core/formatters/tests/GNUFormatTest.java (twoChangesInSameFileAreProperlyMergedWhenThereIsATrailingTabNewLine): New test case.
Diffstat (limited to 'changelog/org.eclipse.linuxtools.changelog.core')
-rw-r--r--changelog/org.eclipse.linuxtools.changelog.core/ChangeLog8
-rw-r--r--changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/changelog/core/formatters/GNUFormat.java50
2 files changed, 57 insertions, 1 deletions
diff --git a/changelog/org.eclipse.linuxtools.changelog.core/ChangeLog b/changelog/org.eclipse.linuxtools.changelog.core/ChangeLog
index 80804ece2a..5596bba758 100644
--- a/changelog/org.eclipse.linuxtools.changelog.core/ChangeLog
+++ b/changelog/org.eclipse.linuxtools.changelog.core/ChangeLog
@@ -1,3 +1,11 @@
+2010-12-10 Severin Gehwolf <sgehwolf@redhat.com>
+
+ * src/org/eclipse/linuxtools/changelog/core/formatters/GNUFormat.java (mergeChangelog): Added call
+ to removeWhitespaceOnlyLines.
+ (removeWhitespaceOnlyLines): New method. Lines containing whitespace only are removed by next merge.
+ This happens only if entries of the same file with changes in different functions happen to
+ contain whitespace only lines. See Eclipse BZ #331688 for more info.
+
2010-12-03 Jeff Johnston <jjohnstn@redhat.com>
* META-INF/MANIFEST.MF: Bump up version to 2.7.0 for 0.7 release.
diff --git a/changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/changelog/core/formatters/GNUFormat.java b/changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/changelog/core/formatters/GNUFormat.java
index 17b0c35263..ddecca9ac8 100644
--- a/changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/changelog/core/formatters/GNUFormat.java
+++ b/changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/changelog/core/formatters/GNUFormat.java
@@ -111,8 +111,9 @@ public class GNUFormat implements IFormatterChangeLogContrib {
"\t") // $NON-NLS-1$
|| changelog_doc.get(
nextFunctLoc + foundFunc, 1)
- .equals("\n")) // $NON-NLS-1$
+ .equals("\n")) { // $NON-NLS-1$
foundFunc--;
+ }
} catch (BadLocationException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
@@ -133,6 +134,8 @@ public class GNUFormat implements IFormatterChangeLogContrib {
if (functLogEntry >= nextChangeEntry) {
functLogEntry = nextChangeEntry - 1;
try {
+ // Get rid of some potential lines containing whitespace only.
+ functLogEntry = removeWhitespaceOnlyLines(changelog_doc, functLogEntry);
while (changelog_doc.get(functLogEntry, 1).equals("\n")) // $NON-NLS-1$
functLogEntry--;
} catch (BadLocationException e) {
@@ -204,6 +207,51 @@ public class GNUFormat implements IFormatterChangeLogContrib {
}
+ /**
+ * Remove any empty lines (i.e. lines only containing whitespace) between
+ * <code>offset</code> and index backed-up until a '\n' preceded by some non-whitespace
+ * character is reached. Whitespace will be merged to '\n\n'. For example
+ * consider the following string "(main): Removed.\n\t\ \n\n\t\n" and
+ * <code>offset</code> pointing to the last '\n'. This string would be
+ * changed to: "(main): Removed.\n\n".
+ *
+ * @param changelog_doc
+ * @param offset
+ * @return The new offset.
+ */
+ private int removeWhitespaceOnlyLines(IDocument changelog_doc, int offset) {
+ int initialOffset = offset;
+ int backedUpOffset = offset;
+ char charAtOffset;
+ try {
+ charAtOffset = changelog_doc.get(offset, 1).charAt(0);
+ } catch (BadLocationException e) {
+ e.printStackTrace();
+ return offset;
+ }
+ while( backedUpOffset > 0 && (charAtOffset == '\n' || charAtOffset == '\t' || charAtOffset == ' ') ) {
+ backedUpOffset--;
+ try {
+ charAtOffset = changelog_doc.get(backedUpOffset, 1).charAt(0);
+ } catch (BadLocationException e) {
+ e.printStackTrace();
+ break;
+ }
+ }
+ if ( (initialOffset - backedUpOffset) > 2 ) {
+ try {
+ int replaceLength = (initialOffset - backedUpOffset - 2);
+ changelog_doc.replace(backedUpOffset + 2, replaceLength, "");
+ // change offset accordingly
+ offset -= replaceLength;
+ } catch (BadLocationException e) {
+ // exception should have been thrown earlier if that's
+ // really a bad location...
+ }
+ }
+ return offset;
+ }
+
private IWorkspaceRoot getWorkspaceRoot() {
return ResourcesPlugin.getWorkspace().getRoot();
}

Back to the top