Browse Source
These types were deprecated in 0.9.1 (aka 384a19eee0
).
If anyone is still using them, its time to stop.
Change-Id: I3f73347ba78c639e0c6a504812bc1a0702f829b1
stable-4.3
Shawn Pearce
9 years ago
10 changed files with 111 additions and 1618 deletions
@ -1,319 +0,0 @@ |
|||||||
/* |
|
||||||
* Copyright (C) 2008, Robin Rosenberg <robin.rosenberg@dewire.com> |
|
||||||
* Copyright (C) 2006-2008, Shawn O. Pearce <spearce@spearce.org> |
|
||||||
* and other copyright owners as documented in the project's IP log. |
|
||||||
* |
|
||||||
* This program and the accompanying materials are made available |
|
||||||
* under the terms of the Eclipse Distribution License v1.0 which |
|
||||||
* accompanies this distribution, is reproduced below, and is |
|
||||||
* available at http://www.eclipse.org/org/documents/edl-v10.php
|
|
||||||
* |
|
||||||
* All rights reserved. |
|
||||||
* |
|
||||||
* Redistribution and use in source and binary forms, with or |
|
||||||
* without modification, are permitted provided that the following |
|
||||||
* conditions are met: |
|
||||||
* |
|
||||||
* - Redistributions of source code must retain the above copyright |
|
||||||
* notice, this list of conditions and the following disclaimer. |
|
||||||
* |
|
||||||
* - Redistributions in binary form must reproduce the above |
|
||||||
* copyright notice, this list of conditions and the following |
|
||||||
* disclaimer in the documentation and/or other materials provided |
|
||||||
* with the distribution. |
|
||||||
* |
|
||||||
* - Neither the name of the Eclipse Foundation, Inc. nor the |
|
||||||
* names of its contributors may be used to endorse or promote |
|
||||||
* products derived from this software without specific prior |
|
||||||
* written permission. |
|
||||||
* |
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND |
|
||||||
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, |
|
||||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
|
||||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
||||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
|
||||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
|
||||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
|
||||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
|
||||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
|
||||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
||||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
|
||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
||||||
*/ |
|
||||||
|
|
||||||
package org.eclipse.jgit.lib; |
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals; |
|
||||||
import static org.junit.Assert.assertFalse; |
|
||||||
import static org.junit.Assert.assertNotNull; |
|
||||||
import static org.junit.Assert.assertSame; |
|
||||||
import static org.junit.Assert.assertTrue; |
|
||||||
|
|
||||||
import java.io.IOException; |
|
||||||
import java.io.UnsupportedEncodingException; |
|
||||||
import java.util.ArrayList; |
|
||||||
import java.util.List; |
|
||||||
|
|
||||||
import org.eclipse.jgit.test.resources.SampleDataRepositoryTestCase; |
|
||||||
import org.junit.Test; |
|
||||||
|
|
||||||
@SuppressWarnings("deprecation") |
|
||||||
public class T0002_TreeTest extends SampleDataRepositoryTestCase { |
|
||||||
private static final ObjectId SOME_FAKE_ID = ObjectId.fromString( |
|
||||||
"0123456789abcdef0123456789abcdef01234567"); |
|
||||||
|
|
||||||
private static int compareNamesUsingSpecialCompare(String a, String b) |
|
||||||
throws UnsupportedEncodingException { |
|
||||||
char lasta = '\0'; |
|
||||||
byte[] abytes; |
|
||||||
if (a.length() > 0 && a.charAt(a.length()-1) == '/') { |
|
||||||
lasta = '/'; |
|
||||||
a = a.substring(0, a.length() - 1); |
|
||||||
} |
|
||||||
abytes = a.getBytes("ISO-8859-1"); |
|
||||||
char lastb = '\0'; |
|
||||||
byte[] bbytes; |
|
||||||
if (b.length() > 0 && b.charAt(b.length()-1) == '/') { |
|
||||||
lastb = '/'; |
|
||||||
b = b.substring(0, b.length() - 1); |
|
||||||
} |
|
||||||
bbytes = b.getBytes("ISO-8859-1"); |
|
||||||
return Tree.compareNames(abytes, bbytes, lasta, lastb); |
|
||||||
} |
|
||||||
|
|
||||||
@Test |
|
||||||
public void test000_sort_01() throws UnsupportedEncodingException { |
|
||||||
assertEquals(0, compareNamesUsingSpecialCompare("a","a")); |
|
||||||
} |
|
||||||
|
|
||||||
@Test |
|
||||||
public void test000_sort_02() throws UnsupportedEncodingException { |
|
||||||
assertEquals(-1, compareNamesUsingSpecialCompare("a","b")); |
|
||||||
assertEquals(1, compareNamesUsingSpecialCompare("b","a")); |
|
||||||
} |
|
||||||
|
|
||||||
@Test |
|
||||||
public void test000_sort_03() throws UnsupportedEncodingException { |
|
||||||
assertEquals(1, compareNamesUsingSpecialCompare("a:","a")); |
|
||||||
assertEquals(1, compareNamesUsingSpecialCompare("a/","a")); |
|
||||||
assertEquals(-1, compareNamesUsingSpecialCompare("a","a/")); |
|
||||||
assertEquals(-1, compareNamesUsingSpecialCompare("a","a:")); |
|
||||||
assertEquals(1, compareNamesUsingSpecialCompare("a:","a/")); |
|
||||||
assertEquals(-1, compareNamesUsingSpecialCompare("a/","a:")); |
|
||||||
} |
|
||||||
|
|
||||||
@Test |
|
||||||
public void test000_sort_04() throws UnsupportedEncodingException { |
|
||||||
assertEquals(-1, compareNamesUsingSpecialCompare("a.a","a/a")); |
|
||||||
assertEquals(1, compareNamesUsingSpecialCompare("a/a","a.a")); |
|
||||||
} |
|
||||||
|
|
||||||
@Test |
|
||||||
public void test000_sort_05() throws UnsupportedEncodingException { |
|
||||||
assertEquals(-1, compareNamesUsingSpecialCompare("a.","a/")); |
|
||||||
assertEquals(1, compareNamesUsingSpecialCompare("a/","a.")); |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
@Test |
|
||||||
public void test001_createEmpty() throws IOException { |
|
||||||
final Tree t = new Tree(db); |
|
||||||
assertTrue("isLoaded", t.isLoaded()); |
|
||||||
assertTrue("isModified", t.isModified()); |
|
||||||
assertTrue("no parent", t.getParent() == null); |
|
||||||
assertTrue("isRoot", t.isRoot()); |
|
||||||
assertTrue("no name", t.getName() == null); |
|
||||||
assertTrue("no nameUTF8", t.getNameUTF8() == null); |
|
||||||
assertTrue("has entries array", t.members() != null); |
|
||||||
assertEquals("entries is empty", 0, t.members().length); |
|
||||||
assertEquals("full name is empty", "", t.getFullName()); |
|
||||||
assertTrue("no id", t.getId() == null); |
|
||||||
assertTrue("database is r", t.getRepository() == db); |
|
||||||
assertTrue("no foo child", t.findTreeMember("foo") == null); |
|
||||||
assertTrue("no foo child", t.findBlobMember("foo") == null); |
|
||||||
} |
|
||||||
|
|
||||||
@Test |
|
||||||
public void test002_addFile() throws IOException { |
|
||||||
final Tree t = new Tree(db); |
|
||||||
t.setId(SOME_FAKE_ID); |
|
||||||
assertTrue("has id", t.getId() != null); |
|
||||||
assertFalse("not modified", t.isModified()); |
|
||||||
|
|
||||||
final String n = "bob"; |
|
||||||
final FileTreeEntry f = t.addFile(n); |
|
||||||
assertNotNull("have file", f); |
|
||||||
assertEquals("name matches", n, f.getName()); |
|
||||||
assertEquals("name matches", f.getName(), new String(f.getNameUTF8(), |
|
||||||
"UTF-8")); |
|
||||||
assertEquals("full name matches", n, f.getFullName()); |
|
||||||
assertTrue("no id", f.getId() == null); |
|
||||||
assertTrue("is modified", t.isModified()); |
|
||||||
assertTrue("has no id", t.getId() == null); |
|
||||||
assertTrue("found bob", t.findBlobMember(f.getName()) == f); |
|
||||||
|
|
||||||
final TreeEntry[] i = t.members(); |
|
||||||
assertNotNull("members array not null", i); |
|
||||||
assertTrue("iterator is not empty", i != null && i.length > 0); |
|
||||||
assertTrue("iterator returns file", i != null && i[0] == f); |
|
||||||
assertTrue("iterator is empty", i != null && i.length == 1); |
|
||||||
} |
|
||||||
|
|
||||||
@Test |
|
||||||
public void test004_addTree() throws IOException { |
|
||||||
final Tree t = new Tree(db); |
|
||||||
t.setId(SOME_FAKE_ID); |
|
||||||
assertTrue("has id", t.getId() != null); |
|
||||||
assertFalse("not modified", t.isModified()); |
|
||||||
|
|
||||||
final String n = "bob"; |
|
||||||
final Tree f = t.addTree(n); |
|
||||||
assertNotNull("have tree", f); |
|
||||||
assertEquals("name matches", n, f.getName()); |
|
||||||
assertEquals("name matches", f.getName(), new String(f.getNameUTF8(), |
|
||||||
"UTF-8")); |
|
||||||
assertEquals("full name matches", n, f.getFullName()); |
|
||||||
assertTrue("no id", f.getId() == null); |
|
||||||
assertTrue("parent matches", f.getParent() == t); |
|
||||||
assertTrue("repository matches", f.getRepository() == db); |
|
||||||
assertTrue("isLoaded", f.isLoaded()); |
|
||||||
assertFalse("has items", f.members().length > 0); |
|
||||||
assertFalse("is root", f.isRoot()); |
|
||||||
assertTrue("parent is modified", t.isModified()); |
|
||||||
assertTrue("parent has no id", t.getId() == null); |
|
||||||
assertTrue("found bob child", t.findTreeMember(f.getName()) == f); |
|
||||||
|
|
||||||
final TreeEntry[] i = t.members(); |
|
||||||
assertTrue("iterator is not empty", i.length > 0); |
|
||||||
assertTrue("iterator returns file", i[0] == f); |
|
||||||
assertEquals("iterator is empty", 1, i.length); |
|
||||||
} |
|
||||||
|
|
||||||
@Test |
|
||||||
public void test005_addRecursiveFile() throws IOException { |
|
||||||
final Tree t = new Tree(db); |
|
||||||
final FileTreeEntry f = t.addFile("a/b/c"); |
|
||||||
assertNotNull("created f", f); |
|
||||||
assertEquals("c", f.getName()); |
|
||||||
assertEquals("b", f.getParent().getName()); |
|
||||||
assertEquals("a", f.getParent().getParent().getName()); |
|
||||||
assertTrue("t is great-grandparent", t == f.getParent().getParent() |
|
||||||
.getParent()); |
|
||||||
} |
|
||||||
|
|
||||||
@Test |
|
||||||
public void test005_addRecursiveTree() throws IOException { |
|
||||||
final Tree t = new Tree(db); |
|
||||||
final Tree f = t.addTree("a/b/c"); |
|
||||||
assertNotNull("created f", f); |
|
||||||
assertEquals("c", f.getName()); |
|
||||||
assertEquals("b", f.getParent().getName()); |
|
||||||
assertEquals("a", f.getParent().getParent().getName()); |
|
||||||
assertTrue("t is great-grandparent", t == f.getParent().getParent() |
|
||||||
.getParent()); |
|
||||||
} |
|
||||||
|
|
||||||
@Test |
|
||||||
public void test006_addDeepTree() throws IOException { |
|
||||||
final Tree t = new Tree(db); |
|
||||||
|
|
||||||
final Tree e = t.addTree("e"); |
|
||||||
assertNotNull("have e", e); |
|
||||||
assertTrue("e.parent == t", e.getParent() == t); |
|
||||||
final Tree f = t.addTree("f"); |
|
||||||
assertNotNull("have f", f); |
|
||||||
assertTrue("f.parent == t", f.getParent() == t); |
|
||||||
final Tree g = f.addTree("g"); |
|
||||||
assertNotNull("have g", g); |
|
||||||
assertTrue("g.parent == f", g.getParent() == f); |
|
||||||
final Tree h = g.addTree("h"); |
|
||||||
assertNotNull("have h", h); |
|
||||||
assertTrue("h.parent = g", h.getParent() == g); |
|
||||||
|
|
||||||
h.setId(SOME_FAKE_ID); |
|
||||||
assertTrue("h not modified", !h.isModified()); |
|
||||||
g.setId(SOME_FAKE_ID); |
|
||||||
assertTrue("g not modified", !g.isModified()); |
|
||||||
f.setId(SOME_FAKE_ID); |
|
||||||
assertTrue("f not modified", !f.isModified()); |
|
||||||
e.setId(SOME_FAKE_ID); |
|
||||||
assertTrue("e not modified", !e.isModified()); |
|
||||||
t.setId(SOME_FAKE_ID); |
|
||||||
assertTrue("t not modified.", !t.isModified()); |
|
||||||
|
|
||||||
assertEquals("full path of h ok", "f/g/h", h.getFullName()); |
|
||||||
assertTrue("Can find h", t.findTreeMember(h.getFullName()) == h); |
|
||||||
assertTrue("Can't find f/z", t.findBlobMember("f/z") == null); |
|
||||||
assertTrue("Can't find y/z", t.findBlobMember("y/z") == null); |
|
||||||
|
|
||||||
final FileTreeEntry i = h.addFile("i"); |
|
||||||
assertNotNull(i); |
|
||||||
assertEquals("full path of i ok", "f/g/h/i", i.getFullName()); |
|
||||||
assertTrue("Can find i", t.findBlobMember(i.getFullName()) == i); |
|
||||||
assertTrue("h modified", h.isModified()); |
|
||||||
assertTrue("g modified", g.isModified()); |
|
||||||
assertTrue("f modified", f.isModified()); |
|
||||||
assertTrue("e not modified", !e.isModified()); |
|
||||||
assertTrue("t modified", t.isModified()); |
|
||||||
|
|
||||||
assertTrue("h no id", h.getId() == null); |
|
||||||
assertTrue("g no id", g.getId() == null); |
|
||||||
assertTrue("f no id", f.getId() == null); |
|
||||||
assertTrue("e has id", e.getId() != null); |
|
||||||
assertTrue("t no id", t.getId() == null); |
|
||||||
} |
|
||||||
|
|
||||||
@Test |
|
||||||
public void test007_manyFileLookup() throws IOException { |
|
||||||
final Tree t = new Tree(db); |
|
||||||
final List<FileTreeEntry> files = new ArrayList<FileTreeEntry>(26 * 26); |
|
||||||
for (char level1 = 'a'; level1 <= 'z'; level1++) { |
|
||||||
for (char level2 = 'a'; level2 <= 'z'; level2++) { |
|
||||||
final String n = "." + level1 + level2 + "9"; |
|
||||||
final FileTreeEntry f = t.addFile(n); |
|
||||||
assertNotNull("File " + n + " added.", f); |
|
||||||
assertEquals(n, f.getName()); |
|
||||||
files.add(f); |
|
||||||
} |
|
||||||
} |
|
||||||
assertEquals(files.size(), t.memberCount()); |
|
||||||
final TreeEntry[] ents = t.members(); |
|
||||||
assertNotNull(ents); |
|
||||||
assertEquals(files.size(), ents.length); |
|
||||||
for (int k = 0; k < ents.length; k++) { |
|
||||||
assertTrue("File " + files.get(k).getName() |
|
||||||
+ " is at " + k + ".", files.get(k) == ents[k]); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
@Test |
|
||||||
public void test008_SubtreeInternalSorting() throws IOException { |
|
||||||
final Tree t = new Tree(db); |
|
||||||
final FileTreeEntry e0 = t.addFile("a-b"); |
|
||||||
final FileTreeEntry e1 = t.addFile("a-"); |
|
||||||
final FileTreeEntry e2 = t.addFile("a=b"); |
|
||||||
final Tree e3 = t.addTree("a"); |
|
||||||
final FileTreeEntry e4 = t.addFile("a="); |
|
||||||
|
|
||||||
final TreeEntry[] ents = t.members(); |
|
||||||
assertSame(e1, ents[0]); |
|
||||||
assertSame(e0, ents[1]); |
|
||||||
assertSame(e3, ents[2]); |
|
||||||
assertSame(e4, ents[3]); |
|
||||||
assertSame(e2, ents[4]); |
|
||||||
} |
|
||||||
|
|
||||||
@Test |
|
||||||
public void test009_SymlinkAndGitlink() throws IOException { |
|
||||||
final Tree symlinkTree = mapTree("symlink"); |
|
||||||
assertTrue("Symlink entry exists", symlinkTree.existsBlob("symlink.txt")); |
|
||||||
final Tree gitlinkTree = mapTree("gitlink"); |
|
||||||
assertTrue("Gitlink entry exists", gitlinkTree.existsBlob("submodule")); |
|
||||||
} |
|
||||||
|
|
||||||
private Tree mapTree(String name) throws IOException { |
|
||||||
ObjectId id = db.resolve(name + "^{tree}"); |
|
||||||
return new Tree(db, id, db.open(id).getCachedBytes()); |
|
||||||
} |
|
||||||
} |
|
@ -1,115 +0,0 @@ |
|||||||
/* |
|
||||||
* Copyright (C) 2007, Robin Rosenberg <robin.rosenberg@dewire.com> |
|
||||||
* Copyright (C) 2006-2007, Shawn O. Pearce <spearce@spearce.org> |
|
||||||
* and other copyright owners as documented in the project's IP log. |
|
||||||
* |
|
||||||
* This program and the accompanying materials are made available |
|
||||||
* under the terms of the Eclipse Distribution License v1.0 which |
|
||||||
* accompanies this distribution, is reproduced below, and is |
|
||||||
* available at http://www.eclipse.org/org/documents/edl-v10.php
|
|
||||||
* |
|
||||||
* All rights reserved. |
|
||||||
* |
|
||||||
* Redistribution and use in source and binary forms, with or |
|
||||||
* without modification, are permitted provided that the following |
|
||||||
* conditions are met: |
|
||||||
* |
|
||||||
* - Redistributions of source code must retain the above copyright |
|
||||||
* notice, this list of conditions and the following disclaimer. |
|
||||||
* |
|
||||||
* - Redistributions in binary form must reproduce the above |
|
||||||
* copyright notice, this list of conditions and the following |
|
||||||
* disclaimer in the documentation and/or other materials provided |
|
||||||
* with the distribution. |
|
||||||
* |
|
||||||
* - Neither the name of the Eclipse Foundation, Inc. nor the |
|
||||||
* names of its contributors may be used to endorse or promote |
|
||||||
* products derived from this software without specific prior |
|
||||||
* written permission. |
|
||||||
* |
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND |
|
||||||
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, |
|
||||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
|
||||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
||||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
|
||||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
|
||||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
|
||||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
|
||||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
|
||||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
||||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
|
||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
||||||
*/ |
|
||||||
|
|
||||||
package org.eclipse.jgit.lib; |
|
||||||
|
|
||||||
import java.io.IOException; |
|
||||||
|
|
||||||
/** |
|
||||||
* A representation of a file (blob) object in a {@link Tree}. |
|
||||||
* |
|
||||||
* @deprecated To look up information about a single path, use |
|
||||||
* {@link org.eclipse.jgit.treewalk.TreeWalk#forPath(Repository, String, org.eclipse.jgit.revwalk.RevTree)}. |
|
||||||
* To lookup information about multiple paths at once, use a |
|
||||||
* {@link org.eclipse.jgit.treewalk.TreeWalk} and obtain the current entry's |
|
||||||
* information from its getter methods. |
|
||||||
*/ |
|
||||||
@Deprecated |
|
||||||
public class FileTreeEntry extends TreeEntry { |
|
||||||
private FileMode mode; |
|
||||||
|
|
||||||
/** |
|
||||||
* Constructor for a File (blob) object. |
|
||||||
* |
|
||||||
* @param parent |
|
||||||
* The {@link Tree} holding this object (or null) |
|
||||||
* @param id |
|
||||||
* the SHA-1 of the blob (or null for a yet unhashed file) |
|
||||||
* @param nameUTF8 |
|
||||||
* raw object name in the parent tree |
|
||||||
* @param execute |
|
||||||
* true if the executable flag is set |
|
||||||
*/ |
|
||||||
public FileTreeEntry(final Tree parent, final ObjectId id, |
|
||||||
final byte[] nameUTF8, final boolean execute) { |
|
||||||
super(parent, id, nameUTF8); |
|
||||||
setExecutable(execute); |
|
||||||
} |
|
||||||
|
|
||||||
public FileMode getMode() { |
|
||||||
return mode; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* @return true if this file is executable |
|
||||||
*/ |
|
||||||
public boolean isExecutable() { |
|
||||||
return getMode().equals(FileMode.EXECUTABLE_FILE); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* @param execute set/reset the executable flag |
|
||||||
*/ |
|
||||||
public void setExecutable(final boolean execute) { |
|
||||||
mode = execute ? FileMode.EXECUTABLE_FILE : FileMode.REGULAR_FILE; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* @return an {@link ObjectLoader} that will return the data |
|
||||||
* @throws IOException |
|
||||||
*/ |
|
||||||
public ObjectLoader openReader() throws IOException { |
|
||||||
return getRepository().open(getId(), Constants.OBJ_BLOB); |
|
||||||
} |
|
||||||
|
|
||||||
public String toString() { |
|
||||||
final StringBuilder r = new StringBuilder(); |
|
||||||
r.append(ObjectId.toString(getId())); |
|
||||||
r.append(' '); |
|
||||||
r.append(isExecutable() ? 'X' : 'F'); |
|
||||||
r.append(' '); |
|
||||||
r.append(getFullName()); |
|
||||||
return r.toString(); |
|
||||||
} |
|
||||||
} |
|
@ -1,87 +0,0 @@ |
|||||||
/* |
|
||||||
* Copyright (C) 2009, Jonas Fonseca <fonseca@diku.dk> |
|
||||||
* Copyright (C) 2007, Robin Rosenberg <robin.rosenberg@dewire.com> |
|
||||||
* Copyright (C) 2007, Shawn O. Pearce <spearce@spearce.org> |
|
||||||
* and other copyright owners as documented in the project's IP log. |
|
||||||
* |
|
||||||
* This program and the accompanying materials are made available |
|
||||||
* under the terms of the Eclipse Distribution License v1.0 which |
|
||||||
* accompanies this distribution, is reproduced below, and is |
|
||||||
* available at http://www.eclipse.org/org/documents/edl-v10.php
|
|
||||||
* |
|
||||||
* All rights reserved. |
|
||||||
* |
|
||||||
* Redistribution and use in source and binary forms, with or |
|
||||||
* without modification, are permitted provided that the following |
|
||||||
* conditions are met: |
|
||||||
* |
|
||||||
* - Redistributions of source code must retain the above copyright |
|
||||||
* notice, this list of conditions and the following disclaimer. |
|
||||||
* |
|
||||||
* - Redistributions in binary form must reproduce the above |
|
||||||
* copyright notice, this list of conditions and the following |
|
||||||
* disclaimer in the documentation and/or other materials provided |
|
||||||
* with the distribution. |
|
||||||
* |
|
||||||
* - Neither the name of the Eclipse Foundation, Inc. nor the |
|
||||||
* names of its contributors may be used to endorse or promote |
|
||||||
* products derived from this software without specific prior |
|
||||||
* written permission. |
|
||||||
* |
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND |
|
||||||
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, |
|
||||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
|
||||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
||||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
|
||||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
|
||||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
|
||||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
|
||||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
|
||||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
||||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
|
||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
||||||
*/ |
|
||||||
|
|
||||||
package org.eclipse.jgit.lib; |
|
||||||
|
|
||||||
/** |
|
||||||
* A tree entry representing a gitlink entry used for submodules. |
|
||||||
* |
|
||||||
* Note. Java cannot really handle these as file system objects. |
|
||||||
* |
|
||||||
* @deprecated To look up information about a single path, use |
|
||||||
* {@link org.eclipse.jgit.treewalk.TreeWalk#forPath(Repository, String, org.eclipse.jgit.revwalk.RevTree)}. |
|
||||||
* To lookup information about multiple paths at once, use a |
|
||||||
* {@link org.eclipse.jgit.treewalk.TreeWalk} and obtain the current entry's |
|
||||||
* information from its getter methods. |
|
||||||
*/ |
|
||||||
@Deprecated |
|
||||||
public class GitlinkTreeEntry extends TreeEntry { |
|
||||||
|
|
||||||
/** |
|
||||||
* Construct a {@link GitlinkTreeEntry} with the specified name and SHA-1 in |
|
||||||
* the specified parent |
|
||||||
* |
|
||||||
* @param parent |
|
||||||
* @param id |
|
||||||
* @param nameUTF8 |
|
||||||
*/ |
|
||||||
public GitlinkTreeEntry(final Tree parent, final ObjectId id, |
|
||||||
final byte[] nameUTF8) { |
|
||||||
super(parent, id, nameUTF8); |
|
||||||
} |
|
||||||
|
|
||||||
public FileMode getMode() { |
|
||||||
return FileMode.GITLINK; |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public String toString() { |
|
||||||
final StringBuilder r = new StringBuilder(); |
|
||||||
r.append(ObjectId.toString(getId())); |
|
||||||
r.append(" G "); //$NON-NLS-1$
|
|
||||||
r.append(getFullName()); |
|
||||||
return r.toString(); |
|
||||||
} |
|
||||||
} |
|
@ -1,85 +0,0 @@ |
|||||||
/* |
|
||||||
* Copyright (C) 2007, Robin Rosenberg <robin.rosenberg@dewire.com> |
|
||||||
* Copyright (C) 2006-2007, Shawn O. Pearce <spearce@spearce.org> |
|
||||||
* and other copyright owners as documented in the project's IP log. |
|
||||||
* |
|
||||||
* This program and the accompanying materials are made available |
|
||||||
* under the terms of the Eclipse Distribution License v1.0 which |
|
||||||
* accompanies this distribution, is reproduced below, and is |
|
||||||
* available at http://www.eclipse.org/org/documents/edl-v10.php
|
|
||||||
* |
|
||||||
* All rights reserved. |
|
||||||
* |
|
||||||
* Redistribution and use in source and binary forms, with or |
|
||||||
* without modification, are permitted provided that the following |
|
||||||
* conditions are met: |
|
||||||
* |
|
||||||
* - Redistributions of source code must retain the above copyright |
|
||||||
* notice, this list of conditions and the following disclaimer. |
|
||||||
* |
|
||||||
* - Redistributions in binary form must reproduce the above |
|
||||||
* copyright notice, this list of conditions and the following |
|
||||||
* disclaimer in the documentation and/or other materials provided |
|
||||||
* with the distribution. |
|
||||||
* |
|
||||||
* - Neither the name of the Eclipse Foundation, Inc. nor the |
|
||||||
* names of its contributors may be used to endorse or promote |
|
||||||
* products derived from this software without specific prior |
|
||||||
* written permission. |
|
||||||
* |
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND |
|
||||||
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, |
|
||||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
|
||||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
||||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
|
||||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
|
||||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
|
||||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
|
||||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
|
||||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
||||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
|
||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
||||||
*/ |
|
||||||
|
|
||||||
package org.eclipse.jgit.lib; |
|
||||||
|
|
||||||
/** |
|
||||||
* A tree entry representing a symbolic link. |
|
||||||
* |
|
||||||
* Note. Java cannot really handle these as file system objects. |
|
||||||
* |
|
||||||
* @deprecated To look up information about a single path, use |
|
||||||
* {@link org.eclipse.jgit.treewalk.TreeWalk#forPath(Repository, String, org.eclipse.jgit.revwalk.RevTree)}. |
|
||||||
* To lookup information about multiple paths at once, use a |
|
||||||
* {@link org.eclipse.jgit.treewalk.TreeWalk} and obtain the current entry's |
|
||||||
* information from its getter methods. |
|
||||||
*/ |
|
||||||
@Deprecated |
|
||||||
public class SymlinkTreeEntry extends TreeEntry { |
|
||||||
|
|
||||||
/** |
|
||||||
* Construct a {@link SymlinkTreeEntry} with the specified name and SHA-1 in |
|
||||||
* the specified parent |
|
||||||
* |
|
||||||
* @param parent |
|
||||||
* @param id |
|
||||||
* @param nameUTF8 |
|
||||||
*/ |
|
||||||
public SymlinkTreeEntry(final Tree parent, final ObjectId id, |
|
||||||
final byte[] nameUTF8) { |
|
||||||
super(parent, id, nameUTF8); |
|
||||||
} |
|
||||||
|
|
||||||
public FileMode getMode() { |
|
||||||
return FileMode.SYMLINK; |
|
||||||
} |
|
||||||
|
|
||||||
public String toString() { |
|
||||||
final StringBuilder r = new StringBuilder(); |
|
||||||
r.append(ObjectId.toString(getId())); |
|
||||||
r.append(" S "); //$NON-NLS-1$
|
|
||||||
r.append(getFullName()); |
|
||||||
return r.toString(); |
|
||||||
} |
|
||||||
} |
|
@ -1,601 +0,0 @@ |
|||||||
/* |
|
||||||
* Copyright (C) 2007, Robin Rosenberg <me@lathund.dewire.com> |
|
||||||
* Copyright (C) 2007-2008, Robin Rosenberg <robin.rosenberg@dewire.com> |
|
||||||
* Copyright (C) 2006-2008, Shawn O. Pearce <spearce@spearce.org> |
|
||||||
* and other copyright owners as documented in the project's IP log. |
|
||||||
* |
|
||||||
* This program and the accompanying materials are made available |
|
||||||
* under the terms of the Eclipse Distribution License v1.0 which |
|
||||||
* accompanies this distribution, is reproduced below, and is |
|
||||||
* available at http://www.eclipse.org/org/documents/edl-v10.php
|
|
||||||
* |
|
||||||
* All rights reserved. |
|
||||||
* |
|
||||||
* Redistribution and use in source and binary forms, with or |
|
||||||
* without modification, are permitted provided that the following |
|
||||||
* conditions are met: |
|
||||||
* |
|
||||||
* - Redistributions of source code must retain the above copyright |
|
||||||
* notice, this list of conditions and the following disclaimer. |
|
||||||
* |
|
||||||
* - Redistributions in binary form must reproduce the above |
|
||||||
* copyright notice, this list of conditions and the following |
|
||||||
* disclaimer in the documentation and/or other materials provided |
|
||||||
* with the distribution. |
|
||||||
* |
|
||||||
* - Neither the name of the Eclipse Foundation, Inc. nor the |
|
||||||
* names of its contributors may be used to endorse or promote |
|
||||||
* products derived from this software without specific prior |
|
||||||
* written permission. |
|
||||||
* |
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND |
|
||||||
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, |
|
||||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
|
||||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
||||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
|
||||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
|
||||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
|
||||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
|
||||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
|
||||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
||||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
|
||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
||||||
*/ |
|
||||||
|
|
||||||
package org.eclipse.jgit.lib; |
|
||||||
|
|
||||||
import java.io.IOException; |
|
||||||
import java.text.MessageFormat; |
|
||||||
|
|
||||||
import org.eclipse.jgit.errors.CorruptObjectException; |
|
||||||
import org.eclipse.jgit.errors.EntryExistsException; |
|
||||||
import org.eclipse.jgit.errors.MissingObjectException; |
|
||||||
import org.eclipse.jgit.errors.ObjectWritingException; |
|
||||||
import org.eclipse.jgit.internal.JGitText; |
|
||||||
import org.eclipse.jgit.util.RawParseUtils; |
|
||||||
|
|
||||||
/** |
|
||||||
* A representation of a Git tree entry. A Tree is a directory in Git. |
|
||||||
* |
|
||||||
* @deprecated To look up information about a single path, use |
|
||||||
* {@link org.eclipse.jgit.treewalk.TreeWalk#forPath(Repository, String, org.eclipse.jgit.revwalk.RevTree)}. |
|
||||||
* To lookup information about multiple paths at once, use a |
|
||||||
* {@link org.eclipse.jgit.treewalk.TreeWalk} and obtain the current entry's |
|
||||||
* information from its getter methods. |
|
||||||
*/ |
|
||||||
@Deprecated |
|
||||||
public class Tree extends TreeEntry { |
|
||||||
private static final TreeEntry[] EMPTY_TREE = {}; |
|
||||||
|
|
||||||
/** |
|
||||||
* Compare two names represented as bytes. Since git treats names of trees and |
|
||||||
* blobs differently we have one parameter that represents a '/' for trees. For |
|
||||||
* other objects the value should be NUL. The names are compare by their positive |
|
||||||
* byte value (0..255). |
|
||||||
* |
|
||||||
* A blob and a tree with the same name will not compare equal. |
|
||||||
* |
|
||||||
* @param a name |
|
||||||
* @param b name |
|
||||||
* @param lasta '/' if a is a tree, else NUL |
|
||||||
* @param lastb '/' if b is a tree, else NUL |
|
||||||
* |
|
||||||
* @return < 0 if a is sorted before b, 0 if they are the same, else b |
|
||||||
*/ |
|
||||||
public static final int compareNames(final byte[] a, final byte[] b, final int lasta,final int lastb) { |
|
||||||
return compareNames(a, b, 0, b.length, lasta, lastb); |
|
||||||
} |
|
||||||
|
|
||||||
private static final int compareNames(final byte[] a, final byte[] nameUTF8, |
|
||||||
final int nameStart, final int nameEnd, final int lasta, int lastb) { |
|
||||||
int j,k; |
|
||||||
for (j = 0, k = nameStart; j < a.length && k < nameEnd; j++, k++) { |
|
||||||
final int aj = a[j] & 0xff; |
|
||||||
final int bk = nameUTF8[k] & 0xff; |
|
||||||
if (aj < bk) |
|
||||||
return -1; |
|
||||||
else if (aj > bk) |
|
||||||
return 1; |
|
||||||
} |
|
||||||
if (j < a.length) { |
|
||||||
int aj = a[j]&0xff; |
|
||||||
if (aj < lastb) |
|
||||||
return -1; |
|
||||||
else if (aj > lastb) |
|
||||||
return 1; |
|
||||||
else |
|
||||||
if (j == a.length - 1) |
|
||||||
return 0; |
|
||||||
else |
|
||||||
return -1; |
|
||||||
} |
|
||||||
if (k < nameEnd) { |
|
||||||
int bk = nameUTF8[k] & 0xff; |
|
||||||
if (lasta < bk) |
|
||||||
return -1; |
|
||||||
else if (lasta > bk) |
|
||||||
return 1; |
|
||||||
else |
|
||||||
if (k == nameEnd - 1) |
|
||||||
return 0; |
|
||||||
else |
|
||||||
return 1; |
|
||||||
} |
|
||||||
if (lasta < lastb) |
|
||||||
return -1; |
|
||||||
else if (lasta > lastb) |
|
||||||
return 1; |
|
||||||
|
|
||||||
final int namelength = nameEnd - nameStart; |
|
||||||
if (a.length == namelength) |
|
||||||
return 0; |
|
||||||
else if (a.length < namelength) |
|
||||||
return -1; |
|
||||||
else |
|
||||||
return 1; |
|
||||||
} |
|
||||||
|
|
||||||
private static final byte[] substring(final byte[] s, final int nameStart, |
|
||||||
final int nameEnd) { |
|
||||||
if (nameStart == 0 && nameStart == s.length) |
|
||||||
return s; |
|
||||||
final byte[] n = new byte[nameEnd - nameStart]; |
|
||||||
System.arraycopy(s, nameStart, n, 0, n.length); |
|
||||||
return n; |
|
||||||
} |
|
||||||
|
|
||||||
private static final int binarySearch(final TreeEntry[] entries, |
|
||||||
final byte[] nameUTF8, final int nameUTF8last, final int nameStart, final int nameEnd) { |
|
||||||
if (entries.length == 0) |
|
||||||
return -1; |
|
||||||
int high = entries.length; |
|
||||||
int low = 0; |
|
||||||
do { |
|
||||||
final int mid = (low + high) >>> 1; |
|
||||||
final int cmp = compareNames(entries[mid].getNameUTF8(), nameUTF8, |
|
||||||
nameStart, nameEnd, TreeEntry.lastChar(entries[mid]), nameUTF8last); |
|
||||||
if (cmp < 0) |
|
||||||
low = mid + 1; |
|
||||||
else if (cmp == 0) |
|
||||||
return mid; |
|
||||||
else |
|
||||||
high = mid; |
|
||||||
} while (low < high); |
|
||||||
return -(low + 1); |
|
||||||
} |
|
||||||
|
|
||||||
private final Repository db; |
|
||||||
|
|
||||||
private TreeEntry[] contents; |
|
||||||
|
|
||||||
/** |
|
||||||
* Constructor for a new Tree |
|
||||||
* |
|
||||||
* @param repo The repository that owns the Tree. |
|
||||||
*/ |
|
||||||
public Tree(final Repository repo) { |
|
||||||
super(null, null, null); |
|
||||||
db = repo; |
|
||||||
contents = EMPTY_TREE; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Construct a Tree object with known content and hash value |
|
||||||
* |
|
||||||
* @param repo |
|
||||||
* @param myId |
|
||||||
* @param raw |
|
||||||
* @throws IOException |
|
||||||
*/ |
|
||||||
public Tree(final Repository repo, final ObjectId myId, final byte[] raw) |
|
||||||
throws IOException { |
|
||||||
super(null, myId, null); |
|
||||||
db = repo; |
|
||||||
readTree(raw); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Construct a new Tree under another Tree |
|
||||||
* |
|
||||||
* @param parent |
|
||||||
* @param nameUTF8 |
|
||||||
*/ |
|
||||||
public Tree(final Tree parent, final byte[] nameUTF8) { |
|
||||||
super(parent, null, nameUTF8); |
|
||||||
db = parent.getRepository(); |
|
||||||
contents = EMPTY_TREE; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Construct a Tree with a known SHA-1 under another tree. Data is not yet |
|
||||||
* specified and will have to be loaded on demand. |
|
||||||
* |
|
||||||
* @param parent |
|
||||||
* @param id |
|
||||||
* @param nameUTF8 |
|
||||||
*/ |
|
||||||
public Tree(final Tree parent, final ObjectId id, final byte[] nameUTF8) { |
|
||||||
super(parent, id, nameUTF8); |
|
||||||
db = parent.getRepository(); |
|
||||||
} |
|
||||||
|
|
||||||
public FileMode getMode() { |
|
||||||
return FileMode.TREE; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* @return true if this Tree is the top level Tree. |
|
||||||
*/ |
|
||||||
public boolean isRoot() { |
|
||||||
return getParent() == null; |
|
||||||
} |
|
||||||
|
|
||||||
public Repository getRepository() { |
|
||||||
return db; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* @return true of the data of this Tree is loaded |
|
||||||
*/ |
|
||||||
public boolean isLoaded() { |
|
||||||
return contents != null; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Forget the in-memory data for this tree. |
|
||||||
*/ |
|
||||||
public void unload() { |
|
||||||
if (isModified()) |
|
||||||
throw new IllegalStateException(JGitText.get().cannotUnloadAModifiedTree); |
|
||||||
contents = null; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Adds a new or existing file with the specified name to this tree. |
|
||||||
* Trees are added if necessary as the name may contain '/':s. |
|
||||||
* |
|
||||||
* @param name Name |
|
||||||
* @return a {@link FileTreeEntry} for the added file. |
|
||||||
* @throws IOException |
|
||||||
*/ |
|
||||||
public FileTreeEntry addFile(final String name) throws IOException { |
|
||||||
return addFile(Repository.gitInternalSlash(Constants.encode(name)), 0); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Adds a new or existing file with the specified name to this tree. |
|
||||||
* Trees are added if necessary as the name may contain '/':s. |
|
||||||
* |
|
||||||
* @param s an array containing the name |
|
||||||
* @param offset when the name starts in the tree. |
|
||||||
* |
|
||||||
* @return a {@link FileTreeEntry} for the added file. |
|
||||||
* @throws IOException |
|
||||||
*/ |
|
||||||
public FileTreeEntry addFile(final byte[] s, final int offset) |
|
||||||
throws IOException { |
|
||||||
int slash; |
|
||||||
int p; |
|
||||||
|
|
||||||
for (slash = offset; slash < s.length && s[slash] != '/'; slash++) { |
|
||||||
// search for path component terminator
|
|
||||||
} |
|
||||||
|
|
||||||
ensureLoaded(); |
|
||||||
byte xlast = slash<s.length ? (byte)'/' : 0; |
|
||||||
p = binarySearch(contents, s, xlast, offset, slash); |
|
||||||
if (p >= 0 && slash < s.length && contents[p] instanceof Tree) |
|
||||||
return ((Tree) contents[p]).addFile(s, slash + 1); |
|
||||||
|
|
||||||
final byte[] newName = substring(s, offset, slash); |
|
||||||
if (p >= 0) |
|
||||||
throw new EntryExistsException(RawParseUtils.decode(newName)); |
|
||||||
else if (slash < s.length) { |
|
||||||
final Tree t = new Tree(this, newName); |
|
||||||
insertEntry(p, t); |
|
||||||
return t.addFile(s, slash + 1); |
|
||||||
} else { |
|
||||||
final FileTreeEntry f = new FileTreeEntry(this, null, newName, |
|
||||||
false); |
|
||||||
insertEntry(p, f); |
|
||||||
return f; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Adds a new or existing Tree with the specified name to this tree. |
|
||||||
* Trees are added if necessary as the name may contain '/':s. |
|
||||||
* |
|
||||||
* @param name Name |
|
||||||
* @return a {@link FileTreeEntry} for the added tree. |
|
||||||
* @throws IOException |
|
||||||
*/ |
|
||||||
public Tree addTree(final String name) throws IOException { |
|
||||||
return addTree(Repository.gitInternalSlash(Constants.encode(name)), 0); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Adds a new or existing Tree with the specified name to this tree. |
|
||||||
* Trees are added if necessary as the name may contain '/':s. |
|
||||||
* |
|
||||||
* @param s an array containing the name |
|
||||||
* @param offset when the name starts in the tree. |
|
||||||
* |
|
||||||
* @return a {@link FileTreeEntry} for the added tree. |
|
||||||
* @throws IOException |
|
||||||
*/ |
|
||||||
public Tree addTree(final byte[] s, final int offset) throws IOException { |
|
||||||
int slash; |
|
||||||
int p; |
|
||||||
|
|
||||||
for (slash = offset; slash < s.length && s[slash] != '/'; slash++) { |
|
||||||
// search for path component terminator
|
|
||||||
} |
|
||||||
|
|
||||||
ensureLoaded(); |
|
||||||
p = binarySearch(contents, s, (byte)'/', offset, slash); |
|
||||||
if (p >= 0 && slash < s.length && contents[p] instanceof Tree) |
|
||||||
return ((Tree) contents[p]).addTree(s, slash + 1); |
|
||||||
|
|
||||||
final byte[] newName = substring(s, offset, slash); |
|
||||||
if (p >= 0) |
|
||||||
throw new EntryExistsException(RawParseUtils.decode(newName)); |
|
||||||
|
|
||||||
final Tree t = new Tree(this, newName); |
|
||||||
insertEntry(p, t); |
|
||||||
return slash == s.length ? t : t.addTree(s, slash + 1); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Add the specified tree entry to this tree. |
|
||||||
* |
|
||||||
* @param e |
|
||||||
* @throws IOException |
|
||||||
*/ |
|
||||||
public void addEntry(final TreeEntry e) throws IOException { |
|
||||||
final int p; |
|
||||||
|
|
||||||
ensureLoaded(); |
|
||||||
p = binarySearch(contents, e.getNameUTF8(), TreeEntry.lastChar(e), 0, e.getNameUTF8().length); |
|
||||||
if (p < 0) { |
|
||||||
e.attachParent(this); |
|
||||||
insertEntry(p, e); |
|
||||||
} else { |
|
||||||
throw new EntryExistsException(e.getName()); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private void insertEntry(int p, final TreeEntry e) { |
|
||||||
final TreeEntry[] c = contents; |
|
||||||
final TreeEntry[] n = new TreeEntry[c.length + 1]; |
|
||||||
p = -(p + 1); |
|
||||||
for (int k = c.length - 1; k >= p; k--) |
|
||||||
n[k + 1] = c[k]; |
|
||||||
n[p] = e; |
|
||||||
for (int k = p - 1; k >= 0; k--) |
|
||||||
n[k] = c[k]; |
|
||||||
contents = n; |
|
||||||
setModified(); |
|
||||||
} |
|
||||||
|
|
||||||
void removeEntry(final TreeEntry e) { |
|
||||||
final TreeEntry[] c = contents; |
|
||||||
final int p = binarySearch(c, e.getNameUTF8(), TreeEntry.lastChar(e), 0, |
|
||||||
e.getNameUTF8().length); |
|
||||||
if (p >= 0) { |
|
||||||
final TreeEntry[] n = new TreeEntry[c.length - 1]; |
|
||||||
for (int k = c.length - 1; k > p; k--) |
|
||||||
n[k - 1] = c[k]; |
|
||||||
for (int k = p - 1; k >= 0; k--) |
|
||||||
n[k] = c[k]; |
|
||||||
contents = n; |
|
||||||
setModified(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* @return number of members in this tree |
|
||||||
* @throws IOException |
|
||||||
*/ |
|
||||||
public int memberCount() throws IOException { |
|
||||||
ensureLoaded(); |
|
||||||
return contents.length; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Return all members of the tree sorted in Git order. |
|
||||||
* |
|
||||||
* Entries are sorted by the numerical unsigned byte |
|
||||||
* values with (sub)trees having an implicit '/'. An |
|
||||||
* example of a tree with three entries. a:b is an |
|
||||||
* actual file name here. |
|
||||||
* |
|
||||||
* <p> |
|
||||||
* 100644 blob e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 a.b |
|
||||||
* 040000 tree 4277b6e69d25e5efa77c455340557b384a4c018a a |
|
||||||
* 100644 blob e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 a:b |
|
||||||
* |
|
||||||
* @return all entries in this Tree, sorted. |
|
||||||
* @throws IOException |
|
||||||
*/ |
|
||||||
public TreeEntry[] members() throws IOException { |
|
||||||
ensureLoaded(); |
|
||||||
final TreeEntry[] c = contents; |
|
||||||
if (c.length != 0) { |
|
||||||
final TreeEntry[] r = new TreeEntry[c.length]; |
|
||||||
for (int k = c.length - 1; k >= 0; k--) |
|
||||||
r[k] = c[k]; |
|
||||||
return r; |
|
||||||
} else |
|
||||||
return c; |
|
||||||
} |
|
||||||
|
|
||||||
private boolean exists(final String s, byte slast) throws IOException { |
|
||||||
return findMember(s, slast) != null; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* @param path to the tree. |
|
||||||
* @return true if a tree with the specified path can be found under this |
|
||||||
* tree. |
|
||||||
* @throws IOException |
|
||||||
*/ |
|
||||||
public boolean existsTree(String path) throws IOException { |
|
||||||
return exists(path,(byte)'/'); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* @param path of the non-tree entry. |
|
||||||
* @return true if a blob, symlink, or gitlink with the specified name |
|
||||||
* can be found under this tree. |
|
||||||
* @throws IOException |
|
||||||
*/ |
|
||||||
public boolean existsBlob(String path) throws IOException { |
|
||||||
return exists(path,(byte)0); |
|
||||||
} |
|
||||||
|
|
||||||
private TreeEntry findMember(final String s, byte slast) throws IOException { |
|
||||||
return findMember(Repository.gitInternalSlash(Constants.encode(s)), slast, 0); |
|
||||||
} |
|
||||||
|
|
||||||
private TreeEntry findMember(final byte[] s, final byte slast, final int offset) |
|
||||||
throws IOException { |
|
||||||
int slash; |
|
||||||
int p; |
|
||||||
|
|
||||||
for (slash = offset; slash < s.length && s[slash] != '/'; slash++) { |
|
||||||
// search for path component terminator
|
|
||||||
} |
|
||||||
|
|
||||||
ensureLoaded(); |
|
||||||
byte xlast = slash<s.length ? (byte)'/' : slast; |
|
||||||
p = binarySearch(contents, s, xlast, offset, slash); |
|
||||||
if (p >= 0) { |
|
||||||
final TreeEntry r = contents[p]; |
|
||||||
if (slash < s.length-1) |
|
||||||
return r instanceof Tree ? ((Tree) r).findMember(s, slast, slash + 1) |
|
||||||
: null; |
|
||||||
return r; |
|
||||||
} |
|
||||||
return null; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* @param s |
|
||||||
* blob name |
|
||||||
* @return a {@link TreeEntry} representing an object with the specified |
|
||||||
* relative path. |
|
||||||
* @throws IOException |
|
||||||
*/ |
|
||||||
public TreeEntry findBlobMember(String s) throws IOException { |
|
||||||
return findMember(s,(byte)0); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* @param s Tree Name |
|
||||||
* @return a Tree with the name s or null |
|
||||||
* @throws IOException |
|
||||||
*/ |
|
||||||
public TreeEntry findTreeMember(String s) throws IOException { |
|
||||||
return findMember(s,(byte)'/'); |
|
||||||
} |
|
||||||
|
|
||||||
private void ensureLoaded() throws IOException, MissingObjectException { |
|
||||||
if (!isLoaded()) { |
|
||||||
ObjectLoader ldr = db.open(getId(), Constants.OBJ_TREE); |
|
||||||
readTree(ldr.getCachedBytes()); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private void readTree(final byte[] raw) throws IOException { |
|
||||||
final int rawSize = raw.length; |
|
||||||
int rawPtr = 0; |
|
||||||
TreeEntry[] temp; |
|
||||||
int nextIndex = 0; |
|
||||||
|
|
||||||
while (rawPtr < rawSize) { |
|
||||||
while (rawPtr < rawSize && raw[rawPtr] != 0) |
|
||||||
rawPtr++; |
|
||||||
rawPtr++; |
|
||||||
rawPtr += Constants.OBJECT_ID_LENGTH; |
|
||||||
nextIndex++; |
|
||||||
} |
|
||||||
|
|
||||||
temp = new TreeEntry[nextIndex]; |
|
||||||
rawPtr = 0; |
|
||||||
nextIndex = 0; |
|
||||||
while (rawPtr < rawSize) { |
|
||||||
int c = raw[rawPtr++]; |
|
||||||
if (c < '0' || c > '7') |
|
||||||
throw new CorruptObjectException(getId(), JGitText.get().corruptObjectInvalidEntryMode); |
|
||||||
int mode = c - '0'; |
|
||||||
for (;;) { |
|
||||||
c = raw[rawPtr++]; |
|
||||||
if (' ' == c) |
|
||||||
break; |
|
||||||
else if (c < '0' || c > '7') |
|
||||||
throw new CorruptObjectException(getId(), JGitText.get().corruptObjectInvalidMode); |
|
||||||
mode <<= 3; |
|
||||||
mode += c - '0'; |
|
||||||
} |
|
||||||
|
|
||||||
int nameLen = 0; |
|
||||||
while (raw[rawPtr + nameLen] != 0) |
|
||||||
nameLen++; |
|
||||||
final byte[] name = new byte[nameLen]; |
|
||||||
System.arraycopy(raw, rawPtr, name, 0, nameLen); |
|
||||||
rawPtr += nameLen + 1; |
|
||||||
|
|
||||||
final ObjectId id = ObjectId.fromRaw(raw, rawPtr); |
|
||||||
rawPtr += Constants.OBJECT_ID_LENGTH; |
|
||||||
|
|
||||||
final TreeEntry ent; |
|
||||||
if (FileMode.REGULAR_FILE.equals(mode)) |
|
||||||
ent = new FileTreeEntry(this, id, name, false); |
|
||||||
else if (FileMode.EXECUTABLE_FILE.equals(mode)) |
|
||||||
ent = new FileTreeEntry(this, id, name, true); |
|
||||||
else if (FileMode.TREE.equals(mode)) |
|
||||||
ent = new Tree(this, id, name); |
|
||||||
else if (FileMode.SYMLINK.equals(mode)) |
|
||||||
ent = new SymlinkTreeEntry(this, id, name); |
|
||||||
else if (FileMode.GITLINK.equals(mode)) |
|
||||||
ent = new GitlinkTreeEntry(this, id, name); |
|
||||||
else |
|
||||||
throw new CorruptObjectException(getId(), MessageFormat.format( |
|
||||||
JGitText.get().corruptObjectInvalidMode2, Integer.toOctalString(mode))); |
|
||||||
temp[nextIndex++] = ent; |
|
||||||
} |
|
||||||
|
|
||||||
contents = temp; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Format this Tree in canonical format. |
|
||||||
* |
|
||||||
* @return canonical encoding of the tree object. |
|
||||||
* @throws IOException |
|
||||||
* the tree cannot be loaded, or its not in a writable state. |
|
||||||
*/ |
|
||||||
public byte[] format() throws IOException { |
|
||||||
TreeFormatter fmt = new TreeFormatter(); |
|
||||||
for (TreeEntry e : members()) { |
|
||||||
ObjectId id = e.getId(); |
|
||||||
if (id == null) |
|
||||||
throw new ObjectWritingException(MessageFormat.format(JGitText |
|
||||||
.get().objectAtPathDoesNotHaveId, e.getFullName())); |
|
||||||
|
|
||||||
fmt.append(e.getNameUTF8(), e.getMode(), id); |
|
||||||
} |
|
||||||
return fmt.toByteArray(); |
|
||||||
} |
|
||||||
|
|
||||||
public String toString() { |
|
||||||
final StringBuilder r = new StringBuilder(); |
|
||||||
r.append(ObjectId.toString(getId())); |
|
||||||
r.append(" T "); //$NON-NLS-1$
|
|
||||||
r.append(getFullName()); |
|
||||||
return r.toString(); |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
@ -1,256 +0,0 @@ |
|||||||
/* |
|
||||||
* Copyright (C) 2007-2008, Robin Rosenberg <robin.rosenberg@dewire.com> |
|
||||||
* Copyright (C) 2006-2007, Shawn O. Pearce <spearce@spearce.org> |
|
||||||
* and other copyright owners as documented in the project's IP log. |
|
||||||
* |
|
||||||
* This program and the accompanying materials are made available |
|
||||||
* under the terms of the Eclipse Distribution License v1.0 which |
|
||||||
* accompanies this distribution, is reproduced below, and is |
|
||||||
* available at http://www.eclipse.org/org/documents/edl-v10.php
|
|
||||||
* |
|
||||||
* All rights reserved. |
|
||||||
* |
|
||||||
* Redistribution and use in source and binary forms, with or |
|
||||||
* without modification, are permitted provided that the following |
|
||||||
* conditions are met: |
|
||||||
* |
|
||||||
* - Redistributions of source code must retain the above copyright |
|
||||||
* notice, this list of conditions and the following disclaimer. |
|
||||||
* |
|
||||||
* - Redistributions in binary form must reproduce the above |
|
||||||
* copyright notice, this list of conditions and the following |
|
||||||
* disclaimer in the documentation and/or other materials provided |
|
||||||
* with the distribution. |
|
||||||
* |
|
||||||
* - Neither the name of the Eclipse Foundation, Inc. nor the |
|
||||||
* names of its contributors may be used to endorse or promote |
|
||||||
* products derived from this software without specific prior |
|
||||||
* written permission. |
|
||||||
* |
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND |
|
||||||
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, |
|
||||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
|
||||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
||||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
|
||||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
|
||||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
|
||||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
|
||||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
|
||||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
||||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
|
||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
||||||
*/ |
|
||||||
|
|
||||||
package org.eclipse.jgit.lib; |
|
||||||
|
|
||||||
import java.io.IOException; |
|
||||||
|
|
||||||
import org.eclipse.jgit.util.RawParseUtils; |
|
||||||
|
|
||||||
/** |
|
||||||
* This class represents an entry in a tree, like a blob or another tree. |
|
||||||
* |
|
||||||
* @deprecated To look up information about a single path, use |
|
||||||
* {@link org.eclipse.jgit.treewalk.TreeWalk#forPath(Repository, String, org.eclipse.jgit.revwalk.RevTree)}. |
|
||||||
* To lookup information about multiple paths at once, use a |
|
||||||
* {@link org.eclipse.jgit.treewalk.TreeWalk} and obtain the current entry's |
|
||||||
* information from its getter methods. |
|
||||||
*/ |
|
||||||
@Deprecated |
|
||||||
public abstract class TreeEntry implements Comparable { |
|
||||||
private byte[] nameUTF8; |
|
||||||
|
|
||||||
private Tree parent; |
|
||||||
|
|
||||||
private ObjectId id; |
|
||||||
|
|
||||||
/** |
|
||||||
* Construct a named tree entry. |
|
||||||
* |
|
||||||
* @param myParent |
|
||||||
* @param myId |
|
||||||
* @param myNameUTF8 |
|
||||||
*/ |
|
||||||
protected TreeEntry(final Tree myParent, final ObjectId myId, |
|
||||||
final byte[] myNameUTF8) { |
|
||||||
nameUTF8 = myNameUTF8; |
|
||||||
parent = myParent; |
|
||||||
id = myId; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* @return parent of this tree. |
|
||||||
*/ |
|
||||||
public Tree getParent() { |
|
||||||
return parent; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Delete this entry. |
|
||||||
*/ |
|
||||||
public void delete() { |
|
||||||
getParent().removeEntry(this); |
|
||||||
detachParent(); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Detach this entry from it's parent. |
|
||||||
*/ |
|
||||||
public void detachParent() { |
|
||||||
parent = null; |
|
||||||
} |
|
||||||
|
|
||||||
void attachParent(final Tree p) { |
|
||||||
parent = p; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* @return the repository owning this entry. |
|
||||||
*/ |
|
||||||
public Repository getRepository() { |
|
||||||
return getParent().getRepository(); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* @return the raw byte name of this entry. |
|
||||||
*/ |
|
||||||
public byte[] getNameUTF8() { |
|
||||||
return nameUTF8; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* @return the name of this entry. |
|
||||||
*/ |
|
||||||
public String getName() { |
|
||||||
if (nameUTF8 != null) |
|
||||||
return RawParseUtils.decode(nameUTF8); |
|
||||||
return null; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Rename this entry. |
|
||||||
* |
|
||||||
* @param n The new name |
|
||||||
* @throws IOException |
|
||||||
*/ |
|
||||||
public void rename(final String n) throws IOException { |
|
||||||
rename(Constants.encode(n)); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Rename this entry. |
|
||||||
* |
|
||||||
* @param n The new name |
|
||||||
* @throws IOException |
|
||||||
*/ |
|
||||||
public void rename(final byte[] n) throws IOException { |
|
||||||
final Tree t = getParent(); |
|
||||||
if (t != null) { |
|
||||||
delete(); |
|
||||||
} |
|
||||||
nameUTF8 = n; |
|
||||||
if (t != null) { |
|
||||||
t.addEntry(this); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* @return true if this entry is new or modified since being loaded. |
|
||||||
*/ |
|
||||||
public boolean isModified() { |
|
||||||
return getId() == null; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Mark this entry as modified. |
|
||||||
*/ |
|
||||||
public void setModified() { |
|
||||||
setId(null); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* @return SHA-1 of this tree entry (null for new unhashed entries) |
|
||||||
*/ |
|
||||||
public ObjectId getId() { |
|
||||||
return id; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Set (update) the SHA-1 of this entry. Invalidates the id's of all |
|
||||||
* entries above this entry as they will have to be recomputed. |
|
||||||
* |
|
||||||
* @param n SHA-1 for this entry. |
|
||||||
*/ |
|
||||||
public void setId(final ObjectId n) { |
|
||||||
// If we have a parent and our id is being cleared or changed then force
|
|
||||||
// the parent's id to become unset as it depends on our id.
|
|
||||||
//
|
|
||||||
final Tree p = getParent(); |
|
||||||
if (p != null && id != n) { |
|
||||||
if ((id == null && n != null) || (id != null && n == null) |
|
||||||
|| !id.equals(n)) { |
|
||||||
p.setId(null); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
id = n; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* @return repository relative name of this entry |
|
||||||
*/ |
|
||||||
public String getFullName() { |
|
||||||
final StringBuilder r = new StringBuilder(); |
|
||||||
appendFullName(r); |
|
||||||
return r.toString(); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* @return repository relative name of the entry |
|
||||||
* FIXME better encoding |
|
||||||
*/ |
|
||||||
public byte[] getFullNameUTF8() { |
|
||||||
return getFullName().getBytes(); |
|
||||||
} |
|
||||||
|
|
||||||
public int compareTo(final Object o) { |
|
||||||
if (this == o) |
|
||||||
return 0; |
|
||||||
if (o instanceof TreeEntry) |
|
||||||
return Tree.compareNames(nameUTF8, ((TreeEntry) o).nameUTF8, lastChar(this), lastChar((TreeEntry)o)); |
|
||||||
return -1; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Helper for accessing tree/blob methods. |
|
||||||
* |
|
||||||
* @param treeEntry |
|
||||||
* @return '/' for Tree entries and NUL for non-treeish objects. |
|
||||||
*/ |
|
||||||
final public static int lastChar(TreeEntry treeEntry) { |
|
||||||
if (!(treeEntry instanceof Tree)) |
|
||||||
return '\0'; |
|
||||||
else |
|
||||||
return '/'; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* @return mode (type of object) |
|
||||||
*/ |
|
||||||
public abstract FileMode getMode(); |
|
||||||
|
|
||||||
private void appendFullName(final StringBuilder r) { |
|
||||||
final TreeEntry p = getParent(); |
|
||||||
final String n = getName(); |
|
||||||
if (p != null) { |
|
||||||
p.appendFullName(r); |
|
||||||
if (r.length() > 0) { |
|
||||||
r.append('/'); |
|
||||||
} |
|
||||||
} |
|
||||||
if (n != null) { |
|
||||||
r.append(n); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
Loading…
Reference in new issue