Example usage for org.eclipse.jgit.util.io NullOutputStream INSTANCE

List of usage examples for org.eclipse.jgit.util.io NullOutputStream INSTANCE

Introduction

In this page you can find the example usage for org.eclipse.jgit.util.io NullOutputStream INSTANCE.

Prototype

NullOutputStream INSTANCE

To view the source code for org.eclipse.jgit.util.io NullOutputStream INSTANCE.

Click Source Link

Document

The canonical instance.

Usage

From source file:boa.datagen.scm.GitCommit.java

License:Apache License

private void getChangeFiles(final RevCommit parent, final RevCommit rc,
        final HashMap<String, String> rChangedPaths, final HashMap<String, String> rRemovedPaths,
        final HashMap<String, String> rAddedPaths) {
    final DiffFormatter df = new DiffFormatter(NullOutputStream.INSTANCE);
    df.setRepository(repository);/* w w w  .  j a va 2s  . com*/
    df.setDiffComparator(RawTextComparator.DEFAULT);
    df.setDetectRenames(true);

    try {
        final AbstractTreeIterator parentIter;
        if (parent == null)
            parentIter = new EmptyTreeIterator();
        else
            parentIter = new CanonicalTreeParser(null, repository.newObjectReader(), parent.getTree());

        for (final DiffEntry diff : df.scan(parentIter,
                new CanonicalTreeParser(null, repository.newObjectReader(), rc.getTree()))) {
            if (diff.getChangeType() == ChangeType.MODIFY || diff.getChangeType() == ChangeType.COPY
                    || diff.getChangeType() == ChangeType.RENAME) {
                if (diff.getOldMode().getObjectType() == Constants.OBJ_BLOB
                        && diff.getNewMode().getObjectType() == Constants.OBJ_BLOB) {
                    String path = diff.getNewPath();
                    rChangedPaths.put(path, diff.getOldPath());
                    filePathGitObjectIds.put(path, diff.getNewId().toObjectId());
                }
            } else if (diff.getChangeType() == ChangeType.ADD) {
                if (diff.getNewMode().getObjectType() == Constants.OBJ_BLOB) {
                    String path = diff.getNewPath();
                    rAddedPaths.put(path, null);
                    filePathGitObjectIds.put(path, diff.getNewId().toObjectId());
                }
            } else if (diff.getChangeType() == ChangeType.DELETE) {
                if (diff.getOldMode().getObjectType() == Constants.OBJ_BLOB) {
                    rRemovedPaths.put(diff.getOldPath(), diff.getOldPath());
                }
            }
        }
    } catch (final IOException e) {
        if (debug)
            System.err.println("Git Error getting commit diffs: " + e.getMessage());
    }
    df.close();
}

From source file:com.gitblit.utils.DiffStatFormatter.java

License:Apache License

public DiffStatFormatter(String commitId, Repository repository) {
    super(NullOutputStream.INSTANCE);
    diffStat = new DiffStat(commitId, repository);
}

From source file:com.google.gerrit.pgm.Reindex.java

License:Apache License

private int indexAll() throws Exception {
    ProgressMonitor pm = new TextProgressMonitor();
    pm.start(1);/*www.ja va 2  s  . co m*/
    pm.beginTask("Collecting projects", ProgressMonitor.UNKNOWN);
    Set<Project.NameKey> projects = Sets.newTreeSet();
    int changeCount = 0;
    try (ReviewDb db = sysInjector.getInstance(ReviewDb.class)) {
        for (Change change : db.changes().all()) {
            changeCount++;
            if (projects.add(change.getProject())) {
                pm.update(1);
            }
        }
    }
    pm.endTask();

    SiteIndexer batchIndexer = sysInjector.getInstance(SiteIndexer.class);
    SiteIndexer.Result result = batchIndexer.setNumChanges(changeCount).setProgressOut(System.err)
            .setVerboseOut(verbose ? System.out : NullOutputStream.INSTANCE).indexAll(index, projects);
    int n = result.doneCount() + result.failedCount();
    double t = result.elapsed(TimeUnit.MILLISECONDS) / 1000d;
    System.out.format("Reindexed %d changes in %.01fs (%.01f/s)\n", n, t, n / t);
    return result.success() ? 0 : 1;
}

