Merge branch 'master' into stable-4.0

* master:
  Silence non-externalized string warnings in org.eclipse.jgit
  Externalize translatable texts in org.eclipse.jgit
  Don't invalidate pack file on InterruptedIOException
  Update Mars target platforms to use Mars RC2 orbit
  Update build to use eclipse-jarsigner-plugin 1.1.2
  Guard agains null ReflogReader if named ref does not exist
  FS: Allow to manually set the path to the Git system config file
  FS: Fix a minor typo in runInShell() docs
  FS: Improve javadoc of some recently introduced methods
  Cleanup code and Eclipse compile errors in new gitrepo API
  Refactor to expose ManifestParser.
  FS: Remove the gitprefix logic
  SystemReader: Use discoverGitSystemConfig() in openSystemConfig()
  FS: Add a method to discover the system-wide config file
  FS: Extend readPipe() to optionally take additional environment
  FS: Document readpipe()'s encoding parameter
  Split discoverGitPrefix() code out into discoverGitExe()
  Equalize discoverGitPrefix() implementations between POSIX and Win32
  Move resolveGrandparentFile() to the base class for wider use
  Replace deprecated release() methods by close()
  Use AutoClosable to close resources in bundle org.eclipse.jgit
  ReceivePack: support quiet capability
  Fix ObjectReader resources leak

Change-Id: I0cd9f7ad57f26f0a0cbf412845d00ba1efbea346
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
This commit is contained in:
Matthias Sohn 2015-05-26 11:39:19 +02:00
commit 04b3cd0e15
128 changed files with 2082 additions and 1656 deletions

View File

@ -94,9 +94,9 @@ Warnings/Caveats
Git is installed. Make sure Git can be found via the PATH
environment variable. When installing Git for Windows check the "Run
Git from the Windows Command Prompt" option. There are other options
like the jgit.gitprefix system property or Eclipse settings that can
be used for pointing out where C Git is installed. Modifying PATH is
the recommended option if C Git is installed.
like Eclipse settings that can be used for pointing out where C Git
is installed. Modifying PATH is the recommended option if C Git is
installed.
- We try to use the same notation of $HOME as C Git does. On Windows
this is often not the same value as the user.home system property.

View File

@ -117,7 +117,7 @@ protected void advertise(HttpServletRequest req,
try {
rp.sendAdvertisedRefs(pck);
} finally {
rp.getRevWalk().release();
rp.getRevWalk().close();
}
}
}

View File

@ -117,7 +117,7 @@ protected void advertise(HttpServletRequest req,
up.setBiDirectionalPipe(false);
up.sendAdvertisedRefs(pck);
} finally {
up.getRevWalk().release();
up.getRevWalk().close();
}
}
}

View File

