1 /*******************************************************************************
2 * Copyright (C) 2011, 2017 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
.core
.synchronize
;
13 import java
.util
.ArrayList
;
14 import java
.util
.Collection
;
15 import java
.util
.List
;
17 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
18 import org
.eclipse
.egit
.core
.internal
.CoreText
;
19 import org
.eclipse
.jgit
.lib
.ObjectId
;
20 import org
.eclipse
.jgit
.lib
.Repository
;
21 import org
.eclipse
.jgit
.revwalk
.RevCommit
;
22 import org
.eclipse
.osgi
.util
.NLS
;
23 import org
.eclipse
.team
.core
.TeamException
;
24 import org
.eclipse
.team
.core
.variants
.IResourceVariant
;
26 class GitRemoteFolder
extends GitRemoteResource
{
28 private final GitSyncObjectCache cachedData
;
29 private final Repository repo
;
37 * given object sha-1 id or {@code null} if this object doesn't
41 GitRemoteFolder(Repository repo
, GitSyncObjectCache cachedData
,
42 RevCommit commitId
, ObjectId objectId
, String path
) {
43 super(commitId
, objectId
, path
);
45 this.cachedData
= cachedData
;
49 public boolean isContainer() {
54 protected void fetchContents(IProgressMonitor monitor
) throws TeamException
{
55 // should be never used on folder
59 public boolean equals(Object object
) {
63 if (object
instanceof GitRemoteFolder
) {
64 GitRemoteFolder that
= (GitRemoteFolder
) object
;
66 return getPath().equals(that
.getPath())
67 && getObjectId().equals(that
.getObjectId());
74 public int hashCode() {
75 return getObjectId().hashCode() ^
getPath().hashCode();
78 GitRemoteResource
[] members(IProgressMonitor monitor
) {
79 Collection
<GitSyncObjectCache
> members
= cachedData
.members();
80 if (members
== null || members
.size() == 0)
81 return new GitRemoteResource
[0];
83 List
<IResourceVariant
> result
= new ArrayList
<IResourceVariant
>();
86 NLS
.bind(CoreText
.GitRemoteFolder_fetchingMembers
, getPath()),
87 cachedData
.membersCount());
89 for (GitSyncObjectCache member
: members
) {
90 ThreeWayDiffEntry diffEntry
= member
.getDiffEntry();
91 String memberPath
= diffEntry
.getPath();
93 GitRemoteResource obj
;
94 ObjectId id
= diffEntry
.getRemoteId().toObjectId();
95 if (diffEntry
.isTree()) {
96 obj
= new GitRemoteFolder(repo
, member
, getCommitId(), id
,
99 obj
= new GitRemoteFile(repo
, getCommitId(), id
, memberPath
,
100 diffEntry
.getMetadata());
109 return result
.toArray(new GitRemoteResource
[0]);