summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorTobias Pfeifer2013-01-17 08:45:00 (EST)
committer Tobias Pfeifer2013-01-30 07:27:50 (EST)
commit0d09b1cab7bcadd43be6c023028f7aca579944ab (patch)
treef872dcf22e2872002a764333e3df37ad95c260f5
parenteb6093293022e468c2aea93a11f63b366e0d3891 (diff)
downloadjgit-0d09b1cab7bcadd43be6c023028f7aca579944ab.zip
jgit-0d09b1cab7bcadd43be6c023028f7aca579944ab.tar.gz
jgit-0d09b1cab7bcadd43be6c023028f7aca579944ab.tar.bz2
Extract method to output the first header line of a git diffrefs/changes/03/10003/4
In order to be able to determine the range of the first header line (e.g. "diff --git a/file1 b/file2") in subclasses, the code that formats the first header line is extracted. Required by egit's change: Ia61398146c0336ab332234f24d341561292554db Change-Id: I9dd5eb964ed8b6869745c3162159b7425ac2c44a Signed-off-by: Tobias Pfeifer <to.pfeifer@sap.com>
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java33
1 files changed, 27 insertions, 6 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java b/org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java
index 4af1084..fe0db33 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java
@@ -299,7 +299,7 @@ public class DiffFormatter {
/**
* Get the prefix applied in front of new file paths.
- *
+ *
* @return the prefix
* @since 2.0
*/
@@ -1008,6 +1008,31 @@ public class DiffFormatter {
return false;
}
+ /**
+ * Output the first header line
+ *
+ * @param o
+ * The stream the formatter will write the first header line to
+ * @param type
+ * The {@link ChangeType}
+ * @param oldPath
+ * old path to the file
+ * @param newPath
+ * new path to the file
+ * @throws IOException
+ * the stream threw an exception while writing to it.
+ */
+ protected void formatGitDiffFirstHeaderLine(ByteArrayOutputStream o,
+ final ChangeType type, final String oldPath, final String newPath)
+ throws IOException {
+ o.write(encodeASCII("diff --git ")); //$NON-NLS-1$
+ o.write(encode(quotePath(oldPrefix + (type == ADD ? newPath : oldPath))));
+ o.write(' ');
+ o.write(encode(quotePath(newPrefix
+ + (type == DELETE ? oldPath : newPath))));
+ o.write('\n');
+ }
+
private void formatHeader(ByteArrayOutputStream o, DiffEntry ent)
throws IOException {
final ChangeType type = ent.getChangeType();
@@ -1016,11 +1041,7 @@ public class DiffFormatter {
final FileMode oldMode = ent.getOldMode();
final FileMode newMode = ent.getNewMode();
- o.write(encodeASCII("diff --git ")); //$NON-NLS-1$
- o.write(encode(quotePath(oldPrefix + (type == ADD ? newp : oldp))));
- o.write(' ');
- o.write(encode(quotePath(newPrefix + (type == DELETE ? oldp : newp))));
- o.write('\n');
+ formatGitDiffFirstHeaderLine(o, type, oldp, newp);
switch (type) {
case ADD: