Mercurial > hg4j
comparison src/org/tmatesoft/hg/internal/DiffHelper.java @ 680:58a6900f845d
Blame: alternative strategy to handle merge revisions: map(diff(p1->base->p2)) to understand merge intentions better
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Sun, 21 Jul 2013 17:15:34 +0200 |
parents | 507602cb4fb3 |
children |
comparison
equal
deleted
inserted
replaced
679:19f5167c2155 | 680:58a6900f845d |
---|---|
81 matchInspector = insp; | 81 matchInspector = insp; |
82 findMatchingBlocks(0, seq1.chunkCount(), 0, seq2.chunkCount()); | 82 findMatchingBlocks(0, seq1.chunkCount(), 0, seq2.chunkCount()); |
83 insp.end(); | 83 insp.end(); |
84 } | 84 } |
85 | 85 |
86 /** | |
87 * look up every line in s2 that match lines in s1 | |
88 * idea: pure additions in s2 are diff-ed against s1 again and again, to see if there are any matches | |
89 */ | |
90 void findAllMatchAlternatives(final MatchInspector<T> insp) { | |
91 assert seq1.chunkCount() > 0; | |
92 final IntSliceSeq insertions = new IntSliceSeq(2); | |
93 final boolean matchedAny[] = new boolean[] {false}; | |
94 DeltaInspector<T> myInsp = new DeltaInspector<T>() { | |
95 @Override | |
96 protected void unchanged(int s1From, int s2From, int length) { | |
97 matchedAny[0] = true; | |
98 insp.match(s1From, s2From, length); | |
99 } | |
100 @Override | |
101 protected void added(int s1InsertPoint, int s2From, int s2To) { | |
102 insertions.add(s2From, s2To); | |
103 } | |
104 }; | |
105 matchInspector = myInsp; | |
106 myInsp.begin(seq1, seq2); | |
107 IntSliceSeq s2RangesToCheck = new IntSliceSeq(2, 1, 0); | |
108 s2RangesToCheck.add(0, seq2.chunkCount()); | |
109 do { | |
110 IntSliceSeq nextCheck = new IntSliceSeq(2); | |
111 for (IntTuple t : s2RangesToCheck) { | |
112 int s2Start = t.at(0); | |
113 int s2End = t.at(1); | |
114 myInsp.changeStartS1 = 0; | |
115 myInsp.changeStartS2 = s2Start; | |
116 insp.begin(seq1, seq2); | |
117 matchedAny[0] = false; | |
118 findMatchingBlocks(0, seq1.chunkCount(), s2Start, s2End); | |
119 insp.end(); | |
120 myInsp.end(); | |
121 if (matchedAny[0]) { | |
122 nextCheck.addAll(insertions); | |
123 } | |
124 insertions.clear(); | |
125 } | |
126 s2RangesToCheck = nextCheck; | |
127 } while (s2RangesToCheck.size() > 0); | |
128 } | |
129 | |
86 /** | 130 /** |
87 * implementation based on Python's difflib.py and SequenceMatcher | 131 * implementation based on Python's difflib.py and SequenceMatcher |
88 */ | 132 */ |
89 public int longestMatch(int startS1, int endS1, int startS2, int endS2) { | 133 public int longestMatch(int startS1, int endS1, int startS2, int endS2) { |
90 matchStartS1 = matchStartS2 = 0; | 134 matchStartS1 = matchStartS2 = 0; |