From source file:com.google.gerrit.server.index.ChangeBatchIndexer.java

License:Apache License

public Result indexAll(ChangeIndex index, Iterable<Project.NameKey> projects, int numProjects, int numChanges,
        OutputStream progressOut, OutputStream verboseOut) {
    if (progressOut == null) {
        progressOut = NullOutputStream.INSTANCE;
    }//from  www  . j a v a 2s .c  o  m
    PrintWriter verboseWriter = verboseOut != null ? new PrintWriter(verboseOut) : null;

    Stopwatch sw = Stopwatch.createStarted();
    final MultiProgressMonitor mpm = new MultiProgressMonitor(progressOut, "Reindexing changes");
    final Task projTask = mpm.beginSubTask("projects",
            numProjects >= 0 ? numProjects : MultiProgressMonitor.UNKNOWN);
    final Task doneTask = mpm.beginSubTask(null, numChanges >= 0 ? numChanges : MultiProgressMonitor.UNKNOWN);
    final Task failedTask = mpm.beginSubTask("failed", MultiProgressMonitor.UNKNOWN);

    final List<ListenableFuture<?>> futures = Lists.newArrayList();
    final AtomicBoolean ok = new AtomicBoolean(true);

    for (final Project.NameKey project : projects) {
        final ListenableFuture<?> future = executor.submit(
                reindexProject(indexerFactory.create(index), project, doneTask, failedTask, verboseWriter));
        futures.add(future);
        future.addListener(new Runnable() {
            @Override
            public void run() {
                try {
                    future.get();
                } catch (InterruptedException e) {
                    fail(project, e);
                } catch (ExecutionException e) {
                    fail(project, e);
                } catch (RuntimeException e) {
                    failAndThrow(project, e);
                } catch (Error e) {
                    failAndThrow(project, e);
                } finally {
                    projTask.update(1);
                }
            }

            private void fail(Project.NameKey project, Throwable t) {
                log.error("Failed to index project " + project, t);
                ok.set(false);
            }

            private void failAndThrow(Project.NameKey project, RuntimeException e) {
                fail(project, e);
                throw e;
            }

            private void failAndThrow(Project.NameKey project, Error e) {
                fail(project, e);
                throw e;
            }
        }, MoreExecutors.sameThreadExecutor());
    }

    try {
        mpm.waitFor(Futures.transform(Futures.successfulAsList(futures), new AsyncFunction<List<?>, Void>() {
            @Override
            public ListenableFuture<Void> apply(List<?> input) {
                mpm.end();
                return Futures.immediateFuture(null);
            }
        }));
    } catch (ExecutionException e) {
        log.error("Error in batch indexer", e);
        ok.set(false);
    }
    return new Result(sw, ok.get(), doneTask.getCount(), failedTask.getCount());
}

From source file:com.google.gitiles.CommitSoyData.java

License:Open Source License

private Object computeDiffTree(RevCommit commit) throws IOException {
    AbstractTreeIterator oldTree;//from   www  . j av a2 s  . c o m
    GitilesView.Builder diffUrl = GitilesView.diff().copyFrom(view).setTreePath("");
    switch (commit.getParentCount()) {
    case 0:
        oldTree = new EmptyTreeIterator();
        diffUrl.setOldRevision(Revision.NULL);
        break;
    case 1:
        oldTree = getTreeIterator(walk, commit.getParent(0));
        diffUrl.setOldRevision(view.getRevision().getName() + "^", commit.getParent(0));
        break;
    default:
        // TODO(dborowitz): handle merges
        return NullData.INSTANCE;
    }
    AbstractTreeIterator newTree = getTreeIterator(walk, commit);

    DiffFormatter diff = new DiffFormatter(NullOutputStream.INSTANCE);
    try {
        diff.setRepository(repo);
        diff.setDetectRenames(true);

        List<Object> result = Lists.newArrayList();
        for (DiffEntry e : diff.scan(oldTree, newTree)) {
            Map<String, Object> entry = Maps.newHashMapWithExpectedSize(5);
            entry.put("path", e.getNewPath());
            entry.put("url", GitilesView.path().copyFrom(view).setTreePath(e.getNewPath()).toUrl());
            entry.put("diffUrl", diffUrl.setAnchor("F" + result.size()).toUrl());
            entry.put("changeType", e.getChangeType().toString());
            if (e.getChangeType() == ChangeType.COPY || e.getChangeType() == ChangeType.RENAME) {
                entry.put("oldPath", e.getOldPath());
            }
            result.add(entry);
        }
        return result;
    } finally {
        diff.release();
    }
}

