From 9dcd8c2c900722cbda7490c1a132fc4b96737c28 Mon Sep 17 00:00:00 2001 From: Robin Rosenberg Date: Wed, 17 Apr 2013 00:31:11 +0200 Subject: Make the Reflog a public API again Change-Id: I8ced7098da5b345fd9af2fdfafd1ef6a44ccee0d --- .../src/org/eclipse/jgit/api/ReflogCommand.java | 6 +- .../src/org/eclipse/jgit/api/StashDropCommand.java | 6 +- .../src/org/eclipse/jgit/api/StashListCommand.java | 2 +- .../jgit/internal/storage/dfs/DfsRepository.java | 2 +- .../jgit/internal/storage/file/CheckoutEntry.java | 78 ----------- .../internal/storage/file/CheckoutEntryImpl.java | 75 +++++++++++ .../jgit/internal/storage/file/FileRepository.java | 3 +- .../org/eclipse/jgit/internal/storage/file/GC.java | 1 + .../jgit/internal/storage/file/ReflogEntry.java | 136 ------------------- .../internal/storage/file/ReflogEntryImpl.java | 137 ++++++++++++++++++++ .../jgit/internal/storage/file/ReflogReader.java | 144 --------------------- .../internal/storage/file/ReflogReaderImpl.java | 133 +++++++++++++++++++ .../jgit/internal/storage/file/ReflogWriter.java | 1 + .../src/org/eclipse/jgit/lib/CheckoutEntry.java | 18 +++ .../src/org/eclipse/jgit/lib/ReflogEntry.java | 79 +++++++++++ .../src/org/eclipse/jgit/lib/ReflogReader.java | 87 +++++++++++++ .../src/org/eclipse/jgit/lib/Repository.java | 7 +- 17 files changed, 543 insertions(+), 372 deletions(-) delete mode 100644 org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/CheckoutEntry.java create mode 100644 org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/CheckoutEntryImpl.java delete mode 100644 org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ReflogEntry.java create mode 100644 org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ReflogEntryImpl.java delete mode 100644 org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ReflogReader.java create mode 100644 org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ReflogReaderImpl.java create mode 100644 org.eclipse.jgit/src/org/eclipse/jgit/lib/CheckoutEntry.java create mode 100644 org.eclipse.jgit/src/org/eclipse/jgit/lib/ReflogEntry.java create mode 100644 org.eclipse.jgit/src/org/eclipse/jgit/lib/ReflogReader.java (limited to 'org.eclipse.jgit/src') diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/ReflogCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/ReflogCommand.java index 373eb3c645..8cd78aebe1 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/ReflogCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/ReflogCommand.java @@ -49,9 +49,9 @@ import java.util.Collection; import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.api.errors.InvalidRefNameException; 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.ReflogEntry; +import org.eclipse.jgit.lib.ReflogReader; import org.eclipse.jgit.lib.Repository; /** @@ -96,7 +96,7 @@ public class ReflogCommand extends GitCommand> { checkCallable(); try { - ReflogReader reader = new ReflogReader(repo, ref); + ReflogReader reader = repo.getReflogReader(ref); return reader.getReverseEntries(); } catch (IOException e) { throw new InvalidRefNameException(MessageFormat.format( diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/StashDropCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/StashDropCommand.java index a3779103fc..e4431c37b1 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/StashDropCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/StashDropCommand.java @@ -54,13 +54,13 @@ import org.eclipse.jgit.api.errors.InvalidRefNameException; import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.errors.LockFailedException; 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.lib.ObjectId; import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.RefUpdate; 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.util.FileUtils; @@ -181,9 +181,9 @@ public class StashDropCommand extends GitCommand { return null; } - ReflogReader reader = new ReflogReader(repo, R_STASH); List entries; try { + ReflogReader reader = repo.getReflogReader(R_STASH); entries = reader.getReverseEntries(); } catch (IOException e) { throw new JGitInternalException(JGitText.get().stashDropFailed, e); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/StashListCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/StashListCommand.java index 3d498fc127..bbbb7ace3d 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/StashListCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/StashListCommand.java @@ -53,8 +53,8 @@ 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.internal.JGitText; -import org.eclipse.jgit.internal.storage.file.ReflogEntry; import org.eclipse.jgit.lib.Constants; +import org.eclipse.jgit.lib.ReflogEntry; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevWalk; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsRepository.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsRepository.java index e2b9ddd2f0..122f6d3d19 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsRepository.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsRepository.java @@ -47,9 +47,9 @@ import java.io.IOException; import java.text.MessageFormat; 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.RefUpdate; +import org.eclipse.jgit.lib.ReflogReader; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.StoredConfig; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/CheckoutEntry.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/CheckoutEntry.java deleted file mode 100644 index 7f3a398359..0000000000 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/CheckoutEntry.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (C) 2011, Robin Rosenberg - * 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.internal.storage.file; - -/** - * Parsed information about a checkout. - */ -public class CheckoutEntry { - static final String CHECKOUT_MOVING_FROM = "checkout: moving from "; //$NON-NLS-1$ - - private String from; - - private String to; - - CheckoutEntry(ReflogEntry reflogEntry) { - String comment = reflogEntry.getComment(); - int p1 = CHECKOUT_MOVING_FROM.length(); - int p2 = comment.indexOf(" to ", p1); //$NON-NLS-1$ - int p3 = comment.length(); - from = comment.substring(p1,p2); - to = comment.substring(p2 + " to ".length(), p3); //$NON-NLS-1$ - } - - /** - * @return the name of the branch before checkout - */ - public String getFromBranch() { - return from; - } - - /** - * @return the name of the branch after checkout - */ - public String getToBranch() { - return to; - } -} \ No newline at end of file diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/CheckoutEntryImpl.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/CheckoutEntryImpl.java new file mode 100644 index 0000000000..e968119ad9 --- /dev/null +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/CheckoutEntryImpl.java @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2011-2013, Robin Rosenberg + * 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.internal.storage.file; + +import org.eclipse.jgit.lib.CheckoutEntry; +import org.eclipse.jgit.lib.ReflogEntry; + +/** + * Parsed information about a checkout. + */ +public class CheckoutEntryImpl implements CheckoutEntry { + static final String CHECKOUT_MOVING_FROM = "checkout: moving from "; //$NON-NLS-1$ + + private String from; + + private String to; + + CheckoutEntryImpl(ReflogEntry reflogEntry) { + String comment = reflogEntry.getComment(); + int p1 = CHECKOUT_MOVING_FROM.length(); + int p2 = comment.indexOf(" to ", p1); //$NON-NLS-1$ + int p3 = comment.length(); + from = comment.substring(p1,p2); + to = comment.substring(p2 + " to ".length(), p3); //$NON-NLS-1$ + } + + public String getFromBranch() { + return from; + } + + public String getToBranch() { + return to; + } +} \ No newline at end of file diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileRepository.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileRepository.java index 95c4c1228f..364fdeb4a1 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileRepository.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileRepository.java @@ -66,6 +66,7 @@ import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.RefDatabase; import org.eclipse.jgit.lib.RefUpdate; +import org.eclipse.jgit.lib.ReflogReader; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.storage.file.FileBasedConfig; import org.eclipse.jgit.storage.file.FileRepositoryBuilder; @@ -414,7 +415,7 @@ public class FileRepository extends Repository { public ReflogReader getReflogReader(String refName) throws IOException { Ref ref = getRef(refName); if (ref != null) - return new ReflogReader(this, ref.getName()); + return new ReflogReaderImpl(this, ref.getName()); return null; } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java index 9950819cbf..ccf35e8968 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java @@ -88,6 +88,7 @@ import org.eclipse.jgit.lib.ProgressMonitor; import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.Ref.Storage; import org.eclipse.jgit.lib.RefDatabase; +import org.eclipse.jgit.lib.ReflogEntry; import org.eclipse.jgit.revwalk.ObjectWalk; import org.eclipse.jgit.revwalk.RevObject; import org.eclipse.jgit.revwalk.RevWalk; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ReflogEntry.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ReflogEntry.java deleted file mode 100644 index fb48519439..0000000000 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ReflogEntry.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Copyright (C) 2011, Chris Aniszczyk - * Copyright (C) 2009, Robin Rosenberg - * 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.internal.storage.file; - -import java.io.Serializable; - -import org.eclipse.jgit.internal.JGitText; -import org.eclipse.jgit.lib.Constants; -import org.eclipse.jgit.lib.ObjectId; -import org.eclipse.jgit.lib.PersonIdent; -import org.eclipse.jgit.util.RawParseUtils; - -/** - * Parsed reflog entry - */ -public class ReflogEntry implements Serializable { - private static final long serialVersionUID = 1L; - - private ObjectId oldId; - - private ObjectId newId; - - private PersonIdent who; - - private String comment; - - ReflogEntry(byte[] raw, int pos) { - oldId = ObjectId.fromString(raw, pos); - pos += Constants.OBJECT_ID_STRING_LENGTH; - if (raw[pos++] != ' ') - throw new IllegalArgumentException( - JGitText.get().rawLogMessageDoesNotParseAsLogEntry); - newId = ObjectId.fromString(raw, pos); - pos += Constants.OBJECT_ID_STRING_LENGTH; - if (raw[pos++] != ' ') { - throw new IllegalArgumentException( - JGitText.get().rawLogMessageDoesNotParseAsLogEntry); - } - who = RawParseUtils.parsePersonIdentOnly(raw, pos); - int p0 = RawParseUtils.next(raw, pos, '\t'); - if (p0 >= raw.length) - comment = ""; // personident has no \t, no comment present //$NON-NLS-1$ - else { - int p1 = RawParseUtils.nextLF(raw, p0); - comment = p1 > p0 ? RawParseUtils.decode(raw, p0, p1 - 1) : ""; //$NON-NLS-1$ - } - } - - /** - * @return the commit id before the change - */ - public ObjectId getOldId() { - return oldId; - } - - /** - * @return the commit id after the change - */ - public ObjectId getNewId() { - return newId; - } - - /** - * @return user performing the change - */ - public PersonIdent getWho() { - return who; - } - - /** - * @return textual description of the change - */ - public String getComment() { - return comment; - } - - @SuppressWarnings("nls") - @Override - public String toString() { - return "Entry[" + oldId.name() + ", " + newId.name() + ", " + getWho() - + ", " + getComment() + "]"; - } - - /** - * @return a {@link CheckoutEntry} with parsed information about a branch - * switch, or null if the entry is not a checkout - */ - public CheckoutEntry parseCheckout() { - if (getComment().startsWith(CheckoutEntry.CHECKOUT_MOVING_FROM)) - return new CheckoutEntry(this); - else - return null; - } -} \ No newline at end of file diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ReflogEntryImpl.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ReflogEntryImpl.java new file mode 100644 index 0000000000..60f04b8d1f --- /dev/null +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ReflogEntryImpl.java @@ -0,0 +1,137 @@ +/* + * Copyright (C) 2011, Chris Aniszczyk + * Copyright (C) 2009, Robin Rosenberg + * 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.internal.storage.file; + +import java.io.Serializable; + +import org.eclipse.jgit.internal.JGitText; +import org.eclipse.jgit.lib.CheckoutEntry; +import org.eclipse.jgit.lib.Constants; +import org.eclipse.jgit.lib.ObjectId; +import org.eclipse.jgit.lib.PersonIdent; +import org.eclipse.jgit.lib.ReflogEntry; +import org.eclipse.jgit.util.RawParseUtils; + +/** + * Parsed reflog entry + */ +public class ReflogEntryImpl implements Serializable, ReflogEntry { + private static final long serialVersionUID = 1L; + + private ObjectId oldId; + + private ObjectId newId; + + private PersonIdent who; + + private String comment; + + ReflogEntryImpl(byte[] raw, int pos) { + oldId = ObjectId.fromString(raw, pos); + pos += Constants.OBJECT_ID_STRING_LENGTH; + if (raw[pos++] != ' ') + throw new IllegalArgumentException( + JGitText.get().rawLogMessageDoesNotParseAsLogEntry); + newId = ObjectId.fromString(raw, pos); + pos += Constants.OBJECT_ID_STRING_LENGTH; + if (raw[pos++] != ' ') { + throw new IllegalArgumentException( + JGitText.get().rawLogMessageDoesNotParseAsLogEntry); + } + who = RawParseUtils.parsePersonIdentOnly(raw, pos); + int p0 = RawParseUtils.next(raw, pos, '\t'); + if (p0 >= raw.length) + comment = ""; // personident has no \t, no comment present //$NON-NLS-1$ + else { + int p1 = RawParseUtils.nextLF(raw, p0); + comment = p1 > p0 ? RawParseUtils.decode(raw, p0, p1 - 1) : ""; //$NON-NLS-1$ + } + } + + /* (non-Javadoc) + * @see org.eclipse.jgit.internal.storage.file.ReflogEntry#getOldId() + */ + public ObjectId getOldId() { + return oldId; + } + + /* (non-Javadoc) + * @see org.eclipse.jgit.internal.storage.file.ReflogEntry#getNewId() + */ + public ObjectId getNewId() { + return newId; + } + + /* (non-Javadoc) + * @see org.eclipse.jgit.internal.storage.file.ReflogEntry#getWho() + */ + public PersonIdent getWho() { + return who; + } + + /* (non-Javadoc) + * @see org.eclipse.jgit.internal.storage.file.ReflogEntry#getComment() + */ + public String getComment() { + return comment; + } + + @SuppressWarnings("nls") + @Override + public String toString() { + return "Entry[" + oldId.name() + ", " + newId.name() + ", " + getWho() + + ", " + getComment() + "]"; + } + + /* (non-Javadoc) + * @see org.eclipse.jgit.internal.storage.file.ReflogEntry#parseCheckout() + */ + public CheckoutEntry parseCheckout() { + if (getComment().startsWith(CheckoutEntryImpl.CHECKOUT_MOVING_FROM)) + return new CheckoutEntryImpl(this); + else + return null; + } +} \ No newline at end of file diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ReflogReader.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ReflogReader.java deleted file mode 100644 index c814cb4196..0000000000 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ReflogReader.java +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright (C) 2009, Robin Rosenberg - * Copyright (C) 2009, Robin Rosenberg - * 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.internal.storage.file; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import org.eclipse.jgit.lib.Constants; -import org.eclipse.jgit.lib.Repository; -import org.eclipse.jgit.util.IO; -import org.eclipse.jgit.util.RawParseUtils; - -/** - * Utility for reading reflog entries - */ -public class ReflogReader { - private File logName; - - /** - * @param db - * @param refname - */ - public ReflogReader(Repository db, String 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 - */ - public ReflogEntry getLastEntry() throws IOException { - return getReverseEntry(0); - } - - /** - * @return all reflog entries in reverse order - * @throws IOException - */ - public List getReverseEntries() throws IOException { - 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 - */ - public ReflogEntry getReverseEntry(int number) throws IOException { - if (number < 0) - throw new IllegalArgumentException(); - - final byte[] log; - try { - log = IO.readFully(logName); - } catch (FileNotFoundException e) { - return null; - } - - int rs = RawParseUtils.prevLF(log, log.length); - int current = 0; - while (rs >= 0) { - rs = RawParseUtils.prevLF(log, rs); - if (number == current) - return new ReflogEntry(log, rs < 0 ? 0 : rs + 2); - current++; - } - return null; - } - - /** - * @param max - * max number of entries to read - * @return all reflog entries in reverse order - * @throws IOException - */ - public List getReverseEntries(int max) throws IOException { - final byte[] log; - try { - log = IO.readFully(logName); - } catch (FileNotFoundException e) { - return Collections.emptyList(); - } - - int rs = RawParseUtils.prevLF(log, log.length); - List ret = new ArrayList(); - while (rs >= 0 && max-- > 0) { - rs = RawParseUtils.prevLF(log, rs); - ReflogEntry entry = new ReflogEntry(log, rs < 0 ? 0 : rs + 2); - ret.add(entry); - } - return ret; - } -} diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ReflogReaderImpl.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ReflogReaderImpl.java new file mode 100644 index 0000000000..dadc631194 --- /dev/null +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ReflogReaderImpl.java @@ -0,0 +1,133 @@ +/* + * Copyright (C) 2009, Robin Rosenberg + * 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.internal.storage.file; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +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.util.IO; +import org.eclipse.jgit.util.RawParseUtils; + +/** + * Utility for reading reflog entries + */ +class ReflogReaderImpl implements ReflogReader { + private File logName; + + /** + * @param db + * @param refname + */ + ReflogReaderImpl(Repository db, String refname) { + logName = new File(db.getDirectory(), Constants.LOGS + '/' + refname); + } + + /* (non-Javadoc) + * @see org.eclipse.jgit.internal.storage.file.ReflogReaader#getLastEntry() + */ + public ReflogEntry getLastEntry() throws IOException { + return getReverseEntry(0); + } + + /* (non-Javadoc) + * @see org.eclipse.jgit.internal.storage.file.ReflogReaader#getReverseEntries() + */ + public List getReverseEntries() throws IOException { + return getReverseEntries(Integer.MAX_VALUE); + } + + /* (non-Javadoc) + * @see org.eclipse.jgit.internal.storage.file.ReflogReaader#getReverseEntry(int) + */ + public ReflogEntry getReverseEntry(int number) throws IOException { + if (number < 0) + throw new IllegalArgumentException(); + + final byte[] log; + try { + log = IO.readFully(logName); + } catch (FileNotFoundException e) { + return null; + } + + int rs = RawParseUtils.prevLF(log, log.length); + int current = 0; + while (rs >= 0) { + rs = RawParseUtils.prevLF(log, rs); + if (number == current) + return new ReflogEntryImpl(log, rs < 0 ? 0 : rs + 2); + current++; + } + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.jgit.internal.storage.file.ReflogReaader#getReverseEntries(int) + */ + public List getReverseEntries(int max) throws IOException { + final byte[] log; + try { + log = IO.readFully(logName); + } catch (FileNotFoundException e) { + return Collections.emptyList(); + } + + int rs = RawParseUtils.prevLF(log, log.length); + List ret = new ArrayList(); + while (rs >= 0 && max-- > 0) { + rs = RawParseUtils.prevLF(log, rs); + ReflogEntry entry = new ReflogEntryImpl(log, rs < 0 ? 0 : rs + 2); + ret.add(entry); + } + return ret; + } +} diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ReflogWriter.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ReflogWriter.java index 5dc017cd97..9ec35075d1 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ReflogWriter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ReflogWriter.java @@ -67,6 +67,7 @@ import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.PersonIdent; import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.RefUpdate; +import org.eclipse.jgit.lib.ReflogEntry; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.util.FS; import org.eclipse.jgit.util.FileUtils; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/CheckoutEntry.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/CheckoutEntry.java new file mode 100644 index 0000000000..58f17d6f4c --- /dev/null +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/CheckoutEntry.java @@ -0,0 +1,18 @@ +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(); + +} \ No newline at end of file diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ReflogEntry.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ReflogEntry.java new file mode 100644 index 0000000000..97875832a9 --- /dev/null +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ReflogEntry.java @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2011-2013, Robin Rosenberg + * 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(); + +} \ No newline at end of file diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ReflogReader.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ReflogReader.java new file mode 100644 index 0000000000..563ad497de --- /dev/null +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ReflogReader.java @@ -0,0 +1,87 @@ +/* + * Copyright (C) 2013, Robin Rosenberg + * 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 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 getReverseEntries(int max) + throws IOException; + +} \ No newline at end of file diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java index de14282cfd..79f02c0230 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java @@ -76,9 +76,6 @@ import org.eclipse.jgit.events.IndexChangedListener; import org.eclipse.jgit.events.ListenerList; import org.eclipse.jgit.events.RepositoryEvent; 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.RevCommit; import org.eclipse.jgit.revwalk.RevObject; @@ -757,7 +754,7 @@ public abstract class Repository { private String resolveReflogCheckout(int checkoutNo) throws IOException { - List reflogEntries = new ReflogReader(this, Constants.HEAD) + List reflogEntries = getReflogReader(Constants.HEAD) .getReverseEntries(); for (ReflogEntry entry : reflogEntries) { CheckoutEntry checkout = entry.parseCheckout(); @@ -778,7 +775,7 @@ public abstract class Repository { JGitText.get().invalidReflogRevision, time)); } assert number >= 0; - ReflogReader reader = new ReflogReader(this, ref.getName()); + ReflogReader reader = getReflogReader(ref.getName()); ReflogEntry entry = reader.getReverseEntry(number); if (entry == null) throw new RevisionSyntaxException(MessageFormat.format( -- cgit v1.2.3