1
2
3
4
5
6
7
8
9
10
11 package org.eclipse.jgit.internal.storage.dfs;
12
13 import java.io.IOException;
14 import java.io.InputStream;
15 import java.text.MessageFormat;
16 import java.util.Collections;
17
18 import org.eclipse.jgit.attributes.AttributesNode;
19 import org.eclipse.jgit.attributes.AttributesNodeProvider;
20 import org.eclipse.jgit.attributes.AttributesRule;
21 import org.eclipse.jgit.internal.JGitText;
22 import org.eclipse.jgit.lib.Constants;
23 import org.eclipse.jgit.lib.RefUpdate;
24 import org.eclipse.jgit.lib.ReflogReader;
25 import org.eclipse.jgit.lib.Repository;
26 import org.eclipse.jgit.lib.StoredConfig;
27
28
29
30
31 public abstract class DfsRepository extends Repository {
32 private final DfsConfig config;
33
34 private final DfsRepositoryDescription description;
35
36
37
38
39
40
41
42 protected DfsRepository(DfsRepositoryBuilder builder) {
43 super(builder);
44 this.config = new DfsConfig();
45 this.description = builder.getRepositoryDescription();
46 }
47
48
49 @Override
50 public abstract DfsObjDatabase getObjectDatabase();
51
52
53
54
55
56
57 public DfsRepositoryDescription getDescription() {
58 return description;
59 }
60
61
62
63
64
65
66
67
68 public boolean exists() throws IOException {
69 if (getRefDatabase() instanceof DfsRefDatabase) {
70 return ((DfsRefDatabase) getRefDatabase()).exists();
71 }
72 return true;
73 }
74
75
76 @Override
77 public void create(boolean bare) throws IOException {
78 if (exists())
79 throw new IOException(MessageFormat.format(
80 JGitText.get().repositoryAlreadyExists, ""));
81
82 String master = Constants.R_HEADS + Constants.MASTER;
83 RefUpdate.Result result = updateRef(Constants.HEAD, true).link(master);
84 if (result != RefUpdate.Result.NEW)
85 throw new IOException(result.name());
86 }
87
88
89 @Override
90 public StoredConfig getConfig() {
91 return config;
92 }
93
94
95 @Override
96 public String getIdentifier() {
97 return getDescription().getRepositoryName();
98 }
99
100
101 @Override
102 public void scanForRepoChanges() throws IOException {
103 getRefDatabase().refresh();
104 getObjectDatabase().clearCache();
105 }
106
107
108 @Override
109 public void notifyIndexChanged(boolean internal) {
110
111
112 }
113
114
115 @Override
116 public ReflogReader getReflogReader(String refName) throws IOException {
117 throw new UnsupportedOperationException();
118 }
119
120
121 @Override
122 public AttributesNodeProvider createAttributesNodeProvider() {
123
124
125 return new EmptyAttributesNodeProvider();
126 }
127
128 private static class EmptyAttributesNodeProvider implements
129 AttributesNodeProvider {
130 private EmptyAttributesNode emptyAttributesNode = new EmptyAttributesNode();
131
132 @Override
133 public AttributesNode getInfoAttributesNode() throws IOException {
134 return emptyAttributesNode;
135 }
136
137 @Override
138 public AttributesNode getGlobalAttributesNode() throws IOException {
139 return emptyAttributesNode;
140 }
141
142 private static class EmptyAttributesNode extends AttributesNode {
143
144 public EmptyAttributesNode() {
145 super(Collections.<AttributesRule> emptyList());
146 }
147
148 @Override
149 public void parse(InputStream in) throws IOException {
150
151 }
152 }
153 }
154 }