Change-Id: I8ced7098da5b345fd9af2fdfafd1ef6a44ccee0dtags/v3.0.0.201305080800-m7
import org.eclipse.jgit.errors.TransportException; | import org.eclipse.jgit.errors.TransportException; | ||||
import org.eclipse.jgit.http.server.GitServlet; | import org.eclipse.jgit.http.server.GitServlet; | ||||
import org.eclipse.jgit.internal.JGitText; | import org.eclipse.jgit.internal.JGitText; | ||||
import org.eclipse.jgit.internal.storage.file.ReflogEntry; | |||||
import org.eclipse.jgit.internal.storage.file.ReflogReader; | |||||
import org.eclipse.jgit.junit.TestRepository; | import org.eclipse.jgit.junit.TestRepository; | ||||
import org.eclipse.jgit.junit.TestRng; | import org.eclipse.jgit.junit.TestRng; | ||||
import org.eclipse.jgit.junit.http.AccessEvent; | import org.eclipse.jgit.junit.http.AccessEvent; | ||||
import org.eclipse.jgit.lib.NullProgressMonitor; | import org.eclipse.jgit.lib.NullProgressMonitor; | ||||
import org.eclipse.jgit.lib.ObjectId; | import org.eclipse.jgit.lib.ObjectId; | ||||
import org.eclipse.jgit.lib.Ref; | import org.eclipse.jgit.lib.Ref; | ||||
import org.eclipse.jgit.lib.ReflogEntry; | |||||
import org.eclipse.jgit.lib.ReflogReader; | |||||
import org.eclipse.jgit.lib.Repository; | import org.eclipse.jgit.lib.Repository; | ||||
import org.eclipse.jgit.lib.StoredConfig; | import org.eclipse.jgit.lib.StoredConfig; | ||||
import org.eclipse.jgit.revwalk.RevBlob; | import org.eclipse.jgit.revwalk.RevBlob; |
import org.eclipse.jgit.api.Git; | import org.eclipse.jgit.api.Git; | ||||
import org.eclipse.jgit.api.ReflogCommand; | import org.eclipse.jgit.api.ReflogCommand; | ||||
import org.eclipse.jgit.internal.storage.file.ReflogEntry; | |||||
import org.eclipse.jgit.lib.Constants; | import org.eclipse.jgit.lib.Constants; | ||||
import org.eclipse.jgit.lib.ReflogEntry; | |||||
import org.eclipse.jgit.lib.Repository; | import org.eclipse.jgit.lib.Repository; | ||||
import org.kohsuke.args4j.Argument; | import org.kohsuke.args4j.Argument; | ||||
import org.eclipse.jgit.api.errors.GitAPIException; | import org.eclipse.jgit.api.errors.GitAPIException; | ||||
import org.eclipse.jgit.api.errors.JGitInternalException; | import org.eclipse.jgit.api.errors.JGitInternalException; | ||||
import org.eclipse.jgit.dircache.DirCache; | import org.eclipse.jgit.dircache.DirCache; | ||||
import org.eclipse.jgit.internal.storage.file.ReflogReader; | |||||
import org.eclipse.jgit.junit.RepositoryTestCase; | import org.eclipse.jgit.junit.RepositoryTestCase; | ||||
import org.eclipse.jgit.lib.ConfigConstants; | import org.eclipse.jgit.lib.ConfigConstants; | ||||
import org.eclipse.jgit.lib.Constants; | import org.eclipse.jgit.lib.Constants; | ||||
import org.eclipse.jgit.lib.FileMode; | import org.eclipse.jgit.lib.FileMode; | ||||
import org.eclipse.jgit.lib.ReflogReader; | |||||
import org.eclipse.jgit.lib.RepositoryState; | import org.eclipse.jgit.lib.RepositoryState; | ||||
import org.eclipse.jgit.merge.ResolveMerger.MergeFailureReason; | import org.eclipse.jgit.merge.ResolveMerger.MergeFailureReason; | ||||
import org.eclipse.jgit.revwalk.RevCommit; | import org.eclipse.jgit.revwalk.RevCommit; |
import org.eclipse.jgit.api.errors.NoMessageException; | import org.eclipse.jgit.api.errors.NoMessageException; | ||||
import org.eclipse.jgit.errors.IncorrectObjectTypeException; | import org.eclipse.jgit.errors.IncorrectObjectTypeException; | ||||
import org.eclipse.jgit.errors.MissingObjectException; | import org.eclipse.jgit.errors.MissingObjectException; | ||||
import org.eclipse.jgit.internal.storage.file.ReflogReader; | |||||
import org.eclipse.jgit.junit.RepositoryTestCase; | import org.eclipse.jgit.junit.RepositoryTestCase; | ||||
import org.eclipse.jgit.lib.Constants; | import org.eclipse.jgit.lib.Constants; | ||||
import org.eclipse.jgit.lib.ObjectId; | import org.eclipse.jgit.lib.ObjectId; | ||||
import org.eclipse.jgit.lib.PersonIdent; | import org.eclipse.jgit.lib.PersonIdent; | ||||
import org.eclipse.jgit.lib.RefUpdate; | import org.eclipse.jgit.lib.RefUpdate; | ||||
import org.eclipse.jgit.lib.ReflogReader; | |||||
import org.eclipse.jgit.revwalk.RevCommit; | import org.eclipse.jgit.revwalk.RevCommit; | ||||
import org.eclipse.jgit.treewalk.TreeWalk; | import org.eclipse.jgit.treewalk.TreeWalk; | ||||
import org.eclipse.jgit.util.FS; | import org.eclipse.jgit.util.FS; |
import java.util.Collection; | import java.util.Collection; | ||||
import org.eclipse.jgit.internal.storage.file.ReflogEntry; | |||||
import org.eclipse.jgit.junit.RepositoryTestCase; | import org.eclipse.jgit.junit.RepositoryTestCase; | ||||
import org.eclipse.jgit.lib.Constants; | import org.eclipse.jgit.lib.Constants; | ||||
import org.eclipse.jgit.lib.ObjectId; | import org.eclipse.jgit.lib.ObjectId; | ||||
import org.eclipse.jgit.lib.ReflogEntry; | |||||
import org.eclipse.jgit.revwalk.RevCommit; | import org.eclipse.jgit.revwalk.RevCommit; | ||||
import org.junit.Before; | import org.junit.Before; | ||||
import org.junit.Test; | import org.junit.Test; |
import org.eclipse.jgit.api.errors.GitAPIException; | import org.eclipse.jgit.api.errors.GitAPIException; | ||||
import org.eclipse.jgit.api.errors.JGitInternalException; | import org.eclipse.jgit.api.errors.JGitInternalException; | ||||
import org.eclipse.jgit.dircache.DirCache; | import org.eclipse.jgit.dircache.DirCache; | ||||
import org.eclipse.jgit.internal.storage.file.ReflogReader; | |||||
import org.eclipse.jgit.junit.RepositoryTestCase; | import org.eclipse.jgit.junit.RepositoryTestCase; | ||||
import org.eclipse.jgit.lib.ConfigConstants; | import org.eclipse.jgit.lib.ConfigConstants; | ||||
import org.eclipse.jgit.lib.Constants; | import org.eclipse.jgit.lib.Constants; | ||||
import org.eclipse.jgit.lib.FileMode; | import org.eclipse.jgit.lib.FileMode; | ||||
import org.eclipse.jgit.lib.ReflogReader; | |||||
import org.eclipse.jgit.lib.RepositoryState; | import org.eclipse.jgit.lib.RepositoryState; | ||||
import org.eclipse.jgit.merge.ResolveMerger.MergeFailureReason; | import org.eclipse.jgit.merge.ResolveMerger.MergeFailureReason; | ||||
import org.eclipse.jgit.revwalk.RevCommit; | import org.eclipse.jgit.revwalk.RevCommit; |
import org.eclipse.jgit.api.errors.UnmergedPathsException; | import org.eclipse.jgit.api.errors.UnmergedPathsException; | ||||
import org.eclipse.jgit.diff.DiffEntry; | import org.eclipse.jgit.diff.DiffEntry; | ||||
import org.eclipse.jgit.internal.storage.file.ReflogEntry; | |||||
import org.eclipse.jgit.internal.storage.file.ReflogReader; | |||||
import org.eclipse.jgit.junit.RepositoryTestCase; | import org.eclipse.jgit.junit.RepositoryTestCase; | ||||
import org.eclipse.jgit.lib.Constants; | import org.eclipse.jgit.lib.Constants; | ||||
import org.eclipse.jgit.lib.ObjectId; | import org.eclipse.jgit.lib.ObjectId; | ||||
import org.eclipse.jgit.lib.PersonIdent; | import org.eclipse.jgit.lib.PersonIdent; | ||||
import org.eclipse.jgit.lib.Ref; | import org.eclipse.jgit.lib.Ref; | ||||
import org.eclipse.jgit.lib.ReflogEntry; | |||||
import org.eclipse.jgit.lib.ReflogReader; | |||||
import org.eclipse.jgit.revwalk.RevCommit; | import org.eclipse.jgit.revwalk.RevCommit; | ||||
import org.eclipse.jgit.revwalk.RevWalk; | import org.eclipse.jgit.revwalk.RevWalk; | ||||
import org.eclipse.jgit.treewalk.TreeWalk; | import org.eclipse.jgit.treewalk.TreeWalk; | ||||
assertEquals("content", read(committedFile)); | assertEquals("content", read(committedFile)); | ||||
validateStashedCommit(stashed); | validateStashedCommit(stashed); | ||||
ReflogReader reader = new ReflogReader(git.getRepository(), | |||||
ReflogReader reader = git.getRepository().getReflogReader( | |||||
Constants.R_STASH); | Constants.R_STASH); | ||||
ReflogEntry entry = reader.getLastEntry(); | ReflogEntry entry = reader.getLastEntry(); | ||||
assertNotNull(entry); | assertNotNull(entry); |
import java.util.List; | import java.util.List; | ||||
import org.eclipse.jgit.api.errors.JGitInternalException; | import org.eclipse.jgit.api.errors.JGitInternalException; | ||||
import org.eclipse.jgit.internal.storage.file.ReflogEntry; | |||||
import org.eclipse.jgit.internal.storage.file.ReflogReader; | |||||
import org.eclipse.jgit.junit.RepositoryTestCase; | import org.eclipse.jgit.junit.RepositoryTestCase; | ||||
import org.eclipse.jgit.lib.Constants; | import org.eclipse.jgit.lib.Constants; | ||||
import org.eclipse.jgit.lib.ObjectId; | import org.eclipse.jgit.lib.ObjectId; | ||||
import org.eclipse.jgit.lib.Ref; | import org.eclipse.jgit.lib.Ref; | ||||
import org.eclipse.jgit.lib.ReflogEntry; | |||||
import org.eclipse.jgit.lib.ReflogReader; | |||||
import org.eclipse.jgit.revwalk.RevCommit; | import org.eclipse.jgit.revwalk.RevCommit; | ||||
import org.junit.Before; | import org.junit.Before; | ||||
import org.junit.Test; | import org.junit.Test; | ||||
stashRef = git.getRepository().getRef(Constants.R_STASH); | stashRef = git.getRepository().getRef(Constants.R_STASH); | ||||
assertNull(stashRef); | assertNull(stashRef); | ||||
ReflogReader reader = new ReflogReader(git.getRepository(), | |||||
ReflogReader reader = git.getRepository().getReflogReader( | |||||
Constants.R_STASH); | Constants.R_STASH); | ||||
assertTrue(reader.getReverseEntries().isEmpty()); | |||||
assertNull(reader); | |||||
} | } | ||||
@Test | @Test | ||||
assertNull(git.stashDrop().setAll(true).call()); | assertNull(git.stashDrop().setAll(true).call()); | ||||
assertNull(git.getRepository().getRef(Constants.R_STASH)); | assertNull(git.getRepository().getRef(Constants.R_STASH)); | ||||
ReflogReader reader = new ReflogReader(git.getRepository(), | |||||
ReflogReader reader = git.getRepository().getReflogReader( | |||||
Constants.R_STASH); | Constants.R_STASH); | ||||
assertTrue(reader.getReverseEntries().isEmpty()); | |||||
assertNull(reader); | |||||
} | } | ||||
@Test | @Test | ||||
assertNotNull(stashRef); | assertNotNull(stashRef); | ||||
assertEquals(firstStash, stashRef.getObjectId()); | assertEquals(firstStash, stashRef.getObjectId()); | ||||
ReflogReader reader = new ReflogReader(git.getRepository(), | |||||
ReflogReader reader = git.getRepository().getReflogReader( | |||||
Constants.R_STASH); | Constants.R_STASH); | ||||
List<ReflogEntry> entries = reader.getReverseEntries(); | List<ReflogEntry> entries = reader.getReverseEntries(); | ||||
assertEquals(1, entries.size()); | assertEquals(1, entries.size()); | ||||
assertNotNull(stashRef); | assertNotNull(stashRef); | ||||
assertEquals(thirdStash, stashRef.getObjectId()); | assertEquals(thirdStash, stashRef.getObjectId()); | ||||
ReflogReader reader = new ReflogReader(git.getRepository(), | |||||
ReflogReader reader = git.getRepository().getReflogReader( | |||||
Constants.R_STASH); | Constants.R_STASH); | ||||
List<ReflogEntry> entries = reader.getReverseEntries(); | List<ReflogEntry> entries = reader.getReverseEntries(); | ||||
assertEquals(2, entries.size()); | assertEquals(2, entries.size()); | ||||
assertNotNull(stashRef); | assertNotNull(stashRef); | ||||
assertEquals(thirdStash, stashRef.getObjectId()); | assertEquals(thirdStash, stashRef.getObjectId()); | ||||
ReflogReader reader = new ReflogReader(git.getRepository(), | |||||
ReflogReader reader = git.getRepository().getReflogReader( | |||||
Constants.R_STASH); | Constants.R_STASH); | ||||
List<ReflogEntry> entries = reader.getReverseEntries(); | List<ReflogEntry> entries = reader.getReverseEntries(); | ||||
assertEquals(2, entries.size()); | assertEquals(2, entries.size()); |
import java.util.Map; | import java.util.Map; | ||||
import java.util.Map.Entry; | import java.util.Map.Entry; | ||||
import org.eclipse.jgit.internal.storage.file.FileRepository; | |||||
import org.eclipse.jgit.internal.storage.file.LockFile; | |||||
import org.eclipse.jgit.internal.storage.file.RefDirectory; | |||||
import org.eclipse.jgit.internal.storage.file.RefDirectoryUpdate; | |||||
import org.eclipse.jgit.internal.storage.file.ReflogReader; | |||||
import org.eclipse.jgit.junit.SampleDataRepositoryTestCase; | import org.eclipse.jgit.junit.SampleDataRepositoryTestCase; | ||||
import org.eclipse.jgit.lib.AnyObjectId; | import org.eclipse.jgit.lib.AnyObjectId; | ||||
import org.eclipse.jgit.lib.Constants; | import org.eclipse.jgit.lib.Constants; | ||||
import org.eclipse.jgit.lib.RefRename; | import org.eclipse.jgit.lib.RefRename; | ||||
import org.eclipse.jgit.lib.RefUpdate; | import org.eclipse.jgit.lib.RefUpdate; | ||||
import org.eclipse.jgit.lib.RefUpdate.Result; | import org.eclipse.jgit.lib.RefUpdate.Result; | ||||
import org.eclipse.jgit.lib.ReflogEntry; | |||||
import org.eclipse.jgit.lib.ReflogReader; | |||||
import org.eclipse.jgit.lib.Repository; | import org.eclipse.jgit.lib.Repository; | ||||
import org.eclipse.jgit.revwalk.RevCommit; | import org.eclipse.jgit.revwalk.RevCommit; | ||||
import org.eclipse.jgit.revwalk.RevWalk; | import org.eclipse.jgit.revwalk.RevWalk; | ||||
assertNotSame(newid, r.getObjectId()); | assertNotSame(newid, r.getObjectId()); | ||||
assertSame(ObjectId.class, r.getObjectId().getClass()); | assertSame(ObjectId.class, r.getObjectId().getClass()); | ||||
assertEquals(newid, r.getObjectId()); | assertEquals(newid, r.getObjectId()); | ||||
List<org.eclipse.jgit.internal.storage.file.ReflogEntry> reverseEntries1 = db.getReflogReader("refs/heads/abc").getReverseEntries(); | |||||
org.eclipse.jgit.internal.storage.file.ReflogEntry entry1 = reverseEntries1.get(0); | |||||
List<ReflogEntry> reverseEntries1 = db | |||||
.getReflogReader("refs/heads/abc").getReverseEntries(); | |||||
ReflogEntry entry1 = reverseEntries1.get(0); | |||||
assertEquals(1, reverseEntries1.size()); | assertEquals(1, reverseEntries1.size()); | ||||
assertEquals(ObjectId.zeroId(), entry1.getOldId()); | assertEquals(ObjectId.zeroId(), entry1.getOldId()); | ||||
assertEquals(r.getObjectId(), entry1.getNewId()); | assertEquals(r.getObjectId(), entry1.getNewId()); | ||||
assertEquals(new PersonIdent(db).toString(), entry1.getWho().toString()); | assertEquals(new PersonIdent(db).toString(), entry1.getWho().toString()); | ||||
assertEquals("", entry1.getComment()); | assertEquals("", entry1.getComment()); | ||||
List<org.eclipse.jgit.internal.storage.file.ReflogEntry> reverseEntries2 = db.getReflogReader("HEAD").getReverseEntries(); | |||||
List<ReflogEntry> reverseEntries2 = db.getReflogReader("HEAD") | |||||
.getReverseEntries(); | |||||
assertEquals(0, reverseEntries2.size()); | assertEquals(0, reverseEntries2.size()); | ||||
} | } | ||||
// the branch HEAD referred to is left untouched | // the branch HEAD referred to is left untouched | ||||
assertEquals(pid, db.resolve("refs/heads/master")); | assertEquals(pid, db.resolve("refs/heads/master")); | ||||
ReflogReader reflogReader = new ReflogReader(db, "HEAD"); | |||||
org.eclipse.jgit.internal.storage.file.ReflogEntry e = reflogReader.getReverseEntries().get(0); | |||||
ReflogReader reflogReader = db.getReflogReader("HEAD"); | |||||
ReflogEntry e = reflogReader.getReverseEntries().get(0); | |||||
assertEquals(pid, e.getOldId()); | assertEquals(pid, e.getOldId()); | ||||
assertEquals(ppid, e.getNewId()); | assertEquals(ppid, e.getNewId()); | ||||
assertEquals("GIT_COMMITTER_EMAIL", e.getWho().getEmailAddress()); | assertEquals("GIT_COMMITTER_EMAIL", e.getWho().getEmailAddress()); | ||||
// the branch HEAD referred to is left untouched | // the branch HEAD referred to is left untouched | ||||
assertNull(db.resolve("refs/heads/unborn")); | assertNull(db.resolve("refs/heads/unborn")); | ||||
ReflogReader reflogReader = new ReflogReader(db, "HEAD"); | |||||
org.eclipse.jgit.internal.storage.file.ReflogEntry e = reflogReader.getReverseEntries().get(0); | |||||
ReflogReader reflogReader = db.getReflogReader("HEAD"); | |||||
ReflogEntry e = reflogReader.getReverseEntries().get(0); | |||||
assertEquals(ObjectId.zeroId(), e.getOldId()); | assertEquals(ObjectId.zeroId(), e.getOldId()); | ||||
assertEquals(ppid, e.getNewId()); | assertEquals(ppid, e.getNewId()); | ||||
assertEquals("GIT_COMMITTER_EMAIL", e.getWho().getEmailAddress()); | assertEquals("GIT_COMMITTER_EMAIL", e.getWho().getEmailAddress()); | ||||
ObjectId oldfromId = db.resolve(fromName); | ObjectId oldfromId = db.resolve(fromName); | ||||
ObjectId oldHeadId = db.resolve(Constants.HEAD); | ObjectId oldHeadId = db.resolve(Constants.HEAD); | ||||
writeReflog(db, oldfromId, "Just a message", fromName); | writeReflog(db, oldfromId, "Just a message", fromName); | ||||
List<org.eclipse.jgit.internal.storage.file.ReflogEntry> oldFromLog = db | |||||
List<ReflogEntry> oldFromLog = db | |||||
.getReflogReader(fromName).getReverseEntries(); | .getReflogReader(fromName).getReverseEntries(); | ||||
List<org.eclipse.jgit.internal.storage.file.ReflogEntry> oldHeadLog = oldHeadId != null ? db | |||||
List<ReflogEntry> oldHeadLog = oldHeadId != null ? db | |||||
.getReflogReader(Constants.HEAD).getReverseEntries() : null; | .getReflogReader(Constants.HEAD).getReverseEntries() : null; | ||||
assertTrue("internal check, we have a log", new File(db.getDirectory(), | assertTrue("internal check, we have a log", new File(db.getDirectory(), |
import java.text.SimpleDateFormat; | import java.text.SimpleDateFormat; | ||||
import java.util.List; | import java.util.List; | ||||
import org.eclipse.jgit.internal.storage.file.CheckoutEntry; | |||||
import org.eclipse.jgit.internal.storage.file.ReflogEntry; | |||||
import org.eclipse.jgit.internal.storage.file.ReflogReader; | |||||
import org.eclipse.jgit.junit.SampleDataRepositoryTestCase; | import org.eclipse.jgit.junit.SampleDataRepositoryTestCase; | ||||
import org.eclipse.jgit.lib.CheckoutEntry; | |||||
import org.eclipse.jgit.lib.Constants; | import org.eclipse.jgit.lib.Constants; | ||||
import org.eclipse.jgit.lib.ObjectId; | import org.eclipse.jgit.lib.ObjectId; | ||||
import org.eclipse.jgit.lib.PersonIdent; | import org.eclipse.jgit.lib.PersonIdent; | ||||
import org.eclipse.jgit.lib.ReflogEntry; | |||||
import org.eclipse.jgit.lib.ReflogReader; | |||||
import org.junit.Test; | import org.junit.Test; | ||||
public class ReflogReaderTest extends SampleDataRepositoryTestCase { | public class ReflogReaderTest extends SampleDataRepositoryTestCase { | ||||
public void testReadOneLine() throws Exception { | public void testReadOneLine() throws Exception { | ||||
setupReflog("logs/refs/heads/master", oneLine); | setupReflog("logs/refs/heads/master", oneLine); | ||||
ReflogReader reader = new ReflogReader(db, "refs/heads/master"); | |||||
ReflogReader reader = new ReflogReaderImpl(db, "refs/heads/master"); | |||||
ReflogEntry e = reader.getLastEntry(); | ReflogEntry e = reader.getLastEntry(); | ||||
assertEquals(ObjectId | assertEquals(ObjectId | ||||
.fromString("da85355dfc525c9f6f3927b876f379f46ccf826e"), e | .fromString("da85355dfc525c9f6f3927b876f379f46ccf826e"), e | ||||
public void testReadTwoLine() throws Exception { | public void testReadTwoLine() throws Exception { | ||||
setupReflog("logs/refs/heads/master", twoLine); | setupReflog("logs/refs/heads/master", twoLine); | ||||
ReflogReader reader = new ReflogReader(db, "refs/heads/master"); | |||||
ReflogReader reader = new ReflogReaderImpl(db, "refs/heads/master"); | |||||
List<ReflogEntry> reverseEntries = reader.getReverseEntries(); | List<ReflogEntry> reverseEntries = reader.getReverseEntries(); | ||||
assertEquals(2, reverseEntries.size()); | assertEquals(2, reverseEntries.size()); | ||||
ReflogEntry e = reverseEntries.get(0); | ReflogEntry e = reverseEntries.get(0); | ||||
@Test | @Test | ||||
public void testReadWhileAppendIsInProgress() throws Exception { | public void testReadWhileAppendIsInProgress() throws Exception { | ||||
setupReflog("logs/refs/heads/master", twoLineWithAppendInProgress); | setupReflog("logs/refs/heads/master", twoLineWithAppendInProgress); | ||||
ReflogReader reader = new ReflogReader(db, "refs/heads/master"); | |||||
ReflogReader reader = new ReflogReaderImpl(db, "refs/heads/master"); | |||||
List<ReflogEntry> reverseEntries = reader.getReverseEntries(); | List<ReflogEntry> reverseEntries = reader.getReverseEntries(); | ||||
assertEquals(2, reverseEntries.size()); | assertEquals(2, reverseEntries.size()); | ||||
ReflogEntry e = reverseEntries.get(0); | ReflogEntry e = reverseEntries.get(0); | ||||
public void testSpecificEntryNumber() throws Exception { | public void testSpecificEntryNumber() throws Exception { | ||||
setupReflog("logs/refs/heads/master", twoLine); | setupReflog("logs/refs/heads/master", twoLine); | ||||
ReflogReader reader = new ReflogReader(db, "refs/heads/master"); | |||||
ReflogReader reader = new ReflogReaderImpl(db, "refs/heads/master"); | |||||
ReflogEntry e = reader.getReverseEntry(0); | ReflogEntry e = reader.getReverseEntry(0); | ||||
assertEquals( | assertEquals( | ||||
ObjectId.fromString("c6734895958052a9dbc396cff4459dc1a25029ab"), | ObjectId.fromString("c6734895958052a9dbc396cff4459dc1a25029ab"), |
import org.eclipse.jgit.api.errors.GitAPIException; | import org.eclipse.jgit.api.errors.GitAPIException; | ||||
import org.eclipse.jgit.api.errors.InvalidRefNameException; | import org.eclipse.jgit.api.errors.InvalidRefNameException; | ||||
import org.eclipse.jgit.internal.JGitText; | import org.eclipse.jgit.internal.JGitText; | ||||
import org.eclipse.jgit.internal.storage.file.ReflogEntry; | |||||
import org.eclipse.jgit.internal.storage.file.ReflogReader; | |||||
import org.eclipse.jgit.lib.Constants; | import org.eclipse.jgit.lib.Constants; | ||||
import org.eclipse.jgit.lib.ReflogEntry; | |||||
import org.eclipse.jgit.lib.ReflogReader; | |||||
import org.eclipse.jgit.lib.Repository; | import org.eclipse.jgit.lib.Repository; | ||||
/** | /** | ||||
checkCallable(); | checkCallable(); | ||||
try { | try { | ||||
ReflogReader reader = new ReflogReader(repo, ref); | |||||
ReflogReader reader = repo.getReflogReader(ref); | |||||
return reader.getReverseEntries(); | return reader.getReverseEntries(); | ||||
} catch (IOException e) { | } catch (IOException e) { | ||||
throw new InvalidRefNameException(MessageFormat.format( | throw new InvalidRefNameException(MessageFormat.format( |
import org.eclipse.jgit.api.errors.JGitInternalException; | import org.eclipse.jgit.api.errors.JGitInternalException; | ||||
import org.eclipse.jgit.errors.LockFailedException; | import org.eclipse.jgit.errors.LockFailedException; | ||||
import org.eclipse.jgit.internal.JGitText; | import org.eclipse.jgit.internal.JGitText; | ||||
import org.eclipse.jgit.internal.storage.file.ReflogEntry; | |||||
import org.eclipse.jgit.internal.storage.file.ReflogReader; | |||||
import org.eclipse.jgit.internal.storage.file.ReflogWriter; | import org.eclipse.jgit.internal.storage.file.ReflogWriter; | ||||
import org.eclipse.jgit.lib.ObjectId; | import org.eclipse.jgit.lib.ObjectId; | ||||
import org.eclipse.jgit.lib.Ref; | import org.eclipse.jgit.lib.Ref; | ||||
import org.eclipse.jgit.lib.RefUpdate; | import org.eclipse.jgit.lib.RefUpdate; | ||||
import org.eclipse.jgit.lib.RefUpdate.Result; | import org.eclipse.jgit.lib.RefUpdate.Result; | ||||
import org.eclipse.jgit.lib.ReflogEntry; | |||||
import org.eclipse.jgit.lib.ReflogReader; | |||||
import org.eclipse.jgit.lib.Repository; | import org.eclipse.jgit.lib.Repository; | ||||
import org.eclipse.jgit.util.FileUtils; | import org.eclipse.jgit.util.FileUtils; | ||||
return null; | return null; | ||||
} | } | ||||
ReflogReader reader = new ReflogReader(repo, R_STASH); | |||||
List<ReflogEntry> entries; | List<ReflogEntry> entries; | ||||
try { | try { | ||||
ReflogReader reader = repo.getReflogReader(R_STASH); | |||||
entries = reader.getReverseEntries(); | entries = reader.getReverseEntries(); | ||||
} catch (IOException e) { | } catch (IOException e) { | ||||
throw new JGitInternalException(JGitText.get().stashDropFailed, e); | throw new JGitInternalException(JGitText.get().stashDropFailed, e); |
import org.eclipse.jgit.api.errors.InvalidRefNameException; | import org.eclipse.jgit.api.errors.InvalidRefNameException; | ||||
import org.eclipse.jgit.api.errors.JGitInternalException; | import org.eclipse.jgit.api.errors.JGitInternalException; | ||||
import org.eclipse.jgit.internal.JGitText; | import org.eclipse.jgit.internal.JGitText; | ||||
import org.eclipse.jgit.internal.storage.file.ReflogEntry; | |||||
import org.eclipse.jgit.lib.Constants; | import org.eclipse.jgit.lib.Constants; | ||||
import org.eclipse.jgit.lib.ReflogEntry; | |||||
import org.eclipse.jgit.lib.Repository; | import org.eclipse.jgit.lib.Repository; | ||||
import org.eclipse.jgit.revwalk.RevCommit; | import org.eclipse.jgit.revwalk.RevCommit; | ||||
import org.eclipse.jgit.revwalk.RevWalk; | import org.eclipse.jgit.revwalk.RevWalk; |
import java.text.MessageFormat; | import java.text.MessageFormat; | ||||
import org.eclipse.jgit.internal.JGitText; | import org.eclipse.jgit.internal.JGitText; | ||||
import org.eclipse.jgit.internal.storage.file.ReflogReader; | |||||
import org.eclipse.jgit.lib.Constants; | import org.eclipse.jgit.lib.Constants; | ||||
import org.eclipse.jgit.lib.RefUpdate; | import org.eclipse.jgit.lib.RefUpdate; | ||||
import org.eclipse.jgit.lib.ReflogReader; | |||||
import org.eclipse.jgit.lib.Repository; | import org.eclipse.jgit.lib.Repository; | ||||
import org.eclipse.jgit.lib.StoredConfig; | import org.eclipse.jgit.lib.StoredConfig; | ||||
/* | /* | ||||
* Copyright (C) 2011, Robin Rosenberg <robin.rosenberg@dewire.com> | |||||
* Copyright (C) 2011-2013, Robin Rosenberg <robin.rosenberg@dewire.com> | |||||
* and other copyright owners as documented in the project's IP log. | * and other copyright owners as documented in the project's IP log. | ||||
* | * | ||||
* This program and the accompanying materials are made available | * This program and the accompanying materials are made available | ||||
package org.eclipse.jgit.internal.storage.file; | package org.eclipse.jgit.internal.storage.file; | ||||
import org.eclipse.jgit.lib.CheckoutEntry; | |||||
import org.eclipse.jgit.lib.ReflogEntry; | |||||
/** | /** | ||||
* Parsed information about a checkout. | * Parsed information about a checkout. | ||||
*/ | */ | ||||
public class CheckoutEntry { | |||||
public class CheckoutEntryImpl implements CheckoutEntry { | |||||
static final String CHECKOUT_MOVING_FROM = "checkout: moving from "; //$NON-NLS-1$ | static final String CHECKOUT_MOVING_FROM = "checkout: moving from "; //$NON-NLS-1$ | ||||
private String from; | private String from; | ||||
private String to; | private String to; | ||||
CheckoutEntry(ReflogEntry reflogEntry) { | |||||
CheckoutEntryImpl(ReflogEntry reflogEntry) { | |||||
String comment = reflogEntry.getComment(); | String comment = reflogEntry.getComment(); | ||||
int p1 = CHECKOUT_MOVING_FROM.length(); | int p1 = CHECKOUT_MOVING_FROM.length(); | ||||
int p2 = comment.indexOf(" to ", p1); //$NON-NLS-1$ | int p2 = comment.indexOf(" to ", p1); //$NON-NLS-1$ | ||||
to = comment.substring(p2 + " to ".length(), p3); //$NON-NLS-1$ | to = comment.substring(p2 + " to ".length(), p3); //$NON-NLS-1$ | ||||
} | } | ||||
/** | |||||
* @return the name of the branch before checkout | |||||
*/ | |||||
public String getFromBranch() { | public String getFromBranch() { | ||||
return from; | return from; | ||||
} | } | ||||
/** | |||||
* @return the name of the branch after checkout | |||||
*/ | |||||
public String getToBranch() { | public String getToBranch() { | ||||
return to; | return to; | ||||
} | } |
import org.eclipse.jgit.lib.Ref; | import org.eclipse.jgit.lib.Ref; | ||||
import org.eclipse.jgit.lib.RefDatabase; | import org.eclipse.jgit.lib.RefDatabase; | ||||
import org.eclipse.jgit.lib.RefUpdate; | import org.eclipse.jgit.lib.RefUpdate; | ||||
import org.eclipse.jgit.lib.ReflogReader; | |||||
import org.eclipse.jgit.lib.Repository; | import org.eclipse.jgit.lib.Repository; | ||||
import org.eclipse.jgit.storage.file.FileBasedConfig; | import org.eclipse.jgit.storage.file.FileBasedConfig; | ||||
import org.eclipse.jgit.storage.file.FileRepositoryBuilder; | import org.eclipse.jgit.storage.file.FileRepositoryBuilder; | ||||
public ReflogReader getReflogReader(String refName) throws IOException { | public ReflogReader getReflogReader(String refName) throws IOException { | ||||
Ref ref = getRef(refName); | Ref ref = getRef(refName); | ||||
if (ref != null) | if (ref != null) | ||||
return new ReflogReader(this, ref.getName()); | |||||
return new ReflogReaderImpl(this, ref.getName()); | |||||
return null; | return null; | ||||
} | } | ||||
} | } |
import org.eclipse.jgit.lib.Ref; | import org.eclipse.jgit.lib.Ref; | ||||
import org.eclipse.jgit.lib.Ref.Storage; | import org.eclipse.jgit.lib.Ref.Storage; | ||||
import org.eclipse.jgit.lib.RefDatabase; | import org.eclipse.jgit.lib.RefDatabase; | ||||
import org.eclipse.jgit.lib.ReflogEntry; | |||||
import org.eclipse.jgit.revwalk.ObjectWalk; | import org.eclipse.jgit.revwalk.ObjectWalk; | ||||
import org.eclipse.jgit.revwalk.RevObject; | import org.eclipse.jgit.revwalk.RevObject; | ||||
import org.eclipse.jgit.revwalk.RevWalk; | import org.eclipse.jgit.revwalk.RevWalk; |
import java.io.Serializable; | import java.io.Serializable; | ||||
import org.eclipse.jgit.internal.JGitText; | import org.eclipse.jgit.internal.JGitText; | ||||
import org.eclipse.jgit.lib.CheckoutEntry; | |||||
import org.eclipse.jgit.lib.Constants; | import org.eclipse.jgit.lib.Constants; | ||||
import org.eclipse.jgit.lib.ObjectId; | import org.eclipse.jgit.lib.ObjectId; | ||||
import org.eclipse.jgit.lib.PersonIdent; | import org.eclipse.jgit.lib.PersonIdent; | ||||
import org.eclipse.jgit.lib.ReflogEntry; | |||||
import org.eclipse.jgit.util.RawParseUtils; | import org.eclipse.jgit.util.RawParseUtils; | ||||
/** | /** | ||||
* Parsed reflog entry | * Parsed reflog entry | ||||
*/ | */ | ||||
public class ReflogEntry implements Serializable { | |||||
public class ReflogEntryImpl implements Serializable, ReflogEntry { | |||||
private static final long serialVersionUID = 1L; | private static final long serialVersionUID = 1L; | ||||
private ObjectId oldId; | private ObjectId oldId; | ||||
private String comment; | private String comment; | ||||
ReflogEntry(byte[] raw, int pos) { | |||||
ReflogEntryImpl(byte[] raw, int pos) { | |||||
oldId = ObjectId.fromString(raw, pos); | oldId = ObjectId.fromString(raw, pos); | ||||
pos += Constants.OBJECT_ID_STRING_LENGTH; | pos += Constants.OBJECT_ID_STRING_LENGTH; | ||||
if (raw[pos++] != ' ') | if (raw[pos++] != ' ') | ||||
} | } | ||||
} | } | ||||
/** | |||||
* @return the commit id before the change | |||||
/* (non-Javadoc) | |||||
* @see org.eclipse.jgit.internal.storage.file.ReflogEntry#getOldId() | |||||
*/ | */ | ||||
public ObjectId getOldId() { | public ObjectId getOldId() { | ||||
return oldId; | return oldId; | ||||
} | } | ||||
/** | |||||
* @return the commit id after the change | |||||
/* (non-Javadoc) | |||||
* @see org.eclipse.jgit.internal.storage.file.ReflogEntry#getNewId() | |||||
*/ | */ | ||||
public ObjectId getNewId() { | public ObjectId getNewId() { | ||||
return newId; | return newId; | ||||
} | } | ||||
/** | |||||
* @return user performing the change | |||||
/* (non-Javadoc) | |||||
* @see org.eclipse.jgit.internal.storage.file.ReflogEntry#getWho() | |||||
*/ | */ | ||||
public PersonIdent getWho() { | public PersonIdent getWho() { | ||||
return who; | return who; | ||||
} | } | ||||
/** | |||||
* @return textual description of the change | |||||
/* (non-Javadoc) | |||||
* @see org.eclipse.jgit.internal.storage.file.ReflogEntry#getComment() | |||||
*/ | */ | ||||
public String getComment() { | public String getComment() { | ||||
return comment; | return comment; | ||||
+ ", " + getComment() + "]"; | + ", " + getComment() + "]"; | ||||
} | } | ||||
/** | |||||
* @return a {@link CheckoutEntry} with parsed information about a branch | |||||
* switch, or null if the entry is not a checkout | |||||
/* (non-Javadoc) | |||||
* @see org.eclipse.jgit.internal.storage.file.ReflogEntry#parseCheckout() | |||||
*/ | */ | ||||
public CheckoutEntry parseCheckout() { | public CheckoutEntry parseCheckout() { | ||||
if (getComment().startsWith(CheckoutEntry.CHECKOUT_MOVING_FROM)) | |||||
return new CheckoutEntry(this); | |||||
if (getComment().startsWith(CheckoutEntryImpl.CHECKOUT_MOVING_FROM)) | |||||
return new CheckoutEntryImpl(this); | |||||
else | else | ||||
return null; | return null; | ||||
} | } |
/* | /* | ||||
* Copyright (C) 2009, Robin Rosenberg | |||||
* Copyright (C) 2009, Robin Rosenberg <robin.rosenberg@dewire.com> | * Copyright (C) 2009, Robin Rosenberg <robin.rosenberg@dewire.com> | ||||
* and other copyright owners as documented in the project's IP log. | * and other copyright owners as documented in the project's IP log. | ||||
* | * | ||||
import java.util.List; | import java.util.List; | ||||
import org.eclipse.jgit.lib.Constants; | import org.eclipse.jgit.lib.Constants; | ||||
import org.eclipse.jgit.lib.ReflogEntry; | |||||
import org.eclipse.jgit.lib.ReflogReader; | |||||
import org.eclipse.jgit.lib.Repository; | import org.eclipse.jgit.lib.Repository; | ||||
import org.eclipse.jgit.util.IO; | import org.eclipse.jgit.util.IO; | ||||
import org.eclipse.jgit.util.RawParseUtils; | import org.eclipse.jgit.util.RawParseUtils; | ||||
/** | /** | ||||
* Utility for reading reflog entries | * Utility for reading reflog entries | ||||
*/ | */ | ||||
public class ReflogReader { | |||||
class ReflogReaderImpl implements ReflogReader { | |||||
private File logName; | private File logName; | ||||
/** | /** | ||||
* @param db | * @param db | ||||
* @param refname | * @param refname | ||||
*/ | */ | ||||
public ReflogReader(Repository db, String refname) { | |||||
ReflogReaderImpl(Repository db, String refname) { | |||||
logName = new File(db.getDirectory(), Constants.LOGS + '/' + refname); | logName = new File(db.getDirectory(), Constants.LOGS + '/' + refname); | ||||
} | } | ||||
/** | |||||
* Get the last entry in the reflog | |||||
* | |||||
* @return the latest reflog entry, or null if no log | |||||
* @throws IOException | |||||
/* (non-Javadoc) | |||||
* @see org.eclipse.jgit.internal.storage.file.ReflogReaader#getLastEntry() | |||||
*/ | */ | ||||
public ReflogEntry getLastEntry() throws IOException { | public ReflogEntry getLastEntry() throws IOException { | ||||
return getReverseEntry(0); | return getReverseEntry(0); | ||||
} | } | ||||
/** | |||||
* @return all reflog entries in reverse order | |||||
* @throws IOException | |||||
/* (non-Javadoc) | |||||
* @see org.eclipse.jgit.internal.storage.file.ReflogReaader#getReverseEntries() | |||||
*/ | */ | ||||
public List<ReflogEntry> getReverseEntries() throws IOException { | public List<ReflogEntry> getReverseEntries() throws IOException { | ||||
return getReverseEntries(Integer.MAX_VALUE); | return getReverseEntries(Integer.MAX_VALUE); | ||||
} | } | ||||
/** | |||||
* Get specific entry in the reflog relative to the last entry which is | |||||
* considered entry zero. | |||||
* | |||||
* @param number | |||||
* @return reflog entry or null if not found | |||||
* @throws IOException | |||||
/* (non-Javadoc) | |||||
* @see org.eclipse.jgit.internal.storage.file.ReflogReaader#getReverseEntry(int) | |||||
*/ | */ | ||||
public ReflogEntry getReverseEntry(int number) throws IOException { | public ReflogEntry getReverseEntry(int number) throws IOException { | ||||
if (number < 0) | if (number < 0) | ||||
while (rs >= 0) { | while (rs >= 0) { | ||||
rs = RawParseUtils.prevLF(log, rs); | rs = RawParseUtils.prevLF(log, rs); | ||||
if (number == current) | if (number == current) | ||||
return new ReflogEntry(log, rs < 0 ? 0 : rs + 2); | |||||
return new ReflogEntryImpl(log, rs < 0 ? 0 : rs + 2); | |||||
current++; | current++; | ||||
} | } | ||||
return null; | return null; | ||||
} | } | ||||
/** | |||||
* @param max | |||||
* max number of entries to read | |||||
* @return all reflog entries in reverse order | |||||
* @throws IOException | |||||
/* (non-Javadoc) | |||||
* @see org.eclipse.jgit.internal.storage.file.ReflogReaader#getReverseEntries(int) | |||||
*/ | */ | ||||
public List<ReflogEntry> getReverseEntries(int max) throws IOException { | public List<ReflogEntry> getReverseEntries(int max) throws IOException { | ||||
final byte[] log; | final byte[] log; | ||||
List<ReflogEntry> ret = new ArrayList<ReflogEntry>(); | List<ReflogEntry> ret = new ArrayList<ReflogEntry>(); | ||||
while (rs >= 0 && max-- > 0) { | while (rs >= 0 && max-- > 0) { | ||||
rs = RawParseUtils.prevLF(log, rs); | rs = RawParseUtils.prevLF(log, rs); | ||||
ReflogEntry entry = new ReflogEntry(log, rs < 0 ? 0 : rs + 2); | |||||
ReflogEntry entry = new ReflogEntryImpl(log, rs < 0 ? 0 : rs + 2); | |||||
ret.add(entry); | ret.add(entry); | ||||
} | } | ||||
return ret; | return ret; |
import org.eclipse.jgit.lib.PersonIdent; | import org.eclipse.jgit.lib.PersonIdent; | ||||
import org.eclipse.jgit.lib.Ref; | import org.eclipse.jgit.lib.Ref; | ||||
import org.eclipse.jgit.lib.RefUpdate; | import org.eclipse.jgit.lib.RefUpdate; | ||||
import org.eclipse.jgit.lib.ReflogEntry; | |||||
import org.eclipse.jgit.lib.Repository; | import org.eclipse.jgit.lib.Repository; | ||||
import org.eclipse.jgit.util.FS; | import org.eclipse.jgit.util.FS; | ||||
import org.eclipse.jgit.util.FileUtils; | import org.eclipse.jgit.util.FileUtils; |
package org.eclipse.jgit.lib; | |||||
/** | |||||
* Parsed information about a checkout. | |||||
*/ | |||||
public interface CheckoutEntry { | |||||
/** | |||||
* @return the name of the branch before checkout | |||||
*/ | |||||
public abstract String getFromBranch(); | |||||
/** | |||||
* @return the name of the branch after checkout | |||||
*/ | |||||
public abstract String getToBranch(); | |||||
} |
/* | |||||
* Copyright (C) 2011-2013, Robin Rosenberg <robin.rosenberg@dewire.com> | |||||
* and other copyright owners as documented in the project's IP log. | |||||
* | |||||
* This program and the accompanying materials are made available | |||||
* under the terms of the Eclipse Distribution License v1.0 which | |||||
* accompanies this distribution, is reproduced below, and is | |||||
* available at http://www.eclipse.org/org/documents/edl-v10.php | |||||
* | |||||
* All rights reserved. | |||||
* | |||||
* Redistribution and use in source and binary forms, with or | |||||
* without modification, are permitted provided that the following | |||||
* conditions are met: | |||||
* | |||||
* - Redistributions of source code must retain the above copyright | |||||
* notice, this list of conditions and the following disclaimer. | |||||
* | |||||
* - Redistributions in binary form must reproduce the above | |||||
* copyright notice, this list of conditions and the following | |||||
* disclaimer in the documentation and/or other materials provided | |||||
* with the distribution. | |||||
* | |||||
* - Neither the name of the Eclipse Foundation, Inc. nor the | |||||
* names of its contributors may be used to endorse or promote | |||||
* products derived from this software without specific prior | |||||
* written permission. | |||||
* | |||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND | |||||
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, | |||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | |||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | |||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | |||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||||
*/ | |||||
package org.eclipse.jgit.lib; | |||||
import org.eclipse.jgit.lib.ObjectId; | |||||
import org.eclipse.jgit.lib.PersonIdent; | |||||
/** | |||||
* Parsed reflog entry | |||||
*/ | |||||
public interface ReflogEntry { | |||||
/** | |||||
* @return the commit id before the change | |||||
*/ | |||||
public abstract ObjectId getOldId(); | |||||
/** | |||||
* @return the commit id after the change | |||||
*/ | |||||
public abstract ObjectId getNewId(); | |||||
/** | |||||
* @return user performing the change | |||||
*/ | |||||
public abstract PersonIdent getWho(); | |||||
/** | |||||
* @return textual description of the change | |||||
*/ | |||||
public abstract String getComment(); | |||||
/** | |||||
* @return a {@link CheckoutEntry} with parsed information about a branch | |||||
* switch, or null if the entry is not a checkout | |||||
*/ | |||||
public abstract CheckoutEntry parseCheckout(); | |||||
} |
/* | |||||
* Copyright (C) 2013, Robin Rosenberg <robin.rosenberg@dewire.com> | |||||
* and other copyright owners as documented in the project's IP log. | |||||
* | |||||
* This program and the accompanying materials are made available | |||||
* under the terms of the Eclipse Distribution License v1.0 which | |||||
* accompanies this distribution, is reproduced below, and is | |||||
* available at http://www.eclipse.org/org/documents/edl-v10.php | |||||
* | |||||
* All rights reserved. | |||||
* | |||||
* Redistribution and use in source and binary forms, with or | |||||
* without modification, are permitted provided that the following | |||||
* conditions are met: | |||||
* | |||||
* - Redistributions of source code must retain the above copyright | |||||
* notice, this list of conditions and the following disclaimer. | |||||
* | |||||
* - Redistributions in binary form must reproduce the above | |||||
* copyright notice, this list of conditions and the following | |||||
* disclaimer in the documentation and/or other materials provided | |||||
* with the distribution. | |||||
* | |||||
* - Neither the name of the Eclipse Foundation, Inc. nor the | |||||
* names of its contributors may be used to endorse or promote | |||||
* products derived from this software without specific prior | |||||
* written permission. | |||||
* | |||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND | |||||
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, | |||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | |||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | |||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | |||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||||
*/ | |||||
package org.eclipse.jgit.lib; | |||||
import java.io.IOException; | |||||
import java.util.List; | |||||
/** | |||||
* Utility for reading reflog entries | |||||
*/ | |||||
public interface ReflogReader { | |||||
/** | |||||
* Get the last entry in the reflog | |||||
* | |||||
* @return the latest reflog entry, or null if no log | |||||
* @throws IOException | |||||
*/ | |||||
public abstract ReflogEntry getLastEntry() throws IOException; | |||||
/** | |||||
* @return all reflog entries in reverse order | |||||
* @throws IOException | |||||
*/ | |||||
public abstract List<ReflogEntry> getReverseEntries() throws IOException; | |||||
/** | |||||
* Get specific entry in the reflog relative to the last entry which is | |||||
* considered entry zero. | |||||
* | |||||
* @param number | |||||
* @return reflog entry or null if not found | |||||
* @throws IOException | |||||
*/ | |||||
public abstract ReflogEntry getReverseEntry(int number) throws IOException; | |||||
/** | |||||
* @param max | |||||
* max number of entries to read | |||||
* @return all reflog entries in reverse order | |||||
* @throws IOException | |||||
*/ | |||||
public abstract List<ReflogEntry> getReverseEntries(int max) | |||||
throws IOException; | |||||
} |
import org.eclipse.jgit.events.ListenerList; | import org.eclipse.jgit.events.ListenerList; | ||||
import org.eclipse.jgit.events.RepositoryEvent; | import org.eclipse.jgit.events.RepositoryEvent; | ||||
import org.eclipse.jgit.internal.JGitText; | import org.eclipse.jgit.internal.JGitText; | ||||
import org.eclipse.jgit.internal.storage.file.CheckoutEntry; | |||||
import org.eclipse.jgit.internal.storage.file.ReflogEntry; | |||||
import org.eclipse.jgit.internal.storage.file.ReflogReader; | |||||
import org.eclipse.jgit.revwalk.RevBlob; | import org.eclipse.jgit.revwalk.RevBlob; | ||||
import org.eclipse.jgit.revwalk.RevCommit; | import org.eclipse.jgit.revwalk.RevCommit; | ||||
import org.eclipse.jgit.revwalk.RevObject; | import org.eclipse.jgit.revwalk.RevObject; | ||||
private String resolveReflogCheckout(int checkoutNo) | private String resolveReflogCheckout(int checkoutNo) | ||||
throws IOException { | throws IOException { | ||||
List<ReflogEntry> reflogEntries = new ReflogReader(this, Constants.HEAD) | |||||
List<ReflogEntry> reflogEntries = getReflogReader(Constants.HEAD) | |||||
.getReverseEntries(); | .getReverseEntries(); | ||||
for (ReflogEntry entry : reflogEntries) { | for (ReflogEntry entry : reflogEntries) { | ||||
CheckoutEntry checkout = entry.parseCheckout(); | CheckoutEntry checkout = entry.parseCheckout(); | ||||
JGitText.get().invalidReflogRevision, time)); | JGitText.get().invalidReflogRevision, time)); | ||||
} | } | ||||
assert number >= 0; | assert number >= 0; | ||||
ReflogReader reader = new ReflogReader(this, ref.getName()); | |||||
ReflogReader reader = getReflogReader(ref.getName()); | |||||
ReflogEntry entry = reader.getReverseEntry(number); | ReflogEntry entry = reader.getReverseEntry(number); | ||||
if (entry == null) | if (entry == null) | ||||
throw new RevisionSyntaxException(MessageFormat.format( | throw new RevisionSyntaxException(MessageFormat.format( |