@ -77,6 +77,8 @@ import org.eclipse.jgit.lib.RefUpdate.Result;
import org.eclipse.jgit.lib.Repository ;
import org.eclipse.jgit.lib.Repository ;
import org.eclipse.jgit.lib.RepositoryState ;
import org.eclipse.jgit.lib.RepositoryState ;
import org.eclipse.jgit.revwalk.RevCommit ;
import org.eclipse.jgit.revwalk.RevCommit ;
import org.eclipse.jgit.revwalk.RevObject ;
import org.eclipse.jgit.revwalk.RevTag ;
import org.eclipse.jgit.revwalk.RevWalk ;
import org.eclipse.jgit.revwalk.RevWalk ;
import org.eclipse.jgit.treewalk.CanonicalTreeParser ;
import org.eclipse.jgit.treewalk.CanonicalTreeParser ;
import org.eclipse.jgit.treewalk.FileTreeIterator ;
import org.eclipse.jgit.treewalk.FileTreeIterator ;
@ -150,13 +152,16 @@ public class CommitCommand extends GitCommand<RevCommit> {
checkCallable ( ) ;
checkCallable ( ) ;
Collections . sort ( only ) ;
Collections . sort ( only ) ;
RevWalk rw = new RevWalk ( repo ) ;
try {
RepositoryState state = repo . getRepositoryState ( ) ;
RepositoryState state = repo . getRepositoryState ( ) ;
if ( ! state . canCommit ( ) )
if ( ! state . canCommit ( ) )
throw new WrongRepositoryStateException ( MessageFormat . format (
throw new WrongRepositoryStateException ( MessageFormat . format (
JGitText . get ( ) . cannotCommitOnARepoWithState , state . name ( ) ) ) ;
JGitText . get ( ) . cannotCommitOnARepoWithState ,
processOptions ( state ) ;
state . name ( ) ) ) ;
processOptions ( state , rw ) ;
try {
if ( all & & ! repo . isBare ( ) & & repo . getWorkTree ( ) ! = null ) {
if ( all & & ! repo . isBare ( ) & & repo . getWorkTree ( ) ! = null ) {
Git git = new Git ( repo ) ;
Git git = new Git ( repo ) ;
try {
try {
@ -182,8 +187,7 @@ public class CommitCommand extends GitCommand<RevCommit> {
if ( headId ! = null )
if ( headId ! = null )
if ( amend ) {
if ( amend ) {
RevCommit previousCommit = new RevWalk ( repo )
RevCommit previousCommit = rw . parseCommit ( headId ) ;
. parseCommit ( headId ) ;
for ( RevCommit p : previousCommit . getParents ( ) )
for ( RevCommit p : previousCommit . getParents ( ) )
parents . add ( p . getId ( ) ) ;
parents . add ( p . getId ( ) ) ;
if ( author = = null )
if ( author = = null )
@ -196,7 +200,7 @@ public class CommitCommand extends GitCommand<RevCommit> {
DirCache index = repo . lockDirCache ( ) ;
DirCache index = repo . lockDirCache ( ) ;
try {
try {
if ( ! only . isEmpty ( ) )
if ( ! only . isEmpty ( ) )
index = createTemporaryIndex ( headId , index ) ;
index = createTemporaryIndex ( headId , index , rw ) ;
ObjectInserter odi = repo . newObjectInserter ( ) ;
ObjectInserter odi = repo . newObjectInserter ( ) ;
try {
try {
@ -219,9 +223,7 @@ public class CommitCommand extends GitCommand<RevCommit> {
ObjectId commitId = odi . insert ( commit ) ;
ObjectId commitId = odi . insert ( commit ) ;
odi . flush ( ) ;
odi . flush ( ) ;
RevWalk revWalk = new RevWalk ( repo ) ;
RevCommit revCommit = rw . parseCommit ( commitId ) ;
try {
RevCommit revCommit = revWalk . parseCommit ( commitId ) ;
RefUpdate ru = repo . updateRef ( Constants . HEAD ) ;
RefUpdate ru = repo . updateRef ( Constants . HEAD ) ;
ru . setNewObjectId ( commitId ) ;
ru . setNewObjectId ( commitId ) ;
if ( reflogComment ! = null ) {
if ( reflogComment ! = null ) {
@ -259,16 +261,13 @@ public class CommitCommand extends GitCommand<RevCommit> {
}
}
case REJECTED :
case REJECTED :
case LOCK_FAILURE :
case LOCK_FAILURE :
throw new ConcurrentRefUpdateException ( JGitText
throw new ConcurrentRefUpdateException (
. get ( ) . couldNotLockHEAD , ru . getRef ( ) , rc ) ;
JGitText . get ( ) . couldNotLockHEAD , ru . getRef ( ) ,
rc ) ;
default :
default :
throw new JGitInternalException ( MessageFormat
throw new JGitInternalException ( MessageFormat . format (
. format ( JGitText . get ( ) . updatingRefFailed ,
JGitText . get ( ) . updatingRefFailed ,
Constants . HEAD ,
Constants . HEAD , commitId . toString ( ) , rc ) ) ;
commitId . toString ( ) , rc ) ) ;
}
} finally {
revWalk . release ( ) ;
}
}
} finally {
} finally {
odi . release ( ) ;
odi . release ( ) ;
@ -281,6 +280,8 @@ public class CommitCommand extends GitCommand<RevCommit> {
} catch ( IOException e ) {
} catch ( IOException e ) {
throw new JGitInternalException (
throw new JGitInternalException (
JGitText . get ( ) . exceptionCaughtDuringExecutionOfCommitCommand , e ) ;
JGitText . get ( ) . exceptionCaughtDuringExecutionOfCommitCommand , e ) ;
} finally {
rw . dispose ( ) ;
}
}
}
}
@ -297,7 +298,8 @@ public class CommitCommand extends GitCommand<RevCommit> {
+ changeId . getName ( ) + "\n" ) ; //$NON-NLS-1$
+ changeId . getName ( ) + "\n" ) ; //$NON-NLS-1$
}
}
private DirCache createTemporaryIndex ( ObjectId headId , DirCache index )
private DirCache createTemporaryIndex ( ObjectId headId , DirCache index ,
RevWalk rw )
throws IOException {
throws IOException {
ObjectInserter inserter = null ;
ObjectInserter inserter = null ;
@ -317,7 +319,7 @@ public class CommitCommand extends GitCommand<RevCommit> {
int fIdx = treeWalk . addTree ( new FileTreeIterator ( repo ) ) ;
int fIdx = treeWalk . addTree ( new FileTreeIterator ( repo ) ) ;
int hIdx = - 1 ;
int hIdx = - 1 ;
if ( headId ! = null )
if ( headId ! = null )
hIdx = treeWalk . addTree ( new RevWalk ( repo ) . parseTree ( headId ) ) ;
hIdx = treeWalk . addTree ( rw . parseTree ( headId ) ) ;
treeWalk . setRecursive ( true ) ;
treeWalk . setRecursive ( true ) ;
String lastAddedFile = null ;
String lastAddedFile = null ;
@ -473,11 +475,14 @@ public class CommitCommand extends GitCommand<RevCommit> {
*
*
* @param state
* @param state
* the state of the repository we are working on
* the state of the repository we are working on
* @param rw
* the RevWalk to use
*
*
* @throws NoMessageException
* @throws NoMessageException
* if the commit message has not been specified
* if the commit message has not been specified
* /
* /
private void processOptions ( RepositoryState state ) throws NoMessageException {
private void processOptions ( RepositoryState state , RevWalk rw )
throws NoMessageException {
if ( committer = = null )
if ( committer = = null )
committer = new PersonIdent ( repo ) ;
committer = new PersonIdent ( repo ) ;
if ( author = = null & & ! amend )
if ( author = = null & & ! amend )
@ -487,6 +492,12 @@ public class CommitCommand extends GitCommand<RevCommit> {
if ( state = = RepositoryState . MERGING_RESOLVED ) {
if ( state = = RepositoryState . MERGING_RESOLVED ) {
try {
try {
parents = repo . readMergeHeads ( ) ;
parents = repo . readMergeHeads ( ) ;
if ( parents ! = null )
for ( int i = 0 ; i < parents . size ( ) ; i + + ) {
RevObject ro = rw . parseAny ( parents . get ( i ) ) ;
if ( ro instanceof RevTag )
parents . set ( i , rw . peel ( ro ) ) ;
}
} catch ( IOException e ) {
} catch ( IOException e ) {
throw new JGitInternalException ( MessageFormat . format (
throw new JGitInternalException ( MessageFormat . format (
JGitText . get ( ) . exceptionOccurredDuringReadingOfGIT_DIR ,
JGitText . get ( ) . exceptionOccurredDuringReadingOfGIT_DIR ,