aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src/org/eclipse/jgit/patch/HunkHeader.java
diff options
context:
space:
mode:
authorShawn O. Pearce <spearce@spearce.org>2010-07-16 10:22:15 -0700
committerShawn O. Pearce <spearce@spearce.org>2010-07-16 10:22:15 -0700
commit6e155d5f415e7f62f3f25e082dbee558e5be0b2d (patch)
tree3e793afd4e2d1cdce5c6cd55c0ebfdcf51c088d1 /org.eclipse.jgit/src/org/eclipse/jgit/patch/HunkHeader.java
parent0b46e70155e1a14edc77f32e030094fb499887cf (diff)
parent31311cacfd311f9a78bdf012a9f6ba1907b9964a (diff)
downloadjgit-6e155d5f415e7f62f3f25e082dbee558e5be0b2d.tar.gz
jgit-6e155d5f415e7f62f3f25e082dbee558e5be0b2d.zip
Merge branch 'js/rename'
* js/rename: Implemented file path based tie breaking to exact rename detection Added more test cases for RenameDetector Added very small optimization to exact rename detection Fixed Misleading Javadoc Added file path similarity to scoring metric in rename detection Fixed potential div by zero bug Added file size based rename detection optimization Create FileHeader from DiffEntry log: Implement --follow Cache the diff configuration section log: Add whitespace ignore options Format submodule links during differences Redo DiffFormatter API to be easier to use log, diff: Add rename detection support Implement similarity based rename detection Added a preliminary version of rename detection Refactored code out of FileHeader to facilitate rename detection
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/patch/HunkHeader.java')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/patch/HunkHeader.java97
1 files changed, 58 insertions, 39 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/patch/HunkHeader.java b/org.eclipse.jgit/src/org/eclipse/jgit/patch/HunkHeader.java
index bfb20b64e9..a6ea74eb16 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/patch/HunkHeader.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/patch/HunkHeader.java
@@ -116,6 +116,8 @@ public class HunkHeader {
/** Total number of lines of context appearing in this hunk */
int nContext;
+ private EditList editList;
+
HunkHeader(final FileHeader fh, final int offset) {
this(fh, offset, new OldImage() {
@Override
@@ -131,6 +133,21 @@ public class HunkHeader {
old = oi;
}
+ HunkHeader(final FileHeader fh, final EditList editList) {
+ this(fh, fh.buf.length);
+ this.editList = editList;
+ endOffset = startOffset;
+ nContext = 0;
+ if (editList.isEmpty()) {
+ newStartLine = 0;
+ newLineCount = 0;
+ } else {
+ newStartLine = editList.get(0).getBeginB();
+ Edit last = editList.get(editList.size() - 1);
+ newLineCount = last.getEndB() - newStartLine;
+ }
+ }
+
/** @return header for the file this hunk applies to */
public FileHeader getFileHeader() {
return file;
@@ -173,48 +190,50 @@ public class HunkHeader {
/** @return a list describing the content edits performed within the hunk. */
public EditList toEditList() {
- final EditList r = new EditList();
- final byte[] buf = file.buf;
- int c = nextLF(buf, startOffset);
- int oLine = old.startLine;
- int nLine = newStartLine;
- Edit in = null;
-
- SCAN: for (; c < endOffset; c = nextLF(buf, c)) {
- switch (buf[c]) {
- case ' ':
- case '\n':
- in = null;
- oLine++;
- nLine++;
- continue;
-
- case '-':
- if (in == null) {
- in = new Edit(oLine - 1, nLine - 1);
- r.add(in);
+ if (editList == null) {
+ editList = new EditList();
+ final byte[] buf = file.buf;
+ int c = nextLF(buf, startOffset);
+ int oLine = old.startLine;
+ int nLine = newStartLine;
+ Edit in = null;
+
+ SCAN: for (; c < endOffset; c = nextLF(buf, c)) {
+ switch (buf[c]) {
+ case ' ':
+ case '\n':
+ in = null;
+ oLine++;
+ nLine++;
+ continue;
+
+ case '-':
+ if (in == null) {
+ in = new Edit(oLine - 1, nLine - 1);
+ editList.add(in);
+ }
+ oLine++;
+ in.extendA();
+ continue;
+
+ case '+':
+ if (in == null) {
+ in = new Edit(oLine - 1, nLine - 1);
+ editList.add(in);
+ }
+ nLine++;
+ in.extendB();
+ continue;
+
+ case '\\': // Matches "\ No newline at end of file"
+ continue;
+
+ default:
+ break SCAN;
}
- oLine++;
- in.extendA();
- continue;
-
- case '+':
- if (in == null) {
- in = new Edit(oLine - 1, nLine - 1);
- r.add(in);
- }
- nLine++;
- in.extendB();
- continue;
-
- case '\\': // Matches "\ No newline at end of file"
- continue;
-
- default:
- break SCAN;
}
}
- return r;
+ return editList;
}
void parseHeader() {