From source file:com.tasktop.c2c.server.scm.service.GitServiceBean.java

License:Open Source License

private static List<com.tasktop.c2c.server.scm.domain.DiffEntry> getDiffEntries(final Repository repo,
        final RevCommit baseCommit, final RevCommit commit, final RawTextComparator cmp, final Integer context)
        throws IOException {
    final DiffFormatter df = new DiffFormatter(NullOutputStream.INSTANCE);
    df.setRepository(repo);/* w  w w  . j av  a  2s.c  o m*/
    df.setDiffComparator(cmp);
    df.setDetectRenames(true);

    RevTree baseTree = null;
    if (baseCommit != null) {
        baseTree = baseCommit.getTree();
    } else {
        RevCommit parentCommit = getParentCommit(repo, commit);
        if (parentCommit != null) {
            baseTree = parentCommit.getTree();
        }
    }
    final List<com.tasktop.c2c.server.scm.domain.DiffEntry> retval = new ArrayList<com.tasktop.c2c.server.scm.domain.DiffEntry>();
    for (DiffEntry de : df.scan(getTreeIterator(repo, baseTree), getTreeIterator(repo, commit.getTree()))) {
        retval.add(GitBrowseUtil.getDiffEntry(de, repo, context));
    }
    return retval;
}

From source file:org.eclipse.orion.server.gerritfs.DiffCommand.java

License:Eclipse Distribution License

/**
 * Executes the {@code Diff} command with all the options and parameters collected by the setter methods (e.g. {@link #setCached(boolean)} of this class.
 * Each instance of this class should only be used for one invocation of the command. Don't call this method twice on an instance.
 *
 * @return a DiffEntry for each path which is different
 *//*from   w  w  w  . j  a v a2s.c om*/
@Override
public List<DiffEntry> call() throws GitAPIException {
    final DiffFormatter diffFmt;
    if (out != null && !showNameAndStatusOnly)
        diffFmt = new DiffFormatter(new BufferedOutputStream(out));
    else
        diffFmt = new DiffFormatter(NullOutputStream.INSTANCE);
    if (ignoreWS)
        diffFmt.setDiffComparator(RawTextComparator.WS_IGNORE_ALL);
    diffFmt.setRepository(repo);
    diffFmt.setProgressMonitor(monitor);
    try {
        if (cached) {
            if (oldTree == null) {
                ObjectId head = repo.resolve(HEAD + "^{tree}"); //$NON-NLS-1$
                if (head == null)
                    throw new NoHeadException(JGitText.get().cannotReadTree);
                CanonicalTreeParser p = new CanonicalTreeParser();
                ObjectReader reader = repo.newObjectReader();
                try {
                    p.reset(reader, head);
                } finally {
                    reader.release();
                }
                oldTree = p;
            }
            newTree = new DirCacheIterator(repo.readDirCache());
        } else {
            if (oldTree == null)
                oldTree = new DirCacheIterator(repo.readDirCache());
            if (newTree == null)
                newTree = new FileTreeIterator(repo);
        }

        diffFmt.setPathFilter(pathFilter);

        List<DiffEntry> result = diffFmt.scan(oldTree, newTree);
        if (showNameAndStatusOnly)
            return result;
        else {
            if (contextLines >= 0)
                diffFmt.setContext(contextLines);
            if (destinationPrefix != null)
                diffFmt.setNewPrefix(destinationPrefix);
            if (sourcePrefix != null)
                diffFmt.setOldPrefix(sourcePrefix);
            diffFmt.format(result);
            diffFmt.flush();
            return result;
        }
    } catch (IOException e) {
        throw new JGitInternalException(e.getMessage(), e);
    } finally {
        diffFmt.release();
    }
}

