diff --git a/src/main/java/git/lfs/migrate/GitConverter.java b/src/main/java/git/lfs/migrate/GitConverter.java index 537bfe5..8d08ebe 100644 --- a/src/main/java/git/lfs/migrate/GitConverter.java +++ b/src/main/java/git/lfs/migrate/GitConverter.java @@ -112,7 +112,7 @@ public Iterable depends() throws IOException { @NotNull @Override - public ObjectId convert(@NotNull ObjectInserter inserter, @NotNull ConvertResolver resolver, @Nullable Uploader uploader) throws IOException { + public ObjectId convert(@NotNull Repository dstRepo, @NotNull ObjectInserter inserter, @NotNull ConvertResolver resolver, @Nullable Uploader uploader) throws IOException { return objectId; } }; @@ -131,7 +131,7 @@ public Iterable depends() { @NotNull @Override - public ObjectId convert(@NotNull ObjectInserter inserter, @NotNull ConvertResolver resolver, @Nullable Uploader uploader) throws IOException { + public ObjectId convert(@NotNull Repository dstRepo, @NotNull ObjectInserter inserter, @NotNull ConvertResolver resolver, @Nullable Uploader uploader) throws IOException { final ObjectId id = resolver.resolve(TaskType.Simple, "", revObject.getObject()); final TagBuilder builder = new TagBuilder(); builder.setMessage(revObject.getFullMessage()); @@ -159,7 +159,7 @@ public Iterable depends() { @NotNull @Override - public ObjectId convert(@NotNull ObjectInserter inserter, @NotNull ConvertResolver resolver, @Nullable Uploader uploader) throws IOException { + public ObjectId convert(@NotNull Repository dstRepo, @NotNull ObjectInserter inserter, @NotNull ConvertResolver resolver, @Nullable Uploader uploader) throws IOException { final CommitBuilder builder = new CommitBuilder(); builder.setAuthor(revObject.getAuthorIdent()); builder.setCommitter(revObject.getCommitterIdent()); @@ -220,7 +220,7 @@ public Iterable depends() throws IOException { @NotNull @Override - public ObjectId convert(@NotNull ObjectInserter inserter, @NotNull ConvertResolver resolver, @Nullable Uploader uploader) throws IOException { + public ObjectId convert(@NotNull Repository dstRepo, @NotNull ObjectInserter inserter, @NotNull ConvertResolver resolver, @Nullable Uploader uploader) throws IOException { final List entries = getEntries(); // Create new tree. Collections.sort(entries); @@ -270,14 +270,16 @@ public Iterable depends() throws IOException { @NotNull @Override - public ObjectId convert(@NotNull ObjectInserter inserter, @NotNull ConvertResolver resolver, @Nullable Uploader uploader) throws IOException { + public ObjectId convert(@NotNull Repository dstRepo, @NotNull ObjectInserter inserter, @NotNull ConvertResolver resolver, @Nullable Uploader uploader) throws IOException { final ObjectLoader loader = reader.open(id, Constants.OBJ_BLOB); // Is empty blob (see #21)? if (loader.getSize() == 0) { + if (dstRepo.hasObject(id)) return id; return copy(inserter, loader); } // Is object already converted? if (isLfsPointer(loader)) { + if (dstRepo.hasObject(id)) return id; return copy(inserter, loader); } final String hash = (uploader == null) ? createLocalFile(id, loader) : createRemoteFile(id, loader, uploader); @@ -388,7 +390,7 @@ public Iterable depends() throws IOException { @NotNull @Override - public ObjectId convert(@NotNull ObjectInserter inserter, @NotNull ConvertResolver resolver, @Nullable Uploader uploader) throws IOException { + public ObjectId convert(@NotNull Repository dstRepo, @NotNull ObjectInserter inserter, @NotNull ConvertResolver resolver, @Nullable Uploader uploader) throws IOException { final Set attributes = new TreeSet<>(); for (String glob : globs) { attributes.add(glob + "\tfilter=lfs diff=lfs merge=lfs -text"); @@ -423,7 +425,8 @@ public Iterable depends() throws IOException { @NotNull @Override - public ObjectId convert(@NotNull ObjectInserter inserter, @NotNull ConvertResolver resolver, @Nullable Uploader uploader) throws IOException { + public ObjectId convert(@NotNull Repository dstRepo, @NotNull ObjectInserter inserter, @NotNull ConvertResolver resolver, @Nullable Uploader uploader) throws IOException { + if (dstRepo.hasObject(id)) return id; return copy(inserter, reader.open(id)); } }; @@ -469,7 +472,7 @@ public interface ConvertTask { Iterable depends() throws IOException; @NotNull - ObjectId convert(@NotNull ObjectInserter inserter, @NotNull ConvertResolver resolver, @Nullable Uploader uploader) throws IOException; + ObjectId convert(@NotNull Repository dstRepo, @NotNull ObjectInserter inserter, @NotNull ConvertResolver resolver, @Nullable Uploader uploader) throws IOException; } @FunctionalInterface diff --git a/src/main/java/git/lfs/migrate/Main.java b/src/main/java/git/lfs/migrate/Main.java index 44bfce2..a459421 100644 --- a/src/main/java/git/lfs/migrate/Main.java +++ b/src/main/java/git/lfs/migrate/Main.java @@ -156,6 +156,7 @@ public static void processRepository(@NotNull Path srcPath, @NotNull Path dstPat try (DB cache = DBMaker.fileDB(cachePath.resolve("git-lfs-migrate.mapdb").toFile()) .fileMmapEnableIfSupported() + .checksumHeaderBypass() .make()) { final GitConverter converter = new GitConverter(cache, dstPath, globs); dstRepo.create(true); @@ -204,7 +205,7 @@ private static void processSingleThread(@NotNull GitConverter converter, @NotNul } } if (taskReady) { - final ObjectId objectId = converter.convertTask(reader, taskKey).convert(inserter, converted::get, uploader); + final ObjectId objectId = converter.convertTask(reader, taskKey).convert(dstRepo, inserter, converted::get, uploader); converted.put(taskKey, objectId); reporter.increment(); } @@ -259,7 +260,7 @@ private static Deque processWithoutDependencies(@NotNull GitConverter c while (!done.get()) { final TaskKey taskKey = channel.take(); if (taskKey.getType() == GitConverter.TaskType.EndMark) break; - final ObjectId objectId = converter.convertTask(reader, taskKey).convert(inserter, converted::get, uploader); + final ObjectId objectId = converter.convertTask(reader, taskKey).convert(dstRepo, inserter, converted::get, uploader); converted.put(taskKey, objectId); reporter.increment(); }