@ -307,26 +307,27 @@ public String indexState(int includedOptions)
*/
protected void resetIndex(FileTreeIterator treeItr)
throws FileNotFoundException, IOException {
ObjectInserter inserter = db.newObjectInserter();
DirCacheBuilder builder = db.lockDirCache().builder();
DirCacheEntry dce;
try (ObjectInserter inserter = db.newObjectInserter()) {
DirCacheBuilder builder = db.lockDirCache().builder();
DirCacheEntry dce;
while (!treeItr.eof()) {
long len = treeItr.getEntryLength();
while (!treeItr.eof()) {
long len = treeItr.getEntryLength();
dce = new DirCacheEntry(treeItr.getEntryPathString());
dce.setFileMode(treeItr.getEntryFileMode());
dce.setLastModified(treeItr.getEntryLastModified());
dce.setLength((int) len);
FileInputStream in = new FileInputStream(treeItr.getEntryFile());
dce.setObjectId(inserter.insert(Constants.OBJ_BLOB, len, in));
in.close();
builder.add(dce);
treeItr.next(1);
dce = new DirCacheEntry(treeItr.getEntryPathString());
dce.setFileMode(treeItr.getEntryFileMode());
dce.setLastModified(treeItr.getEntryLastModified());
dce.setLength((int) len);
FileInputStream in = new FileInputStream(
treeItr.getEntryFile());
dce.setObjectId(inserter.insert(Constants.OBJ_BLOB, len, in));
in.close();
builder.add(dce);
treeItr.next(1);
}
builder.commit();
inserter.flush();
}
builder.commit();
inserter.flush();
inserter.release();
}
/**
@ -410,14 +411,15 @@ protected void createBranch(ObjectId objectId, String branchName)
protected void checkoutBranch(String branchName)
throws IllegalStateException, IOException {
RevWalk walk = new RevWalk(db);
RevCommit head = walk.parseCommit(db.resolve(Constants.HEAD));
RevCommit branch = walk.parseCommit(db.resolve(branchName));
DirCacheCheckout dco = new DirCacheCheckout(db, head.getTree().getId(),
db.lockDirCache(), branch.getTree().getId());
dco.setFailOnConflict(true);
dco.checkout();
walk.release();
try (RevWalk walk = new RevWalk(db)) {
RevCommit head = walk.parseCommit(db.resolve(Constants.HEAD));
RevCommit branch = walk.parseCommit(db.resolve(branchName));
DirCacheCheckout dco = new DirCacheCheckout(db,
head.getTree().getId(), db.lockDirCache(),
branch.getTree().getId());
dco.setFailOnConflict(true);
dco.checkout();
}
// update the HEAD
RefUpdate refUpdate = db.updateRef(Constants.HEAD);
refUpdate.setRefLogMessage("checkout: moving to " + branchName, false);

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?pde?>
<!-- generated with https://github.com/mbarbero/fr.obeo.releng.targetplatform -->
<target name="jgit-4.5" sequenceNumber="1431244072">
<target name="jgit-4.5" sequenceNumber="1432590632">
<locations>
<location includeMode="slicer" includeAllPlatforms="false" includeSource="true" includeConfigurePhase="true" type="InstallableUnit">
<unit id="org.eclipse.jetty.client" version="9.2.10.v20150310"/>
@ -23,8 +23,8 @@
<repository id="jetty-9.2.10" location="http://download.eclipse.org/jetty/updates/jetty-bundles-9.x/9.2.10.v20150310/"/>
</location>
<location includeMode="slicer" includeAllPlatforms="false" includeSource="true" includeConfigurePhase="true" type="InstallableUnit">
<unit id="org.apache.ant" version="1.9.4.v201410062020"/>
<unit id="org.apache.ant.source" version="1.9.4.v201410062020"/>
<unit id="org.apache.ant" version="1.9.4.v201504302020"/>
<unit id="org.apache.ant.source" version="1.9.4.v201504302020"/>
<unit id="org.apache.commons.compress" version="1.6.0.v201310281400"/>
<unit id="org.apache.commons.compress.source" version="1.6.0.v201310281400"/>
<unit id="org.apache.commons.logging" version="1.1.1.v201101211721"/>
@ -41,8 +41,8 @@
<unit id="org.hamcrest.core.source" version="1.3.0.v201303031735"/>
<unit id="javaewah" version="0.7.9.v201401101600"/>
<unit id="javaewah.source" version="0.7.9.v201401101600"/>
<unit id="org.objenesis" version="1.0.0.v201105211943"/>
<unit id="org.objenesis.source" version="1.0.0.v201105211943"/>
<unit id="org.objenesis" version="1.0.0.v201505121915"/>
<unit id="org.objenesis.source" version="1.0.0.v201505121915"/>
<unit id="org.mockito" version="1.8.4.v201303031500"/>
<unit id="org.mockito.source" version="1.8.4.v201303031500"/>
<unit id="com.jcraft.jsch" version="0.1.51.v201410302000"/>
@ -57,7 +57,7 @@
<unit id="org.slf4j.api.source" version="1.7.2.v20121108-1250"/>
<unit id="org.slf4j.impl.log4j12" version="1.7.2.v20131105-2200"/>
<unit id="org.slf4j.impl.log4j12.source" version="1.7.2.v20131105-2200"/>
<repository location="http://download.eclipse.org/tools/orbit/downloads/drops/S20150202203538/repository/"/>
<repository location="http://download.eclipse.org/tools/orbit/downloads/drops/S20150519210750/repository/"/>
</location>
<location includeMode="slicer" includeAllPlatforms="false" includeSource="true" includeConfigurePhase="true" type="InstallableUnit">
<unit id="org.eclipse.osgi" version="0.0.0"/>

View File

@ -1,7 +1,7 @@
target "jgit-4.5" with source configurePhase
include "projects/jetty-9.2.10.tpd"
include "orbit/S20150202203538-Mars-M5.tpd"
include "orbit/S20150519210750-Mars-RC2.tpd"
location "http://download.eclipse.org/releases/mars/" {
org.eclipse.osgi lazy

View File

@ -1,9 +1,9 @@
target "S20141023165154-Mars-M3" with source configurePhase
// see http://download.eclipse.org/tools/orbit/downloads/
location "http://download.eclipse.org/tools/orbit/downloads/drops/S20150202203538/repository/" {
org.apache.ant [1.9.4.v201410062020,1.9.4.v201410062020]
org.apache.ant.source [1.9.4.v201410062020,1.9.4.v201410062020]
location "http://download.eclipse.org/tools/orbit/downloads/drops/S20150519210750/repository/" {
org.apache.ant [1.9.4.v201504302020,1.9.4.v201504302020]
org.apache.ant.source [1.9.4.v201504302020,1.9.4.v201504302020]
org.apache.commons.compress [1.6.0.v201310281400,1.6.0.v201310281400]
org.apache.commons.compress.source [1.6.0.v201310281400,1.6.0.v201310281400]
org.apache.commons.logging [1.1.1.v201101211721,1.1.1.v201101211721]
@ -20,8 +20,8 @@ location "http://download.eclipse.org/tools/orbit/downloads/drops/S2015020220353
org.hamcrest.core.source [1.3.0.v201303031735,1.3.0.v201303031735]
javaewah [0.7.9.v201401101600,0.7.9.v201401101600]
javaewah.source [0.7.9.v201401101600,0.7.9.v201401101600]
org.objenesis [1.0.0.v201105211943,1.0.0.v201105211943]
org.objenesis.source [1.0.0.v201105211943,1.0.0.v201105211943]
org.objenesis [1.0.0.v201505121915,1.0.0.v201505121915]
org.objenesis.source [1.0.0.v201505121915,1.0.0.v201505121915]
org.mockito [1.8.4.v201303031500,1.8.4.v201303031500]
org.mockito.source [1.8.4.v201303031500,1.8.4.v201303031500]
com.jcraft.jsch [0.1.51.v201410302000,0.1.51.v201410302000]

View File

@ -214,7 +214,7 @@
<plugin>
<groupId>org.eclipse.cbi.maven.plugins</groupId>
<artifactId>eclipse-jarsigner-plugin</artifactId>
<version>1.1.2-SNAPSHOT</version>
<version>1.1.2</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>

View File

@ -67,8 +67,7 @@ abstract class AbstractFetchCommand extends TextBuiltin {
private boolean verbose;
protected void showFetchResult(final FetchResult r) throws IOException {
ObjectReader reader = db.newObjectReader();
try {
try (ObjectReader reader = db.newObjectReader()) {
boolean shownURI = false;
for (final TrackingRefUpdate u : r.getTrackingRefUpdates()) {
if (!verbose && u.getResult() == RefUpdate.Result.NO_CHANGE)
@ -89,8 +88,6 @@ protected void showFetchResult(final FetchResult r) throws IOException {
src, dst);
outw.println();
}
} finally {
reader.release();
}
showRemoteMessages(errw, r.getMessages());
}

View File

@ -156,10 +156,9 @@ protected void run() throws Exception {
else
dateFmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss ZZZZ"); //$NON-NLS-1$
BlameGenerator generator = new BlameGenerator(db, file);
RevFlag scanned = generator.newFlag("SCANNED"); //$NON-NLS-1$
reader = db.newObjectReader();
try {
try (BlameGenerator generator = new BlameGenerator(db, file)) {
RevFlag scanned = generator.newFlag("SCANNED"); //$NON-NLS-1$
generator.setTextComparator(comparator);
if (!reverseRange.isEmpty()) {
@ -247,8 +246,7 @@ protected void run() throws Exception {
} while (++line < end && blame.getSourceCommit(line) == c);
}
} finally {
generator.release();
reader.release();
reader.close();
}
}

View File

@ -204,15 +204,12 @@ else if (remote)
addRefs(refs, Constants.R_HEADS);
addRefs(refs, Constants.R_REMOTES);
ObjectReader reader = db.newObjectReader();
try {
try (ObjectReader reader = db.newObjectReader()) {
for (final Entry<String, Ref> e : printRefs.entrySet()) {
final Ref ref = e.getValue();
printHead(reader, e.getKey(),
current.equals(ref.getName()), ref);
}
} finally {
reader.release();
}
}
}

View File

@ -184,11 +184,8 @@ protected void run() throws Exception {
if (head == null)
die(MessageFormat.format(CLIText.get().notATree, HEAD));
CanonicalTreeParser p = new CanonicalTreeParser();
ObjectReader reader = db.newObjectReader();
try {
try (ObjectReader reader = db.newObjectReader()) {
p.reset(reader, head);
} finally {
reader.release();
}
oldTree = p;
}
@ -219,7 +216,7 @@ protected void run() throws Exception {
diffFmt.flush();
}
} finally {
diffFmt.release();
diffFmt.close();
}
}

View File

@ -63,8 +63,7 @@ class IndexPack extends TextBuiltin {
@Override
protected void run() throws Exception {
BufferedInputStream in = new BufferedInputStream(ins);
ObjectInserter inserter = db.newObjectInserter();
try {
try (ObjectInserter inserter = db.newObjectInserter()) {
PackParser p = inserter.newPackParser(in);
p.setAllowThin(fixThin);
if (indexVersion != -1 && p instanceof ObjectDirectoryPackParser) {
@ -73,8 +72,6 @@ protected void run() throws Exception {
}
p.parse(new TextProgressMonitor(errw));
inserter.flush();
} finally {
inserter.release();
}
}
}

View File

@ -223,7 +223,7 @@ protected void run() throws Exception {
super.run();
} finally {
diffFmt.release();
diffFmt.close();
}
}

View File

@ -125,11 +125,8 @@ protected void run() throws Exception {
push.setTimeout(timeout);
Iterable<PushResult> results = push.call();
for (PushResult result : results) {
ObjectReader reader = db.newObjectReader();
try {
try (ObjectReader reader = db.newObjectReader()) {
printPushResult(reader, result.getURI(), result);
} finally {
reader.release();
}
}
}

View File

@ -184,8 +184,7 @@ protected void run() throws Exception {
else
objectId = db.resolve(objectName);
RevWalk rw = new RevWalk(db);
try {
try (RevWalk rw = new RevWalk(db)) {
RevObject obj = rw.parseAny(objectId);
while (obj instanceof RevTag) {
show((RevTag) obj);
@ -216,11 +215,9 @@ protected void run() throws Exception {
CLIText.get().cannotReadBecause, obj.name(),
obj.getType()));
}
} finally {
rw.release();
}
} finally {
diffFmt.release();
diffFmt.close();
}
}

View File

@ -173,8 +173,7 @@ private void run(Repository db) throws Exception {
int maxN = 0;
AbbreviatedObjectId startId;
ObjectReader or = db.newObjectReader();
try {
try (ObjectReader or = db.newObjectReader()) {
final MutableObjectId id = new MutableObjectId();
RevWalk rw = new RevWalk(or);
TreeWalk tw = new TreeWalk(or);
@ -232,8 +231,6 @@ private void run(Repository db) throws Exception {
if (count > 0 && files > count)
break;
}
} finally {
or.release();
}
Collections.sort(all, new Comparator<Test>() {

View File

@ -134,12 +134,12 @@ protected void run() throws Exception {
}
private void recreateCommitGraph() throws IOException {
final RevWalk rw = new RevWalk(db);
final Map<ObjectId, ToRewrite> toRewrite = new HashMap<ObjectId, ToRewrite>();
List<ToRewrite> queue = new ArrayList<ToRewrite>();
final BufferedReader br = new BufferedReader(new InputStreamReader(
new FileInputStream(graph), Constants.CHARSET));
try {
try (RevWalk rw = new RevWalk(db);
final BufferedReader br = new BufferedReader(
new InputStreamReader(new FileInputStream(graph),
Constants.CHARSET))) {
String line;
while ((line = br.readLine()) != null) {
final String[] parts = line.split("[ \t]{1,}"); //$NON-NLS-1$
@ -162,52 +162,52 @@ private void recreateCommitGraph() throws IOException {
toRewrite.put(oldId, t);
queue.add(t);
}
} finally {
br.close();
}
pm.beginTask("Rewriting commits", queue.size());
final ObjectInserter oi = db.newObjectInserter();
final ObjectId emptyTree = oi.insert(Constants.OBJ_TREE, new byte[] {});
final PersonIdent me = new PersonIdent("jgit rebuild-commitgraph", //$NON-NLS-1$
"rebuild-commitgraph@localhost"); //$NON-NLS-1$
while (!queue.isEmpty()) {
final ListIterator<ToRewrite> itr = queue
.listIterator(queue.size());
queue = new ArrayList<ToRewrite>();
REWRITE: while (itr.hasPrevious()) {
final ToRewrite t = itr.previous();
final ObjectId[] newParents = new ObjectId[t.oldParents.length];
for (int k = 0; k < t.oldParents.length; k++) {
final ToRewrite p = toRewrite.get(t.oldParents[k]);
if (p != null) {
if (p.newId == null) {
// Must defer until after the parent is rewritten.
queue.add(t);
continue REWRITE;
try (ObjectInserter oi = db.newObjectInserter()) {
final ObjectId emptyTree = oi.insert(Constants.OBJ_TREE,
new byte[] {});
final PersonIdent me = new PersonIdent("jgit rebuild-commitgraph", //$NON-NLS-1$
"rebuild-commitgraph@localhost"); //$NON-NLS-1$
while (!queue.isEmpty()) {
final ListIterator<ToRewrite> itr = queue
.listIterator(queue.size());
queue = new ArrayList<ToRewrite>();
REWRITE: while (itr.hasPrevious()) {
final ToRewrite t = itr.previous();
final ObjectId[] newParents = new ObjectId[t.oldParents.length];
for (int k = 0; k < t.oldParents.length; k++) {
final ToRewrite p = toRewrite.get(t.oldParents[k]);
if (p != null) {
if (p.newId == null) {
// Must defer until after the parent is
// rewritten.
queue.add(t);
continue REWRITE;
} else {
newParents[k] = p.newId;
}
} else {
newParents[k] = p.newId;
// We have the old parent object. Use it.
//
newParents[k] = t.oldParents[k];
}
} else {
// We have the old parent object. Use it.
//
newParents[k] = t.oldParents[k];
}
}
final CommitBuilder newc = new CommitBuilder();
newc.setTreeId(emptyTree);
newc.setAuthor(new PersonIdent(me, new Date(t.commitTime)));
newc.setCommitter(newc.getAuthor());
newc.setParentIds(newParents);
newc.setMessage("ORIGINAL " + t.oldId.name() + "\n"); //$NON-NLS-2$
t.newId = oi.insert(newc);
rewrites.put(t.oldId, t.newId);
pm.update(1);
final CommitBuilder newc = new CommitBuilder();
newc.setTreeId(emptyTree);
newc.setAuthor(new PersonIdent(me, new Date(t.commitTime)));
newc.setCommitter(newc.getAuthor());
newc.setParentIds(newParents);
newc.setMessage("ORIGINAL " + t.oldId.name() + "\n"); //$NON-NLS-2$
t.newId = oi.insert(newc);
rewrites.put(t.oldId, t.newId);
pm.update(1);
}
}
oi.flush();
}
oi.flush();
oi.release();
pm.endTask();
}
@ -275,11 +275,11 @@ protected void writeFile(final String name, final byte[] content)
}
private Map<String, Ref> computeNewRefs() throws IOException {
final RevWalk rw = new RevWalk(db);
final Map<String, Ref> refs = new HashMap<String, Ref>();
final BufferedReader br = new BufferedReader(new InputStreamReader(
new FileInputStream(refList), Constants.CHARSET));
try {
try (RevWalk rw = new RevWalk(db);
BufferedReader br = new BufferedReader(
new InputStreamReader(new FileInputStream(refList),
Constants.CHARSET))) {
String line;
while ((line = br.readLine()) != null) {
final String[] parts = line.split("[ \t]{1,}"); //$NON-NLS-1$
@ -302,9 +302,6 @@ private Map<String, Ref> computeNewRefs() throws IOException {
refs.put(name, new ObjectIdRef.Unpeeled(Ref.Storage.PACKED,
name, id));
}
} finally {
rw.release();
br.close();
}
return refs;
}

View File

@ -300,8 +300,7 @@ private void run(Repository db) throws Exception {
long fileCnt = 0;
long lineCnt = 0;
ObjectReader or = db.newObjectReader();
try {
try (ObjectReader or = db.newObjectReader()) {
final MutableObjectId id = new MutableObjectId();
RevWalk rw = new RevWalk(or);
TreeWalk tw = new TreeWalk(or);
@ -340,8 +339,6 @@ private void run(Repository db) throws Exception {
for (Function fun : all)
testOne(fun, txt, lines, cnt);
}
} finally {
or.release();
}
if (db.getDirectory() != null) {

View File

@ -125,8 +125,7 @@ public int parseArguments(final Parameters params) throws CmdLineException {
throw new CmdLineException(MessageFormat.format(CLIText.get().notATree, name));
final CanonicalTreeParser p = new CanonicalTreeParser();
final ObjectReader curs = clp.getRepository().newObjectReader();
try {
try (ObjectReader curs = clp.getRepository().newObjectReader()) {
p.reset(curs, clp.getRevWalk().parseTree(id));
} catch (MissingObjectException e) {
throw new CmdLineException(MessageFormat.format(CLIText.get().notATree, name));
@ -134,8 +133,6 @@ public int parseArguments(final Parameters params) throws CmdLineException {
throw new CmdLineException(MessageFormat.format(CLIText.get().notATree, name));
} catch (IOException e) {
throw new CmdLineException(MessageFormat.format(CLIText.get().cannotReadBecause, name, e.getMessage()));
} finally {
curs.release();
}
setter.addValue(p);

View File

@ -624,7 +624,7 @@ public FS newInstance() {
return this;
}
protected File discoverGitPrefix() {
protected File discoverGitExe() {
return null;
}
@ -669,7 +669,7 @@ public FS newInstance() {
return this;
}
protected File discoverGitPrefix() {
protected File discoverGitExe() {
return null;
}

View File

@ -414,17 +414,19 @@ public void testCloneRepositoryWithSubmodules() throws Exception {
assertEquals(commit, pathStatus.getHeadId());
assertEquals(commit, pathStatus.getIndexId());
SubmoduleWalk walk = SubmoduleWalk.forIndex(git2.getRepository());
assertTrue(walk.next());
Repository clonedSub1 = walk.getRepository();
addRepoToClose(clonedSub1);
assertNotNull(clonedSub1);
assertEquals(
new File(git2.getRepository().getWorkTree(), walk.getPath()),
clonedSub1.getWorkTree());
assertEquals(new File(new File(git2.getRepository().getDirectory(),
"modules"), walk.getPath()), clonedSub1.getDirectory());
walk.release();
try (SubmoduleWalk walk = SubmoduleWalk
.forIndex(git2.getRepository())) {
assertTrue(walk.next());
Repository clonedSub1 = walk.getRepository();
addRepoToClose(clonedSub1);
assertNotNull(clonedSub1);
assertEquals(new File(git2.getRepository().getWorkTree(),
walk.getPath()), clonedSub1.getWorkTree());
assertEquals(
new File(new File(git2.getRepository().getDirectory(),
"modules"), walk.getPath()),
clonedSub1.getDirectory());
}
}
@Test

View File

@ -108,7 +108,7 @@ public FS newInstance() {
return this;
}
protected File discoverGitPrefix() {
protected File discoverGitExe() {
return null;
}
@ -153,7 +153,7 @@ public FS newInstance() {
return this;
}
protected File discoverGitPrefix() {
protected File discoverGitExe() {
return null;
}
@ -509,9 +509,9 @@ public void commitOnlyShouldCommitUnmergedPathAndNotAffectOthers()
+ "[unmerged2, mode:100644, stage:3]",
indexState(0));
TreeWalk walk = TreeWalk.forPath(db, "unmerged1", commit.getTree());
assertEquals(FileMode.REGULAR_FILE, walk.getFileMode(0));
walk.release();
try (TreeWalk walk = TreeWalk.forPath(db, "unmerged1", commit.getTree())) {
assertEquals(FileMode.REGULAR_FILE, walk.getFileMode(0));
}
}
private static void addUnmergedEntry(String file, DirCacheBuilder builder) {

View File

@ -247,12 +247,9 @@ private AbstractTreeIterator getTreeIterator(String name)
if (id == null)
throw new IllegalArgumentException(name);
final CanonicalTreeParser p = new CanonicalTreeParser();
final ObjectReader or = db.newObjectReader();
try {
try (ObjectReader or = db.newObjectReader()) {
p.reset(or, new RevWalk(db).parseTree(id));
return p;
} finally {
or.release();
}
}
}

View File

@ -193,8 +193,8 @@ public void testUpdateWorkingDirectoryFromIndex2() throws Exception {
public static void validateIndex(Git git) throws NoWorkTreeException,
IOException {
DirCache dc = git.getRepository().lockDirCache();
ObjectReader r = git.getRepository().getObjectDatabase().newReader();
try {
try (ObjectReader r = git.getRepository().getObjectDatabase()
.newReader()) {
for (int i = 0; i < dc.getEntryCount(); ++i) {
DirCacheEntry entry = dc.getEntry(i);
if (entry.getLength() > 0)
@ -203,7 +203,6 @@ public static void validateIndex(Git git) throws NoWorkTreeException,
}
} finally {
dc.unlock();
r.release();
}
}

View File

@ -474,34 +474,35 @@ private void doTestPullWithRebase(Callable<PullResult> pullSetup,
}
assertFileContentsEqual(sourceFile, "content");
RevWalk rw = new RevWalk(dbTarget);
rw.sort(RevSort.TOPO);
rw.markStart(rw.parseCommit(dbTarget.resolve("refs/heads/master")));
try (RevWalk rw = new RevWalk(dbTarget)) {
rw.sort(RevSort.TOPO);
rw.markStart(rw.parseCommit(dbTarget.resolve("refs/heads/master")));
RevCommit next;
if (expectedPullMode == TestPullMode.MERGE) {
next = rw.next();
assertEquals(2, next.getParentCount());
assertEquals(merge, next.getParent(0));
assertEquals(sourceCommit, next.getParent(1));
// since both parents are known do no further checks here
} else {
if (expectedPullMode == TestPullMode.REBASE_PREASERVE) {
RevCommit next;
if (expectedPullMode == TestPullMode.MERGE) {
next = rw.next();
assertEquals(2, next.getParentCount());
assertEquals(merge, next.getParent(0));
assertEquals(sourceCommit, next.getParent(1));
// since both parents are known do no further checks here
} else {
if (expectedPullMode == TestPullMode.REBASE_PREASERVE) {
next = rw.next();
assertEquals(2, next.getParentCount());
}
next = rw.next();
assertEquals(t2.getShortMessage(), next.getShortMessage());
next = rw.next();
assertEquals(t1.getShortMessage(), next.getShortMessage());
next = rw.next();
assertEquals(sourceCommit, next);
next = rw.next();
assertEquals("Initial commit for source",
next.getShortMessage());
next = rw.next();
assertNull(next);
}
next = rw.next();
assertEquals(t2.getShortMessage(), next.getShortMessage());
next = rw.next();
assertEquals(t1.getShortMessage(), next.getShortMessage());
next = rw.next();
assertEquals(sourceCommit, next);
next = rw.next();
assertEquals("Initial commit for source", next.getShortMessage());
next = rw.next();
assertNull(next);
}
rw.release();
}
@Override

View File

@ -114,13 +114,14 @@ public void setUp() throws Exception {
private void checkoutCommit(RevCommit commit) throws IllegalStateException,
IOException {
RevWalk walk = new RevWalk(db);
RevCommit head = walk.parseCommit(db.resolve(Constants.HEAD));
DirCacheCheckout dco = new DirCacheCheckout(db, head.getTree(), db
.lockDirCache(), commit.getTree());
dco.setFailOnConflict(true);
dco.checkout();
walk.release();
RevCommit head;
try (RevWalk walk = new RevWalk(db)) {
head = walk.parseCommit(db.resolve(Constants.HEAD));
DirCacheCheckout dco = new DirCacheCheckout(db, head.getTree(),
db.lockDirCache(), commit.getTree());
dco.setFailOnConflict(true);
dco.checkout();
}
// update the HEAD
RefUpdate refUpdate = db.updateRef(Constants.HEAD, true);
refUpdate.setNewObjectId(commit);
@ -472,11 +473,12 @@ private void doTestRebasePreservingMerges(boolean testConflict)
}
private String readFile(String path, RevCommit commit) throws IOException {
TreeWalk walk = TreeWalk.forPath(db, path, commit.getTree());
ObjectLoader loader = db.open(walk.getObjectId(0), Constants.OBJ_BLOB);
String result = RawParseUtils.decode(loader.getCachedBytes());
walk.release();
return result;
try (TreeWalk walk = TreeWalk.forPath(db, path, commit.getTree())) {
ObjectLoader loader = db.open(walk.getObjectId(0),
Constants.OBJ_BLOB);
String result = RawParseUtils.decode(loader.getCachedBytes());
return result;
}
}
@Test
@ -2073,14 +2075,11 @@ private TreeWalk createTreeWalk() {
private List<DiffEntry> diffWorkingAgainstHead(final RevCommit commit,
RevWalk revWalk)
throws IOException {
TreeWalk walk = createTreeWalk();
RevCommit parentCommit = revWalk.parseCommit(commit.getParent(0));
try {
try (TreeWalk walk = createTreeWalk()) {
walk.addTree(parentCommit.getTree());
walk.addTree(commit.getTree());
return DiffEntry.scan(walk);
} finally {
walk.release();
}
}

View File

@ -537,16 +537,10 @@ private void assertReflog(ObjectId prevHead, ObjectId head)
*/
private boolean inHead(String path) throws IOException {
ObjectId headId = db.resolve(Constants.HEAD);
RevWalk rw = new RevWalk(db);
TreeWalk tw = null;
try {
tw = TreeWalk.forPath(db, path, rw.parseTree(headId));
try (RevWalk rw = new RevWalk(db);
TreeWalk tw = TreeWalk.forPath(db, path,
rw.parseTree(headId))) {
return tw != null;
} finally {
rw.release();
rw.dispose();
if (tw != null)
tw.release();
}
}

View File

@ -118,12 +118,9 @@ private void validateStashedCommit(final RevCommit commit,
assertEquals(parentCount, commit.getParentCount());
// Load parents
RevWalk walk = new RevWalk(db);
try {
try (RevWalk walk = new RevWalk(db)) {
for (RevCommit parent : commit.getParents())
walk.parseBody(parent);
} finally {
walk.release();
}
assertEquals(1, commit.getParent(1).getParentCount());
@ -144,37 +141,28 @@ private TreeWalk createTreeWalk() {
private List<DiffEntry> diffWorkingAgainstHead(final RevCommit commit)
throws IOException {
TreeWalk walk = createTreeWalk();
try {
try (TreeWalk walk = createTreeWalk()) {
walk.addTree(commit.getParent(0).getTree());
walk.addTree(commit.getTree());
return DiffEntry.scan(walk);
} finally {
walk.release();
}
}
private List<DiffEntry> diffIndexAgainstHead(final RevCommit commit)
throws IOException {
TreeWalk walk = createTreeWalk();
try {
try (TreeWalk walk = createTreeWalk()) {
walk.addTree(commit.getParent(0).getTree());
walk.addTree(commit.getParent(1).getTree());
return DiffEntry.scan(walk);
} finally {
walk.release();
}
}
private List<DiffEntry> diffIndexAgainstWorking(final RevCommit commit)
throws IOException {
TreeWalk walk = createTreeWalk();
try {
try (TreeWalk walk = createTreeWalk()) {
walk.addTree(commit.getParent(1).getTree());
walk.addTree(commit.getTree());
return DiffEntry.scan(walk);
} finally {
walk.release();
}
}
@ -224,11 +212,12 @@ public void newFileInIndexThenModifiedInWorkTree() throws Exception {
writeTrashFile("file", "content2");
RevCommit stashedWorkTree = Git.wrap(db).stashCreate().call();
validateStashedCommit(stashedWorkTree);
RevWalk walk = new RevWalk(db);
RevCommit stashedIndex = stashedWorkTree.getParent(1);
walk.parseBody(stashedIndex);
walk.parseBody(stashedIndex.getTree());
walk.parseBody(stashedIndex.getParent(0));
try (RevWalk walk = new RevWalk(db)) {
RevCommit stashedIndex = stashedWorkTree.getParent(1);
walk.parseBody(stashedIndex);
walk.parseBody(stashedIndex.getTree());
walk.parseBody(stashedIndex.getParent(0));
}
List<DiffEntry> workTreeStashAgainstWorkTree = diffWorkingAgainstHead(stashedWorkTree);
assertEquals(1, workTreeStashAgainstWorkTree.size());
List<DiffEntry> workIndexAgainstWorkTree = diffIndexAgainstHead(stashedWorkTree);

View File

@ -70,8 +70,7 @@ public void testBoundLineDelete() throws Exception {
git.add().addFilepattern("file.txt").call();
RevCommit c2 = git.commit().setMessage("create file").call();
BlameGenerator generator = new BlameGenerator(db, "file.txt");
try {
try (BlameGenerator generator = new BlameGenerator(db, "file.txt")) {
generator.push(null, db.resolve(Constants.HEAD));
assertEquals(3, generator.getResultContents().size());
@ -94,8 +93,6 @@ public void testBoundLineDelete() throws Exception {
assertEquals("file.txt", generator.getSourcePath());
assertFalse(generator.next());
} finally {
generator.release();
}
}
@ -123,8 +120,7 @@ public void testRenamedBoundLineDelete() throws Exception {
git.add().addFilepattern(FILENAME_2).call();
RevCommit c2 = git.commit().setMessage("change file2").call();
BlameGenerator generator = new BlameGenerator(db, FILENAME_2);
try {
try (BlameGenerator generator = new BlameGenerator(db, FILENAME_2)) {
generator.push(null, db.resolve(Constants.HEAD));
assertEquals(3, generator.getResultContents().size());
@ -147,13 +143,10 @@ public void testRenamedBoundLineDelete() throws Exception {
assertEquals(FILENAME_1, generator.getSourcePath());
assertFalse(generator.next());
} finally {
generator.release();
}
// and test again with other BlameGenerator API:
generator = new BlameGenerator(db, FILENAME_2);
try {
try (BlameGenerator generator = new BlameGenerator(db, FILENAME_2)) {
generator.push(null, db.resolve(Constants.HEAD));
BlameResult result = generator.computeBlameResult();
@ -167,9 +160,6 @@ public void testRenamedBoundLineDelete() throws Exception {
assertEquals(c1, result.getSourceCommit(2));
assertEquals(FILENAME_1, result.getSourcePath(2));
} finally {
generator.release();
}
}
@ -193,8 +183,7 @@ public void testLinesAllDeletedShortenedWalk() throws Exception {
git.add().addFilepattern("file.txt").call();
RevCommit c3 = git.commit().setMessage("create file").call();
BlameGenerator generator = new BlameGenerator(db, "file.txt");
try {
try (BlameGenerator generator = new BlameGenerator(db, "file.txt")) {
generator.push(null, db.resolve(Constants.HEAD));
assertEquals(3, generator.getResultContents().size());
@ -204,8 +193,6 @@ public void testLinesAllDeletedShortenedWalk() throws Exception {
assertEquals(3, generator.getResultEnd());
assertFalse(generator.next());
} finally {
generator.release();
}
}

View File

@ -98,8 +98,9 @@ public void setUp() throws Exception {
@Override
@After
public void tearDown() throws Exception {
if (df != null)
df.release();
if (df != null) {
df.close();
}
super.tearDown();
}

View File

@ -0,0 +1,112 @@
/*
* Copyright (C) 2015, Google Inc.
* 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.gitrepo;
import static org.junit.Assert.assertTrue;
import java.io.StringBufferInputStream;
import java.util.HashSet;
import java.util.Set;
import org.junit.Test;
public class ManifestParserTest {
@Test
public void testManifestParser() throws Exception {
String baseUrl = "https://git.google.com/";
StringBuilder xmlContent = new StringBuilder();
Set<String> results = new HashSet<String>();
xmlContent.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
.append("<manifest>")
.append("<remote name=\"remote1\" fetch=\".\" />")
.append("<default revision=\"master\" remote=\"remote1\" />")
.append("<project path=\"foo\" name=\"")
.append("foo")
.append("\" groups=\"a,test\" />")
.append("<project path=\"bar\" name=\"")
.append("bar")
.append("\" groups=\"notdefault\" />")
.append("<project path=\"foo/a\" name=\"")
.append("a")
.append("\" groups=\"a\" />")
.append("<project path=\"b\" name=\"")
.append("b")
.append("\" groups=\"b\" />")
.append("</manifest>");
ManifestParser parser = new ManifestParser(
null, null, "master", baseUrl, null, null);
parser.read(new StringBufferInputStream(xmlContent.toString()));
// Unfiltered projects should have them all.
results.clear();
results.add("foo");
results.add("bar");
results.add("foo/a");
results.add("b");
for (RepoProject proj : parser.getProjects()) {
String msg = String.format(
"project \"%s\" should be included in unfiltered projects",
proj.path);
assertTrue(msg, results.contains(proj.path));
results.remove(proj.path);
}
assertTrue(
"Unfiltered projects shouldn't contain any unexpected results",
results.isEmpty());
// Filtered projects should have foo & b
results.clear();
results.add("foo");
results.add("b");
for (RepoProject proj : parser.getFilteredProjects()) {
String msg = String.format(
"project \"%s\" should be included in filtered projects",
proj.path);
assertTrue(msg, results.contains(proj.path));
results.remove(proj.path);
}
assertTrue(
"Filtered projects shouldn't contain any unexpected results",
results.isEmpty());
}
}

View File

@ -78,12 +78,11 @@ public void setUp() {
@Test
public void testInserterDiscardsPack() throws IOException {
ObjectInserter ins = db.newObjectInserter();
ins.insert(Constants.OBJ_BLOB, Constants.encode("foo"));
ins.insert(Constants.OBJ_BLOB, Constants.encode("bar"));
assertEquals(0, db.getObjectDatabase().listPacks().size());
ins.release();
try (ObjectInserter ins = db.newObjectInserter()) {
ins.insert(Constants.OBJ_BLOB, Constants.encode("foo"));
ins.insert(Constants.OBJ_BLOB, Constants.encode("bar"));
assertEquals(0, db.getObjectDatabase().listPacks().size());
}
assertEquals(0, db.getObjectDatabase().listPacks().size());
}

View File

@ -94,8 +94,9 @@ public void setUp() throws Exception {
@After
public void tearDown() throws Exception {
if (reader != null)
reader.release();
if (reader != null) {
reader.close();
}
}
@Test

View File

@ -150,11 +150,11 @@ public void testObjectMovedWithinPack()
// within the pack has been modified.
//
final RevObject o2 = writeBlob(eden, "o2");
final PackWriter pw = new PackWriter(eden);
pw.addObject(o2);
pw.addObject(o1);
write(out1, pw);
pw.release();
try (PackWriter pw = new PackWriter(eden)) {
pw.addObject(o2);
pw.addObject(o1);
write(out1, pw);
}
// Try the old name, then the new name. The old name should cause the
// pack to reload when it opens and the index and pack mismatch.
@ -216,18 +216,18 @@ private RevObject parse(final AnyObjectId id)
private File[] pack(final Repository src, final RevObject... list)
throws IOException {
final PackWriter pw = new PackWriter(src);
for (final RevObject o : list) {
pw.addObject(o);
}
try (PackWriter pw = new PackWriter(src)) {
for (final RevObject o : list) {
pw.addObject(o);
}
final ObjectId name = pw.computeName();
final File packFile = fullPackFileName(name, ".pack");
final File idxFile = fullPackFileName(name, ".idx");
final File[] files = new File[] { packFile, idxFile };
write(files, pw);
pw.release();
return files;
final ObjectId name = pw.computeName();
final File packFile = fullPackFileName(name, ".pack");
final File idxFile = fullPackFileName(name, ".idx");
final File[] files = new File[] { packFile, idxFile };
write(files, pw);
return files;
}
}
private static void write(final File[] files, final PackWriter pw)
@ -282,13 +282,10 @@ private RevObject writeBlob(final Repository repo, final String data)
throws IOException {
final RevWalk revWalk = new RevWalk(repo);
final byte[] bytes = Constants.encode(data);
final ObjectInserter inserter = repo.newObjectInserter();
final ObjectId id;
try {
try (ObjectInserter inserter = repo.newObjectInserter()) {
id = inserter.insert(Constants.OBJ_BLOB, bytes);
inserter.flush();
} finally {
inserter.release();
}
try {
parse(id);

View File

@ -373,8 +373,9 @@ private static byte[] digest(TemporaryBuffer.Heap buf)
@After
public void release() {
if (inserter != null)
inserter.release();
if (inserter != null) {
inserter.close();
}
}
private PackParser index(byte[] raw) throws IOException {

View File

@ -120,11 +120,11 @@ public void setUp() throws Exception {
@After
public void tearDown() throws Exception {
if (writer != null) {
writer.release();
writer.close();
writer = null;
}
if (inserter != null) {
inserter.release();
inserter.close();
inserter = null;
}
super.tearDown();
@ -514,26 +514,26 @@ private static void assertContent(PackIndex pi, List<ObjectId> expected) {
private static PackIndex writePack(FileRepository repo,
Set<? extends ObjectId> want, Set<ObjectIdSet> excludeObjects)
throws IOException {
PackWriter pw = new PackWriter(repo);
pw.setDeltaBaseAsOffset(true);
pw.setReuseDeltaCommits(false);
for (ObjectIdSet idx : excludeObjects)
pw.excludeObjects(idx);
pw.preparePack(NullProgressMonitor.INSTANCE, want,
Collections.<ObjectId> emptySet());
String id = pw.computeName().getName();
File packdir = new File(repo.getObjectsDirectory(), "pack");
File packFile = new File(packdir, "pack-" + id + ".pack");
FileOutputStream packOS = new FileOutputStream(packFile);
pw.writePack(NullProgressMonitor.INSTANCE,
NullProgressMonitor.INSTANCE, packOS);
packOS.close();
File idxFile = new File(packdir, "pack-" + id + ".idx");
FileOutputStream idxOS = new FileOutputStream(idxFile);
pw.writeIndex(idxOS);
idxOS.close();
pw.release();
return PackIndex.open(idxFile);
try (PackWriter pw = new PackWriter(repo)) {
pw.setDeltaBaseAsOffset(true);
pw.setReuseDeltaCommits(false);
for (ObjectIdSet idx : excludeObjects)
pw.excludeObjects(idx);
pw.preparePack(NullProgressMonitor.INSTANCE, want,
Collections.<ObjectId> emptySet());
String id = pw.computeName().getName();
File packdir = new File(repo.getObjectsDirectory(), "pack");
File packFile = new File(packdir, "pack-" + id + ".pack");
FileOutputStream packOS = new FileOutputStream(packFile);
pw.writePack(NullProgressMonitor.INSTANCE,
NullProgressMonitor.INSTANCE, packOS);
packOS.close();
File idxFile = new File(packdir, "pack-" + id + ".idx");
FileOutputStream idxOS = new FileOutputStream(idxFile);
pw.writeIndex(idxOS);
idxOS.close();
return PackIndex.open(idxFile);
}
}
// TODO: testWritePackDeltasCycle()
@ -639,7 +639,7 @@ private void createVerifyOpenPack(final Set<ObjectId> interestings,
writer.setIgnoreMissingUninteresting(ignoreMissingUninteresting);
writer.preparePack(m, interestings, uninterestings);
writer.writePack(m, m, os);
writer.release();
writer.close();
verifyOpenPack(thin);
}
@ -650,7 +650,7 @@ private void createVerifyOpenPack(final List<RevObject> objectSource)
writer.preparePack(objectSource.iterator());
assertEquals(objectSource.size(), writer.getObjectCount());
writer.writePack(m, m, os);
writer.release();
writer.close();
verifyOpenPack(false);
}

View File

@ -304,11 +304,12 @@ public void test002_WriteEmptyTree() throws IOException {
// object (as it already exists in the pack).
//
final Repository newdb = createBareRepository();
final ObjectInserter oi = newdb.newObjectInserter();
final ObjectId treeId = oi.insert(new TreeFormatter());
oi.release();
try (final ObjectInserter oi = newdb.newObjectInserter()) {
final ObjectId treeId = oi.insert(new TreeFormatter());
assertEquals("4b825dc642cb6eb9a060e54bf8d69288fbee4904",
treeId.name());
}
assertEquals("4b825dc642cb6eb9a060e54bf8d69288fbee4904", treeId.name());
final File o = new File(new File(new File(newdb.getDirectory(),
"objects"), "4b"), "825dc642cb6eb9a060e54bf8d69288fbee4904");
assertTrue("Exists " + o, o.isFile());
@ -569,8 +570,7 @@ public void test025_computeSha1NoStore() throws IOException {
@Test
public void test026_CreateCommitMultipleparents() throws IOException {
final ObjectId treeId;
final ObjectInserter oi = db.newObjectInserter();
try {
try (final ObjectInserter oi = db.newObjectInserter()) {
final ObjectId blobId = oi.insert(Constants.OBJ_BLOB,
"and this is the data in me\n".getBytes(Constants.CHARSET
.name()));
@ -578,8 +578,6 @@ public void test026_CreateCommitMultipleparents() throws IOException {
fmt.append("i-am-a-file", FileMode.REGULAR_FILE, blobId);
treeId = oi.insert(fmt);
oi.flush();
} finally {
oi.release();
}
assertEquals(ObjectId
.fromString("00b1f73724f493096d1ffa0b0f1f1482dbb8c936"), treeId);
@ -741,80 +739,59 @@ public void test30_stripWorkDir() {
private ObjectId insertEmptyBlob() throws IOException {
final ObjectId emptyId;
ObjectInserter oi = db.newObjectInserter();
try {
try (ObjectInserter oi = db.newObjectInserter()) {
emptyId = oi.insert(Constants.OBJ_BLOB, new byte[] {});
oi.flush();
} finally {
oi.release();
}
return emptyId;
}
private ObjectId insertTree(Tree tree) throws IOException {
ObjectInserter oi = db.newObjectInserter();
try {
try (ObjectInserter oi = db.newObjectInserter()) {
ObjectId id = oi.insert(Constants.OBJ_TREE, tree.format());
oi.flush();
return id;
} finally {
oi.release();
}
}
private ObjectId insertTree(TreeFormatter tree) throws IOException {
ObjectInserter oi = db.newObjectInserter();
try {
try (ObjectInserter oi = db.newObjectInserter()) {
ObjectId id = oi.insert(tree);
oi.flush();
return id;
} finally {
oi.release();
}
}
private ObjectId insertCommit(final CommitBuilder builder)
throws IOException, UnsupportedEncodingException {
ObjectInserter oi = db.newObjectInserter();
try {
try (ObjectInserter oi = db.newObjectInserter()) {
ObjectId id = oi.insert(builder);
oi.flush();
return id;
} finally {
oi.release();
}
}
private RevCommit parseCommit(AnyObjectId id)
throws MissingObjectException, IncorrectObjectTypeException,
IOException {
RevWalk rw = new RevWalk(db);
try {
try (RevWalk rw = new RevWalk(db)) {
return rw.parseCommit(id);
} finally {
rw.release();
}
}
private ObjectId insertTag(final TagBuilder tag) throws IOException,
UnsupportedEncodingException {
ObjectInserter oi = db.newObjectInserter();
try {
try (ObjectInserter oi = db.newObjectInserter()) {
ObjectId id = oi.insert(tag);
oi.flush();
return id;
} finally {
oi.release();
}
}
private RevTag parseTag(AnyObjectId id) throws MissingObjectException,
IncorrectObjectTypeException, IOException {
RevWalk rw = new RevWalk(db);
try {
try (RevWalk rw = new RevWalk(db)) {
return rw.parseTag(id);
} finally {
rw.release();
}
}

View File

@ -356,15 +356,12 @@ private ObjectId buildTree(HashMap<String, String> headEntries)
}
ObjectId genSha1(String data) {
ObjectInserter w = db.newObjectInserter();
try {
try (ObjectInserter w = db.newObjectInserter()) {
ObjectId id = w.insert(Constants.OBJ_BLOB, data.getBytes());
w.flush();
return id;
} catch (IOException e) {
fail(e.toString());
} finally {
w.release();
}
return null;
}

View File

@ -384,13 +384,10 @@ public void testUnchangedComplex() throws IOException, GitAPIException {
}
private ObjectId insertTree(Tree tree) throws IOException {
ObjectInserter oi = db.newObjectInserter();
try {
try (ObjectInserter oi = db.newObjectInserter()) {
ObjectId id = oi.insert(Constants.OBJ_TREE, tree.format());
oi.flush();
return id;
} finally {
oi.release();
}
}

View File

@ -109,14 +109,11 @@ private void commit(String commitMsg, PersonIdent author,
commit.setAuthor(author);
commit.setCommitter(committer);
commit.setMessage(commitMsg);
ObjectInserter inserter = db.newObjectInserter();
ObjectId id;
try {
try (ObjectInserter inserter = db.newObjectInserter()) {
commit.setTreeId(inserter.insert(new TreeFormatter()));
id = inserter.insert(commit);
inserter.flush();
} finally {
inserter.release();
}
int nl = commitMsg.indexOf('\n');

View File

@ -86,8 +86,8 @@ public void setUp() throws Exception {
@Override
@After
public void tearDown() throws Exception {
reader.release();
inserter.release();
reader.close();
inserter.close();
super.tearDown();
}

View File

@ -127,8 +127,8 @@ public void setUp() throws Exception {
@Override
@After
public void tearDown() throws Exception {
reader.release();
inserter.release();
reader.close();
inserter.close();
super.tearDown();
}

View File

@ -91,8 +91,8 @@ public void setUp() throws Exception {
@Override
@After
public void tearDown() throws Exception {
reader.release();
inserter.release();
reader.close();
inserter.close();
super.tearDown();
}

View File

@ -229,15 +229,12 @@ public void testEmptyTreeCorruption() throws Exception {
Tree A_A = A.addTree("A");
Tree A_B = A.addTree("B");
final ObjectInserter inserter = db.newObjectInserter();
try {
try (final ObjectInserter inserter = db.newObjectInserter()) {
A_A.setId(inserter.insert(Constants.OBJ_TREE, A_A.format()));
A_B.setId(inserter.insert(Constants.OBJ_TREE, A_B.format()));
A.setId(inserter.insert(Constants.OBJ_TREE, A.format()));
root.setId(inserter.insert(Constants.OBJ_TREE, root.format()));
inserter.flush();
} finally {
inserter.release();
}
tree_root = rw.parseTree(root.getId());

View File

@ -103,12 +103,9 @@ public void withCommitLoadedByDifferentRevWalk() throws Exception {
RevCommit a = commit();
Ref branchA = branch("a", a);
RevWalk walk = new RevWalk(db);
try {
try (RevWalk walk = new RevWalk(db)) {
RevCommit parsedCommit = walk.parseCommit(a.getId());
assertContains(parsedCommit, asList(branchA));
} finally {
walk.release();
}
}

View File

@ -486,8 +486,9 @@ private static void digest(TemporaryBuffer.Heap buf) throws IOException {
@After
public void release() {
if (inserter != null)
inserter.release();
if (inserter != null) {
inserter.close();
}
}
private PackParser index(InputStream in) throws IOException {

View File

@ -543,8 +543,9 @@ private static void digest(TemporaryBuffer.Heap buf) throws IOException {
@After
public void release() {
if (inserter != null)
inserter.release();
if (inserter != null) {
inserter.close();
}
}
private void openPack(TemporaryBuffer.Heap buf) throws IOException {

View File

@ -89,20 +89,19 @@ public void testSymlinkNotModifiedThoughNormalized() throws Exception {
DirCacheEditor dce = dc.editor();
final String UNNORMALIZED = "target/";
final byte[] UNNORMALIZED_BYTES = Constants.encode(UNNORMALIZED);
ObjectInserter oi = db.newObjectInserter();
final ObjectId linkid = oi.insert(Constants.OBJ_BLOB,
UNNORMALIZED_BYTES, 0,
UNNORMALIZED_BYTES.length);
oi.release();
dce.add(new DirCacheEditor.PathEdit("link") {
@Override
public void apply(DirCacheEntry ent) {
ent.setFileMode(FileMode.SYMLINK);
ent.setObjectId(linkid);
ent.setLength(UNNORMALIZED_BYTES.length);
}
});
assertTrue(dce.commit());
try (ObjectInserter oi = db.newObjectInserter()) {
final ObjectId linkid = oi.insert(Constants.OBJ_BLOB,
UNNORMALIZED_BYTES, 0, UNNORMALIZED_BYTES.length);
dce.add(new DirCacheEditor.PathEdit("link") {
@Override
public void apply(DirCacheEntry ent) {
ent.setFileMode(FileMode.SYMLINK);
ent.setObjectId(linkid);
ent.setLength(UNNORMALIZED_BYTES.length);
}
});
assertTrue(dce.commit());
}
new Git(db).commit().setMessage("Adding link").call();
new Git(db).reset().setMode(ResetType.HARD).call();
DirCacheIterator dci = new DirCacheIterator(db.readDirCache());
@ -129,19 +128,19 @@ public void testSymlinkModifiedNotNormalized() throws Exception {
DirCacheEditor dce = dc.editor();
final String NORMALIZED = "target";
final byte[] NORMALIZED_BYTES = Constants.encode(NORMALIZED);
ObjectInserter oi = db.newObjectInserter();
final ObjectId linkid = oi.insert(Constants.OBJ_BLOB, NORMALIZED_BYTES,
0, NORMALIZED_BYTES.length);
oi.release();
dce.add(new DirCacheEditor.PathEdit("link") {
@Override
public void apply(DirCacheEntry ent) {
ent.setFileMode(FileMode.SYMLINK);
ent.setObjectId(linkid);
ent.setLength(NORMALIZED_BYTES.length);
}
});
assertTrue(dce.commit());
try (ObjectInserter oi = db.newObjectInserter()) {
final ObjectId linkid = oi.insert(Constants.OBJ_BLOB,
NORMALIZED_BYTES, 0, NORMALIZED_BYTES.length);
dce.add(new DirCacheEditor.PathEdit("link") {
@Override
public void apply(DirCacheEntry ent) {
ent.setFileMode(FileMode.SYMLINK);
ent.setObjectId(linkid);
ent.setLength(NORMALIZED_BYTES.length);
}
});
assertTrue(dce.commit());
}
new Git(db).commit().setMessage("Adding link").call();
new Git(db).reset().setMode(ResetType.HARD).call();
DirCacheIterator dci = new DirCacheIterator(db.readDirCache());
@ -166,21 +165,21 @@ public void apply(DirCacheEntry ent) {
public void testSymlinkActuallyModified() throws Exception {
final String NORMALIZED = "target";
final byte[] NORMALIZED_BYTES = Constants.encode(NORMALIZED);
ObjectInserter oi = db.newObjectInserter();
final ObjectId linkid = oi.insert(Constants.OBJ_BLOB, NORMALIZED_BYTES,
0, NORMALIZED_BYTES.length);
oi.release();
DirCache dc = db.lockDirCache();
DirCacheEditor dce = dc.editor();
dce.add(new DirCacheEditor.PathEdit("link") {
@Override
public void apply(DirCacheEntry ent) {
ent.setFileMode(FileMode.SYMLINK);
ent.setObjectId(linkid);
ent.setLength(NORMALIZED_BYTES.length);
}
});
assertTrue(dce.commit());
try (ObjectInserter oi = db.newObjectInserter()) {
final ObjectId linkid = oi.insert(Constants.OBJ_BLOB,
NORMALIZED_BYTES, 0, NORMALIZED_BYTES.length);
DirCache dc = db.lockDirCache();
DirCacheEditor dce = dc.editor();
dce.add(new DirCacheEditor.PathEdit("link") {
@Override
public void apply(DirCacheEntry ent) {
ent.setFileMode(FileMode.SYMLINK);
ent.setObjectId(linkid);
ent.setLength(NORMALIZED_BYTES.length);
}
});
assertTrue(dce.commit());
}
new Git(db).commit().setMessage("Adding link").call();
new Git(db).reset().setMode(ResetType.HARD).call();

View File

@ -274,9 +274,9 @@ public void testDirCacheMatchingId() throws Exception {
ObjectId fromRaw = ObjectId.fromRaw(fti.idBuffer(), fti.idOffset());
assertEquals("6b584e8ece562ebffc15d38808cd6b98fc3d97ea",
fromRaw.getName());
ObjectReader objectReader = db.newObjectReader();
assertFalse(fti.isModified(dce, false, objectReader));
objectReader.release();
try (ObjectReader objectReader = db.newObjectReader()) {
assertFalse(fti.isModified(dce, false, objectReader));
}
}
@Test
@ -291,15 +291,15 @@ public void testIsModifiedSymlinkAsFile() throws Exception {
// Modify previously committed DirCacheEntry and write it back to disk
DirCacheEntry dce = db.readDirCache().getEntry("symlink");
dce.setFileMode(FileMode.SYMLINK);
ObjectReader objectReader = db.newObjectReader();
DirCacheCheckout.checkoutEntry(db, dce, objectReader);
try (ObjectReader objectReader = db.newObjectReader()) {
DirCacheCheckout.checkoutEntry(db, dce, objectReader);
FileTreeIterator fti = new FileTreeIterator(trash, db.getFS(), db
.getConfig().get(WorkingTreeOptions.KEY));
while (!fti.getEntryPathString().equals("symlink"))
fti.next(1);
assertFalse(fti.isModified(dce, false, objectReader));
objectReader.release();
FileTreeIterator fti = new FileTreeIterator(trash, db.getFS(),
db.getConfig().get(WorkingTreeOptions.KEY));
while (!fti.getEntryPathString().equals("symlink"))
fti.next(1);
assertFalse(fti.isModified(dce, false, objectReader));
}
}
@Test
@ -327,9 +327,9 @@ public void testIsModifiedFileSmudged() throws Exception {
// If the rounding trick does not work we could skip the compareMetaData
// test and hope that we are usually testing the intended code path.
assertEquals(MetadataDiff.SMUDGED, fti.compareMetadata(dce));
ObjectReader objectReader = db.newObjectReader();
assertTrue(fti.isModified(dce, false, objectReader));
objectReader.release();
try (ObjectReader objectReader = db.newObjectReader()) {
assertTrue(fti.isModified(dce, false, objectReader));
}
}
@Test

View File

@ -68,70 +68,69 @@ public class ForPathTest extends RepositoryTestCase {
public void testFindObjects() throws Exception {
final DirCache tree0 = DirCache.newInCore();
final DirCacheBuilder b0 = tree0.builder();
ObjectReader or = db.newObjectReader();
ObjectInserter oi = db.newObjectInserter();
try (ObjectReader or = db.newObjectReader();
ObjectInserter oi = db.newObjectInserter()) {
DirCacheEntry aDotB = createEntry("a.b", EXECUTABLE_FILE);
b0.add(aDotB);
DirCacheEntry aSlashB = createEntry("a/b", REGULAR_FILE);
b0.add(aSlashB);
DirCacheEntry aSlashCSlashD = createEntry("a/c/d", REGULAR_FILE);
b0.add(aSlashCSlashD);
DirCacheEntry aZeroB = createEntry("a0b", SYMLINK);
b0.add(aZeroB);
b0.finish();
assertEquals(4, tree0.getEntryCount());
ObjectId tree = tree0.writeTree(oi);
DirCacheEntry aDotB = createEntry("a.b", EXECUTABLE_FILE);
b0.add(aDotB);
DirCacheEntry aSlashB = createEntry("a/b", REGULAR_FILE);
b0.add(aSlashB);
DirCacheEntry aSlashCSlashD = createEntry("a/c/d", REGULAR_FILE);
b0.add(aSlashCSlashD);
DirCacheEntry aZeroB = createEntry("a0b", SYMLINK);
b0.add(aZeroB);
b0.finish();
assertEquals(4, tree0.getEntryCount());
ObjectId tree = tree0.writeTree(oi);
// Find the directories that were implicitly created above.
TreeWalk tw = new TreeWalk(or);
tw.addTree(tree);
ObjectId a = null;
ObjectId aSlashC = null;
while (tw.next()) {
if (tw.getPathString().equals("a")) {
a = tw.getObjectId(0);
tw.enterSubtree();
while (tw.next()) {
if (tw.getPathString().equals("a/c")) {
aSlashC = tw.getObjectId(0);
break;
// Find the directories that were implicitly created above.
TreeWalk tw = new TreeWalk(or);
tw.addTree(tree);
ObjectId a = null;
ObjectId aSlashC = null;
while (tw.next()) {
if (tw.getPathString().equals("a")) {
a = tw.getObjectId(0);
tw.enterSubtree();
while (tw.next()) {
if (tw.getPathString().equals("a/c")) {
aSlashC = tw.getObjectId(0);
break;
}
}
break;
}
break;
}
assertEquals(a, TreeWalk.forPath(or, "a", tree).getObjectId(0));
assertEquals(a, TreeWalk.forPath(or, "a/", tree).getObjectId(0));
assertEquals(null, TreeWalk.forPath(or, "/a", tree));
assertEquals(null, TreeWalk.forPath(or, "/a/", tree));
assertEquals(aDotB.getObjectId(),
TreeWalk.forPath(or, "a.b", tree).getObjectId(0));
assertEquals(null, TreeWalk.forPath(or, "/a.b", tree));
assertEquals(null, TreeWalk.forPath(or, "/a.b/", tree));
assertEquals(aDotB.getObjectId(),
TreeWalk.forPath(or, "a.b/", tree).getObjectId(0));
assertEquals(aZeroB.getObjectId(),
TreeWalk.forPath(or, "a0b", tree).getObjectId(0));
assertEquals(aSlashB.getObjectId(),
TreeWalk.forPath(or, "a/b", tree).getObjectId(0));
assertEquals(aSlashB.getObjectId(),
TreeWalk.forPath(or, "b", a).getObjectId(0));
assertEquals(aSlashC,
TreeWalk.forPath(or, "a/c", tree).getObjectId(0));
assertEquals(aSlashC, TreeWalk.forPath(or, "c", a).getObjectId(0));
assertEquals(aSlashCSlashD.getObjectId(),
TreeWalk.forPath(or, "a/c/d", tree).getObjectId(0));
assertEquals(aSlashCSlashD.getObjectId(),
TreeWalk.forPath(or, "c/d", a).getObjectId(0));
}
assertEquals(a, TreeWalk.forPath(or, "a", tree).getObjectId(0));
assertEquals(a, TreeWalk.forPath(or, "a/", tree).getObjectId(0));
assertEquals(null, TreeWalk.forPath(or, "/a", tree));
assertEquals(null, TreeWalk.forPath(or, "/a/", tree));
assertEquals(aDotB.getObjectId(), TreeWalk.forPath(or, "a.b", tree)
.getObjectId(0));
assertEquals(null, TreeWalk.forPath(or, "/a.b", tree));
assertEquals(null, TreeWalk.forPath(or, "/a.b/", tree));
assertEquals(aDotB.getObjectId(), TreeWalk.forPath(or, "a.b/", tree)
.getObjectId(0));
assertEquals(aZeroB.getObjectId(), TreeWalk.forPath(or, "a0b", tree)
.getObjectId(0));
assertEquals(aSlashB.getObjectId(), TreeWalk.forPath(or, "a/b", tree)
.getObjectId(0));
assertEquals(aSlashB.getObjectId(), TreeWalk.forPath(or, "b", a)
.getObjectId(0));
assertEquals(aSlashC, TreeWalk.forPath(or, "a/c", tree).getObjectId(0));
assertEquals(aSlashC, TreeWalk.forPath(or, "c", a).getObjectId(0));
assertEquals(aSlashCSlashD.getObjectId(),
TreeWalk.forPath(or, "a/c/d", tree).getObjectId(0));
assertEquals(aSlashCSlashD.getObjectId(), TreeWalk
.forPath(or, "c/d", a).getObjectId(0));
or.release();
oi.release();
}
}

View File

@ -63,52 +63,51 @@ public class TreeWalkBasicDiffTest extends RepositoryTestCase {
@Test
public void testMissingSubtree_DetectFileAdded_FileModified()
throws Exception {
final ObjectInserter inserter = db.newObjectInserter();
final ObjectId aFileId = inserter.insert(OBJ_BLOB, encode("a"));
final ObjectId bFileId = inserter.insert(OBJ_BLOB, encode("b"));
final ObjectId cFileId1 = inserter.insert(OBJ_BLOB, encode("c-1"));
final ObjectId cFileId2 = inserter.insert(OBJ_BLOB, encode("c-2"));
final ObjectId oldTree, newTree, bFileId, cFileId1, cFileId2;
try (ObjectInserter inserter = db.newObjectInserter()) {
final ObjectId aFileId = inserter.insert(OBJ_BLOB, encode("a"));
bFileId = inserter.insert(OBJ_BLOB, encode("b"));
cFileId1 = inserter.insert(OBJ_BLOB, encode("c-1"));
cFileId2 = inserter.insert(OBJ_BLOB, encode("c-2"));
// Create sub-a/empty, sub-c/empty = hello.
final ObjectId oldTree;
{
final Tree root = new Tree(db);
// Create sub-a/empty, sub-c/empty = hello.
{
final Tree subA = root.addTree("sub-a");
subA.addFile("empty").setId(aFileId);
subA.setId(inserter.insert(OBJ_TREE, subA.format()));
final Tree root = new Tree(db);
{
final Tree subA = root.addTree("sub-a");
subA.addFile("empty").setId(aFileId);
subA.setId(inserter.insert(OBJ_TREE, subA.format()));
}
{
final Tree subC = root.addTree("sub-c");
subC.addFile("empty").setId(cFileId1);
subC.setId(inserter.insert(OBJ_TREE, subC.format()));
}
oldTree = inserter.insert(OBJ_TREE, root.format());
}
{
final Tree subC = root.addTree("sub-c");
subC.addFile("empty").setId(cFileId1);
subC.setId(inserter.insert(OBJ_TREE, subC.format()));
}
oldTree = inserter.insert(OBJ_TREE, root.format());
}
// Create sub-a/empty, sub-b/empty, sub-c/empty.
final ObjectId newTree;
{
final Tree root = new Tree(db);
// Create sub-a/empty, sub-b/empty, sub-c/empty.
{
final Tree subA = root.addTree("sub-a");
subA.addFile("empty").setId(aFileId);
subA.setId(inserter.insert(OBJ_TREE, subA.format()));
final Tree root = new Tree(db);
{
final Tree subA = root.addTree("sub-a");
subA.addFile("empty").setId(aFileId);
subA.setId(inserter.insert(OBJ_TREE, subA.format()));
}
{
final Tree subB = root.addTree("sub-b");
subB.addFile("empty").setId(bFileId);
subB.setId(inserter.insert(OBJ_TREE, subB.format()));
}
{
final Tree subC = root.addTree("sub-c");
subC.addFile("empty").setId(cFileId2);
subC.setId(inserter.insert(OBJ_TREE, subC.format()));
}
newTree = inserter.insert(OBJ_TREE, root.format());
}
{
final Tree subB = root.addTree("sub-b");
subB.addFile("empty").setId(bFileId);
subB.setId(inserter.insert(OBJ_TREE, subB.format()));
}
{
final Tree subC = root.addTree("sub-c");
subC.addFile("empty").setId(cFileId2);
subC.setId(inserter.insert(OBJ_TREE, subC.format()));
}
newTree = inserter.insert(OBJ_TREE, root.format());
inserter.flush();
}
inserter.flush();
inserter.release();
final TreeWalk tw = new TreeWalk(db);
tw.reset(oldTree, newTree);

View File

@ -27,6 +27,7 @@ badEntryName=Bad entry name: {0}
badEscape=Bad escape: {0}
badGroupHeader=Bad group header
badObjectType=Bad object type: {0}
badRef=Bad ref: {0}: {1}
badSectionEntry=Bad section entry: {0}
bareRepositoryNoWorkdirAndIndex=Bare Repository has neither a working tree, nor an index
base64InputNotProperlyPadded=Base64 input not properly padded.
@ -58,16 +59,23 @@ cannotCreateIndexfile=Cannot create an index file with name {0}
cannotCreateTempDir=Cannot create a temp dir
cannotDeleteCheckedOutBranch=Branch {0} is checked out and can not be deleted
cannotDeleteFile=Cannot delete file: {0}
cannotDeleteObjectsPath="Can't delete {0}/{1}: {2}
cannotDeleteStaleTrackingRef=Cannot delete stale tracking ref {0}
cannotDeleteStaleTrackingRef2=Cannot delete stale tracking ref {0}: {1}
cannotDetermineProxyFor=Cannot determine proxy for {0}
cannotDownload=Cannot download {0}
cannotEnterObjectsPath=Can't enter {0}/objects: {1}
cannotEnterPathFromParent=Can't enter {0} from {1}: {2}
cannotExecute=cannot execute: {0}
cannotGet=Cannot get {0}
cannotGetObjectsPath=Can't get {0}/{1}: {2}
cannotListObjectsPath=Can't ls {0}/{1}: {2}
cannotListPackPath=Can't ls {0}/pack: {1}
cannotListRefs=cannot list refs
cannotLock=Cannot lock {0}
cannotLockPackIn=Cannot lock pack in {0}
cannotMatchOnEmptyString=Cannot match on empty string.
cannotMkdirObjectPath=Can't mkdir {0}/{1}: {2}
cannotMoveIndexTo=Cannot move index to {0}
cannotMovePackTo=Cannot move pack to {0}
cannotOpenService=cannot open {0}
@ -80,13 +88,16 @@ cannotReadCommit=Cannot read commit {0}
cannotReadFile=Cannot read file {0}
cannotReadHEAD=cannot read HEAD: {0} {1}
cannotReadObject=Cannot read object
cannotReadObjectsPath=Cannot read {0}/{1}: {2}
cannotReadTree=Cannot read tree {0}
cannotRebaseWithoutCurrentHead=Can not rebase without a current HEAD
cannotResolveLocalTrackingRefForUpdating=Cannot resolve local tracking ref {0} for updating.
cannotSquashFixupWithoutPreviousCommit=Cannot {0} without previous commit.
cannotStoreObjects=cannot store objects
cannotResolveUniquelyAbbrevObjectId=Could not resolve uniquely the abbreviated object ID
cannotUnloadAModifiedTree=Cannot unload a modified tree.
cannotWorkWithOtherStagesThanZeroRightNow=Cannot work with other stages than zero right now. Won't write corrupt index.
cannotWriteObjectsPath="Can't write {0}/{1}: {2}
canOnlyCherryPickCommitsWithOneParent=Cannot cherry-pick commit ''{0}'' because it has {1} parents, only commits with exactly one parent are supported.
canOnlyRevertCommitsWithOneParent=Cannot revert commit ''{0}'' because it has {1} parents, only commits with exactly one parent are supported
commitDoesNotHaveGivenParent=The commit ''{0}'' does not have a parent number {1}.
@ -113,26 +124,60 @@ contextMustBeNonNegative=context must be >= 0
corruptionDetectedReReadingAt=Corruption detected re-reading at {0}
corruptObjectBadStream=bad stream
corruptObjectBadStreamCorruptHeader=bad stream, corrupt header
corruptObjectDuplicateEntryNames=duplicate entry names
corruptObjectGarbageAfterSize=garbage after size
corruptObjectIncorrectLength=incorrect length
corruptObjectIncorrectSorting=incorrectly sorted
corruptObjectInvalidAuthor=invalid author
corruptObjectInvalidCommitter=invalid committer
corruptObjectInvalidEntryMode=invalid entry mode
corruptObjectInvalidMode=invalid mode
corruptObjectInvalidMode2=invalid mode {0}
corruptObjectInvalidModeChar=invalid mode character
corruptObjectInvalidModeStartsZero=mode starts with '0'
corruptObjectInvalidMode2=invalid mode {0,number,#}
corruptObjectInvalidMode3=invalid mode {0} for {1} ''{2}'' in {3}.
corruptObjectInvalidName=invalid name '%s'
corruptObjectInvalidNameAux=invalid name 'AUX'
corruptObjectInvalidNameCon=invalid name 'CON'
corruptObjectInvalidNameCom=invalid name 'COM%c'
corruptObjectInvalidNameEnd=invalid name ends with '%c'
corruptObjectInvalidNameIgnorableUnicode=invalid name '%s' contains ignorable Unicode characters
corruptObjectInvalidNameInvalidUtf8=invalid name contains byte sequence ''{0}'' which is not a valid UTF-8 character
corruptObjectInvalidNameLpt=invalid name 'LPT%c'
corruptObjectInvalidNameNul=invalid name 'NUL'
corruptObjectInvalidNamePrn=invalid name 'PRN'
corruptObjectInvalidObject=invalid object
corruptObjectInvalidParent=invalid parent
corruptObjectInvalidTagger=invalid tagger
corruptObjectInvalidTree=invalid tree
corruptObjectInvalidType=invalid type
corruptObjectInvalidType2=invalid type {0}
corruptObjectMalformedHeader=malformed header: {0}
corruptObjectNameContainsByte=name contains byte 0x%x
corruptObjectNameContainsChar=name contains '%c'
corruptObjectNameContainsNullByte=name contains byte 0x00
corruptObjectNameContainsSlash=name contains '/'
corruptObjectNameDot=invalid name '.'
corruptObjectNameDotDot=invalid name '..'
corruptObjectNameZeroLength=zero length name
corruptObjectNegativeSize=negative size
corruptObjectNoAuthor=no author
corruptObjectNoCommitter=no committer
corruptObjectNoHeader=no header
corruptObjectNoObject=no object
corruptObjectNoObjectHeader=no object header
corruptObjectNoTaggerBadHeader=no tagger/bad header
corruptObjectNoTaggerHeader=no tagger header
corruptObjectNoTagHeader=no tag header
corruptObjectNoTagName=no tag name
corruptObjectNotree=no tree
corruptObjectNotreeHeader=no tree header
corruptObjectNoType=no type
corruptObjectNoTypeHeader=no type header
corruptObjectPackfileChecksumIncorrect=Packfile checksum incorrect.
corruptObjectTruncatedInMode=truncated in mode
corruptObjectTruncatedInName=truncated in name
corruptObjectTruncatedInObjectId=truncated in object id
couldNotCheckOutBecauseOfConflicts=Could not check out because of conflicts
couldNotDeleteLockFileShouldNotHappen=Could not delete lock file. Should not happen
couldNotDeleteTemporaryIndexFileShouldNotHappen=Could not delete temporary index file. Should not happen
@ -144,6 +189,7 @@ couldNotReadObjectWhileParsingCommit=Could not read an object while parsing comm
couldNotRenameDeleteOldIndex=Could not rename delete old index
couldNotRenameTemporaryFile=Could not rename temporary file {0} to new location {1}
couldNotRenameTemporaryIndexFileToIndex=Could not rename temporary index file to index
couldNotRewindToUpstreamCommit=Could not rewind to upstream commit
couldNotURLEncodeToUTF8=Could not URL encode to UTF-8
couldNotWriteFile=Could not write file {0}
countingObjects=Counting objects
@ -180,6 +226,7 @@ duplicateStagesNotAllowed=Duplicate stages not allowed
eitherGitDirOrWorkTreeRequired=One of setGitDir or setWorkTree must be called.
emptyCommit=No changes
emptyPathNotPermitted=Empty path not permitted.
emptyRef=Empty ref: {0}
encryptionError=Encryption error: {0}
endOfFileInEscape=End of file in escape
entryNotFoundByPath=Entry not found by path: {0}
@ -240,6 +287,7 @@ funnyRefname=funny refname
gcFailed=Garbage collection failed.
gitmodulesNotFound=.gitmodules not found in tree.
headRequiredToStash=HEAD required to stash local changes
hiddenFilesStartWithDot=Hiding only allowed for names that start with a period
hoursAgo={0} hours ago
hugeIndexesAreNotSupportedByJgitYet=Huge indexes are not supported by jgit, yet
hunkBelongsToAnotherFile=Hunk belongs to another file
@ -276,8 +324,9 @@ invalidCommitParentNumber=Invalid commit parent number
invalidEncryption=Invalid encryption
invalidGitdirRef = Invalid .git reference in file ''{0}''
invalidGitType=invalid git type: {0}
invalidId=Invalid id {0}
invalidId=Invalid id: {0}
invalidIdLength=Invalid id length {0}; should be {1}
invalidIgnoreParamSubmodule=Found invalid ignore param for submodule {0}.
invalidIntegerValue=Invalid integer value: {0}.{1}={2}
invalidKey=Invalid key: {0}
invalidLineInConfigFile=Invalid line in config file
@ -310,8 +359,10 @@ largeObjectException={0} exceeds size limit
largeObjectOutOfMemory=Out of memory loading {0}
lengthExceedsMaximumArraySize=Length exceeds maximum array size
listingAlternates=Listing alternates
listingPacks=Listing packs
localObjectsIncomplete=Local objects incomplete.
localRefIsMissingObjects=Local ref {0} is missing object(s).
localRepository=local repository
lockCountMustBeGreaterOrEqual1=lockCount must be >= 1
lockError=lock error: {0}
lockOnNotClosed=Lock on {0} not closed.
@ -410,6 +461,8 @@ pathIsNotInWorkingDir=Path is not in working dir
pathNotConfigured=Submodule path is not configured
peeledLineBeforeRef=Peeled line before ref.
peerDidNotSupplyACompleteObjectGraph=peer did not supply a complete object graph
personIdentEmailNonNull=E-mail address of PersonIdent must not be null.
personIdentNameNonNull=Name of PersonIdent must not be null.
prefixRemote=remote:
problemWithResolvingPushRefSpecsLocally=Problem with resolving push ref specs locally: {0}
progressMonUploading=Uploading {0}
@ -453,6 +506,7 @@ repositoryConfigFileInvalid=Repository config file {0} invalid {1}
repositoryIsRequired=Repository is required.
repositoryNotFound=repository not found: {0}
repositoryState_applyMailbox=Apply mailbox
repositoryState_bare=Bare
repositoryState_bisecting=Bisecting
repositoryState_conflicts=Conflicts
repositoryState_merged=Merged
@ -466,6 +520,9 @@ resettingHead=Resetting head to {0}
resolvingDeltas=Resolving deltas
resultLengthIncorrect=result length incorrect
rewinding=Rewinding to commit {0}
s3ActionDeletion=Deletion
s3ActionReading=Reading
s3ActionWriting=Writing
searchForReuse=Finding sources
searchForSizes=Getting sizes
secondsAgo={0} seconds ago
@ -547,6 +604,7 @@ unableToWrite=Unable to write {0}
unencodeableFile=Unencodable file: {0}
unexpectedCompareResult=Unexpected metadata comparison result: {0}
unexpectedEndOfConfigFile=Unexpected end of config file
unexpectedEndOfInput=Unexpected end of input
unexpectedHunkTrailer=Unexpected hunk trailer
unexpectedOddResult=odd: {0} + {1} - {2}
unexpectedRefReport={0}: unexpected ref report: {1}
@ -558,6 +616,7 @@ unknownHost=unknown host
unknownIndexVersionOrCorruptIndex=Unknown index version (or corrupt index): {0}
unknownObject=unknown object
unknownObjectType=Unknown object type {0}.
unknownObjectType2=unknown
unknownRepositoryFormat=Unknown repository format
unknownRepositoryFormat2=Unknown repository format "{0}"; expected "0".
unknownZlibError=Unknown zlib error.
@ -566,16 +625,21 @@ unmergedPaths=Repository contains unmerged paths
unpackException=Exception while parsing pack stream
unreadablePackIndex=Unreadable pack index: {0}
unrecognizedRef=Unrecognized ref: {0}
unsetMark=Mark not set
unsupportedAlternates=Alternates not supported
unsupportedArchiveFormat=Unknown archive format ''{0}''
unsupportedCommand0=unsupported command 0
unsupportedEncryptionAlgorithm=Unsupported encryption algorithm: {0}
unsupportedEncryptionVersion=Unsupported encryption version: {0}
unsupportedGC=Unsupported garbage collector for repository type: {0}
unsupportedMark=Mark not supported
unsupportedOperationNotAddAtEnd=Not add-at-end: {0}
unsupportedPackIndexVersion=Unsupported pack index version {0}
unsupportedPackVersion=Unsupported pack version {0}.
updatingHeadFailed=Updating HEAD failed
updatingReferences=Updating references
updatingRefFailed=Updating the ref {0} to {1} failed. ReturnCode from RefUpdate.update() was {2}
upstreamBranchName=branch ''{0}'' of {1}
uriNotConfigured=Submodule URI not configured
uriNotFound={0} not found
URINotSupported=URI not supported: {0}

View File

@ -124,8 +124,7 @@ public Ref call() throws GitAPIException, RefAlreadyExistsException,
RefNotFoundException, InvalidRefNameException {
checkCallable();
processOptions();
RevWalk revWalk = new RevWalk(repo);
try {
try (RevWalk revWalk = new RevWalk(repo)) {
Ref refToCheck = repo.getRef(name);
boolean exists = refToCheck != null
&& refToCheck.getName().startsWith(Constants.R_HEADS);
@ -270,8 +269,6 @@ else if (upstreamMode == SetupUpstreamMode.NOTRACK)
return result;
} catch (IOException ioe) {
throw new JGitInternalException(ioe.getMessage(), ioe);
} finally {
revWalk.release();
}
}

View File

@ -108,18 +108,21 @@ public List<String> call() throws GitAPIException,
if (!force) {
// check if the branches to be deleted
// are all merged into the current branch
RevWalk walk = new RevWalk(repo);
RevCommit tip = walk.parseCommit(repo.resolve(Constants.HEAD));
for (String branchName : branchNames) {
if (branchName == null)
continue;
Ref currentRef = repo.getRef(branchName);
if (currentRef == null)
continue;
try (RevWalk walk = new RevWalk(repo)) {
RevCommit tip = walk
.parseCommit(repo.resolve(Constants.HEAD));
for (String branchName : branchNames) {
if (branchName == null)
continue;
Ref currentRef = repo.getRef(branchName);
if (currentRef == null)
continue;
RevCommit base = walk.parseCommit(repo.resolve(branchName));
if (!walk.isMergedInto(base, tip)) {
throw new NotMergedException();
RevCommit base = walk
.parseCommit(repo.resolve(branchName));
if (!walk.isMergedInto(base, tip)) {
throw new NotMergedException();
}
}
}
}

View File

@ -139,8 +139,7 @@ private Collection<Ref> filterRefs(Collection<Ref> refs)
if (containsCommitish == null)
return refs;
RevWalk walk = new RevWalk(repo);
try {
try (RevWalk walk = new RevWalk(repo)) {
ObjectId resolved = repo.resolve(containsCommitish);
if (resolved == null)
throw new RefNotFoundException(MessageFormat.format(
@ -149,8 +148,6 @@ private Collection<Ref> filterRefs(Collection<Ref> refs)
RevCommit containsCommit = walk.parseCommit(resolved);
return RevWalkUtils.findBranchesReachableFrom(containsCommit, walk,
refs);
} finally {
walk.release();
}
}

View File

@ -80,9 +80,8 @@ protected ListNotesCommand(Repository repo) {
public List<Note> call() throws GitAPIException {
checkCallable();
List<Note> notes = new ArrayList<Note>();
RevWalk walk = new RevWalk(repo);
NoteMap map = NoteMap.newEmptyMap();
try {
try (RevWalk walk = new RevWalk(repo)) {
Ref ref = repo.getRef(notesRef);
// if we have a notes ref, use it
if (ref != null) {
@ -95,8 +94,6 @@ public List<Note> call() throws GitAPIException {
notes.add(i.next());
} catch (IOException e) {
throw new JGitInternalException(e.getMessage(), e);
} finally {
walk.release();
}
return notes;

View File

@ -78,16 +78,13 @@ public List<Ref> call() throws GitAPIException {
checkCallable();
Map<String, Ref> refList;
List<Ref> tags = new ArrayList<Ref>();
RevWalk revWalk = new RevWalk(repo);
try {
try (RevWalk revWalk = new RevWalk(repo)) {
refList = repo.getRefDatabase().getRefs(Constants.R_TAGS);
for (Ref ref : refList.values()) {
tags.add(ref);
}
} catch (IOException e) {
throw new JGitInternalException(e.getMessage(), e);
} finally {
revWalk.release();
}
Collections.sort(tags, new Comparator<Ref>() {
public int compare(Ref o1, Ref o2) {

View File

@ -369,9 +369,11 @@ public MergeResult call() throws GitAPIException, NoHeadException,
mergeStatus = MergeStatus.MERGED_NOT_COMMITTED;
}
if (commit && !squash) {
newHeadId = new Git(getRepository()).commit()
.setReflogComment(refLogMessage.toString())
.call().getId();
try (Git git = new Git(getRepository())) {
newHeadId = git.commit()
.setReflogComment(refLogMessage.toString())
.call().getId();
}
mergeStatus = MergeStatus.MERGED;
}
if (commit && squash) {
@ -416,7 +418,7 @@ public MergeResult call() throws GitAPIException, NoHeadException,
e), e);
} finally {
if (revWalk != null)
revWalk.release();
revWalk.close();
}
}

View File

@ -69,7 +69,7 @@ public enum MergeStatus {
FAST_FORWARD {
@Override
public String toString() {
return "Fast-forward";
return "Fast-forward"; //$NON-NLS-1$
}
@Override
@ -83,7 +83,7 @@ public boolean isSuccessful() {
FAST_FORWARD_SQUASHED {
@Override
public String toString() {
return "Fast-forward-squashed";
return "Fast-forward-squashed"; //$NON-NLS-1$
}
@Override
@ -95,7 +95,7 @@ public boolean isSuccessful() {
ALREADY_UP_TO_DATE {
@Override
public String toString() {
return "Already-up-to-date";
return "Already-up-to-date"; //$NON-NLS-1$
}
@Override
@ -107,7 +107,7 @@ public boolean isSuccessful() {
FAILED {
@Override
public String toString() {
return "Failed";
return "Failed"; //$NON-NLS-1$
}
@Override
@ -119,7 +119,7 @@ public boolean isSuccessful() {
MERGED {
@Override
public String toString() {
return "Merged";
return "Merged"; //$NON-NLS-1$
}
@Override
@ -133,7 +133,7 @@ public boolean isSuccessful() {
MERGED_SQUASHED {
@Override
public String toString() {
return "Merged-squashed";
return "Merged-squashed"; //$NON-NLS-1$
}
@Override
@ -147,7 +147,7 @@ public boolean isSuccessful() {
MERGED_SQUASHED_NOT_COMMITTED {
@Override
public String toString() {
return "Merged-squashed-not-committed";
return "Merged-squashed-not-committed"; //$NON-NLS-1$
}
@Override
@ -159,7 +159,7 @@ public boolean isSuccessful() {
CONFLICTING {
@Override
public String toString() {
return "Conflicting";
return "Conflicting"; //$NON-NLS-1$
}
@Override
@ -173,7 +173,7 @@ public boolean isSuccessful() {
ABORTED {
@Override
public String toString() {
return "Aborted";
return "Aborted"; //$NON-NLS-1$
}
@Override
@ -186,7 +186,7 @@ public boolean isSuccessful() {
**/
MERGED_NOT_COMMITTED {
public String toString() {
return "Merged-not-committed";
return "Merged-not-committed"; //$NON-NLS-1$
}
@Override
@ -198,7 +198,7 @@ public boolean isSuccessful() {
NOT_SUPPORTED {
@Override
public String toString() {
return "Not-yet-supported";
return "Not-yet-supported"; //$NON-NLS-1$
}
@Override
@ -213,7 +213,7 @@ public boolean isSuccessful() {
*/
CHECKOUT_CONFLICT {
public String toString() {
return "Checkout Conflict";
return "Checkout Conflict"; //$NON-NLS-1$
}
@Override

View File

@ -261,7 +261,7 @@ public PullResult call() throws GitAPIException,
fetchRes = fetch.call();
} else {
// we can skip the fetch altogether
remoteUri = "local repository";
remoteUri = JGitText.get().localRepository;
fetchRes = null;
}
@ -302,9 +302,9 @@ public PullResult call() throws GitAPIException,
}
}
String upstreamName = "branch \'"
+ Repository.shortenRefName(remoteBranchName) + "\' of "
+ remoteUri;
String upstreamName = MessageFormat.format(
JGitText.get().upstreamBranchName,
Repository.shortenRefName(remoteBranchName), remoteUri);
PullResult result;
if (pullRebaseMode.rebase) {

View File

@ -405,11 +405,12 @@ private boolean autoStashApply() throws IOException, GitAPIException {
.call();
} catch (StashApplyFailureException e) {
conflicts = true;
RevWalk rw = new RevWalk(repo);
ObjectId stashId = repo.resolve(stash);
RevCommit commit = rw.parseCommit(stashId);
updateStashRef(commit, commit.getAuthorIdent(),
commit.getShortMessage());
try (RevWalk rw = new RevWalk(repo)) {
ObjectId stashId = repo.resolve(stash);
RevCommit commit = rw.parseCommit(stashId);
updateStashRef(commit, commit.getAuthorIdent(),
commit.getShortMessage());
}
}
}
return conflicts;
@ -444,7 +445,7 @@ private RebaseResult processStep(RebaseTodoLine step, boolean shouldPick)
Collection<ObjectId> ids = or.resolve(step.getCommit());
if (ids.size() != 1)
throw new JGitInternalException(
"Could not resolve uniquely the abbreviated object ID");
JGitText.get().cannotResolveUniquelyAbbrevObjectId);
RevCommit commitToPick = walk.parseCommit(ids.iterator().next());
if (shouldPick) {
if (monitor.isCancelled())
@ -518,21 +519,23 @@ private RebaseResult cherryPickCommitFlattening(RevCommit commitToPick)
// here we should skip this step in order to avoid
// confusing pseudo-changed
String ourCommitName = getOurCommitName();
CherryPickResult cherryPickResult = new Git(repo).cherryPick()
try (Git git = new Git(repo)) {
CherryPickResult cherryPickResult = git.cherryPick()
.include(commitToPick).setOurCommitName(ourCommitName)
.setReflogPrefix(REFLOG_PREFIX).setStrategy(strategy)
.call();
switch (cherryPickResult.getStatus()) {
case FAILED:
if (operation == Operation.BEGIN)
return abort(RebaseResult.failed(cherryPickResult
.getFailingPaths()));
else
switch (cherryPickResult.getStatus()) {
case FAILED:
if (operation == Operation.BEGIN)
return abort(RebaseResult
.failed(cherryPickResult.getFailingPaths()));
else
return stop(commitToPick, Status.STOPPED);
case CONFLICTING:
return stop(commitToPick, Status.STOPPED);
case CONFLICTING:
return stop(commitToPick, Status.STOPPED);
case OK:
newHead = cherryPickResult.getNewHead();
case OK:
newHead = cherryPickResult.getNewHead();
}
}
}
return null;
@ -563,62 +566,67 @@ private RebaseResult cherryPickCommitPreservingMerges(RevCommit commitToPick)
// Use the cherry-pick strategy if all non-first parents did not
// change. This is different from C Git, which always uses the merge
// strategy (see below).
if (otherParentsUnchanged) {
boolean isMerge = commitToPick.getParentCount() > 1;
String ourCommitName = getOurCommitName();
CherryPickCommand pickCommand = new Git(repo).cherryPick()
.include(commitToPick).setOurCommitName(ourCommitName)
.setReflogPrefix(REFLOG_PREFIX).setStrategy(strategy);
if (isMerge) {
pickCommand.setMainlineParentNumber(1);
// We write a MERGE_HEAD and later commit explicitly
pickCommand.setNoCommit(true);
writeMergeInfo(commitToPick, newParents);
}
CherryPickResult cherryPickResult = pickCommand.call();
switch (cherryPickResult.getStatus()) {
case FAILED:
if (operation == Operation.BEGIN)
return abort(RebaseResult.failed(cherryPickResult
.getFailingPaths()));
else
return stop(commitToPick, Status.STOPPED);
case CONFLICTING:
return stop(commitToPick, Status.STOPPED);
case OK:
try (Git git = new Git(repo)) {
if (otherParentsUnchanged) {
boolean isMerge = commitToPick.getParentCount() > 1;
String ourCommitName = getOurCommitName();
CherryPickCommand pickCommand = git.cherryPick()
.include(commitToPick)
.setOurCommitName(ourCommitName)
.setReflogPrefix(REFLOG_PREFIX)
.setStrategy(strategy);
if (isMerge) {
// Commit the merge (setup above using writeMergeInfo())
CommitCommand commit = new Git(repo).commit();
pickCommand.setMainlineParentNumber(1);
// We write a MERGE_HEAD and later commit explicitly
pickCommand.setNoCommit(true);
writeMergeInfo(commitToPick, newParents);
}
CherryPickResult cherryPickResult = pickCommand.call();
switch (cherryPickResult.getStatus()) {
case FAILED:
if (operation == Operation.BEGIN)
return abort(RebaseResult.failed(
cherryPickResult.getFailingPaths()));
else
return stop(commitToPick, Status.STOPPED);
case CONFLICTING:
return stop(commitToPick, Status.STOPPED);
case OK:
if (isMerge) {
// Commit the merge (setup above using
// writeMergeInfo())
CommitCommand commit = git.commit();
commit.setAuthor(commitToPick.getAuthorIdent());
commit.setReflogComment(REFLOG_PREFIX + " " //$NON-NLS-1$
+ commitToPick.getShortMessage());
newHead = commit.call();
} else
newHead = cherryPickResult.getNewHead();
break;
}
} else {
// Use the merge strategy to redo merges, which had some of
// their non-first parents rewritten
MergeCommand merge = git.merge()
.setFastForward(MergeCommand.FastForwardMode.NO_FF)
.setCommit(false);
for (int i = 1; i < commitToPick.getParentCount(); i++)
merge.include(newParents.get(i));
MergeResult mergeResult = merge.call();
if (mergeResult.getMergeStatus().isSuccessful()) {
CommitCommand commit = git.commit();
commit.setAuthor(commitToPick.getAuthorIdent());
commit.setMessage(commitToPick.getFullMessage());
commit.setReflogComment(REFLOG_PREFIX + " " //$NON-NLS-1$
+ commitToPick.getShortMessage());
newHead = commit.call();
} else
newHead = cherryPickResult.getNewHead();
break;
}
} else {
// Use the merge strategy to redo merges, which had some of
// their non-first parents rewritten
MergeCommand merge = new Git(repo).merge()
.setFastForward(MergeCommand.FastForwardMode.NO_FF)
.setCommit(false);
for (int i = 1; i < commitToPick.getParentCount(); i++)
merge.include(newParents.get(i));
MergeResult mergeResult = merge.call();
if (mergeResult.getMergeStatus().isSuccessful()) {
CommitCommand commit = new Git(repo).commit();
commit.setAuthor(commitToPick.getAuthorIdent());
commit.setMessage(commitToPick.getFullMessage());
commit.setReflogComment(REFLOG_PREFIX + " " //$NON-NLS-1$
+ commitToPick.getShortMessage());
newHead = commit.call();
} else {
if (operation == Operation.BEGIN
&& mergeResult.getMergeStatus() == MergeResult.MergeStatus.FAILED)
return abort(RebaseResult.failed(mergeResult
.getFailingPaths()));
return stop(commitToPick, Status.STOPPED);
} else {
if (operation == Operation.BEGIN && mergeResult
.getMergeStatus() == MergeResult.MergeStatus.FAILED)
return abort(RebaseResult
.failed(mergeResult.getFailingPaths()));
return stop(commitToPick, Status.STOPPED);
}
}
}
}
@ -758,24 +766,25 @@ private RevCommit squashIntoPrevious(boolean sequenceContainsSquash,
String commitMessage = rebaseState
.readFile(MESSAGE_SQUASH);
if (nextStep == null
|| ((nextStep.getAction() != Action.FIXUP) && (nextStep
.getAction() != Action.SQUASH))) {
// this is the last step in this sequence
if (sequenceContainsSquash) {
commitMessage = interactiveHandler
.modifyCommitMessage(commitMessage);
}
retNewHead = new Git(repo).commit()
.setMessage(stripCommentLines(commitMessage))
.setAmend(true).setNoVerify(true).call();
rebaseState.getFile(MESSAGE_SQUASH).delete();
rebaseState.getFile(MESSAGE_FIXUP).delete();
try (Git git = new Git(repo)) {
if (nextStep == null || ((nextStep.getAction() != Action.FIXUP)
&& (nextStep.getAction() != Action.SQUASH))) {
// this is the last step in this sequence
if (sequenceContainsSquash) {
commitMessage = interactiveHandler
.modifyCommitMessage(commitMessage);
}
retNewHead = git.commit()
.setMessage(stripCommentLines(commitMessage))
.setAmend(true).setNoVerify(true).call();
rebaseState.getFile(MESSAGE_SQUASH).delete();
rebaseState.getFile(MESSAGE_FIXUP).delete();
} else {
// Next step is either Squash or Fixup
retNewHead = new Git(repo).commit().setMessage(commitMessage)
.setAmend(true).setNoVerify(true).call();
} else {
// Next step is either Squash or Fixup
retNewHead = git.commit().setMessage(commitMessage)
.setAmend(true).setNoVerify(true).call();
}
}
return retNewHead;
}
@ -878,7 +887,8 @@ private void updateHead(String headName, RevCommit aNewHead, RevCommit onto)
case NO_CHANGE:
break;
default:
throw new JGitInternalException("Updating HEAD failed");
throw new JGitInternalException(
JGitText.get().updatingHeadFailed);
}
rup = repo.updateRef(Constants.HEAD);
rup.setRefLogMessage("rebase finished: returning to " + headName, //$NON-NLS-1$
@ -890,7 +900,8 @@ private void updateHead(String headName, RevCommit aNewHead, RevCommit onto)
case NO_CHANGE:
break;
default:
throw new JGitInternalException("Updating HEAD failed");
throw new JGitInternalException(
JGitText.get().updatingHeadFailed);
}
}
}
@ -917,10 +928,10 @@ private RevCommit checkoutCurrentHead() throws IOException, NoHeadException {
} finally {
dc.unlock();
}
RevWalk rw = new RevWalk(repo);
RevCommit commit = rw.parseCommit(repo.resolve(Constants.HEAD));
rw.release();
return commit;
try (RevWalk rw = new RevWalk(repo)) {
RevCommit commit = rw.parseCommit(repo.resolve(Constants.HEAD));
return commit;
}
}
/**
@ -936,27 +947,29 @@ private RevCommit continueRebase() throws GitAPIException, IOException {
throw new UnmergedPathsException();
// determine whether we need to commit
TreeWalk treeWalk = new TreeWalk(repo);
treeWalk.reset();
treeWalk.setRecursive(true);
treeWalk.addTree(new DirCacheIterator(dc));
ObjectId id = repo.resolve(Constants.HEAD + "^{tree}"); //$NON-NLS-1$
if (id == null)
throw new NoHeadException(
JGitText.get().cannotRebaseWithoutCurrentHead);
boolean needsCommit;
try (TreeWalk treeWalk = new TreeWalk(repo)) {
treeWalk.reset();
treeWalk.setRecursive(true);
treeWalk.addTree(new DirCacheIterator(dc));
ObjectId id = repo.resolve(Constants.HEAD + "^{tree}"); //$NON-NLS-1$
if (id == null)
throw new NoHeadException(
JGitText.get().cannotRebaseWithoutCurrentHead);
treeWalk.addTree(id);
treeWalk.addTree(id);
treeWalk.setFilter(TreeFilter.ANY_DIFF);
boolean needsCommit = treeWalk.next();
treeWalk.release();
treeWalk.setFilter(TreeFilter.ANY_DIFF);
needsCommit = treeWalk.next();
}
if (needsCommit) {
CommitCommand commit = new Git(repo).commit();
commit.setMessage(rebaseState.readFile(MESSAGE));
commit.setAuthor(parseAuthor());
return commit.call();
try (Git git = new Git(repo)) {
CommitCommand commit = git.commit();
commit.setMessage(rebaseState.readFile(MESSAGE));
commit.setAuthor(parseAuthor());
return commit.call();
}
}
return null;
}
@ -979,9 +992,10 @@ private RebaseResult stop(RevCommit commitToPick, RebaseResult.Status status)
rebaseState.createFile(AUTHOR_SCRIPT, authorScript);
rebaseState.createFile(MESSAGE, commitToPick.getFullMessage());
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DiffFormatter df = new DiffFormatter(bos);
df.setRepository(repo);
df.format(commitToPick.getParent(0), commitToPick);
try (DiffFormatter df = new DiffFormatter(bos)) {
df.setRepository(repo);
df.format(commitToPick.getParent(0), commitToPick);
}
rebaseState.createFile(PATCH, new String(bos.toByteArray(),
Constants.CHARACTER_ENCODING));
rebaseState.createFile(STOPPED_SHA,
@ -1124,9 +1138,11 @@ else if (!isInteractive() && walk.isMergedInto(headCommit, upstream)) {
private List<RevCommit> calculatePickList(RevCommit headCommit)
throws GitAPIException, NoHeadException, IOException {
LogCommand cmd = new Git(repo).log().addRange(upstreamCommit,
headCommit);
Iterable<RevCommit> commitsToUse = cmd.call();
Iterable<RevCommit> commitsToUse;
try (Git git = new Git(repo)) {
LogCommand cmd = git.log().addRange(upstreamCommit, headCommit);
commitsToUse = cmd.call();
}
List<RevCommit> cherryPickList = new ArrayList<RevCommit>();
for (RevCommit commit : commitsToUse) {
if (preserveMerges || commit.getParentCount() == 1)
@ -1277,7 +1293,7 @@ private void checkParameters() throws WrongRepositoryStateException {
if (this.upstreamCommit == null)
throw new JGitInternalException(MessageFormat
.format(JGitText.get().missingRequiredParameter,
"upstream"));
"upstream")); //$NON-NLS-1$
return;
default:
throw new WrongRepositoryStateException(MessageFormat.format(
@ -1312,7 +1328,7 @@ private RebaseResult abort(RebaseResult result) throws IOException,
}
dco.setFailOnConflict(false);
dco.checkout();
walk.release();
walk.close();
} finally {
monitor.endTask();
}
@ -1384,10 +1400,11 @@ private boolean checkoutCommit(String headName, RevCommit commit)
case FORCED:
break;
default:
throw new IOException("Could not rewind to upstream commit");
throw new IOException(
JGitText.get().couldNotRewindToUpstreamCommit);
}
} finally {
walk.release();
walk.close();
monitor.endTask();
}
return true;
@ -1454,7 +1471,7 @@ public RebaseCommand setUpstream(String upstream)
public RebaseCommand setUpstreamName(String upstreamName) {
if (upstreamCommit == null) {
throw new IllegalStateException(
"setUpstreamName must be called after setUpstream.");
"setUpstreamName must be called after setUpstream."); //$NON-NLS-1$
}
this.upstreamCommitName = upstreamName;
return this;

View File

@ -81,11 +81,10 @@ protected RemoveNoteCommand(Repository repo) {
public Note call() throws GitAPIException {
checkCallable();
RevWalk walk = new RevWalk(repo);
ObjectInserter inserter = repo.newObjectInserter();
NoteMap map = NoteMap.newEmptyMap();
RevCommit notesCommit = null;
try {
try (RevWalk walk = new RevWalk(repo);
ObjectInserter inserter = repo.newObjectInserter()) {
NoteMap map = NoteMap.newEmptyMap();
RevCommit notesCommit = null;
Ref ref = repo.getRef(notesRef);
// if we have a notes ref, use it
if (ref != null) {
@ -94,13 +93,10 @@ public Note call() throws GitAPIException {
}
map.set(id, null, inserter);
commitNoteMap(walk, map, notesCommit, inserter,
"Notes removed by 'git notes remove'");
"Notes removed by 'git notes remove'"); //$NON-NLS-1$
return map.getNote(id);
} catch (IOException e) {
throw new JGitInternalException(e.getMessage(), e);
} finally {
inserter.release();
walk.release();
}
}

View File

@ -157,8 +157,8 @@ public Ref call() throws GitAPIException, CheckoutConflictException {
if (ref != null && commitId == null) {
// @TODO throw an InvalidRefNameException. We can't do that
// now because this would break the API
throw new JGitInternalException("Invalid ref " + ref
+ " specified");
throw new JGitInternalException(MessageFormat
.format(JGitText.get().invalidRefName, ref));
}
final ObjectId commitTree;
@ -234,17 +234,12 @@ else if (repo.readSquashCommitMsg() != null)
}
private RevCommit parseCommit(final ObjectId commitId) {
RevCommit commit;
RevWalk rw = new RevWalk(repo);
try {
commit = rw.parseCommit(commitId);
try (RevWalk rw = new RevWalk(repo)) {
return rw.parseCommit(commitId);
} catch (IOException e) {
throw new JGitInternalException(MessageFormat.format(
JGitText.get().cannotReadCommit, commitId.toString()), e);
} finally {
rw.release();
}
return commit;
}
private ObjectId resolveRefToCommitId() {
@ -276,7 +271,7 @@ public ResetCommand setMode(ResetType mode) {
if (!filepaths.isEmpty())
throw new JGitInternalException(MessageFormat.format(
JGitText.get().illegalCombinationOfArguments,
"[--mixed | --soft | --hard]", "<paths>...")); //$NON-NLS-1$
"[--mixed | --soft | --hard]", "<paths>...")); //$NON-NLS-1$ //$NON-NLS-2$
this.mode = mode;
return this;
}
@ -290,7 +285,7 @@ public ResetCommand setMode(ResetType mode) {
public ResetCommand addPath(String path) {
if (mode != null)
throw new JGitInternalException(MessageFormat.format(
JGitText.get().illegalCombinationOfArguments, "<paths>...",
JGitText.get().illegalCombinationOfArguments, "<paths>...", //$NON-NLS-1$
"[--mixed | --soft | --hard]")); //$NON-NLS-1$
filepaths.add(path);
return this;
@ -305,11 +300,10 @@ private String getRefOrHEAD() {
private void resetIndexForPaths(ObjectId commitTree) {
DirCache dc = null;
try {
try (final TreeWalk tw = new TreeWalk(repo)) {
dc = repo.lockDirCache();
DirCacheBuilder builder = dc.builder();
final TreeWalk tw = new TreeWalk(repo);
tw.addTree(new DirCacheBuildIterator(builder));
if (commitTree != null)
tw.addTree(commitTree);
@ -342,11 +336,9 @@ private void resetIndexForPaths(ObjectId commitTree) {
private void resetIndex(ObjectId commitTree) throws IOException {
DirCache dc = repo.lockDirCache();
TreeWalk walk = null;
try {
try (TreeWalk walk = new TreeWalk(repo)) {
DirCacheBuilder builder = dc.builder();
walk = new TreeWalk(repo);
if (commitTree != null)
walk.addTree(commitTree);
else
@ -380,8 +372,6 @@ private void resetIndex(ObjectId commitTree) throws IOException {
builder.commit();
} finally {
dc.unlock();
if (walk != null)
walk.release();
}
}

View File

@ -126,8 +126,7 @@ public RevCommit call() throws NoMessageException, UnmergedPathsException,
RevCommit newHead = null;
checkCallable();
RevWalk revWalk = new RevWalk(repo);
try {
try (RevWalk revWalk = new RevWalk(repo)) {
// get the head commit
Ref headRef = repo.getRef(Constants.HEAD);
@ -182,9 +181,11 @@ public RevCommit call() throws NoMessageException, UnmergedPathsException,
merger.getResultTreeId());
dco.setFailOnConflict(true);
dco.checkout();
newHead = new Git(getRepository()).commit()
.setMessage(newMessage)
.setReflogComment("revert: " + shortMessage).call(); //$NON-NLS-1$
try (Git git = new Git(getRepository())) {
newHead = git.commit().setMessage(newMessage)
.setReflogComment("revert: " + shortMessage) //$NON-NLS-1$
.call();
}
revertedRefs.add(src);
headCommit = newHead;
} else {
@ -220,8 +221,6 @@ public RevCommit call() throws NoMessageException, UnmergedPathsException,
MessageFormat.format(
JGitText.get().exceptionCaughtDuringExecutionOfRevertCommand,
e), e);
} finally {
revWalk.release();
}
return newHead;
}

View File

@ -144,10 +144,9 @@ public DirCache call() throws GitAPIException,
checkCallable();
DirCache dc = null;
try {
try (final TreeWalk tw = new TreeWalk(repo)) {
dc = repo.lockDirCache();
DirCacheBuilder builder = dc.builder();
final TreeWalk tw = new TreeWalk(repo);
tw.reset(); // drop the first empty tree, which we do not need here
tw.setRecursive(true);
tw.setFilter(PathFilterGroup.createFromStrings(filepatterns));

View File

@ -76,10 +76,9 @@ protected ShowNoteCommand(Repository repo) {
public Note call() throws GitAPIException {
checkCallable();
RevWalk walk = new RevWalk(repo);
NoteMap map = NoteMap.newEmptyMap();
RevCommit notesCommit = null;
try {
try (RevWalk walk = new RevWalk(repo)) {
Ref ref = repo.getRef(notesRef);
// if we have a notes ref, use it
if (ref != null) {
@ -89,8 +88,6 @@ public Note call() throws GitAPIException {
return map.getNote(id);
} catch (IOException e) {
throw new JGitInternalException(e.getMessage(), e);
} finally {
walk.release();
}
}

View File

@ -166,9 +166,8 @@ public ObjectId call() throws GitAPIException,
JGitText.get().stashApplyOnUnsafeRepository,
repo.getRepositoryState()));
ObjectReader reader = repo.newObjectReader();
try {
RevWalk revWalk = new RevWalk(reader);
try (ObjectReader reader = repo.newObjectReader();
RevWalk revWalk = new RevWalk(reader)) {
ObjectId headCommit = repo.resolve(Constants.HEAD);
if (headCommit == null)
@ -192,8 +191,8 @@ public ObjectId call() throws GitAPIException,
untrackedCommit = revWalk.parseCommit(stashCommit.getParent(2));
ResolveMerger merger = (ResolveMerger) strategy.newMerger(repo);
merger.setCommitNames(new String[] { "stashed HEAD", "HEAD",
"stash" });
merger.setCommitNames(new String[] { "stashed HEAD", "HEAD", //$NON-NLS-1$ //$NON-NLS-2$
"stash" }); //$NON-NLS-1$
merger.setBase(stashHeadCommit);
merger.setWorkingTreeIterator(new FileTreeIterator(repo));
if (merger.merge(headCommit, stashCommit)) {
@ -205,8 +204,8 @@ public ObjectId call() throws GitAPIException,
if (applyIndex) {
ResolveMerger ixMerger = (ResolveMerger) strategy
.newMerger(repo, true);
ixMerger.setCommitNames(new String[] { "stashed HEAD",
"HEAD", "stashed index" });
ixMerger.setCommitNames(new String[] { "stashed HEAD", //$NON-NLS-1$
"HEAD", "stashed index" }); //$NON-NLS-1$//$NON-NLS-2$
ixMerger.setBase(stashHeadCommit);
boolean ok = ixMerger.merge(headCommit, stashIndexCommit);
if (ok) {
@ -250,8 +249,6 @@ public ObjectId call() throws GitAPIException,
throw e;
} catch (IOException e) {
throw new JGitInternalException(JGitText.get().stashApplyFailed, e);
} finally {
reader.release();
}
}
@ -286,11 +283,9 @@ public void setApplyUntracked(boolean applyUntracked) {
private void resetIndex(RevTree tree) throws IOException {
DirCache dc = repo.lockDirCache();
TreeWalk walk = null;
try {
try (TreeWalk walk = new TreeWalk(repo)) {
DirCacheBuilder builder = dc.builder();
walk = new TreeWalk(repo);
walk.addTree(tree);
walk.addTree(new DirCacheIterator(dc));
walk.setRecursive(true);
@ -321,15 +316,13 @@ private void resetIndex(RevTree tree) throws IOException {
builder.commit();
} finally {
dc.unlock();
if (walk != null)
walk.release();
}
}
private void resetUntracked(RevTree tree) throws CheckoutConflictException,
IOException {
TreeWalk walk = new TreeWalk(repo); // maybe NameConflictTreeWalk;
try {
// TODO maybe NameConflictTreeWalk ?
try (TreeWalk walk = new TreeWalk(repo)) {
walk.addTree(tree);
walk.addTree(new FileTreeIterator(repo));
walk.setRecursive(true);
@ -359,8 +352,6 @@ private void resetUntracked(RevTree tree) throws CheckoutConflictException,
checkoutPath(entry, reader);
}
} finally {
walk.release();
}
}

View File

@ -94,11 +94,11 @@
*/
public class StashCreateCommand extends GitCommand<RevCommit> {
private static final String MSG_INDEX = "index on {0}: {1} {2}";
private static final String MSG_INDEX = "index on {0}: {1} {2}"; //$NON-NLS-1$
private static final String MSG_UNTRACKED = "untracked files on {0}: {1} {2}";
private static final String MSG_UNTRACKED = "untracked files on {0}: {1} {2}"; //$NON-NLS-1$
private static final String MSG_WORKING_DIR = "WIP on {0}: {1} {2}";
private static final String MSG_WORKING_DIR = "WIP on {0}: {1} {2}"; //$NON-NLS-1$
private String indexMessage = MSG_INDEX;
@ -187,8 +187,9 @@ public StashCreateCommand setIncludeUntracked(boolean includeUntracked) {
private RevCommit parseCommit(final ObjectReader reader,
final ObjectId headId) throws IOException {
final RevWalk walk = new RevWalk(reader);
return walk.parseCommit(headId);
try (final RevWalk walk = new RevWalk(reader)) {
return walk.parseCommit(headId);
}
}
private CommitBuilder createBuilder() {
@ -239,14 +240,13 @@ public RevCommit call() throws GitAPIException {
checkCallable();
Ref head = getHead();
ObjectReader reader = repo.newObjectReader();
try {
try (ObjectReader reader = repo.newObjectReader()) {
RevCommit headCommit = parseCommit(reader, head.getObjectId());
DirCache cache = repo.lockDirCache();
ObjectInserter inserter = repo.newObjectInserter();
ObjectId commitId;
try {
TreeWalk treeWalk = new TreeWalk(reader);
try (ObjectInserter inserter = repo.newObjectInserter();
TreeWalk treeWalk = new TreeWalk(reader)) {
treeWalk.setRecursive(true);
treeWalk.addTree(headCommit.getTree());
treeWalk.addTree(new DirCacheIterator(cache));
@ -380,7 +380,6 @@ public void apply(DirCacheEntry ent) {
}
} finally {
inserter.release();
cache.unlock();
}
@ -391,8 +390,6 @@ public void apply(DirCacheEntry ent) {
return parseCommit(reader, commitId);
} catch (IOException e) {
throw new JGitInternalException(JGitText.get().stashFailed, e);
} finally {
reader.release();
}
}
}

View File

@ -52,6 +52,7 @@
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.InvalidRefNameException;
import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.api.errors.RefNotFoundException;
import org.eclipse.jgit.errors.LockFailedException;
import org.eclipse.jgit.internal.JGitText;
import org.eclipse.jgit.internal.storage.file.ReflogWriter;
@ -184,6 +185,10 @@ public ObjectId call() throws GitAPIException {
List<ReflogEntry> entries;
try {
ReflogReader reader = repo.getReflogReader(R_STASH);
if (reader == null) {
throw new RefNotFoundException(MessageFormat
.format(JGitText.get().refNotResolved, stashRef));
}
entries = reader.getReverseEntries();
} catch (IOException e) {
throw new JGitInternalException(JGitText.get().stashDropFailed, e);

View File

@ -143,8 +143,7 @@ public Collection<String> call() throws InvalidConfigurationException,
RefNotFoundException, GitAPIException {
checkCallable();
try {
SubmoduleWalk generator = SubmoduleWalk.forIndex(repo);
try (SubmoduleWalk generator = SubmoduleWalk.forIndex(repo)) {
if (!paths.isEmpty())
generator.setFilter(PathFilterGroup.createFromStrings(paths));
List<String> updated = new ArrayList<String>();
@ -171,8 +170,7 @@ public Collection<String> call() throws InvalidConfigurationException,
submoduleRepo = clone.call().getRepository();
}
try {
RevWalk walk = new RevWalk(submoduleRepo);
try (RevWalk walk = new RevWalk(submoduleRepo)) {
RevCommit commit = walk
.parseCommit(generator.getObjectId());

View File

@ -128,8 +128,7 @@ public Ref call() throws GitAPIException, ConcurrentRefUpdateException,
RepositoryState state = repo.getRepositoryState();
processOptions(state);
RevWalk revWalk = new RevWalk(repo);
try {
try (RevWalk revWalk = new RevWalk(repo)) {
// if no id is set, we should attempt to use HEAD
if (id == null) {
ObjectId objectId = repo.resolve(Constants.HEAD + "^{commit}"); //$NON-NLS-1$
@ -157,24 +156,19 @@ public Ref call() throws GitAPIException, ConcurrentRefUpdateException,
newTag.setObjectId(id);
// write the tag object
ObjectInserter inserter = repo.newObjectInserter();
try {
try (ObjectInserter inserter = repo.newObjectInserter()) {
ObjectId tagId = inserter.insert(newTag);
inserter.flush();
String tag = newTag.getTag();
return updateTagRef(tagId, revWalk, tag, newTag.toString());
} finally {
inserter.release();
}
} catch (IOException e) {
throw new JGitInternalException(
JGitText.get().exceptionCaughtDuringExecutionOfTagCommand,
e);
} finally {
revWalk.release();
}
}
@ -222,8 +216,9 @@ private void processOptions(RepositoryState state)
if (tagger == null && annotated)
tagger = new PersonIdent(repo);
if (name == null || !Repository.isValidRefName(Constants.R_TAGS + name))
throw new InvalidTagNameException(MessageFormat.format(JGitText
.get().tagNameInvalid, name == null ? "<null>" : name));
throw new InvalidTagNameException(
MessageFormat.format(JGitText.get().tagNameInvalid,
name == null ? "<null>" : name)); //$NON-NLS-1$
if (signed)
throw new UnsupportedOperationException(
JGitText.get().signingNotSupportedOnTag);

View File

@ -172,7 +172,7 @@ private void initRevPool(boolean reverse) {
throw new IllegalStateException();
if (revPool != null)
revPool.release();
revPool.close();
if (reverse)
revPool = new ReverseWalk(getRepository());
@ -450,7 +450,7 @@ public BlameResult computeBlameResult() throws IOException {
r.computeAll();
return r;
} finally {
release();
close();
}
}
@ -513,7 +513,7 @@ public boolean next() throws IOException {
}
private boolean done() {
release();
close();
return false;
}
@ -936,14 +936,6 @@ public RawText getResultContents() throws IOException {
return queue != null ? queue.sourceText : null;
}
/**
* Release the current blame session. Use {@link #close()} instead.
*/
@Deprecated
public void release() {
close();
}
/**
* Release the current blame session.
*

View File

@ -380,14 +380,6 @@ public void flush() throws IOException {
out.flush();
}
/**
* Release the internal ObjectReader state. Use {@link #close()} instead.
*/
@Deprecated
public void release() {
close();
}
/**
* Release the internal ObjectReader state.
*

View File

@ -323,7 +323,7 @@ public List<DiffEntry> compute(ProgressMonitor pm) throws IOException {
try {
return compute(objectReader, pm);
} finally {
objectReader.release();
objectReader.close();
}
}
return Collections.unmodifiableList(entries);

View File

@ -403,8 +403,7 @@ private boolean doCheckout() throws CorruptObjectException, IOException,
MissingObjectException, IncorrectObjectTypeException,
CheckoutConflictException, IndexWriteException {
toBeDeleted.clear();
ObjectReader objectReader = repo.getObjectDatabase().newReader();
try {
try (ObjectReader objectReader = repo.getObjectDatabase().newReader()) {
if (headCommitTree != null)
preScanTwoTrees();
else
@ -454,8 +453,6 @@ private boolean doCheckout() throws CorruptObjectException, IOException,
// commit the index builder - a new index is persisted
if (!builder.commit())
throw new IndexWriteException();
} finally {
objectReader.release();
}
return toBeDeleted.size() == 0;
}
@ -1056,8 +1053,7 @@ private void cleanUpConflicts() throws CheckoutConflictException {
*/
private boolean isModifiedSubtree_IndexWorkingtree(String path)
throws CorruptObjectException, IOException {
NameConflictTreeWalk tw = new NameConflictTreeWalk(repo);
try {
try (NameConflictTreeWalk tw = new NameConflictTreeWalk(repo)) {
tw.addTree(new DirCacheIterator(dc));
tw.addTree(new FileTreeIterator(repo));
tw.setRecursive(true);
@ -1075,8 +1071,6 @@ private boolean isModifiedSubtree_IndexWorkingtree(String path)
}
}
return false;
} finally {
tw.release();
}
}
@ -1105,8 +1099,7 @@ private boolean isModified_IndexTree(String path, ObjectId iId,
*/
private boolean isModifiedSubtree_IndexTree(String path, ObjectId tree)
throws CorruptObjectException, IOException {
NameConflictTreeWalk tw = new NameConflictTreeWalk(repo);
try {
try (NameConflictTreeWalk tw = new NameConflictTreeWalk(repo)) {
tw.addTree(new DirCacheIterator(dc));
tw.addTree(tree);
tw.setRecursive(true);
@ -1124,8 +1117,6 @@ private boolean isModifiedSubtree_IndexTree(String path, ObjectId tree)
return true;
}
return false;
} finally {
tw.release();
}
}

View File

@ -0,0 +1,357 @@
/*
* Copyright (C) 2015, Google Inc.
* 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.gitrepo;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.gitrepo.RepoProject.CopyFile;
import org.eclipse.jgit.gitrepo.internal.RepoText;
import org.eclipse.jgit.internal.JGitText;
import org.eclipse.jgit.lib.Repository;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.helpers.XMLReaderFactory;
/**
* Repo XML manifest parser.
*
* @see <a href="https://code.google.com/p/git-repo/">git-repo project page</a>
* @since 4.0
*/
public class ManifestParser extends DefaultHandler {
private final String filename;
private final String baseUrl;
private final String defaultBranch;
private final Repository rootRepo;
private final Map<String, String> remotes;
private final Set<String> plusGroups;
private final Set<String> minusGroups;
private final List<RepoProject> projects;
private final List<RepoProject> filteredProjects;
private final IncludedFileReader includedReader;
private String defaultRemote;
private String defaultRevision;
private int xmlInRead;
private RepoProject currentProject;
/**
* A callback to read included xml files.
*/
public interface IncludedFileReader {
/**
* Read a file from the same base dir of the manifest xml file.
*
* @param path
* The relative path to the file to read
* @return the {@code InputStream} of the file.
* @throws GitAPIException
* @throws IOException
*/
public InputStream readIncludeFile(String path)
throws GitAPIException, IOException;
}
/**
* @param includedReader
* @param filename
* @param defaultBranch
* @param baseUrl
* @param groups
* @param rootRepo
*/
public ManifestParser(IncludedFileReader includedReader, String filename,
String defaultBranch, String baseUrl, String groups,
Repository rootRepo) {
this.includedReader = includedReader;
this.filename = filename;
this.defaultBranch = defaultBranch;
this.rootRepo = rootRepo;
// Strip trailing /s to match repo behavior.
int lastIndex = baseUrl.length() - 1;
while (lastIndex >= 0 && baseUrl.charAt(lastIndex) == '/')
lastIndex--;
this.baseUrl = baseUrl.substring(0, lastIndex + 1);
plusGroups = new HashSet<String>();
minusGroups = new HashSet<String>();
if (groups == null || groups.length() == 0
|| groups.equals("default")) { //$NON-NLS-1$
// default means "all,-notdefault"
minusGroups.add("notdefault"); //$NON-NLS-1$
} else {
for (String group : groups.split(",")) { //$NON-NLS-1$
if (group.startsWith("-")) //$NON-NLS-1$
minusGroups.add(group.substring(1));
else
plusGroups.add(group);
}
}
remotes = new HashMap<String, String>();
projects = new ArrayList<RepoProject>();
filteredProjects = new ArrayList<RepoProject>();
}
/**
* Read the xml file.
*
* @param inputStream
* @throws IOException
*/
public void read(InputStream inputStream) throws IOException {
xmlInRead++;
final XMLReader xr;
try {
xr = XMLReaderFactory.createXMLReader();
} catch (SAXException e) {
throw new IOException(JGitText.get().noXMLParserAvailable);
}
xr.setContentHandler(this);
try {
xr.parse(new InputSource(inputStream));
} catch (SAXException e) {
IOException error = new IOException(
RepoText.get().errorParsingManifestFile);
error.initCause(e);
throw error;
}
}
@Override
public void startElement(
String uri,
String localName,
String qName,
Attributes attributes) throws SAXException {
if ("project".equals(qName)) { //$NON-NLS-1$
currentProject = new RepoProject(
attributes.getValue("name"), //$NON-NLS-1$
attributes.getValue("path"), //$NON-NLS-1$
attributes.getValue("revision"), //$NON-NLS-1$
attributes.getValue("remote"), //$NON-NLS-1$
attributes.getValue("groups")); //$NON-NLS-1$
} else if ("remote".equals(qName)) { //$NON-NLS-1$
String alias = attributes.getValue("alias"); //$NON-NLS-1$
String fetch = attributes.getValue("fetch"); //$NON-NLS-1$
remotes.put(attributes.getValue("name"), fetch); //$NON-NLS-1$
if (alias != null)
remotes.put(alias, fetch);
} else if ("default".equals(qName)) { //$NON-NLS-1$
defaultRemote = attributes.getValue("remote"); //$NON-NLS-1$
defaultRevision = attributes.getValue("revision"); //$NON-NLS-1$
if (defaultRevision == null)
defaultRevision = defaultBranch;
} else if ("copyfile".equals(qName)) { //$NON-NLS-1$
if (currentProject == null)
throw new SAXException(RepoText.get().invalidManifest);
currentProject.addCopyFile(new CopyFile(
rootRepo,
currentProject.path,
attributes.getValue("src"), //$NON-NLS-1$
attributes.getValue("dest"))); //$NON-NLS-1$
} else if ("include".equals(qName)) { //$NON-NLS-1$
String name = attributes.getValue("name"); //$NON-NLS-1$
InputStream is = null;
if (includedReader != null) {
try {
is = includedReader.readIncludeFile(name);
} catch (Exception e) {
throw new SAXException(MessageFormat.format(
RepoText.get().errorIncludeFile, name), e);
}
} else if (filename != null) {
int index = filename.lastIndexOf('/');
String path = filename.substring(0, index + 1) + name;
try {
is = new FileInputStream(path);
} catch (IOException e) {
throw new SAXException(MessageFormat.format(
RepoText.get().errorIncludeFile, path), e);
}
}
if (is == null) {
throw new SAXException(
RepoText.get().errorIncludeNotImplemented);
}
try {
read(is);
} catch (IOException e) {
throw new SAXException(e);
}
}
}
@Override
public void endElement(
String uri,
String localName,
String qName) throws SAXException {
if ("project".equals(qName)) { //$NON-NLS-1$
projects.add(currentProject);
currentProject = null;
}
}
@Override
public void endDocument() throws SAXException {
xmlInRead--;
if (xmlInRead != 0)
return;
// Only do the following after we finished reading everything.
Map<String, String> remoteUrls = new HashMap<String, String>();
URI baseUri;
try {
baseUri = new URI(baseUrl);
} catch (URISyntaxException e) {
throw new SAXException(e);
}
for (RepoProject proj : projects) {
String remote = proj.remote;
if (remote == null) {
if (defaultRemote == null) {
if (filename != null)
throw new SAXException(MessageFormat.format(
RepoText.get().errorNoDefaultFilename,
filename));
else
throw new SAXException(
RepoText.get().errorNoDefault);
}
remote = defaultRemote;
}
String remoteUrl = remoteUrls.get(remote);
if (remoteUrl == null) {
remoteUrl = baseUri.resolve(remotes.get(remote)).toString();
if (!remoteUrl.endsWith("/")) //$NON-NLS-1$
remoteUrl = remoteUrl + "/"; //$NON-NLS-1$
remoteUrls.put(remote, remoteUrl);
}
proj.setUrl(remoteUrl + proj.name)
.setDefaultRevision(defaultRevision);
}
filteredProjects.addAll(projects);
removeNotInGroup();
removeOverlaps();
}
/**
* Getter for projects.
*
* @return projects list reference, never null
*/
public List<RepoProject> getProjects() {
return projects;
}
/**
* Getter for filterdProjects.
*
* @return filtered projects list reference, never null
*/
public List<RepoProject> getFilteredProjects() {
return filteredProjects;
}
/** Remove projects that are not in our desired groups. */
void removeNotInGroup() {
Iterator<RepoProject> iter = filteredProjects.iterator();
while (iter.hasNext())
if (!inGroups(iter.next()))
iter.remove();
}
/** Remove projects that sits in a subdirectory of any other project. */
void removeOverlaps() {
Collections.sort(filteredProjects);
Iterator<RepoProject> iter = filteredProjects.iterator();
if (!iter.hasNext())
return;
RepoProject last = iter.next();
while (iter.hasNext()) {
RepoProject p = iter.next();
if (last.isAncestorOf(p))
iter.remove();
else
last = p;
}
}
boolean inGroups(RepoProject proj) {
for (String group : minusGroups) {
if (proj.groups.contains(group)) {
// minus groups have highest priority.
return false;
}
}
if (plusGroups.isEmpty() || plusGroups.contains("all")) { //$NON-NLS-1$
// empty plus groups means "all"
return true;
}
for (String group : plusGroups) {
if (proj.groups.contains(group))
return true;
}
return false;
}
}

View File

@ -44,22 +44,12 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.channels.FileChannel;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.GitCommand;
@ -70,6 +60,8 @@
import org.eclipse.jgit.dircache.DirCache;
import org.eclipse.jgit.dircache.DirCacheBuilder;
import org.eclipse.jgit.dircache.DirCacheEntry;
import org.eclipse.jgit.gitrepo.ManifestParser.IncludedFileReader;
import org.eclipse.jgit.gitrepo.RepoProject.CopyFile;
import org.eclipse.jgit.gitrepo.internal.RepoText;
import org.eclipse.jgit.internal.JGitText;
import org.eclipse.jgit.lib.CommitBuilder;
@ -89,12 +81,6 @@
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.util.FileUtils;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.helpers.XMLReaderFactory;
/**
* A class used to execute a repo command.
@ -124,7 +110,7 @@ public class RepoCommand extends GitCommand<RevCommit> {
private InputStream inputStream;
private IncludedFileReader includedReader;
private List<Project> bareProjects;
private List<RepoProject> bareProjects;
private Git git;
private ProgressMonitor monitor;
@ -214,350 +200,10 @@ public byte[] readFile(String uri, String ref, String path)
*/
protected byte[] readFileFromRepo(Repository repo,
String ref, String path) throws GitAPIException, IOException {
ObjectReader reader = repo.newObjectReader();
byte[] result;
try {
try (ObjectReader reader = repo.newObjectReader()) {
ObjectId oid = repo.resolve(ref + ":" + path); //$NON-NLS-1$
result = reader.open(oid).getBytes(Integer.MAX_VALUE);
} finally {
reader.release();
return reader.open(oid).getBytes(Integer.MAX_VALUE);
}
return result;
}
}
/**
* A callback to read included xml files.
*
* @since 3.5
*/
public interface IncludedFileReader {
/**
* Read a file from the same base dir of the manifest xml file.
*
* @param path
* The relative path to the file to read
* @return the {@code InputStream} of the file.
* @throws GitAPIException
* @throws IOException
*/
public InputStream readIncludeFile(String path)
throws GitAPIException, IOException;
}
private static class CopyFile {
final Repository repo;
final String path;
final String src;
final String dest;
CopyFile(Repository repo, String path, String src, String dest) {
this.repo = repo;
this.path = path;
this.src = src;
this.dest = dest;
}
void copy() throws IOException {
File srcFile = new File(repo.getWorkTree(),
path + "/" + src); //$NON-NLS-1$
File destFile = new File(repo.getWorkTree(), dest);
FileInputStream input = new FileInputStream(srcFile);
try {
FileOutputStream output = new FileOutputStream(destFile);
try {
FileChannel channel = input.getChannel();
output.getChannel().transferFrom(channel, 0, channel.size());
} finally {
output.close();
}
} finally {
input.close();
}
}
}
private static class Project implements Comparable<Project> {
final String name;
final String path;
final String revision;
final String remote;
final Set<String> groups;
final List<CopyFile> copyfiles;
Project(String name, String path, String revision,
String remote, String groups) {
this.name = name;
if (path != null)
this.path = path;
else
this.path = name;
this.revision = revision;
this.remote = remote;
this.groups = new HashSet<String>();
if (groups != null && groups.length() > 0)
this.groups.addAll(Arrays.asList(groups.split(","))); //$NON-NLS-1$
copyfiles = new ArrayList<CopyFile>();
}
void addCopyFile(CopyFile copyfile) {
copyfiles.add(copyfile);
}
String getPathWithSlash() {
if (path.endsWith("/")) //$NON-NLS-1$
return path;
else
return path + "/"; //$NON-NLS-1$
}
boolean isAncestorOf(Project that) {
return that.getPathWithSlash().startsWith(this.getPathWithSlash());
}
@Override
public boolean equals(Object o) {
if (o instanceof Project) {
Project that = (Project) o;
return this.getPathWithSlash().equals(that.getPathWithSlash());
}
return false;
}
@Override
public int hashCode() {
return this.getPathWithSlash().hashCode();
}
public int compareTo(Project that) {
return this.getPathWithSlash().compareTo(that.getPathWithSlash());
}
}
private static class XmlManifest extends DefaultHandler {
private final RepoCommand command;
private final String filename;
private final String baseUrl;
private final Map<String, String> remotes;
private final Set<String> plusGroups;
private final Set<String> minusGroups;
private List<Project> projects;
private String defaultRemote;
private String defaultRevision;
private IncludedFileReader includedReader;
private int xmlInRead;
private Project currentProject;
XmlManifest(RepoCommand command, IncludedFileReader includedReader,
String filename, String baseUrl, String groups) {
this.command = command;
this.includedReader = includedReader;
this.filename = filename;
// Strip trailing /s to match repo behavior.
int lastIndex = baseUrl.length() - 1;
while (lastIndex >= 0 && baseUrl.charAt(lastIndex) == '/')
lastIndex--;
this.baseUrl = baseUrl.substring(0, lastIndex + 1);
remotes = new HashMap<String, String>();
projects = new ArrayList<Project>();
plusGroups = new HashSet<String>();
minusGroups = new HashSet<String>();
if (groups == null || groups.length() == 0 || groups.equals("default")) { //$NON-NLS-1$
// default means "all,-notdefault"
minusGroups.add("notdefault"); //$NON-NLS-1$
} else {
for (String group : groups.split(",")) { //$NON-NLS-1$
if (group.startsWith("-")) //$NON-NLS-1$
minusGroups.add(group.substring(1));
else
plusGroups.add(group);
}
}
}
void read(InputStream inputStream) throws IOException {
xmlInRead++;
final XMLReader xr;
try {
xr = XMLReaderFactory.createXMLReader();
} catch (SAXException e) {
throw new IOException(JGitText.get().noXMLParserAvailable);
}
xr.setContentHandler(this);
try {
xr.parse(new InputSource(inputStream));
} catch (SAXException e) {
IOException error = new IOException(
RepoText.get().errorParsingManifestFile);
error.initCause(e);
throw error;
}
}
@Override
public void startElement(
String uri,
String localName,
String qName,
Attributes attributes) throws SAXException {
if ("project".equals(qName)) { //$NON-NLS-1$
currentProject = new Project(
attributes.getValue("name"), //$NON-NLS-1$
attributes.getValue("path"), //$NON-NLS-1$
attributes.getValue("revision"), //$NON-NLS-1$
attributes.getValue("remote"), //$NON-NLS-1$
attributes.getValue("groups")); //$NON-NLS-1$
} else if ("remote".equals(qName)) { //$NON-NLS-1$
String alias = attributes.getValue("alias"); //$NON-NLS-1$
String fetch = attributes.getValue("fetch"); //$NON-NLS-1$
remotes.put(attributes.getValue("name"), fetch); //$NON-NLS-1$
if (alias != null)
remotes.put(alias, fetch);
} else if ("default".equals(qName)) { //$NON-NLS-1$
defaultRemote = attributes.getValue("remote"); //$NON-NLS-1$
defaultRevision = attributes.getValue("revision"); //$NON-NLS-1$
if (defaultRevision == null)
defaultRevision = command.branch;
} else if ("copyfile".equals(qName)) { //$NON-NLS-1$
if (currentProject == null)
throw new SAXException(RepoText.get().invalidManifest);
currentProject.addCopyFile(new CopyFile(
command.repo,
currentProject.path,
attributes.getValue("src"), //$NON-NLS-1$
attributes.getValue("dest"))); //$NON-NLS-1$
} else if ("include".equals(qName)) { //$NON-NLS-1$
String name = attributes.getValue("name"); //$NON-NLS-1$
InputStream is = null;
if (includedReader != null) {
try {
is = includedReader.readIncludeFile(name);
} catch (Exception e) {
throw new SAXException(MessageFormat.format(
RepoText.get().errorIncludeFile, name), e);
}
} else if (filename != null) {
int index = filename.lastIndexOf('/');
String path = filename.substring(0, index + 1) + name;
try {
is = new FileInputStream(path);
} catch (IOException e) {
throw new SAXException(MessageFormat.format(
RepoText.get().errorIncludeFile, path), e);
}
}
if (is == null) {
throw new SAXException(
RepoText.get().errorIncludeNotImplemented);
}
try {
read(is);
} catch (IOException e) {
throw new SAXException(e);
}
}
}
@Override
public void endElement(
String uri,
String localName,
String qName) throws SAXException {
if ("project".equals(qName)) { //$NON-NLS-1$
projects.add(currentProject);
currentProject = null;
}
}
@Override
public void endDocument() throws SAXException {
xmlInRead--;
if (xmlInRead != 0)
return;
// Only do the following after we finished reading everything.
removeNotInGroup();
removeOverlaps();
Map<String, String> remoteUrls = new HashMap<String, String>();
URI baseUri;
try {
baseUri = new URI(baseUrl);
} catch (URISyntaxException e) {
throw new SAXException(e);
}
for (Project proj : projects) {
String remote = proj.remote;
if (remote == null) {
if (defaultRemote == null) {
if (filename != null)
throw new SAXException(MessageFormat.format(
RepoText.get().errorNoDefaultFilename,
filename));
else
throw new SAXException(
RepoText.get().errorNoDefault);
}
remote = defaultRemote;
}
String remoteUrl = remoteUrls.get(remote);
if (remoteUrl == null) {
remoteUrl = baseUri.resolve(remotes.get(remote)).toString();
if (!remoteUrl.endsWith("/")) //$NON-NLS-1$
remoteUrl = remoteUrl + "/"; //$NON-NLS-1$
remoteUrls.put(remote, remoteUrl);
}
command.addSubmodule(remoteUrl + proj.name,
proj.path,
proj.revision == null
? defaultRevision : proj.revision,
proj.copyfiles);
}
}
/** Remove projects that are not in our desired groups. */
void removeNotInGroup() {
Iterator<Project> iter = projects.iterator();
while (iter.hasNext())
if (!inGroups(iter.next()))
iter.remove();
}
/** Remove projects that sits in a subdirectory of any other project. */
void removeOverlaps() {
Collections.sort(projects);
Iterator<Project> iter = projects.iterator();
if (!iter.hasNext())
return;
Project last = iter.next();
while (iter.hasNext()) {
Project p = iter.next();
if (last.isAncestorOf(p))
iter.remove();
else
last = p;
}
}
boolean inGroups(Project proj) {
for (String group : minusGroups) {
if (proj.groups.contains(group)) {
// minus groups have highest priority.
return false;
}
}
if (plusGroups.isEmpty() || plusGroups.contains("all")) { //$NON-NLS-1$
// empty plus groups means "all"
return true;
}
for (String group : plusGroups) {
if (proj.groups.contains(group))
return true;
}
return false;
}
}
@ -693,7 +339,7 @@ public RepoCommand setRemoteReader(final RemoteReader callback) {
*
* @param reader
* @return this command
* @since 3.5
* @since 4.0
*/
public RepoCommand setIncludedFileReader(IncludedFileReader reader) {
this.includedReader = reader;
@ -720,7 +366,7 @@ public RevCommit call() throws GitAPIException {
}
if (repo.isBare()) {
bareProjects = new ArrayList<Project>();
bareProjects = new ArrayList<RepoProject>();
if (author == null)
author = new PersonIdent(repo);
if (callback == null)
@ -728,11 +374,17 @@ public RevCommit call() throws GitAPIException {
} else
git = new Git(repo);
XmlManifest manifest = new XmlManifest(
this, includedReader, path, uri, groups);
ManifestParser parser = new ManifestParser(
includedReader, path, branch, uri, groups, repo);
try {
manifest.read(inputStream);
} catch (IOException e) {
parser.read(inputStream);
for (RepoProject proj : parser.getFilteredProjects()) {
addSubmodule(proj.url,
proj.path,
proj.getRevision(),
proj.copyfiles);
}
} catch (GitAPIException | IOException e) {
throw new ManifestErrorException(e);
}
} finally {
@ -748,10 +400,9 @@ public RevCommit call() throws GitAPIException {
DirCache index = DirCache.newInCore();
DirCacheBuilder builder = index.builder();
ObjectInserter inserter = repo.newObjectInserter();
RevWalk rw = new RevWalk(repo);
try {
try (RevWalk rw = new RevWalk(repo)) {
Config cfg = new Config();
for (Project proj : bareProjects) {
for (RepoProject proj : bareProjects) {
String name = proj.path;
String nameUri = proj.name;
cfg.setString("submodule", name, "path", name); //$NON-NLS-1$ //$NON-NLS-2$
@ -831,8 +482,6 @@ public RevCommit call() throws GitAPIException {
return rw.parseCommit(commitId);
} catch (IOException e) {
throw new ManifestErrorException(e);
} finally {
rw.release();
}
} else {
return git
@ -843,9 +492,9 @@ public RevCommit call() throws GitAPIException {
}
private void addSubmodule(String url, String name, String revision,
List<CopyFile> copyfiles) throws SAXException {
List<CopyFile> copyfiles) throws GitAPIException, IOException {
if (repo.isBare()) {
Project proj = new Project(url, name, revision, null, null);
RepoProject proj = new RepoProject(url, name, revision, null, null);
proj.copyfiles.addAll(copyfiles);
bareProjects.add(proj);
} else {
@ -856,22 +505,18 @@ private void addSubmodule(String url, String name, String revision,
if (monitor != null)
add.setProgressMonitor(monitor);
try {
Repository subRepo = add.call();
if (revision != null) {
Git sub = new Git(subRepo);
sub.checkout().setName(findRef(revision, subRepo)).call();
subRepo.close();
git.add().addFilepattern(name).call();
Repository subRepo = add.call();
if (revision != null) {
try (Git sub = new Git(subRepo)) {
sub.checkout().setName(findRef(revision, subRepo))
.call();
}
for (CopyFile copyfile : copyfiles) {
copyfile.copy();
git.add().addFilepattern(copyfile.dest).call();
}
} catch (GitAPIException e) {
throw new SAXException(e);
} catch (IOException e) {
throw new SAXException(e);
subRepo.close();
git.add().addFilepattern(name).call();
}
for (CopyFile copyfile : copyfiles) {
copyfile.copy();
git.add().addFilepattern(copyfile.dest).call();
}
}
}

View File

@ -0,0 +1,220 @@
/*
* Copyright (C) 2015, Google Inc.
* 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.gitrepo;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.eclipse.jgit.lib.Repository;
/**
* The representation of a repo sub project.
*
* @see <a href="https://code.google.com/p/git-repo/">git-repo project page</a>
* @since 4.0
*/
public class RepoProject implements Comparable<RepoProject> {
final String name;
final String path;
final String revision;
final String remote;
final Set<String> groups;
final List<CopyFile> copyfiles;
String url;
String defaultRevision;
/**
* The representation of a copy file configuration.
*/
public static class CopyFile {
final Repository repo;
final String path;
final String src;
final String dest;
/**
* @param repo
* @param path
* the path of the project containing this copyfile config.
* @param src
* @param dest
*/
public CopyFile(Repository repo, String path, String src, String dest) {
this.repo = repo;
this.path = path;
this.src = src;
this.dest = dest;
}
/**
* Do the copy file action.
*
* @throws IOException
*/
public void copy() throws IOException {
File srcFile = new File(repo.getWorkTree(),
path + "/" + src); //$NON-NLS-1$
File destFile = new File(repo.getWorkTree(), dest);
FileInputStream input = new FileInputStream(srcFile);
try {
FileOutputStream output = new FileOutputStream(destFile);
try {
FileChannel channel = input.getChannel();
output.getChannel().transferFrom(channel, 0, channel.size());
} finally {
output.close();
}
} finally {
input.close();
}
}
}
/**
* @param name
* @param path
* @param revision
* @param remote
* @param groups
*/
public RepoProject(String name, String path, String revision,
String remote, String groups) {
this.name = name;
if (path != null)
this.path = path;
else
this.path = name;
this.revision = revision;
this.remote = remote;
this.groups = new HashSet<String>();
if (groups != null && groups.length() > 0)
this.groups.addAll(Arrays.asList(groups.split(","))); //$NON-NLS-1$
copyfiles = new ArrayList<CopyFile>();
}
/**
* Set the url of the sub repo.
*
* @param url
* @return this for chaining.
*/
public RepoProject setUrl(String url) {
this.url = url;
return this;
}
/**
* Set the default revision for the sub repo.
*
* @param defaultRevision
* @return this for chaining.
*/
public RepoProject setDefaultRevision(String defaultRevision) {
this.defaultRevision = defaultRevision;
return this;
}
/**
* Get the revision of the sub repo.
*
* @return revision if set, or default revision.
*/
public String getRevision() {
return revision == null ? defaultRevision : revision;
}
/**
* Add a copy file configuration.
*
* @param copyfile
*/
public void addCopyFile(CopyFile copyfile) {
copyfiles.add(copyfile);
}
String getPathWithSlash() {
if (path.endsWith("/")) //$NON-NLS-1$
return path;
else
return path + "/"; //$NON-NLS-1$
}
/**
* Check if this sub repo is the ancestor of given sub repo.
*
* @param that
* non null
* @return true if this sub repo is the ancestor of given sub repo.
*/
public boolean isAncestorOf(RepoProject that) {
return that.getPathWithSlash().startsWith(this.getPathWithSlash());
}
@Override
public boolean equals(Object o) {
if (o instanceof RepoProject) {
RepoProject that = (RepoProject) o;
return this.getPathWithSlash().equals(that.getPathWithSlash());
}
return false;
}
@Override
public int hashCode() {
return this.getPathWithSlash().hashCode();
}
@Override
public int compareTo(RepoProject that) {
return this.getPathWithSlash().compareTo(that.getPathWithSlash());
}
}

View File

@ -86,6 +86,7 @@ public static JGitText get() {
/***/ public String badEscape;
/***/ public String badGroupHeader;
/***/ public String badObjectType;
/***/ public String badRef;
/***/ public String badSectionEntry;
/***/ public String bareRepositoryNoWorkdirAndIndex;
/***/ public String base64InputNotProperlyPadded;
@ -117,16 +118,23 @@ public static JGitText get() {
/***/ public String cannotCreateTempDir;
/***/ public String cannotDeleteCheckedOutBranch;
/***/ public String cannotDeleteFile;
/***/ public String cannotDeleteObjectsPath;
/***/ public String cannotDeleteStaleTrackingRef;
/***/ public String cannotDeleteStaleTrackingRef2;
/***/ public String cannotDetermineProxyFor;
/***/ public String cannotDownload;
/***/ public String cannotEnterObjectsPath;
/***/ public String cannotEnterPathFromParent;
/***/ public String cannotExecute;
/***/ public String cannotGet;
/***/ public String cannotGetObjectsPath;
/***/ public String cannotListObjectsPath;
/***/ public String cannotListPackPath;
/***/ public String cannotListRefs;
/***/ public String cannotLock;
/***/ public String cannotLockPackIn;
/***/ public String cannotMatchOnEmptyString;
/***/ public String cannotMkdirObjectPath;
/***/ public String cannotMoveIndexTo;
/***/ public String cannotMovePackTo;
/***/ public String cannotOpenService;
@ -139,13 +147,16 @@ public static JGitText get() {
/***/ public String cannotReadFile;
/***/ public String cannotReadHEAD;
/***/ public String cannotReadObject;
/***/ public String cannotReadObjectsPath;
/***/ public String cannotReadTree;
/***/ public String cannotRebaseWithoutCurrentHead;
/***/ public String cannotResolveLocalTrackingRefForUpdating;
/***/ public String cannotSquashFixupWithoutPreviousCommit;
/***/ public String cannotStoreObjects;
/***/ public String cannotResolveUniquelyAbbrevObjectId;
/***/ public String cannotUnloadAModifiedTree;
/***/ public String cannotWorkWithOtherStagesThanZeroRightNow;
/***/ public String cannotWriteObjectsPath;
/***/ public String canOnlyCherryPickCommitsWithOneParent;
/***/ public String canOnlyRevertCommitsWithOneParent;
/***/ public String commitDoesNotHaveGivenParent;
@ -172,26 +183,60 @@ public static JGitText get() {
/***/ public String corruptionDetectedReReadingAt;
/***/ public String corruptObjectBadStream;
/***/ public String corruptObjectBadStreamCorruptHeader;
/***/ public String corruptObjectDuplicateEntryNames;
/***/ public String corruptObjectGarbageAfterSize;
/***/ public String corruptObjectIncorrectLength;
/***/ public String corruptObjectIncorrectSorting;
/***/ public String corruptObjectInvalidAuthor;
/***/ public String corruptObjectInvalidCommitter;
/***/ public String corruptObjectInvalidEntryMode;
/***/ public String corruptObjectInvalidMode;
/***/ public String corruptObjectInvalidModeChar;
/***/ public String corruptObjectInvalidModeStartsZero;
/***/ public String corruptObjectInvalidMode2;
/***/ public String corruptObjectInvalidMode3;
/***/ public String corruptObjectInvalidName;
/***/ public String corruptObjectInvalidNameAux;
/***/ public String corruptObjectInvalidNameCon;
/***/ public String corruptObjectInvalidNameCom;
/***/ public String corruptObjectInvalidNameEnd;
/***/ public String corruptObjectInvalidNameIgnorableUnicode;
/***/ public String corruptObjectInvalidNameInvalidUtf8;
/***/ public String corruptObjectInvalidNameLpt;
/***/ public String corruptObjectInvalidNameNul;
/***/ public String corruptObjectInvalidNamePrn;
/***/ public String corruptObjectInvalidObject;
/***/ public String corruptObjectInvalidParent;
/***/ public String corruptObjectInvalidTagger;
/***/ public String corruptObjectInvalidTree;
/***/ public String corruptObjectInvalidType;
/***/ public String corruptObjectInvalidType2;
/***/ public String corruptObjectMalformedHeader;
/***/ public String corruptObjectNameContainsByte;
/***/ public String corruptObjectNameContainsChar;
/***/ public String corruptObjectNameContainsNullByte;
/***/ public String corruptObjectNameContainsSlash;
/***/ public String corruptObjectNameDot;
/***/ public String corruptObjectNameDotDot;
/***/ public String corruptObjectNameZeroLength;
/***/ public String corruptObjectNegativeSize;
/***/ public String corruptObjectNoAuthor;
/***/ public String corruptObjectNoCommitter;
/***/ public String corruptObjectNoHeader;
/***/ public String corruptObjectNoObject;
/***/ public String corruptObjectNoObjectHeader;
/***/ public String corruptObjectNoTaggerBadHeader;
/***/ public String corruptObjectNoTaggerHeader;
/***/ public String corruptObjectNoTagHeader;
/***/ public String corruptObjectNoTagName;
/***/ public String corruptObjectNotree;
/***/ public String corruptObjectNotreeHeader;
/***/ public String corruptObjectNoType;
/***/ public String corruptObjectNoTypeHeader;
/***/ public String corruptObjectPackfileChecksumIncorrect;
/***/ public String corruptObjectTruncatedInMode;
/***/ public String corruptObjectTruncatedInName;
/***/ public String corruptObjectTruncatedInObjectId;
/***/ public String corruptPack;
/***/ public String couldNotCheckOutBecauseOfConflicts;
/***/ public String couldNotDeleteLockFileShouldNotHappen;
@ -204,6 +249,7 @@ public static JGitText get() {
/***/ public String couldNotRenameDeleteOldIndex;
/***/ public String couldNotRenameTemporaryFile;
/***/ public String couldNotRenameTemporaryIndexFileToIndex;
/***/ public String couldNotRewindToUpstreamCommit;
/***/ public String couldNotURLEncodeToUTF8;
/***/ public String couldNotWriteFile;
/***/ public String countingObjects;
@ -239,6 +285,7 @@ public static JGitText get() {
/***/ public String eitherGitDirOrWorkTreeRequired;
/***/ public String emptyCommit;
/***/ public String emptyPathNotPermitted;
/***/ public String emptyRef;
/***/ public String encryptionError;
/***/ public String endOfFileInEscape;
/***/ public String entryNotFoundByPath;
@ -299,6 +346,7 @@ public static JGitText get() {
/***/ public String gcFailed;
/***/ public String gitmodulesNotFound;
/***/ public String headRequiredToStash;
/***/ public String hiddenFilesStartWithDot;
/***/ public String hoursAgo;
/***/ public String hugeIndexesAreNotSupportedByJgitYet;
/***/ public String hunkBelongsToAnotherFile;
@ -337,6 +385,7 @@ public static JGitText get() {
/***/ public String invalidGitType;
/***/ public String invalidId;
/***/ public String invalidIdLength;
/***/ public String invalidIgnoreParamSubmodule;
/***/ public String invalidIntegerValue;
/***/ public String invalidKey;
/***/ public String invalidLineInConfigFile;
@ -369,8 +418,10 @@ public static JGitText get() {
/***/ public String largeObjectOutOfMemory;
/***/ public String lengthExceedsMaximumArraySize;
/***/ public String listingAlternates;
/***/ public String listingPacks;
/***/ public String localObjectsIncomplete;
/***/ public String localRefIsMissingObjects;
/***/ public String localRepository;
/***/ public String lockCountMustBeGreaterOrEqual1;
/***/ public String lockError;
/***/ public String lockOnNotClosed;
@ -469,6 +520,8 @@ public static JGitText get() {
/***/ public String pathNotConfigured;
/***/ public String peeledLineBeforeRef;
/***/ public String peerDidNotSupplyACompleteObjectGraph;
/***/ public String personIdentEmailNonNull;
/***/ public String personIdentNameNonNull;
/***/ public String prefixRemote;
/***/ public String problemWithResolvingPushRefSpecsLocally;
/***/ public String progressMonUploading;
@ -512,6 +565,7 @@ public static JGitText get() {
/***/ public String repositoryIsRequired;
/***/ public String repositoryNotFound;
/***/ public String repositoryState_applyMailbox;
/***/ public String repositoryState_bare;
/***/ public String repositoryState_bisecting;
/***/ public String repositoryState_conflicts;
/***/ public String repositoryState_merged;
@ -525,6 +579,9 @@ public static JGitText get() {
/***/ public String resolvingDeltas;
/***/ public String resultLengthIncorrect;
/***/ public String rewinding;
/***/ public String s3ActionDeletion;
/***/ public String s3ActionReading;
/***/ public String s3ActionWriting;
/***/ public String searchForReuse;
/***/ public String searchForSizes;
/***/ public String secondsAgo;
@ -606,6 +663,7 @@ public static JGitText get() {
/***/ public String unencodeableFile;
/***/ public String unexpectedCompareResult;
/***/ public String unexpectedEndOfConfigFile;
/***/ public String unexpectedEndOfInput;
/***/ public String unexpectedHunkTrailer;
/***/ public String unexpectedOddResult;
/***/ public String unexpectedRefReport;
@ -617,6 +675,7 @@ public static JGitText get() {
/***/ public String unknownIndexVersionOrCorruptIndex;
/***/ public String unknownObject;
/***/ public String unknownObjectType;
/***/ public String unknownObjectType2;
/***/ public String unknownRepositoryFormat;
/***/ public String unknownRepositoryFormat2;
/***/ public String unknownZlibError;
@ -625,16 +684,21 @@ public static JGitText get() {
/***/ public String unpackException;
/***/ public String unreadablePackIndex;
/***/ public String unrecognizedRef;
/***/ public String unsetMark;
/***/ public String unsupportedAlternates;
/***/ public String unsupportedArchiveFormat;
/***/ public String unsupportedCommand0;
/***/ public String unsupportedEncryptionAlgorithm;
/***/ public String unsupportedEncryptionVersion;
/***/ public String unsupportedGC;
/***/ public String unsupportedMark;
/***/ public String unsupportedOperationNotAddAtEnd;
/***/ public String unsupportedPackIndexVersion;
/***/ public String unsupportedPackVersion;
/***/ public String updatingHeadFailed;
/***/ public String updatingReferences;
/***/ public String updatingRefFailed;
/***/ public String upstreamBranchName;
/***/ public String uriNotConfigured;
/***/ public String uriNotFound;
/***/ public String URINotSupported;

View File

@ -230,7 +230,7 @@ public boolean pack(ProgressMonitor pm) throws IOException {
objdb.rollbackPack(newPackDesc);
}
} finally {
ctx.release();
ctx.close();
}
}

View File

@ -216,7 +216,7 @@ public void flush() throws IOException {
}
@Override
public void release() {
public void close() {
if (packOut != null) {
try {
packOut.close();
@ -600,8 +600,8 @@ public Set<ObjectId> getShallowCommits() throws IOException {
}
@Override
public void release() {
ctx.release();
public void close() {
ctx.close();
}
}
@ -631,7 +631,7 @@ public ObjectStream openStream() throws IOException {
// The newly created pack is registered in the cache.
return ctx.open(id, type).openStream();
} finally {
ctx.release();
ctx.close();
}
}
@ -642,7 +642,7 @@ size, new BufferedInputStream(new InflaterInputStream(
new ReadBackStream(pos), inf, bufsz), bufsz)) {
@Override
public void close() throws IOException {
ctx.release();
ctx.close();
super.close();
}
};

View File

@ -179,11 +179,8 @@ public DfsPackCompactor exclude(PackWriter.ObjectIdSet set) {
*/
public DfsPackCompactor exclude(DfsPackFile pack) throws IOException {
final PackIndex idx;
DfsReader ctx = (DfsReader) repo.newObjectReader();
try {
try (DfsReader ctx = (DfsReader) repo.newObjectReader()) {
idx = pack.getPackIndex(ctx);
} finally {
ctx.release();
}
return exclude(new PackWriter.ObjectIdSet() {
public boolean contains(AnyObjectId id) {
@ -206,8 +203,7 @@ public void compact(ProgressMonitor pm) throws IOException {
pm = NullProgressMonitor.INSTANCE;
DfsObjDatabase objdb = repo.getObjectDatabase();
DfsReader ctx = (DfsReader) objdb.newReader();
try {
try (DfsReader ctx = (DfsReader) objdb.newReader()) {
PackConfig pc = new PackConfig(repo);
pc.setIndexVersion(2);
pc.setDeltaCompress(false);
@ -236,7 +232,7 @@ public void compact(ProgressMonitor pm) throws IOException {
writeIndex(objdb, pack, pw);
PackWriter.Statistics stats = pw.getStatistics();
pw.release();
pw.close();
pw = null;
pack.setPackStats(stats);
@ -250,11 +246,10 @@ public void compact(ProgressMonitor pm) throws IOException {
}
} finally {
if (pw != null)
pw.release();
pw.close();
}
} finally {
rw = null;
ctx.release();
}
}

View File

@ -61,6 +61,7 @@
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.errors.StoredObjectRepresentationNotAvailableException;
import org.eclipse.jgit.internal.JGitText;
import org.eclipse.jgit.internal.storage.file.BitmapIndexImpl;
import org.eclipse.jgit.internal.storage.file.PackBitmapIndex;
import org.eclipse.jgit.internal.storage.file.PackIndex;
@ -210,7 +211,8 @@ public ObjectLoader open(AnyObjectId objectId, int typeHint)
}
if (typeHint == OBJ_ANY)
throw new MissingObjectException(objectId.copy(), "unknown");
throw new MissingObjectException(objectId.copy(),
JGitText.get().unknownObjectType2);
throw new MissingObjectException(objectId.copy(), typeHint);
}
@ -339,7 +341,8 @@ public ObjectId getObjectId() {
public ObjectLoader open() throws IOException {
if (cur.pack == null)
throw new MissingObjectException(cur.id, "unknown");
throw new MissingObjectException(cur.id,
JGitText.get().unknownObjectType2);
return cur.pack.load(DfsReader.this, cur.offset);
}
@ -376,7 +379,8 @@ public boolean next() throws MissingObjectException, IOException {
if (idItr.hasNext()) {
cur = idItr.next();
if (cur.pack == null)
throw new MissingObjectException(cur.id, "unknown");
throw new MissingObjectException(cur.id,
JGitText.get().unknownObjectType2);
sz = cur.pack.getObjectSize(DfsReader.this, cur.offset);
return true;
} else if (findAllError != null) {
@ -429,7 +433,8 @@ public long getObjectSize(AnyObjectId objectId, int typeHint)
}
if (typeHint == OBJ_ANY)
throw new MissingObjectException(objectId.copy(), "unknown");
throw new MissingObjectException(objectId.copy(),
JGitText.get().unknownObjectType2);
throw new MissingObjectException(objectId.copy(), typeHint);
}
@ -618,7 +623,7 @@ void unpin() {
/** Release the current window cursor. */
@Override
public void release() {
public void close() {
last = null;
block = null;
baseCache = null;

View File

@ -183,8 +183,7 @@ public Ref peel(Ref ref) throws IOException {
private Ref doPeel(final Ref leaf) throws MissingObjectException,
IOException {
RevWalk rw = new RevWalk(repository);
try {
try (RevWalk rw = new RevWalk(repository)) {
RevObject obj = rw.parseAny(leaf.getObjectId());
if (obj instanceof RevTag) {
return new ObjectIdRef.PeeledTag(
@ -198,8 +197,6 @@ private Ref doPeel(final Ref leaf) throws MissingObjectException,
leaf.getName(),
leaf.getObjectId());
}
} finally {
rw.release();
}
}

View File

@ -46,6 +46,7 @@
import java.io.File;
import java.io.IOException;
import org.eclipse.jgit.internal.JGitText;
import org.eclipse.jgit.lib.BaseRepositoryBuilder;
/**
@ -141,7 +142,8 @@ public B setObjectDirectory(File objectDirectory) {
@Override
public B addAlternateObjectDirectory(File other) {
throw new UnsupportedOperationException("Alternates not supported");
throw new UnsupportedOperationException(
JGitText.get().unsupportedAlternates);
}
@Override

View File

@ -112,8 +112,10 @@ public ObjectStream openStream() throws MissingObjectException, IOException {
ObjectId obj = pack.getReverseIdx(ctx).findObject(objectOffset);
return ctx.open(obj, type).openStream();
} finally {
ctx.release();
ctx.close();
}
} finally {
ctx.close();
}
// Align buffer to inflater size, at a larger than default block.

View File

@ -80,6 +80,6 @@ public int read() throws IOException {
@Override
public void close() {
ctx.release();
ctx.close();
}
}

View File

@ -145,7 +145,7 @@ public void flush() throws IOException {
}
@Override
public void release() {
public void close() {
if (deflate != null) {
try {
deflate.end();

View File

@ -51,6 +51,7 @@
import java.io.EOFException;
import java.io.File;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.io.RandomAccessFile;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel.MapMode;
@ -177,6 +178,9 @@ private synchronized PackIndex idx() throws IOException {
packFile.getPath()));
}
loadedIdx = idx;
} catch (InterruptedIOException e) {
// don't invalidate the pack, we are interrupted from another thread
throw e;
} catch (IOException e) {
invalid = true;
throw e;
@ -605,22 +609,26 @@ private void doOpen() throws IOException {
length = fd.length();
onOpenPack();
}
} catch (InterruptedIOException e) {
// don't invalidate the pack, we are interrupted from another thread
openFail(false);
throw e;
} catch (IOException ioe) {
openFail();
openFail(true);
throw ioe;
} catch (RuntimeException re) {
openFail();
openFail(true);
throw re;
} catch (Error re) {
openFail();
openFail(true);
throw re;
}
}
private void openFail() {
private void openFail(boolean invalidate) {
activeWindows = 0;
activeCopyRawData = 0;
invalid = true;
invalid = invalidate;
doClose();
}

View File

@ -477,8 +477,7 @@ public Ref peel(final Ref ref) throws IOException {
private ObjectIdRef doPeel(final Ref leaf) throws MissingObjectException,
IOException {
RevWalk rw = new RevWalk(getRepository());
try {
try (RevWalk rw = new RevWalk(getRepository())) {
RevObject obj = rw.parseAny(leaf.getObjectId());
if (obj instanceof RevTag) {
return new ObjectIdRef.PeeledTag(leaf.getStorage(), leaf
@ -487,8 +486,6 @@ private ObjectIdRef doPeel(final Ref leaf) throws MissingObjectException,
return new ObjectIdRef.PeeledNonTag(leaf.getStorage(), leaf
.getName(), leaf.getObjectId());
}
} finally {
rw.release();
}
}

View File

@ -96,8 +96,7 @@ protected Result doRename() throws IOException {
objId = source.getOldObjectId();
updateHEAD = needToUpdateHEAD();
tmp = refdb.newTemporaryUpdate();
final RevWalk rw = new RevWalk(refdb.getRepository());
try {
try (final RevWalk rw = new RevWalk(refdb.getRepository())) {
// First backup the source so its never unreachable.
tmp.setNewObjectId(objId);
tmp.setForceUpdate(true);
@ -178,7 +177,6 @@ protected Result doRename() throws IOException {
} catch (IOException err) {
FileUtils.delete(refdb.fileFor(tmp.getName()));
}
rw.release();
}
}

View File

@ -128,11 +128,11 @@ protected Result doUpdate(final Result status) throws IOException {
private String toResultString(final Result status) {
switch (status) {
case FORCED:
return "forced-update";
return "forced-update"; //$NON-NLS-1$
case FAST_FORWARD:
return "fast forward";
return "fast forward"; //$NON-NLS-1$
case NEW:
return "created";
return "created"; //$NON-NLS-1$
default:
return null;
}

View File

@ -56,6 +56,7 @@
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.errors.StoredObjectRepresentationNotAvailableException;
import org.eclipse.jgit.internal.JGitText;
import org.eclipse.jgit.internal.storage.pack.CachedPack;
import org.eclipse.jgit.internal.storage.pack.ObjectReuseAsIs;
import org.eclipse.jgit.internal.storage.pack.ObjectToPack;
@ -141,7 +142,8 @@ public ObjectLoader open(AnyObjectId objectId, int typeHint)
final ObjectLoader ldr = db.openObject(this, objectId);
if (ldr == null) {
if (typeHint == OBJ_ANY)
throw new MissingObjectException(objectId.copy(), "unknown");
throw new MissingObjectException(objectId.copy(),
JGitText.get().unknownObjectType2);
throw new MissingObjectException(objectId.copy(), typeHint);
}
if (typeHint != OBJ_ANY && ldr.getType() != typeHint)
@ -160,7 +162,8 @@ public long getObjectSize(AnyObjectId objectId, int typeHint)
long sz = db.getObjectSize(this, objectId);
if (sz < 0) {
if (typeHint == OBJ_ANY)
throw new MissingObjectException(objectId.copy(), "unknown");
throw new MissingObjectException(objectId.copy(),
JGitText.get().unknownObjectType2);
throw new MissingObjectException(objectId.copy(), typeHint);
}
return sz;

View File

@ -288,7 +288,7 @@ public Object call() throws Exception {
runWindow(w);
} finally {
block.pm.endWorker();
or.release();
or.close();
or = null;
}
return null;

View File

@ -987,7 +987,7 @@ public void writePack(ProgressMonitor compressMonitor,
}
stats.totalBytes = out.length();
reader.release();
reader.close();
endPhase(writeMonitor);
}
@ -1005,14 +1005,6 @@ public State getState() {
return state.snapshot();
}
/**
* Release all resources used by this writer. Use {@link #close()} instead.
*/
@Deprecated
public void release() {
close();
}
/**
* Release all resources used by this writer.
*

View File

@ -48,6 +48,7 @@
package org.eclipse.jgit.lib;
import java.io.IOException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@ -63,6 +64,7 @@
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.errors.StopWalkException;
import org.eclipse.jgit.internal.JGitText;
import org.eclipse.jgit.revwalk.RevTree;
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.submodule.SubmoduleWalk;
@ -400,118 +402,122 @@ public boolean diff(final ProgressMonitor monitor, int estWorkTreeSize,
throws IOException {
dirCache = repository.readDirCache();
TreeWalk treeWalk = new TreeWalk(repository);
treeWalk.setRecursive(true);
// add the trees (tree, dirchache, workdir)
if (tree != null)
treeWalk.addTree(tree);
else
treeWalk.addTree(new EmptyTreeIterator());
treeWalk.addTree(new DirCacheIterator(dirCache));
treeWalk.addTree(initialWorkingTreeIterator);
Collection<TreeFilter> filters = new ArrayList<TreeFilter>(4);
try (TreeWalk treeWalk = new TreeWalk(repository)) {
treeWalk.setRecursive(true);
// add the trees (tree, dirchache, workdir)
if (tree != null)
treeWalk.addTree(tree);
else
treeWalk.addTree(new EmptyTreeIterator());
treeWalk.addTree(new DirCacheIterator(dirCache));
treeWalk.addTree(initialWorkingTreeIterator);
Collection<TreeFilter> filters = new ArrayList<TreeFilter>(4);
if (monitor != null) {
// Get the maximum size of the work tree and index
// and add some (quite arbitrary)
if (estIndexSize == 0)
estIndexSize = dirCache.getEntryCount();
int total = Math.max(estIndexSize * 10 / 9,
estWorkTreeSize * 10 / 9);
monitor.beginTask(title, total);
filters.add(new ProgressReportingFilter(monitor, total));
}
if (filter != null)
filters.add(filter);
filters.add(new SkipWorkTreeFilter(INDEX));
indexDiffFilter = new IndexDiffFilter(INDEX, WORKDIR);
filters.add(indexDiffFilter);
treeWalk.setFilter(AndTreeFilter.create(filters));
fileModes.clear();
while (treeWalk.next()) {
AbstractTreeIterator treeIterator = treeWalk.getTree(TREE,
AbstractTreeIterator.class);
DirCacheIterator dirCacheIterator = treeWalk.getTree(INDEX,
DirCacheIterator.class);
WorkingTreeIterator workingTreeIterator = treeWalk.getTree(WORKDIR,
WorkingTreeIterator.class);
if (dirCacheIterator != null) {
final DirCacheEntry dirCacheEntry = dirCacheIterator
.getDirCacheEntry();
if (dirCacheEntry != null) {
int stage = dirCacheEntry.getStage();
if (stage > 0) {
String path = treeWalk.getPathString();
addConflict(path, stage);
continue;
}
}
if (monitor != null) {
// Get the maximum size of the work tree and index
// and add some (quite arbitrary)
if (estIndexSize == 0)
estIndexSize = dirCache.getEntryCount();
int total = Math.max(estIndexSize * 10 / 9,
estWorkTreeSize * 10 / 9);
monitor.beginTask(title, total);
filters.add(new ProgressReportingFilter(monitor, total));
}
if (treeIterator != null) {
if (filter != null)
filters.add(filter);
filters.add(new SkipWorkTreeFilter(INDEX));
indexDiffFilter = new IndexDiffFilter(INDEX, WORKDIR);
filters.add(indexDiffFilter);
treeWalk.setFilter(AndTreeFilter.create(filters));
fileModes.clear();
while (treeWalk.next()) {
AbstractTreeIterator treeIterator = treeWalk.getTree(TREE,
AbstractTreeIterator.class);
DirCacheIterator dirCacheIterator = treeWalk.getTree(INDEX,
DirCacheIterator.class);
WorkingTreeIterator workingTreeIterator = treeWalk
.getTree(WORKDIR, WorkingTreeIterator.class);
if (dirCacheIterator != null) {
if (!treeIterator.idEqual(dirCacheIterator)
|| treeIterator.getEntryRawMode()
!= dirCacheIterator.getEntryRawMode()) {
// in repo, in index, content diff => changed
final DirCacheEntry dirCacheEntry = dirCacheIterator
.getDirCacheEntry();
if (dirCacheEntry != null) {
int stage = dirCacheEntry.getStage();
if (stage > 0) {
String path = treeWalk.getPathString();
addConflict(path, stage);
continue;
}
}
}
if (treeIterator != null) {
if (dirCacheIterator != null) {
if (!treeIterator.idEqual(dirCacheIterator)
|| treeIterator
.getEntryRawMode() != dirCacheIterator
.getEntryRawMode()) {
// in repo, in index, content diff => changed
if (!isEntryGitLink(treeIterator)
|| !isEntryGitLink(dirCacheIterator)
|| ignoreSubmoduleMode != IgnoreSubmoduleMode.ALL)
changed.add(treeWalk.getPathString());
}
} else {
// in repo, not in index => removed
if (!isEntryGitLink(treeIterator)
|| !isEntryGitLink(dirCacheIterator)
|| ignoreSubmoduleMode != IgnoreSubmoduleMode.ALL)
changed.add(treeWalk.getPathString());
removed.add(treeWalk.getPathString());
if (workingTreeIterator != null)
untracked.add(treeWalk.getPathString());
}
} else {
// in repo, not in index => removed
if (!isEntryGitLink(treeIterator)
|| ignoreSubmoduleMode != IgnoreSubmoduleMode.ALL)
removed.add(treeWalk.getPathString());
if (workingTreeIterator != null)
untracked.add(treeWalk.getPathString());
if (dirCacheIterator != null) {
// not in repo, in index => added
if (!isEntryGitLink(dirCacheIterator)
|| ignoreSubmoduleMode != IgnoreSubmoduleMode.ALL)
added.add(treeWalk.getPathString());
} else {
// not in repo, not in index => untracked
if (workingTreeIterator != null
&& !workingTreeIterator.isEntryIgnored()) {
untracked.add(treeWalk.getPathString());
}
}
}
} else {
if (dirCacheIterator != null) {
// not in repo, in index => added
if (!isEntryGitLink(dirCacheIterator)
|| ignoreSubmoduleMode != IgnoreSubmoduleMode.ALL)
added.add(treeWalk.getPathString());
} else {
// not in repo, not in index => untracked
if (workingTreeIterator != null
&& !workingTreeIterator.isEntryIgnored()) {
untracked.add(treeWalk.getPathString());
if (workingTreeIterator == null) {
// in index, not in workdir => missing
if (!isEntryGitLink(dirCacheIterator)
|| ignoreSubmoduleMode != IgnoreSubmoduleMode.ALL)
missing.add(treeWalk.getPathString());
} else {
if (workingTreeIterator.isModified(
dirCacheIterator.getDirCacheEntry(), true,
treeWalk.getObjectReader())) {
// in index, in workdir, content differs => modified
if (!isEntryGitLink(dirCacheIterator)
|| !isEntryGitLink(workingTreeIterator)
|| (ignoreSubmoduleMode != IgnoreSubmoduleMode.ALL
&& ignoreSubmoduleMode != IgnoreSubmoduleMode.DIRTY))
modified.add(treeWalk.getPathString());
}
}
}
}
if (dirCacheIterator != null) {
if (workingTreeIterator == null) {
// in index, not in workdir => missing
if (!isEntryGitLink(dirCacheIterator)
|| ignoreSubmoduleMode != IgnoreSubmoduleMode.ALL)
missing.add(treeWalk.getPathString());
} else {
if (workingTreeIterator.isModified(
dirCacheIterator.getDirCacheEntry(), true,
treeWalk.getObjectReader())) {
// in index, in workdir, content differs => modified
if (!isEntryGitLink(dirCacheIterator) || !isEntryGitLink(workingTreeIterator)
|| (ignoreSubmoduleMode != IgnoreSubmoduleMode.ALL && ignoreSubmoduleMode != IgnoreSubmoduleMode.DIRTY))
modified.add(treeWalk.getPathString());
for (int i = 0; i < treeWalk.getTreeCount(); i++) {
Set<String> values = fileModes.get(treeWalk.getFileMode(i));
String path = treeWalk.getPathString();
if (path != null) {
if (values == null)
values = new HashSet<String>();
values.add(path);
fileModes.put(treeWalk.getFileMode(i), values);
}
}
}
for (int i = 0; i < treeWalk.getTreeCount(); i++) {
Set<String> values = fileModes.get(treeWalk.getFileMode(i));
String path = treeWalk.getPathString();
if (path != null) {
if (values == null)
values = new HashSet<String>();
values.add(path);
fileModes.put(treeWalk.getFileMode(i), values);
}
}
}
if (ignoreSubmoduleMode != IgnoreSubmoduleMode.ALL) {
@ -525,9 +531,9 @@ public boolean diff(final ProgressMonitor monitor, int estWorkTreeSize,
.equals(localIgnoreSubmoduleMode))
continue;
} catch (ConfigInvalidException e) {
IOException e1 = new IOException(
"Found invalid ignore param for submodule "
+ smw.getPath());
IOException e1 = new IOException(MessageFormat.format(
JGitText.get().invalidIgnoreParamSubmodule,
smw.getPath()));
e1.initCause(e);
throw e1;
}

View File

@ -254,25 +254,32 @@ public void checkCommit(final byte[] raw) throws CorruptObjectException {
int ptr = 0;
if ((ptr = match(raw, ptr, tree)) < 0)
throw new CorruptObjectException("no tree header");
throw new CorruptObjectException(
JGitText.get().corruptObjectNotreeHeader);
if ((ptr = id(raw, ptr)) < 0 || raw[ptr++] != '\n')
throw new CorruptObjectException("invalid tree");
throw new CorruptObjectException(
JGitText.get().corruptObjectInvalidTree);
while (match(raw, ptr, parent) >= 0) {
ptr += parent.length;
if ((ptr = id(raw, ptr)) < 0 || raw[ptr++] != '\n')
throw new CorruptObjectException("invalid parent");
throw new CorruptObjectException(
JGitText.get().corruptObjectInvalidParent);
}
if ((ptr = match(raw, ptr, author)) < 0)
throw new CorruptObjectException("no author");
throw new CorruptObjectException(
JGitText.get().corruptObjectNoAuthor);
if ((ptr = personIdent(raw, ptr)) < 0 || raw[ptr++] != '\n')
throw new CorruptObjectException("invalid author");
throw new CorruptObjectException(
JGitText.get().corruptObjectInvalidAuthor);
if ((ptr = match(raw, ptr, committer)) < 0)
throw new CorruptObjectException("no committer");
throw new CorruptObjectException(
JGitText.get().corruptObjectNoCommitter);
if ((ptr = personIdent(raw, ptr)) < 0 || raw[ptr++] != '\n')
throw new CorruptObjectException("invalid committer");
throw new CorruptObjectException(
JGitText.get().corruptObjectInvalidCommitter);
}
/**
@ -287,21 +294,26 @@ public void checkTag(final byte[] raw) throws CorruptObjectException {
int ptr = 0;
if ((ptr = match(raw, ptr, object)) < 0)
throw new CorruptObjectException("no object header");
throw new CorruptObjectException(
JGitText.get().corruptObjectNoObjectHeader);
if ((ptr = id(raw, ptr)) < 0 || raw[ptr++] != '\n')
throw new CorruptObjectException("invalid object");
throw new CorruptObjectException(
JGitText.get().corruptObjectInvalidObject);
if ((ptr = match(raw, ptr, type)) < 0)
throw new CorruptObjectException("no type header");
throw new CorruptObjectException(
JGitText.get().corruptObjectNoTypeHeader);
ptr = nextLF(raw, ptr);
if ((ptr = match(raw, ptr, tag)) < 0)
throw new CorruptObjectException("no tag header");
throw new CorruptObjectException(
JGitText.get().corruptObjectNoTagHeader);
ptr = nextLF(raw, ptr);
if ((ptr = match(raw, ptr, tagger)) > 0) {
if ((ptr = personIdent(raw, ptr)) < 0 || raw[ptr++] != '\n')
throw new CorruptObjectException("invalid tagger");
throw new CorruptObjectException(
JGitText.get().corruptObjectInvalidTagger);
}
}
@ -382,37 +394,46 @@ public void checkTree(final byte[] raw) throws CorruptObjectException {
int thisMode = 0;
for (;;) {
if (ptr == sz)
throw new CorruptObjectException("truncated in mode");
throw new CorruptObjectException(
JGitText.get().corruptObjectTruncatedInMode);
final byte c = raw[ptr++];
if (' ' == c)
break;
if (c < '0' || c > '7')
throw new CorruptObjectException("invalid mode character");
throw new CorruptObjectException(
JGitText.get().corruptObjectInvalidModeChar);
if (thisMode == 0 && c == '0' && !allowZeroMode)
throw new CorruptObjectException("mode starts with '0'");
throw new CorruptObjectException(
JGitText.get().corruptObjectInvalidModeStartsZero);
thisMode <<= 3;
thisMode += c - '0';
}
if (FileMode.fromBits(thisMode).getObjectType() == Constants.OBJ_BAD)
throw new CorruptObjectException("invalid mode " + thisMode);
throw new CorruptObjectException(MessageFormat.format(
JGitText.get().corruptObjectInvalidMode2,
Integer.valueOf(thisMode)));
final int thisNameB = ptr;
ptr = scanPathSegment(raw, ptr, sz);
if (ptr == sz || raw[ptr] != 0)
throw new CorruptObjectException("truncated in name");
throw new CorruptObjectException(
JGitText.get().corruptObjectTruncatedInName);
checkPathSegment2(raw, thisNameB, ptr);
if (normalized != null) {
if (!normalized.add(normalize(raw, thisNameB, ptr)))
throw new CorruptObjectException("duplicate entry names");
throw new CorruptObjectException(
JGitText.get().corruptObjectDuplicateEntryNames);
} else if (duplicateName(raw, thisNameB, ptr))
throw new CorruptObjectException("duplicate entry names");
throw new CorruptObjectException(
JGitText.get().corruptObjectDuplicateEntryNames);
if (lastNameB != 0) {
final int cmp = pathCompare(raw, lastNameB, lastNameE,
lastMode, thisNameB, ptr, thisMode);
if (cmp > 0)
throw new CorruptObjectException("incorrectly sorted");
throw new CorruptObjectException(
JGitText.get().corruptObjectIncorrectSorting);
}
lastNameB = thisNameB;
@ -421,7 +442,8 @@ public void checkTree(final byte[] raw) throws CorruptObjectException {
ptr += 1 + Constants.OBJECT_ID_LENGTH;
if (ptr > sz)
throw new CorruptObjectException("truncated in object id");
throw new CorruptObjectException(
JGitText.get().corruptObjectTruncatedInObjectId);
}
}
@ -432,13 +454,16 @@ private int scanPathSegment(byte[] raw, int ptr, int end)
if (c == 0)
return ptr;
if (c == '/')
throw new CorruptObjectException("name contains '/'");
throw new CorruptObjectException(
JGitText.get().corruptObjectNameContainsSlash);
if (windows && isInvalidOnWindows(c)) {
if (c > 31)
throw new CorruptObjectException(String.format(
"name contains '%c'", c));
JGitText.get().corruptObjectNameContainsChar,
Byte.valueOf(c)));
throw new CorruptObjectException(String.format(
"name contains byte 0x%x", c & 0xff));
JGitText.get().corruptObjectNameContainsByte,
Integer.valueOf(c & 0xff)));
}
}
return ptr;
@ -496,49 +521,55 @@ public void checkPathSegment(byte[] raw, int ptr, int end)
throws CorruptObjectException {
int e = scanPathSegment(raw, ptr, end);
if (e < end && raw[e] == 0)
throw new CorruptObjectException("name contains byte 0x00");
throw new CorruptObjectException(
JGitText.get().corruptObjectNameContainsNullByte);
checkPathSegment2(raw, ptr, end);
}
private void checkPathSegment2(byte[] raw, int ptr, int end)
throws CorruptObjectException {
if (ptr == end)
throw new CorruptObjectException("zero length name");
throw new CorruptObjectException(
JGitText.get().corruptObjectNameZeroLength);
if (raw[ptr] == '.') {
switch (end - ptr) {
case 1:
throw new CorruptObjectException("invalid name '.'");
throw new CorruptObjectException(
JGitText.get().corruptObjectNameDot);
case 2:
if (raw[ptr + 1] == '.')
throw new CorruptObjectException("invalid name '..'");
throw new CorruptObjectException(
JGitText.get().corruptObjectNameDotDot);
break;
case 4:
if (isGit(raw, ptr + 1))
throw new CorruptObjectException(String.format(
"invalid name '%s'",
JGitText.get().corruptObjectInvalidName,
RawParseUtils.decode(raw, ptr, end)));
break;
default:
if (end - ptr > 4 && isNormalizedGit(raw, ptr + 1, end))
throw new CorruptObjectException(String.format(
"invalid name '%s'",
JGitText.get().corruptObjectInvalidName,
RawParseUtils.decode(raw, ptr, end)));
}
} else if (isGitTilde1(raw, ptr, end)) {
throw new CorruptObjectException(String.format("invalid name '%s'",
throw new CorruptObjectException(String.format(
JGitText.get().corruptObjectInvalidName,
RawParseUtils.decode(raw, ptr, end)));
}
if (macosx && isMacHFSGit(raw, ptr, end))
throw new CorruptObjectException(String.format(
"invalid name '%s' contains ignorable Unicode characters",
JGitText.get().corruptObjectInvalidNameIgnorableUnicode,
RawParseUtils.decode(raw, ptr, end)));
if (windows) {
// Windows ignores space and dot at end of file name.
if (raw[end - 1] == ' ' || raw[end - 1] == '.')
throw new CorruptObjectException("invalid name ends with '"
+ ((char) raw[end - 1]) + "'");
throw new CorruptObjectException(String.format(
JGitText.get().corruptObjectInvalidNameEnd,
Character.valueOf(((char) raw[end - 1]))));
if (end - ptr >= 3)
checkNotWindowsDevice(raw, ptr, end);
}
@ -615,7 +646,7 @@ private static void checkTruncatedIgnorableUTF8(byte[] raw, int ptr, int end)
throws CorruptObjectException {
if ((ptr + 2) >= end)
throw new CorruptObjectException(MessageFormat.format(
"invalid name contains byte sequence ''{0}'' which is not a valid UTF-8 character",
JGitText.get().corruptObjectInvalidNameInvalidUtf8,
toHexString(raw, ptr, end)));
}
@ -634,7 +665,8 @@ private static void checkNotWindowsDevice(byte[] raw, int ptr, int end)
&& toLower(raw[ptr + 1]) == 'u'
&& toLower(raw[ptr + 2]) == 'x'
&& (end - ptr == 3 || raw[ptr + 3] == '.'))
throw new CorruptObjectException("invalid name 'AUX'");
throw new CorruptObjectException(
JGitText.get().corruptObjectInvalidNameAux);
break;
case 'c': // CON, COM[1-9]
@ -642,14 +674,16 @@ && toLower(raw[ptr + 2]) == 'x'
&& toLower(raw[ptr + 2]) == 'n'
&& toLower(raw[ptr + 1]) == 'o'
&& (end - ptr == 3 || raw[ptr + 3] == '.'))
throw new CorruptObjectException("invalid name 'CON'");
throw new CorruptObjectException(
JGitText.get().corruptObjectInvalidNameCon);
if (end - ptr >= 4
&& toLower(raw[ptr + 2]) == 'm'
&& toLower(raw[ptr + 1]) == 'o'
&& isPositiveDigit(raw[ptr + 3])
&& (end - ptr == 4 || raw[ptr + 4] == '.'))
throw new CorruptObjectException("invalid name 'COM"
+ ((char) raw[ptr + 3]) + "'");
throw new CorruptObjectException(String.format(
JGitText.get().corruptObjectInvalidNameCom,
Character.valueOf(((char) raw[ptr + 3]))));
break;
case 'l': // LPT[1-9]
@ -658,8 +692,9 @@ && toLower(raw[ptr + 1]) == 'p'
&& toLower(raw[ptr + 2]) == 't'
&& isPositiveDigit(raw[ptr + 3])
&& (end - ptr == 4 || raw[ptr + 4] == '.'))
throw new CorruptObjectException("invalid name 'LPT"
+ ((char) raw[ptr + 3]) + "'");
throw new CorruptObjectException(String.format(
JGitText.get().corruptObjectInvalidNameLpt,
Character.valueOf(((char) raw[ptr + 3]))));
break;
case 'n': // NUL
@ -667,7 +702,8 @@ && isPositiveDigit(raw[ptr + 3])
&& toLower(raw[ptr + 1]) == 'u'
&& toLower(raw[ptr + 2]) == 'l'
&& (end - ptr == 3 || raw[ptr + 3] == '.'))
throw new CorruptObjectException("invalid name 'NUL'");
throw new CorruptObjectException(
JGitText.get().corruptObjectInvalidNameNul);
break;
case 'p': // PRN
@ -675,7 +711,8 @@ && toLower(raw[ptr + 2]) == 'l'
&& toLower(raw[ptr + 1]) == 'r'
&& toLower(raw[ptr + 2]) == 'n'
&& (end - ptr == 3 || raw[ptr + 3] == '.'))
throw new CorruptObjectException("invalid name 'PRN'");
throw new CorruptObjectException(
JGitText.get().corruptObjectInvalidNamePrn);
break;
}
}

View File

@ -45,6 +45,7 @@
package org.eclipse.jgit.lib;
import org.eclipse.jgit.errors.InvalidObjectIdException;
import org.eclipse.jgit.internal.JGitText;
import org.eclipse.jgit.util.NB;
import org.eclipse.jgit.util.RawParseUtils;
@ -52,6 +53,7 @@
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.text.MessageFormat;
/**
* A SHA-1 abstraction.
@ -229,7 +231,8 @@ public static final ObjectId fromString(final byte[] buf, final int offset) {
*/
public static ObjectId fromString(final String str) {
if (str.length() != Constants.OBJECT_ID_STRING_LENGTH)
throw new IllegalArgumentException("Invalid id: " + str);
throw new IllegalArgumentException(
MessageFormat.format(JGitText.get().invalidId, str));
return fromHexString(Constants.encodeASCII(str), 0);
}

View File

@ -52,6 +52,7 @@
import java.io.InputStream;
import java.security.MessageDigest;
import org.eclipse.jgit.internal.JGitText;
import org.eclipse.jgit.transport.PackParser;
/**
@ -63,7 +64,7 @@
* <p>
* Objects written by an inserter may not be immediately visible for reading
* after the insert method completes. Callers must invoke either
* {@link #release()} or {@link #flush()} prior to updating references or
* {@link #close()} or {@link #flush()} prior to updating references or
* otherwise making the returned ObjectIds visible to other code.
*/
public abstract class ObjectInserter implements AutoCloseable {
@ -91,7 +92,7 @@ public void flush() throws IOException {
}
@Override
public void release() {
public void close() {
// Do nothing.
}
}
@ -149,8 +150,8 @@ public void flush() throws IOException {
delegate().flush();
}
public void release() {
delegate().release();
public void close() {
delegate().close();
}
}
@ -263,7 +264,7 @@ public ObjectId idFor(int objectType, long length, InputStream in)
while (length > 0) {
int n = in.read(buf, 0, (int) Math.min(length, buf.length));
if (n < 0)
throw new EOFException("Unexpected end of input");
throw new EOFException(JGitText.get().unexpectedEndOfInput);
md.update(buf, 0, n);
length -= n;
}
@ -416,15 +417,6 @@ public abstract ObjectId insert(int objectType, long length, InputStream in)
*/
public abstract void flush() throws IOException;
/**
* Release any resources used by this inserter.
* <p>
* An inserter that has been released can be used again, but may need to be
* released after the subsequent usage. Use {@link #close()} instead
*/
@Deprecated
public abstract void release();
/**
* Release any resources used by this inserter.
* <p>
@ -434,7 +426,5 @@ public abstract ObjectId insert(int objectType, long length, InputStream in)
* @since 4.0
*/
@Override
public void close() {
release();
}
public abstract void close();
}

Some files were not shown because too many files have changed in this diff Show More