Example usage for org.eclipse.jgit.diff DiffEntry DEV_NULL

List of usage examples for org.eclipse.jgit.diff DiffEntry DEV_NULL

Introduction

In this page you can find the example usage for org.eclipse.jgit.diff DiffEntry DEV_NULL.

Prototype

String DEV_NULL

To view the source code for org.eclipse.jgit.diff DiffEntry DEV_NULL.

Click Source Link

Document

Magical file name used for file adds or deletes.

Usage

From source file:MyDiffFormatter.java

License:Eclipse Distribution License

private void formatOldNewPaths(ByteArrayOutputStream o, DiffEntry ent) throws IOException {
    if (ent.getOldId().equals(ent.getNewId()))
        return;//from ww  w .j a  v  a 2 s . c  o  m

    final String oldp;
    final String newp;

    switch (ent.getChangeType()) {
    case ADD:
        oldp = DiffEntry.DEV_NULL;
        newp = quotePath(newPrefix + ent.getNewPath());
        break;

    case DELETE:
        oldp = quotePath(oldPrefix + ent.getOldPath());
        newp = DiffEntry.DEV_NULL;
        break;

    default:
        oldp = quotePath(oldPrefix + ent.getOldPath());
        newp = quotePath(newPrefix + ent.getNewPath());
        break;
    }

    o.write(encode("--- " + oldp + "\n")); //$NON-NLS-1$ //$NON-NLS-2$
    o.write(encode("+++ " + newp + "\n")); //$NON-NLS-1$ //$NON-NLS-2$
}

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

License:Apache License

@Test
public void diffFileNoParentsText() throws Exception {
    String contents = "foo\ncontents\n";
    RevCommit c = repo.update("master", repo.commit().add("foo", contents));

    FakeHttpServletRequest req = FakeHttpServletRequest.newRequest();
    req.setPathInfo("/test/+diff/" + c.name() + "^!/foo");
    req.setQueryString("format=TEXT");
    FakeHttpServletResponse res = new FakeHttpServletResponse();
    servlet.service(req, res);//from w  ww.j  a v  a  2  s.c om

    Patch p = parsePatch(res.getActualBody());
    FileHeader f = getOnlyElement(p.getFiles());
    assertEquals(ChangeType.ADD, f.getChangeType());
    assertEquals(DiffEntry.DEV_NULL, f.getPath(Side.OLD));
    assertEquals("foo", f.getPath(Side.NEW));

    RawText rt = new RawText(contents.getBytes(UTF_8));
    Edit e = getOnlyElement(getOnlyElement(f.getHunks()).toEditList());
    assertEquals(Type.INSERT, e.getType());
    assertEquals(contents, rt.getString(e.getBeginB(), e.getEndB(), false));
}

From source file:org.gitective.tests.DiffTest.java

License:Open Source License

/**
 * Test diffs introduced by first commit
 *
 * @throws Exception/* w w w . ja v a 2s. co  m*/
 */
@Test
public void first() throws Exception {
    add("test.txt", "content");
    final AtomicReference<Collection<DiffEntry>> ref = new AtomicReference<Collection<DiffEntry>>();
    CommitDiffFilter filter = new CommitDiffFilter() {

        public boolean include(RevCommit commit, Collection<DiffEntry> diffs) throws IOException {
            ref.set(diffs);
            return super.include(commit, diffs);
        }
    };
    new CommitFinder(testRepo).setFilter(filter).find();
    Collection<DiffEntry> diffs = ref.get();
    assertNotNull(diffs);
    assertEquals(1, diffs.size());
    DiffEntry diff = diffs.iterator().next();
    assertEquals(ChangeType.ADD, diff.getChangeType());
    assertEquals(DiffEntry.DEV_NULL, diff.getOldPath());
    assertEquals("test.txt", diff.getNewPath());
}

From source file:org.kie.commons.java.nio.fs.jgit.JGitFileSystemProvider.java

License:Apache License

