Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Valenta2003-09-12 11:38:07 -0400
committerMichael Valenta2003-09-12 11:38:07 -0400
commit5e6ece1660b68f5f2c16d122a2509285d8ef8d07 (patch)
treecd5a3c206a440bccc838c4eb8beb8f5d0b1332cd
parentd41c7eba8406a910c772223c3d6b20a73324da95 (diff)
downloadeclipse.platform.team-5e6ece1660b68f5f2c16d122a2509285d8ef8d07.tar.gz
eclipse.platform.team-5e6ece1660b68f5f2c16d122a2509285d8ef8d07.tar.xz
eclipse.platform.team-5e6ece1660b68f5f2c16d122a2509285d8ef8d07.zip
42982: Retrieving files from CVS doesn't convert the line breaks as it should
-rw-r--r--bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/CRLFDetectInputStream.java72
-rw-r--r--bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Session.java11
2 files changed, 81 insertions, 2 deletions
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/CRLFDetectInputStream.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/CRLFDetectInputStream.java
new file mode 100644
index 000000000..ccbd50c89
--- /dev/null
+++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/CRLFDetectInputStream.java
@@ -0,0 +1,72 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.team.internal.ccvs.core.client;
+
+import java.io.FilterInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.team.internal.ccvs.core.CVSProviderPlugin;
+
+/**
+ * Stream which detects CRLF in text file contents recieved from the server
+ */
+public class CRLFDetectInputStream extends FilterInputStream {
+
+ private boolean previousCR;
+ private String filename;
+
+ protected CRLFDetectInputStream(InputStream in, String filename) {
+ super(in);
+ this.filename = filename;
+ }
+
+ /**
+ * Wraps the underlying stream's method.
+ * Translates CR/LF sequences to LFs transparently.
+ * @throws InterruptedIOException if the operation was interrupted before all of the
+ * bytes specified have been skipped, bytesTransferred will be zero
+ * @throws IOException if an i/o error occurs
+ */
+ public int read() throws IOException {
+ int next = in.read();
+ if (next != -1) {
+ testForCRLF((byte)next);
+ }
+ return next;
+ }
+
+ /**
+ * Wraps the underlying stream's method.
+ * Translates CR/LF sequences to LFs transparently.
+ * @throws InterruptedIOException if the operation was interrupted before all of the
+ * bytes specified have been skipped, bytesTransferred may be non-zero
+ * @throws IOException if an i/o error occurs
+ */
+ public int read(byte[] buffer, int off, int len) throws IOException {
+ int count = super.read(buffer, off, len);
+ for (int i = off; i < count; i++) {
+ testForCRLF(buffer[i]);
+ }
+ return count;
+ }
+
+ /**
+ * Test the byte to see if a CRLF sequence was read
+ */
+ private void testForCRLF(byte next) {
+ if (previousCR && next == '\n') {
+ CVSProviderPlugin.log(IStatus.WARNING, "Server file " + filename + " contains invalid line endings for a text file (CR/LF instead of just LF) or is a binary file that is not properly marked as such.", null);
+ }
+ previousCR = (next == '\r');
+ }
+}
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Session.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Session.java
index 8196edc9b..88bbc3fb2 100644
--- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Session.java
+++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Session.java
@@ -456,7 +456,6 @@ public class Session {
Iterator iter = unhandledMappings.iterator();
while (iter.hasNext()) {
IPath desiredPath = (IPath) iter.next();
- IPath actualPath = (IPath)mappings.get(desiredPath);
status.add(new CVSStatus(IStatus.ERROR, CVSStatus.CASE_VARIANT_EXISTS,
Policy.bind("PruneFolderVisitor.caseVariantExists", desiredPath.toString())));//$NON-NLS-1$
}
@@ -948,7 +947,15 @@ public class Session {
// if not binary, translate line delimiters on the fly
if (! isBinary) {
// switch from LF to CRLF if appropriate
- if (IS_CRLF_PLATFORM) in = new LFtoCRLFInputStream(in);
+ if (IS_CRLF_PLATFORM) {
+ // auto-correct for CRLF line-ends that come from the server
+ in = new CRLFtoLFInputStream(in);
+ // convert LF to CRLF
+ in = new LFtoCRLFInputStream(in);
+ } else {
+ // be nice and warn about text files that contain CRLF
+ in = new CRLFDetectInputStream(in, file.getName());
+ }
}
// write the file locally
file.setContents(in, responseType, true, new NullProgressMonitor());

Back to the top