本文整理汇总了Java中org.eclipse.jgit.lib.FileMode类的典型用法代码示例。如果您正苦于以下问题:Java FileMode类的具体用法?Java FileMode怎么用?Java FileMode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FileMode类属于org.eclipse.jgit.lib包,在下文中一共展示了FileMode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: putEntry
import org.eclipse.jgit.lib.FileMode; //导入依赖的package包/类
@Override
public void putEntry(ZipOutputStream out, ObjectId tree, String path, FileMode mode, ObjectLoader loader) throws IOException {
// loader is null for directories...
if (loader != null) {
ZipEntry entry = new ZipEntry(path);
if (tree instanceof RevCommit) {
long t = ((RevCommit) tree).getCommitTime() * 1000L;
entry.setTime(t);
}
out.putNextEntry(entry);
out.write(loader.getBytes());
out.closeEntry();
}
}
示例2: getPathModel
import org.eclipse.jgit.lib.FileMode; //导入依赖的package包/类
/**
* Returns a path model of the current file in the treewalk.
*
* @param tw
* @param basePath
* @param commit
* @return a path model of the current file in the treewalk
*/
private static PathModel getPathModel(TreeWalk tw, String basePath, RevCommit commit) {
String name;
long size = 0;
if (StringUtils.isEmpty(basePath)) {
name = tw.getPathString();
} else {
name = tw.getPathString().substring(basePath.length() + 1);
}
ObjectId objectId = tw.getObjectId(0);
try {
if (!tw.isSubtree() && (tw.getFileMode(0) != FileMode.GITLINK)) {
size = tw.getObjectReader().getObjectSize(objectId, Constants.OBJ_BLOB);
}
} catch (Throwable t) {
error(t, null, "failed to retrieve blob size for " + tw.getPathString());
}
return new PathModel(name, tw.getPathString(), size, tw.getFileMode(0).getBits(), objectId.getName(), commit.getName());
}
示例3: getSubmoduleCommitId
import org.eclipse.jgit.lib.FileMode; //导入依赖的package包/类
public static String getSubmoduleCommitId(Repository repository, String path, RevCommit commit) {
String commitId = null;
try (TreeWalk tw = new TreeWalk(repository)) {
tw.setFilter(PathFilterGroup.createFromStrings(Collections.singleton(path)));
tw.reset(commit.getTree());
while (tw.next()) {
if (tw.isSubtree() && !path.equals(tw.getPathString())) {
tw.enterSubtree();
continue;
}
if (FileMode.GITLINK == tw.getFileMode(0)) {
commitId = tw.getObjectId(0).getName();
break;
}
}
} catch (Throwable t) {
error(t, repository, "{0} can't find {1} in commit {2}", path, commit.name());
}
return commitId;
}
示例4: getProperties
import org.eclipse.jgit.lib.FileMode; //导入依赖的package包/类
@NotNull
@Override
public Map<String, String> getProperties() throws IOException, SVNException {
final Map<String, String> props = getUpstreamProperties();
final FileMode fileMode = getFileMode();
if (fileMode.equals(FileMode.SYMLINK)) {
props.remove(SVNProperty.EOL_STYLE);
props.remove(SVNProperty.MIME_TYPE);
props.put(SVNProperty.SPECIAL, "*");
} else {
if (fileMode.equals(FileMode.EXECUTABLE_FILE)) {
props.put(SVNProperty.EXECUTABLE, "*");
}
if (fileMode.getObjectType() == Constants.OBJ_BLOB && repo.isObjectBinary(filter, getObjectId())) {
props.remove(SVNProperty.EOL_STYLE);
props.put(SVNProperty.MIME_TYPE, SVNFileUtil.BINARY_MIME_TYPE);
}
}
return props;
}
示例5: createForChild
import org.eclipse.jgit.lib.FileMode; //导入依赖的package包/类
@Nullable
@Override
public GitProperty createForChild(@NotNull String name, @NotNull FileMode fileMode) {
if (matchers.isEmpty() || (fileMode.getObjectType() == Constants.OBJ_BLOB)) {
return null;
}
final List<String> localList = new ArrayList<>();
final List<String> globalList = new ArrayList<>();
final List<PathMatcher> childMatchers = new ArrayList<>();
for (PathMatcher matcher : matchers) {
processMatcher(localList, globalList, childMatchers, matcher.createChild(name, true));
}
if (localList.isEmpty() && globalList.isEmpty() && childMatchers.isEmpty()) {
return null;
}
return new GitIgnore(localList, globalList, childMatchers);
}
示例6: checkProps
import org.eclipse.jgit.lib.FileMode; //导入依赖的package包/类
private void checkProps(@NotNull GitProperty[] gitProperties, @Nullable String local, @Nullable String global, @Nullable String mine, @NotNull FileMode fileMode, @NotNull String... path) {
GitProperty[] props = gitProperties;
for (int i = 0; i < path.length; ++i) {
final String name = path[i];
final FileMode mode = i == path.length - 1 ? fileMode : FileMode.TREE;
props = createForChild(props, name, mode);
}
final Map<String, String> text = new HashMap<>();
for (GitProperty prop : props) {
prop.apply(text);
}
Assert.assertEquals(text.remove("svn:eol-style"), local);
Assert.assertEquals(text.remove("svn:auto-props"), global);
Assert.assertEquals(text.remove("svn:mime-type"), mine);
Assert.assertTrue(text.isEmpty(), text.toString());
}
示例7: getPathModel
import org.eclipse.jgit.lib.FileMode; //导入依赖的package包/类
/**
* Returns a path model of the current file in the treewalk.
*
* @param tw
* @param basePath
* @param commit
* @return a path model of the current file in the treewalk
*/
private static PathModel getPathModel(TreeWalk tw, String basePath, RevCommit commit) {
String name;
long size = 0;
if (StringUtils.isEmpty(basePath)) {
name = tw.getPathString();
} else {
name = tw.getPathString().substring(basePath.length() + 1);
}
ObjectId objectId = tw.getObjectId(0);
try {
if (!tw.isSubtree() && (tw.getFileMode(0) != FileMode.GITLINK)) {
size = tw.getObjectReader().getObjectSize(objectId, Constants.OBJ_BLOB);
}
} catch (Throwable t) {
error(t, null, "failed to retrieve blob size for " + tw.getPathString());
}
return new PathModel(name, tw.getPathString(), size, tw.getFileMode(0).getBits(),
objectId.getName(), commit.getName());
}
示例8: getSubmoduleCommitId
import org.eclipse.jgit.lib.FileMode; //导入依赖的package包/类
public static String getSubmoduleCommitId(Repository repository, String path, RevCommit commit) {
String commitId = null;
RevWalk rw = new RevWalk(repository);
TreeWalk tw = new TreeWalk(repository);
tw.setFilter(PathFilterGroup.createFromStrings(Collections.singleton(path)));
try {
tw.reset(commit.getTree());
while (tw.next()) {
if (tw.isSubtree() && !path.equals(tw.getPathString())) {
tw.enterSubtree();
continue;
}
if (FileMode.GITLINK == tw.getFileMode(0)) {
commitId = tw.getObjectId(0).getName();
break;
}
}
} catch (Throwable t) {
error(t, repository, "{0} can't find {1} in commit {2}", path, commit.name());
} finally {
rw.dispose();
tw.release();
}
return commitId;
}
示例9: checkoutEntry
import org.eclipse.jgit.lib.FileMode; //导入依赖的package包/类
public void checkoutEntry (Repository repository, File file, DirCacheEntry e, ObjectReader od) throws IOException, GitException {
// ... create/overwrite this file ...
if (!ensureParentFolderExists(file.getParentFile())) {
return;
}
boolean exists = file.exists();
if (exists && e.getFileMode() == FileMode.SYMLINK) {
monitor.notifyWarning(MessageFormat.format(Utils.getBundle(CheckoutIndex.class).getString("MSG_Warning_SymLink"), file.getAbsolutePath())); //NOI18N
return;
}
if (Utils.isFromNested(e.getFileMode().getBits())) {
if (!exists) {
file.mkdirs();
}
} else {
if (exists && file.isDirectory()) {
monitor.notifyWarning(MessageFormat.format(Utils.getBundle(CheckoutIndex.class).getString("MSG_Warning_ReplacingDirectory"), file.getAbsolutePath())); //NOI18N
Utils.deleteRecursively(file);
}
file.createNewFile();
if (file.isFile()) {
DirCacheCheckout.checkoutEntry(repository, file, e, od);
} else {
monitor.notifyError(MessageFormat.format(Utils.getBundle(CheckoutIndex.class).getString("MSG_Warning_CannotCreateFile"), file.getAbsolutePath())); //NOI18N
}
}
}
示例10: testAddMissingSymlink
import org.eclipse.jgit.lib.FileMode; //导入依赖的package包/类
public void testAddMissingSymlink () throws Exception {
if (isWindows()) {
return;
}
String path = "folder/file";
File f = new File(workDir, path);
// try with commandline client
File link = new File(workDir, "link");
Files.createSymbolicLink(Paths.get(link.getAbsolutePath()), Paths.get(path));
getClient(workDir).add(new File[] { link }, NULL_PROGRESS_MONITOR);
DirCacheEntry e = repository.readDirCache().getEntry(link.getName());
assertEquals(FileMode.SYMLINK, e.getFileMode());
assertEquals(0, e.getLength());
ObjectReader reader = repository.getObjectDatabase().newReader();
assertTrue(reader.has(e.getObjectId()));
byte[] bytes = reader.open(e.getObjectId()).getBytes();
assertEquals(path, RawParseUtils.decode(bytes));
reader.release();
}
示例11: QuickSearchPanel
import org.eclipse.jgit.lib.FileMode; //导入依赖的package包/类
public QuickSearchPanel(String id, IModel<Project> projectModel, IModel<String> revisionModel) {
super(id);
this.projectModel = projectModel;
this.revisionModel = revisionModel;
Project project = projectModel.getObject();
for (String blobPath: getRecentOpened()) {
try {
RevTree revTree = project.getRevCommit(revisionModel.getObject()).getTree();
TreeWalk treeWalk = TreeWalk.forPath(project.getRepository(), blobPath, revTree);
if (treeWalk != null && treeWalk.getRawMode(0) != FileMode.TREE.getBits()) {
symbolHits.add(new FileHit(blobPath, null));
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
示例12: getSubmodules
import org.eclipse.jgit.lib.FileMode; //导入依赖的package包/类
public Map<String, String> getSubmodules(String revision) {
Map<String, String> submodules = new HashMap<>();
Blob blob = getBlob(new BlobIdent(revision, ".gitmodules", FileMode.REGULAR_FILE.getBits()));
String content = new String(blob.getBytes());
String path = null;
String url = null;
for (String line: LoaderUtils.splitAndTrim(content, "\r\n")) {
if (line.startsWith("[") && line.endsWith("]")) {
if (path != null && url != null)
submodules.put(path, url);
path = url = null;
} else if (line.startsWith("path")) {
path = StringUtils.substringAfter(line, "=").trim();
} else if (line.startsWith("url")) {
url = StringUtils.substringAfter(line, "=").trim();
}
}
if (path != null && url != null)
submodules.put(path, url);
return submodules;
}
示例13: getMode
import org.eclipse.jgit.lib.FileMode; //导入依赖的package包/类
public int getMode(String revision, @Nullable String path) {
if (path != null) {
RevCommit commit = getRevCommit(revision);
try {
TreeWalk treeWalk = TreeWalk.forPath(getRepository(), path, commit.getTree());
if (treeWalk != null) {
return treeWalk.getRawMode(0);
} else {
throw new ObjectNotFoundException("Unable to find blob path '" + path
+ "' in revision '" + revision + "'");
}
} catch (IOException e) {
throw new RuntimeException(e);
}
} else {
return FileMode.TREE.getBits();
}
}
示例14: shouldFailIfOldPathIsTreeWhenRename
import org.eclipse.jgit.lib.FileMode; //导入依赖的package包/类
@Test
public void shouldFailIfOldPathIsTreeWhenRename() throws IOException {
createDir("client");
addFileAndCommit("client/a.java", "a", "add a");
addFileAndCommit("client/b.java", "b", "add b");
createDir("server/src/com/example/a");
createDir("server/src/com/example/b");
addFileAndCommit("server/src/com/example/a/a.java", "a", "add a");
addFileAndCommit("server/src/com/example/b/b.java", "b", "add b");
String refName = "refs/heads/master";
ObjectId oldCommitId = git.getRepository().resolve(refName);
Map<String, BlobContent> newBlobs = new HashMap<>();
newBlobs.put("client/c.java", new BlobContent.Immutable("a".getBytes(), FileMode.REGULAR_FILE));
BlobEdits edits = new BlobEdits(Sets.newHashSet("server/src/com/example/a"), newBlobs);
ObjectId newCommitId = edits.commit(git.getRepository(), refName, oldCommitId, oldCommitId, user,
"test rename");
try (RevWalk revWalk = new RevWalk(git.getRepository())) {
RevTree revTree = revWalk.parseCommit(newCommitId).getTree();
assertNotNull(TreeWalk.forPath(git.getRepository(), "client/c.java", revTree));
assertNull(TreeWalk.forPath(git.getRepository(), "server/src/com/example/a", revTree));
}
}
示例15: shouldFailIfNewPathIsNotUnderTreeWhenRename
import org.eclipse.jgit.lib.FileMode; //导入依赖的package包/类
@Test
public void shouldFailIfNewPathIsNotUnderTreeWhenRename() throws IOException {
createDir("client");
addFileAndCommit("client/a.java", "a", "add a");
addFileAndCommit("client/b.java", "b", "add b");
createDir("server/src/com/example/a");
createDir("server/src/com/example/b");
addFileAndCommit("server/src/com/example/a/a.java", "a", "add a");
addFileAndCommit("server/src/com/example/b/b.java", "b", "add b");
String refName = "refs/heads/master";
ObjectId oldCommitId = git.getRepository().resolve(refName);
Map<String, BlobContent> newBlobs = new HashMap<>();
newBlobs.put("client/a.java/a.java", new BlobContent.Immutable("a".getBytes(), FileMode.REGULAR_FILE));
BlobEdits edits = new BlobEdits(Sets.newHashSet("server/src/com/example/a/a.java"), newBlobs);
try {
edits.commit(git.getRepository(), refName, oldCommitId, oldCommitId, user, "test rename tree");
assertTrue("A NotTreeException should be thrown", false);
} catch (NotTreeException e) {
}
}