From source file:org.eclipse.orion.server.gerritfs.GitDiff.java

License:Open Source License

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    handleAuth(request);//from   w  w w  . j  a va  2  s.com
    try {
        //
        String parts = request.getParameter("parts"); //$NON-NLS-1$
        String pathInfo = request.getPathInfo();
        Pattern ptrn = Pattern.compile("/([^/]*)(?:/([^/]*)(?:/(.*))?)?");
        Matcher matcher = ptrn.matcher(pathInfo);
        matcher.matches();
        String sha = null;
        String projectName = null;
        String refName = null;
        if (matcher.groupCount() > 0) {
            sha = matcher.group(1);
            projectName = matcher.group(2);
            refName = matcher.group(3);
            if (sha == null || sha.equals("")) {
                sha = null;
            } else {
                sha = java.net.URLDecoder.decode(sha, "UTF-8");
            }
            if (projectName == null || projectName.equals("")) {
                projectName = null;
            } else {
                projectName = java.net.URLDecoder.decode(projectName, "UTF-8");
            }
            if (refName == null || refName.equals("")) {
                refName = null;
            } else {
                refName = java.net.URLDecoder.decode(refName, "UTF-8");
            }
        }
        NameKey projName = NameKey.parse(projectName);
        repo = repoManager.openRepository(projName);
        //
        if ("uris".equals(parts)) { //$NON-NLS-1$
            writeJSONResponse(request, response, getDiff(request));
            return;
        }
        if ("diff".equals(parts)) {//$NON-NLS-1$
            handleGetDiff(request, response, repo, sha, refName, response.getOutputStream());

        } else {
            handleGetDiffs(request, response, repo, sha, refName, NullOutputStream.INSTANCE);
        }
        //         if ("diffs".equals(parts)) //$NON-NLS-1$
        // return handleGetDiffs(request, response, db, gitSegment,
        // pattern);
    } catch (Exception e) {

    }
    return; // unknown part

}

From source file:org.guvnor.asset.management.backend.command.ListCommitsCommand.java

License:Apache License

protected List<String> getFilesInCommit(Repository repository, ObjectId commitId) {
    List<String> list = new ArrayList<String>();

    RevWalk rw = new RevWalk(repository);

    try {//from  www  .ja v a2s .  c o m
        RevCommit commit = rw.parseCommit(commitId);
        if (commit == null) {
            return list;
        }

        if (commit.getParentCount() == 0) {
            TreeWalk tw = new TreeWalk(repository);
            tw.reset();
            tw.setRecursive(true);
            tw.addTree(commit.getTree());
            while (tw.next()) {
                list.add(tw.getPathString());
            }
            tw.release();
        } else {
            RevCommit parent = rw.parseCommit(commit.getParent(0).getId());
            DiffFormatter df = new DiffFormatter(NullOutputStream.INSTANCE);
            df.setRepository(repository);
            df.setDiffComparator(RawTextComparator.DEFAULT);
            df.setDetectRenames(true);
            List<DiffEntry> diffs = df.scan(parent.getTree(), commit.getTree());
            for (DiffEntry diff : diffs) {

                if (diff.getChangeType().equals(DiffEntry.ChangeType.DELETE)) {
                    list.add(diff.getOldPath());
                } else if (diff.getChangeType().equals(DiffEntry.ChangeType.RENAME)) {
                    list.add(diff.getNewPath());
                } else {
                    list.add(diff.getNewPath());
                }

            }
        }
    } catch (Throwable t) {
        logger.error("Unable to determine files in commit due to {} in repository {}", t, repository);
    } finally {
        rw.dispose();
    }
    return list;
}

From source file:org.kercoin.magrit.sshd.commands.AbstractCommandTest.java

License:Open Source License

@Test
public void testSetOutputStream() {
    // given ---------------------------------
    cmd.logStreams = true;//from  w w  w .  j  a  va2 s  .c  o m

    // when ----------------------------------
    cmd.setOutputStream(NullOutputStream.INSTANCE);

    // then ----------------------------------
    assertThat(cmd.getOutputStream()).isInstanceOf(LoggerOutputStream.class);
}