Search in sources :

Example 1 with PatchBuilder

use of jetbrains.buildServer.vcs.patches.PatchBuilder in project teamcity-git by JetBrains.

the class BulkPatchBuilderImpl method buildPatches.

public void buildPatches(@NotNull final VcsRoot root, @NotNull final CheckoutRules rules, @NotNull final List<BulkPatchBuilderRequest> requests, @NotNull final BulkPatchBuilder patch) throws VcsException, IOException {
    final OperationContext ctx = myVcs.createContext(root, "bulk patch " + requests.size() + " commits");
    GitVcsRoot gitRoot = ctx.getGitRoot();
    myVcs.getRepositoryManager().runWithDisabledRemove(gitRoot.getRepositoryDir(), () -> {
        try {
            final Repository myRepo = ctx.getRepository();
            final ObjectReader contentsReader = myRepo.getObjectDatabase().newReader();
            final ObjectReader treesReader = myRepo.getObjectDatabase().newReader();
            for (BulkPatchBuilderRequest request : requests) {
                final PatchBuilder patchBuilder = patch.startPatch(request);
                final String prevBase = request.getFromVersion();
                final String toBase = request.getToVersion();
                try {
                    new GitPatchBuilder(ctx, patchBuilder, prevBase, toBase, rules, myConfig.verboseTreeWalkLog(), mySshMetaFactory) {

                        @NotNull
                        @Override
                        protected ObjectReader newObjectReaderForTree() {
                            return treesReader;
                        }

                        @NotNull
                        @Override
                        protected ContentLoaderFactory contentLoaderFactory() {
                            return new ContentLoaderFactory() {

                                @Nullable
                                public ObjectLoader open(@NotNull final Repository repo, @NotNull final ObjectId id) throws IOException {
                                    assert repo == myRepo;
                                    return contentsReader.open(id);
                                }
                            };
                        }
                    }.buildPatch();
                } catch (Throwable e) {
                    throw new VcsException("Failed to build patch " + prevBase + " -> " + toBase + ". " + e.getMessage(), e);
                } finally {
                    patch.endPatch(request, patchBuilder);
                }
            }
        } catch (Throwable e) {
            throw new VcsException("Failed to complete bulk patch." + e.getMessage(), e);
        } finally {
            ctx.close();
        }
    });
}
Also used : ObjectId(org.eclipse.jgit.lib.ObjectId) IOException(java.io.IOException) NotNull(org.jetbrains.annotations.NotNull) Repository(org.eclipse.jgit.lib.Repository) PatchBuilder(jetbrains.buildServer.vcs.patches.PatchBuilder) VcsException(jetbrains.buildServer.vcs.VcsException) ObjectReader(org.eclipse.jgit.lib.ObjectReader) ObjectLoader(org.eclipse.jgit.lib.ObjectLoader) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

IOException (java.io.IOException)1 VcsException (jetbrains.buildServer.vcs.VcsException)1 PatchBuilder (jetbrains.buildServer.vcs.patches.PatchBuilder)1 ObjectId (org.eclipse.jgit.lib.ObjectId)1 ObjectLoader (org.eclipse.jgit.lib.ObjectLoader)1 ObjectReader (org.eclipse.jgit.lib.ObjectReader)1 Repository (org.eclipse.jgit.lib.Repository)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1