1 /*******************************************************************************
2 * Copyright (C) 2010, 2013 Dariusz Luksza <dariusz@luksza.org> and others.
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License 2.0
6 * which accompanies this distribution, and is available at
7 * https://www.eclipse.org/legal/epl-2.0/
9 * SPDX-License-Identifier: EPL-2.0
10 *******************************************************************************/
11 package org
.eclipse
.egit
.ui
.internal
.synchronize
.model
;
15 import org
.eclipse
.compare
.structuremergeviewer
.Differencer
;
16 import org
.eclipse
.core
.runtime
.IPath
;
17 import org
.eclipse
.core
.runtime
.Path
;
18 import org
.eclipse
.egit
.core
.synchronize
.GitCommitsModelCache
.Change
;
19 import org
.eclipse
.egit
.ui
.internal
.UIText
;
20 import org
.eclipse
.egit
.ui
.internal
.synchronize
.model
.TreeBuilder
.FileModelFactory
;
21 import org
.eclipse
.egit
.ui
.internal
.synchronize
.model
.TreeBuilder
.TreeModelFactory
;
22 import org
.eclipse
.jgit
.lib
.Repository
;
25 * Git cache representation in EGit Change Set
27 public class GitModelCache
extends GitModelObjectContainer
{
29 private final Path location
;
31 private final Repository repo
;
33 private GitModelObject
[] children
;
36 * Constructs model node that represents current status of Git cache.
42 * repository associated with this object
44 * cache containing all changed objects
46 public GitModelCache(GitModelRepository parent
, Repository repo
,
47 Map
<String
, Change
> cache
) {
48 this(parent
, repo
, cache
, new FileModelFactory() {
50 public GitModelBlob
createFileModel(
51 GitModelObjectContainer objParent
, Repository nestedRepo
,
52 Change change
, IPath path
) {
53 return new GitModelCacheFile(objParent
, nestedRepo
, change
,
58 public boolean isWorkingTree() {
68 * repository associated with this object
70 * list of changes associated with this object
72 * leaf instance factory
74 protected GitModelCache(GitModelRepository parent
, final Repository repo
,
75 Map
<String
, Change
> changes
, final FileModelFactory fileFactory
) {
78 this.location
= new Path(repo
.getWorkTree().toString());
80 this.children
= TreeBuilder
.build(this, repo
, changes
, fileFactory
,
81 new TreeModelFactory() {
83 public GitModelTree
createTreeModel(
84 GitModelObjectContainer parentObject
,
87 return new GitModelCacheTree(parentObject
, repo
,
88 fullPath
, fileFactory
);
94 public String
getName() {
95 return UIText
.GitModelIndex_index
;
99 public GitModelObject
[] getChildren() {
104 public int getKind() {
105 return Differencer
.CHANGE
| Differencer
.RIGHT
;
109 public int repositoryHashCode() {
110 return repo
.getWorkTree().hashCode();
114 public boolean equals(Object obj
) {
118 if (obj
instanceof GitModelCache
119 && !(obj
instanceof GitModelWorkingTree
)) {
120 GitModelCache left
= (GitModelCache
) obj
;
121 return left
.getParent().equals(getParent());
128 public int hashCode() {
129 return repositoryHashCode();
133 public IPath
getLocation() {
138 public String
toString() {
139 return "ModelCache"; //$NON-NLS-1$
143 public void dispose() {
144 if (children
!= null) {
145 for (GitModelObject object
: children
)