blob: 10d1e06c213337910d951259cb973613fea265c6 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
/*******************************************************************************
* Copyright (C) 2010, Dariusz Luksza <dariusz@luksza.org>
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.eclipse.egit.core.synchronize.dto;
import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.egit.core.project.RepositoryMapping;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
/**
* Simple data transfer object containing all necessary information for
* launching synchronization
*/
public class GitSynchronizeData {
private final boolean includeLocal;
private final Repository repo;
private final Ref srcRev;
private final Ref dstRev;
private final Set<IProject> projects;
private final String repoParentPath;
/**
* Constructs {@link GitSynchronizeData} object
*
* @param repository
* @param srcRev
* @param dstRev
* @param includeLocal
* <code>true</code> if local changes should be included in
* comparison
* @throws IOException
*/
public GitSynchronizeData(Repository repository, String srcRev,
String dstRev, boolean includeLocal) throws IOException {
repo = repository;
this.srcRev = repo.getRef(srcRev);
this.dstRev = repo.getRef(dstRev);
this.includeLocal = includeLocal;
repoParentPath = repo.getDirectory().getParentFile().getAbsolutePath();
projects = new HashSet<IProject>();
final IProject[] workspaceProjects = ResourcesPlugin.getWorkspace()
.getRoot().getProjects();
for (IProject project : workspaceProjects) {
RepositoryMapping mapping = RepositoryMapping.getMapping(project);
if (mapping != null && mapping.getRepository() == repo)
projects.add(project);
}
}
/**
* @return instance of repository that should be synchronized
*/
public Repository getRepository() {
return repo;
}
/**
* @return synchronize source rev name
*/
public Ref getSrcRev() {
return srcRev;
}
/**
* @return synchronize destination rev name
*/
public Ref getDstRev() {
return dstRev;
}
/**
* @return list of project's that are connected with this repository
*/
public Set<IProject> getProjects() {
return Collections.unmodifiableSet(projects);
}
/**
* @param file
* @return <true> if given {@link File} is contained by this repository
*/
public boolean contains(File file) {
return file.getAbsoluteFile().toString().startsWith(repoParentPath);
}
/**
* @return <code>true</code> if local changes should be included in
* comparison
*/
public boolean shouldIncludeLocal() {
return includeLocal;
}
}
|