Skip to content
This repository has been archived by the owner on Jun 24, 2024. It is now read-only.

Commit

Permalink
Switch to DivSuffixSort and fix patchgen bug.
Browse files Browse the repository at this point in the history
Credit to admo@google.com for investigating DivsuffixSort and making it
work well with the existing framework.

This speeds up patch generation by up to 50%. It also fixes issue 7,
which could cause bad patches to be generated when multiple entries in
the "new" archive were matches for an entry in the "old" archive (e.g.,
a file copied to two paths in the "new" archive).
  • Loading branch information
andrewhayden committed Jul 29, 2016
1 parent 8ffe39d commit 729c0d5
Show file tree
Hide file tree
Showing 8 changed files with 2,349 additions and 60 deletions.
24 changes: 24 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,27 @@
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

===========================================================================

The following applies to DivSuffixSorter.java:

MIT License:

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
* Plans archive transformations to be made prior to differencing.
Expand Down Expand Up @@ -86,8 +88,8 @@ class PreDiffPlanner {
* @throws IOException if there are any problems reading the input files
*/
PreDiffPlan generatePreDiffPlan() throws IOException {
List<TypedRange<Void>> oldFilePlan = new ArrayList<>();
List<TypedRange<JreDeflateParameters>> newFilePlan = new ArrayList<>();
Set<TypedRange<Void>> oldFilePlan = new HashSet<>();
Set<TypedRange<JreDeflateParameters>> newFilePlan = new HashSet<>();
List<QualifiedRecommendation> qualifiedRecommendations = new ArrayList<>();

// This will be used to find files that have been renamed, but not modified. This is relatively
Expand Down Expand Up @@ -148,12 +150,14 @@ PreDiffPlan generatePreDiffPlan() throws IOException {
}
}

Collections.sort(oldFilePlan);
Collections.sort(newFilePlan);
List<TypedRange<Void>> oldFilePlanList = new ArrayList<>(oldFilePlan);
Collections.sort(oldFilePlanList);
List<TypedRange<JreDeflateParameters>> newFilePlanList = new ArrayList<>(newFilePlan);
Collections.sort(newFilePlanList);
return new PreDiffPlan(
Collections.unmodifiableList(qualifiedRecommendations),
Collections.unmodifiableList(oldFilePlan),
Collections.unmodifiableList(newFilePlan));
Collections.unmodifiableList(oldFilePlanList),
Collections.unmodifiableList(newFilePlanList));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ public static void generatePatch(

// Do the suffix search.
try (final RandomAccessObject groupArray =
new QuickSuffixSorter(randomAccessObjectFactory).suffixSort(oldData)) {
new DivSuffixSorter(randomAccessObjectFactory).suffixSort(oldData)) {
BsDiffMatcher matcher = new BsDiffMatcher(oldData, newData, groupArray, minimumMatchLength);
generatePatchWithMatcher(oldData, newData, matcher, outputStream);
}
Expand Down
Loading

0 comments on commit 729c0d5

Please sign in to comment.