private synchronized void notifyDiffs(final JGitFileSystem fs, final String tree, final ObjectId oldHead,
        final ObjectId newHead) {

    final String host = tree + "@" + fs.getName();
    final Path root = JGitPathImpl.createRoot(fs, "/", host, false);

    final List<DiffEntry> diff = JGitUtil.getDiff(fs.gitRepo().getRepository(), oldHead, newHead);
    final List<WatchEvent<?>> events = new ArrayList<WatchEvent<?>>(diff.size());

    for (final DiffEntry diffEntry : diff) {
        final Path oldPath;
        if (!diffEntry.getOldPath().equals(DiffEntry.DEV_NULL)) {
            oldPath = JGitPathImpl.create(fs, "/" + diffEntry.getOldPath(), host, null, false);
        } else {//from www  . ja  v  a  2 s.  c  o  m
            oldPath = null;
        }

        final Path newPath;
        if (!diffEntry.getNewPath().equals(DiffEntry.DEV_NULL)) {
            JGitPathInfo pathInfo = resolvePath(fs.gitRepo(), tree, diffEntry.getNewPath());
            newPath = JGitPathImpl.create(fs, "/" + pathInfo.getPath(), host, pathInfo.getObjectId(), false);
        } else {
            newPath = null;
        }

        events.add(new WatchEvent() {
            @Override
            public Kind kind() {
                switch (diffEntry.getChangeType()) {
                case ADD:
                case COPY:
                    return StandardWatchEventKind.ENTRY_CREATE;
                case DELETE:
                    return StandardWatchEventKind.ENTRY_DELETE;
                case MODIFY:
                    return StandardWatchEventKind.ENTRY_MODIFY;
                case RENAME:
                    return StandardWatchEventKind.ENTRY_RENAME;
                default:
                    throw new RuntimeException();
                }
            }

            @Override
            public int count() {
                return 1;
            }

            @Override
            public Object context() {
                switch (diffEntry.getChangeType()) {
                case ADD:
                case COPY:
                    return newPath;
                case DELETE:
                    return oldPath;
                case MODIFY:
                    return oldPath;
                case RENAME:
                    return new Pair<Path, Path>(oldPath, newPath);
                default:
                    throw new RuntimeException();
                }
            }
        });
        fs.publishEvents(root, events);
    }
}

From source file:org.uberfire.java.nio.fs.jgit.JGitFileSystemProvider.java

License:Apache License

private void notifyDiffs(final JGitFileSystem fs, final String _tree, final String sessionId,
        final String userName, final ObjectId oldHead, final ObjectId newHead) {

    final String tree;
    if (_tree.startsWith("refs/")) {
        tree = _tree.substring(_tree.lastIndexOf("/") + 1);
    } else {//from   w ww  .j  a v a 2s .  c  o m
        tree = _tree;
    }

    final String host = tree + "@" + fs.getName();
    final Path root = JGitPathImpl.createRoot(fs, "/", host, false);

    final List<DiffEntry> diff = JGitUtil.getDiff(fs.gitRepo().getRepository(), oldHead, newHead);
    final List<WatchEvent<?>> events = new ArrayList<WatchEvent<?>>(diff.size());

    for (final DiffEntry diffEntry : diff) {
        final Path oldPath;
        if (!diffEntry.getOldPath().equals(DiffEntry.DEV_NULL)) {
            oldPath = JGitPathImpl.create(fs, "/" + diffEntry.getOldPath(), host, null, false);
        } else {
            oldPath = null;
        }

        final Path newPath;
        if (!diffEntry.getNewPath().equals(DiffEntry.DEV_NULL)) {
            JGitPathInfo pathInfo = resolvePath(fs.gitRepo(), tree, diffEntry.getNewPath());
            newPath = JGitPathImpl.create(fs, "/" + pathInfo.getPath(), host, pathInfo.getObjectId(), false);
        } else {
            newPath = null;
        }

        events.add(new WatchEvent() {
            @Override
            public Kind kind() {
                switch (diffEntry.getChangeType()) {
                case ADD:
                case COPY:
                    return StandardWatchEventKind.ENTRY_CREATE;
                case DELETE:
                    return StandardWatchEventKind.ENTRY_DELETE;
                case MODIFY:
                    return StandardWatchEventKind.ENTRY_MODIFY;
                case RENAME:
                    return StandardWatchEventKind.ENTRY_RENAME;
                default:
                    throw new RuntimeException();
                }
            }

            @Override
            public int count() {
                return 1;
            }

            @Override
            public Object context() {
                return new WatchContext() {

                    @Override
                    public Path getPath() {
                        return newPath;
                    }

                    @Override
                    public Path getOldPath() {
                        return oldPath;
                    }

                    @Override
                    public String getSessionId() {
                        return sessionId;
                    }

                    @Override
                    public String getUser() {
                        return userName;
                    }
                };
            }

            @Override
            public String toString() {
                return "WatchEvent{" + "newPath=" + newPath + ", oldPath=" + oldPath + ", sessionId='"
                        + sessionId + '\'' + ", userName='" + userName + '\'' + ", changeType="
                        + diffEntry.getChangeType() + '}';
            }
        });
    }
    if (!events.isEmpty()) {
        fs.publishEvents(root, events);
    }
}