use of org.eclipse.egit.core.synchronize.GitCommitsModelCache.Change in project egit by eclipse.
the class TreeBuilder method build.
/**
* @param root
* the root node of the tree to build, which will become the
* parent of the first level of children
* @param repo
* @param changes
* @param fileFactory
* @param treeFactory
* @return the children of the root nodes
*/
public static GitModelObject[] build(final GitModelObjectContainer root, final Repository repo, final Map<String, Change> changes, final FileModelFactory fileFactory, final TreeModelFactory treeFactory) {
if (changes == null || changes.isEmpty())
return new GitModelObject[] {};
final IPath rootPath = new Path(repo.getWorkTree().getAbsolutePath());
final List<GitModelObject> rootChildren = new ArrayList<>();
final Map<IPath, Node> nodes = new HashMap<>();
for (Map.Entry<String, Change> entry : changes.entrySet()) {
String repoRelativePath = entry.getKey();
Change change = entry.getValue();
GitModelObjectContainer parent = root;
List<GitModelObject> children = rootChildren;
IPath path = rootPath;
// $NON-NLS-1$
String[] segments = repoRelativePath.split("/");
for (int i = 0; i < segments.length; i++) {
path = path.append(segments[i]);
// Changes represent files, so the last segment is the file name
boolean fileNode = (i == segments.length - 1);
if (!fileNode) {
Node node = nodes.get(path);
if (node == null) {
GitModelTree tree = treeFactory.createTreeModel(parent, path, change.getKind());
node = new Node(tree);
nodes.put(path, node);
children.add(tree);
}
parent = node.tree;
children = node.children;
} else {
GitModelBlob file = fileFactory.createFileModel(parent, repo, change, path);
children.add(file);
}
}
}
for (Node object : nodes.values()) {
GitModelTree tree = object.tree;
tree.setChildren(object.children);
}
return rootChildren.toArray(new GitModelObject[rootChildren.size()]);
}
use of org.eclipse.egit.core.synchronize.GitCommitsModelCache.Change in project egit by eclipse.
the class GitModelCommit method createChildren.
private GitModelObject[] createChildren() {
FileModelFactory fileModelFactory = new FileModelFactory() {
@Override
public GitModelBlob createFileModel(GitModelObjectContainer parent, Repository repository, Change change, IPath fullPath) {
return new GitModelBlob(parent, repository, change, fullPath);
}
@Override
public boolean isWorkingTree() {
return false;
}
};
TreeModelFactory treeModelFactory = new TreeModelFactory() {
@Override
public GitModelTree createTreeModel(GitModelObjectContainer parent, IPath fullPath, int kind) {
return new GitModelTree(parent, fullPath, kind);
}
};
return TreeBuilder.build(this, repo, commit.getChildren(), fileModelFactory, treeModelFactory);
}
use of org.eclipse.egit.core.synchronize.GitCommitsModelCache.Change in project egit by eclipse.
the class WorkingTreeChangeCacheTest method shouldListSingleWorkspaceDeletion.
@Test
public void shouldListSingleWorkspaceDeletion() throws Exception {
// given
writeTrashFile(db, "a.txt", "trash");
try (Git git = new Git(db)) {
git.add().addFilepattern("a.txt").call();
}
deleteTrashFile(db, "a.txt");
// when
Map<String, Change> result = WorkingTreeChangeCache.build(db);
// then
assertThat(result.size(), is(1));
assertFileDeletion(result, "a.txt", "a.txt");
}
use of org.eclipse.egit.core.synchronize.GitCommitsModelCache.Change in project egit by eclipse.
the class WorkingTreeChangeCacheTest method shouldListSingleWorkspaceChange.
@Test
public void shouldListSingleWorkspaceChange() throws Exception {
// given
writeTrashFile(db, "a.txt", "trash");
try (Git git = new Git(db)) {
git.add().addFilepattern("a.txt").call();
}
writeTrashFile(db, "a.txt", "modification");
// when
Map<String, Change> result = WorkingTreeChangeCache.build(db);
// then
assertThat(result.size(), is(1));
assertFileChange(result, "a.txt", "a.txt");
}
use of org.eclipse.egit.core.synchronize.GitCommitsModelCache.Change in project egit by eclipse.
the class WorkingTreeChangeCacheTest method shouldListSingleWorkspaceDeletionInFolder.
@Test
public void shouldListSingleWorkspaceDeletionInFolder() throws Exception {
// given
writeTrashFile(db, "folder/a.txt", "trash");
try (Git git = new Git(db)) {
git.add().addFilepattern("folder/a.txt").call();
}
deleteTrashFile(db, "folder/a.txt");
// when
Map<String, Change> result = WorkingTreeChangeCache.build(db);
// then
assertThat(result.size(), is(1));
assertFileDeletion(result, "folder/a.txt", "a.txt");
}
Aggregations