Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge remote branch 'jonas/master'

Conflicts:
	src/org/nbgit/client/CheckoutBuilder.java

Signed-off-by: Alex Coles <alex@alexbcoles.com>
  • Loading branch information...
commit fc1c1bff8c62c5f354fec64904b2376ec37b73bd 2 parents 6b2838a + 180f329
@myabc authored
View
2  manifest.mf
@@ -3,4 +3,4 @@ OpenIDE-Module: org.nbgit
OpenIDE-Module-Layer: org/nbgit/resources/layer.xml
OpenIDE-Module-Localizing-Bundle: org/nbgit/Bundle.properties
OpenIDE-Module-Requires: org.netbeans.api.javahelp.Help
-OpenIDE-Module-Specification-Version: 0.3
+OpenIDE-Module-Specification-Version: 0.4
View
6 nbproject/project.properties
@@ -4,6 +4,12 @@ auxiliary.org-netbeans-modules-editor-indent.CodeStyle.project.spaces-per-tab=4
auxiliary.org-netbeans-modules-editor-indent.CodeStyle.project.tab-size=4
auxiliary.org-netbeans-modules-editor-indent.CodeStyle.project.text-limit-width=80
auxiliary.org-netbeans-modules-editor-indent.CodeStyle.usedProfile=project
+auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.absoluteLabelIndent=true
+auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.continuationIndentSize=4
+auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.redundantDoWhileBraces=LEAVE_ALONE
+auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.redundantForBraces=LEAVE_ALONE
+auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.redundantIfBraces=LEAVE_ALONE
+auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.redundantWhileBraces=LEAVE_ALONE
file.reference.org.eclipse.jgit-0.8.4.jar=release/modules/ext/org.eclipse.jgit-0.8.4.jar
file.reference.org.eclipse.jgit.ui-0.8.4.jar=release/modules/ext/org.eclipse.jgit.ui-0.8.4.jar
javahelp.base=org/nbgit/docs
View
9 nbproject/project.xml
@@ -52,15 +52,6 @@
</run-dependency>
</dependency>
<dependency>
- <code-name-base>org.netbeans.modules.editor.lib</code-name-base>
- <build-prerequisite/>
- <compile-dependency/>
- <run-dependency>
- <release-version>2</release-version>
- <specification-version>2.2.10</specification-version>
- </run-dependency>
- </dependency>
- <dependency>
<code-name-base>org.netbeans.modules.editor.mimelookup</code-name-base>
<build-prerequisite/>
<compile-dependency/>
View
50 src/org/nbgit/client/CheckoutBuilder.java
@@ -44,10 +44,14 @@
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
+import org.eclipse.jgit.dircache.DirCache;
+import org.eclipse.jgit.dircache.DirCacheEntry;
import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.GitIndex;
+import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.Tree;
+import org.eclipse.jgit.lib.TreeEntry;
/**
* Build a checkout of files from a revision.
@@ -55,9 +59,10 @@
public class CheckoutBuilder extends ClientBuilder {
private static final String BACKUP_EXT = ".orig";
- private final HashMap<String, File> fileMappings = new HashMap<String, File>();
+ private final HashMap<RevisionEntry, File> fileMappings = new HashMap<RevisionEntry, File>();
private boolean backup;
private Tree tree;
+ private DirCache index;
private CheckoutBuilder(Repository repository) {
super(repository);
@@ -107,16 +112,33 @@ public CheckoutBuilder revision(String revision)
* @param file to be checked out.
* @param destination where the file should be checked out.
* @return the builder.
- * @throws FileNotFoundException if revision has been specified and file
- * is not found in the revision's snapshot.
+ * @throws FileNotFoundException if the file cannot be resolved.
* @throws IOException if checking of file existance fails.
*/
public CheckoutBuilder file(File file, File destination)
throws IOException, FileNotFoundException {
String path = toPath(file);
- if (tree != null && !tree.existsBlob(path))
+ ObjectId blobId = null;
+ int modeBits = 0;
+
+ if (tree != null) {
+ TreeEntry entry = tree.findBlobMember(path);
+ if (entry != null) {
+ blobId = entry.getId();
+ modeBits = entry.getMode().getBits();
+ }
+ } else {
+ if (index == null)
+ index = DirCache.read(repository);
+ DirCacheEntry entry = index.getEntry(path);
+ if (entry != null) {
+ blobId = entry.getObjectId();
+ modeBits = entry.getRawMode();
+ }
+ }
+ if (blobId == null)
throw new FileNotFoundException(path);
- fileMappings.put(path, destination);
+ fileMappings.put(RevisionEntry.create(path, blobId, modeBits), destination);
return this;
}
@@ -127,8 +149,7 @@ public CheckoutBuilder file(File file, File destination)
*
* @param files to be checked out.
* @return the builder.
- * @throws FileNotFoundException if revision has been specified and file
- * is not found in the revision's snapshot.
+ * @throws FileNotFoundException if the file cannot be resolved.
* @throws IOException if checking of file existance fails.
*/
public CheckoutBuilder files(Collection<File> files)
@@ -157,21 +178,12 @@ public CheckoutBuilder backup(boolean backup) {
* @throws IOException if the checkout fails.
*/
public void checkout() throws IOException {
- GitIndex index = new GitIndex(repository);
-
- if (tree != null)
- index.readTree(tree);
-
- for (Map.Entry<String, File> mapping : fileMappings.entrySet()) {
- GitIndex.Entry entry = index.getEntry(mapping.getKey());
-
- if (entry == null)
- continue;
-
+ for (Map.Entry<RevisionEntry, File> mapping : fileMappings.entrySet()) {
+ RevisionEntry entry = mapping.getKey();
File file = mapping.getValue();
if (backup)
backupFile(file);
- checkoutEntry(entry, file);
+ checkoutEntry(entry.getObjectId(), entry.getModeBits(), file);
}
}
View
31 src/org/nbgit/client/IndexBuilder.java
@@ -39,6 +39,7 @@
import java.io.IOException;
import java.util.Collection;
import org.nbgit.OutputLogger;
+import org.eclipse.jgit.lib.GitIndex.Entry;
import org.eclipse.jgit.lib.GitIndex;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Repository;
@@ -68,10 +69,10 @@ public static IndexBuilder create(File workDir) throws IOException {
}
public IndexBuilder add(File file) throws IOException {
- String action = index.getEntry(toPath(file)) == null ? ADDING : UPDATING;
+ GitIndex.Entry entry = index.getEntry(toPath(file));
+ String action = entry == null ? ADDING : UPDATING;
log(action, file);
- GitIndex.Entry entry = index.add(repository.getWorkDir(), file);
- entry.setAssumeValid(false);
+ addOrUpdateEntry(entry, file);
return this;
}
@@ -83,17 +84,14 @@ public IndexBuilder addAll(Collection<File> files) throws IOException {
public IndexBuilder move(File src, File dst) throws IOException {
log(MOVING, src, dst);
- index.remove(repository.getWorkDir(), src);
- index.add(repository.getWorkDir(), dst);
+ removeEntry(src);
+ addOrUpdateEntry(null, dst);
return this;
}
public IndexBuilder delete(File file) {
log(DELETING, file);
- try {
- index.remove(repository.getWorkDir(), file);
- } catch (IOException willNeverHappen) {
- }
+ removeEntry(file);
return this;
}
@@ -115,4 +113,19 @@ public IndexBuilder log(OutputLogger logger) {
return log(IndexBuilder.class, logger);
}
+ private void removeEntry(File file) {
+ try {
+ index.remove(repository.getWorkDir(), file);
+ } catch (IOException willNeverHappen) {
+ }
+ }
+
+ private void addOrUpdateEntry(GitIndex.Entry entry, File file) throws IOException {
+ if (entry == null)
+ entry = index.add(repository.getWorkDir(), file);
+ else
+ entry.update(file);
+ entry.setAssumeValid(false);
+ }
+
}
View
67 src/org/nbgit/client/RevisionEntry.java
@@ -0,0 +1,67 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2009 Jonas Fonseca <fonseca@diku.dk>
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common
+ * Development and Distribution License("CDDL") (collectively, the
+ * "License"). You may not use this file except in compliance with the
+ * License. You can obtain a copy of the License at
+ * http://www.netbeans.org/cddl-gplv2.html. See the License for the
+ * specific language governing permissions and limitations under the
+ * License. When distributing the software, include this License Header
+ * Notice in each file.
+ *
+ * This particular file is subject to the "Classpath" exception as provided
+ * by Sun in the GPL Version 2 section of the License file that
+ * accompanied this code. If applicable, add the following below the
+ * License Header, with the fields enclosed by brackets [] replaced by
+ * your own identifying information:
+ * "Portions Copyrighted [year] [name of copyright owner]"
+ *
+ * Contributor(s):
+ *
+ * If you wish your version of this file to be governed by only the CDDL
+ * or only the GPL Version 2, indicate your decision by adding
+ * "[Contributor] elects to include this software in this distribution
+ * under the [CDDL or GPL Version 2] license." If you do not indicate a
+ * single choice of license, a recipient has the option to distribute
+ * your version of this file under either the CDDL, the GPL Version 2 or
+ * to extend the choice of license to its licensees as provided above.
+ * However, if you add GPL Version 2 code and therefore, elected the GPL
+ * Version 2 license, then the option applies only if the new code is
+ * made subject to such option by the copyright holder.
+ */
+package org.nbgit.client;
+
+import org.eclipse.jgit.lib.ObjectId;
+
+public class RevisionEntry {
+
+ private final ObjectId objectId;
+ private final int modeBits;
+ private final String path;
+
+ private RevisionEntry(String path, ObjectId objectId, int modeBits) {
+ this.path = path;
+ this.objectId = objectId;
+ this.modeBits = modeBits;
+ }
+
+ public static RevisionEntry create(String path, ObjectId objectId, int modeBits) {
+ return new RevisionEntry(path, objectId, modeBits);
+ }
+
+ public String getPath() {
+ return path;
+ }
+
+ public ObjectId getObjectId() {
+ return objectId;
+ }
+
+ public int getModeBits() {
+ return modeBits;
+ }
+}
View
1  src/org/nbgit/resources/layer.xml
@@ -72,7 +72,6 @@ made subject to such option by the copyright holder.
<folder name="Windows2">
<folder name="Components">
- <file name="BrowserTopComponent.settings" url="BrowserTopComponentSettings.xml"/>
<file name="gitversioning.settings" url="settings.xml"/>
</folder>
<folder name="Modes">
View
2  src/org/nbgit/resources/settings.xml
@@ -42,7 +42,7 @@ made subject to such option by the copyright holder.
-->
<!DOCTYPE settings PUBLIC "-//NetBeans//DTD Session settings 1.0//EN" "http://www.netbeans.org/dtds/sessionsettings-1_0.dtd">
<settings version="1.0">
- <module name="org.nbgit" spec="0.3"/>
+ <module name="org.nbgit" spec="0.4"/>
<instanceof class="org.openide.windows.TopComponent"/>
<instanceof class="org.nbgit.ui.status.GitVersioningTopComponent"/>
<instance class="org.nbgit.ui.status.GitVersioningTopComponent" method="getDefault"/>
View
8 src/org/nbgit/ui/ContextAction.java
@@ -46,7 +46,9 @@
import javax.swing.Action;
import org.nbgit.util.GitUtils;
import org.netbeans.modules.versioning.spi.VCSContext;
+import org.openide.DialogDisplayer;
import org.openide.LifecycleManager;
+import org.openide.NotifyDescriptor;
/**
* Base for all context-sensitive Git actions.
@@ -80,5 +82,11 @@ public void actionPerformed(final ActionEvent event) {
performAction(event);
}
+ protected static void notifyLater(Exception exception) {
+ NotifyDescriptor e =
+ new NotifyDescriptor.Message(exception, NotifyDescriptor.ERROR_MESSAGE);
+ DialogDisplayer.getDefault().notifyLater(e);
+ }
+
protected abstract void performAction(ActionEvent event);
}
View
2  src/org/nbgit/ui/browser/BrowserTopComponent.java
@@ -53,7 +53,7 @@
public final class BrowserTopComponent extends TopComponent {
private static final String ICON_PATH = "org/nbgit/resources/icons/gitvcs-icon.png"; // NOI18N
- private static final String PREFERRED_ID = "BrowserTopComponent"; // NOI18N
+ private static final String PREFERRED_ID = "org-nbgit-ui-browser"; // NOI18N
private int commitIndex = -1;
public BrowserTopComponent(BrowserModel model) {
View
14 src/org/nbgit/ui/clone/CloneAction.java
@@ -46,10 +46,8 @@
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
-import java.net.URL;
import javax.swing.SwingUtilities;
import org.nbgit.Git;
-import org.nbgit.GitModuleConfig;
import org.nbgit.GitProgressMonitor;
import org.nbgit.GitProgressSupport;
import org.nbgit.OutputLogger;
@@ -59,8 +57,6 @@
import org.netbeans.api.project.Project;
import org.netbeans.api.project.ProjectManager;
import org.netbeans.modules.versioning.spi.VCSContext;
-import org.openide.DialogDisplayer;
-import org.openide.NotifyDescriptor;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileUtil;
import org.openide.util.Exceptions;
@@ -74,7 +70,6 @@
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.RefUpdate;
import org.eclipse.jgit.lib.Repository;
-import org.eclipse.jgit.lib.RepositoryConfig;
import org.eclipse.jgit.lib.Tree;
import org.eclipse.jgit.lib.WorkDirCheckout;
import org.eclipse.jgit.transport.FetchResult;
@@ -199,11 +194,9 @@ protected void perform() {
}
} catch (URISyntaxException usex) {
- NotifyDescriptor.Exception e = new NotifyDescriptor.Exception(usex);
- DialogDisplayer.getDefault().notifyLater(e);
+ notifyLater(usex);
} catch (IOException ex) {
- NotifyDescriptor.Exception e = new NotifyDescriptor.Exception(ex);
- DialogDisplayer.getDefault().notifyLater(e);
+ notifyLater(ex);
} finally {
if (!isLocalClone) {
logger.outputInRed(NbBundle.getMessage(CloneAction.class, "MSG_CLONE_DONE")); // NOI18N
@@ -233,8 +226,7 @@ public void run() {
logger.outputInRed(NbBundle.getMessage(CloneAction.class, "MSG_EXTERNAL_CLONE_PRJ_NOT_FOUND_CANT_SETASMAIN")); // NOI18N
}
} catch (IOException ioe) {
- NotifyDescriptor.Exception e = new NotifyDescriptor.Exception(ioe);
- DialogDisplayer.getDefault().notifyLater(e);
+ notifyLater(ioe);
} finally {
logger.outputInRed(NbBundle.getMessage(CloneAction.class, "MSG_CLONE_DONE")); // NOI18N
logger.output(""); // NOI18N
View
4 src/org/nbgit/ui/commit/CommitAction.java
@@ -76,7 +76,6 @@
import org.netbeans.modules.versioning.util.VersioningListener;
import org.openide.DialogDescriptor;
import org.openide.DialogDisplayer;
-import org.openide.NotifyDescriptor;
import org.openide.util.HelpCtx;
import org.openide.util.NbBundle;
import org.openide.util.RequestProcessor;
@@ -397,8 +396,7 @@ private static void performCommit(String message, Map<GitFileNode, CommitOptions
"MSG_COMMIT_INIT_SEP", commitCandidates, prjName));
}
} catch (Exception ex) {
- NotifyDescriptor.Exception e = new NotifyDescriptor.Exception(ex);
- DialogDisplayer.getDefault().notifyLater(e);
+ notifyLater(ex);
} finally {
cache.refreshCached(ctx);
logger.outputInRed(NbBundle.getMessage(CommitAction.class, "MSG_COMMIT_DONE")); // NOI18N
View
8 src/org/nbgit/ui/init/InitAction.java
@@ -60,8 +60,6 @@
import org.nbgit.util.GitUtils;
import org.netbeans.api.queries.SharabilityQuery;
import org.netbeans.modules.versioning.spi.VCSContext;
-import org.openide.DialogDisplayer;
-import org.openide.NotifyDescriptor;
import org.openide.util.NbBundle;
import org.openide.util.RequestProcessor;
import org.eclipse.jgit.lib.Repository;
@@ -191,8 +189,7 @@ public void perform() {
repo.create();
} catch (IOException ex) {
- NotifyDescriptor.Exception e = new NotifyDescriptor.Exception(ex);
- DialogDisplayer.getDefault().notifyLater(e);
+ notifyLater(ex);
}
}
};
@@ -216,8 +213,7 @@ public void perform() {
logger.output(""); // NOI18N
logger.outputInRed(NbBundle.getMessage(InitAction.class, "MSG_CREATE_DONE_WARNING")); // NOI18N
} catch (IOException ex) {
- NotifyDescriptor.Exception e = new NotifyDescriptor.Exception(ex);
- DialogDisplayer.getDefault().notifyLater(e);
+ notifyLater(ex);
} finally {
logger.outputInRed(NbBundle.getMessage(InitAction.class, "MSG_CREATE_DONE")); // NOI18N
logger.output(""); // NOI18N
View
18 src/org/nbgit/util/GitCommand.java
@@ -53,19 +53,12 @@
import org.nbgit.ui.log.RepositoryRevision;
import org.netbeans.api.queries.SharabilityQuery;
import org.openide.util.Exceptions;
-import org.eclipse.jgit.lib.Commit;
+import org.eclipse.jgit.dircache.DirCache;
+import org.eclipse.jgit.dircache.DirCacheEntry;
import org.eclipse.jgit.lib.Constants;
-import org.eclipse.jgit.lib.GitIndex;
-import org.eclipse.jgit.lib.GitIndex.Entry;
import org.eclipse.jgit.lib.IndexDiff;
import org.eclipse.jgit.lib.ObjectId;
-import org.eclipse.jgit.lib.ObjectLoader;
-import org.eclipse.jgit.lib.ObjectWriter;
-import org.eclipse.jgit.lib.PersonIdent;
-import org.eclipse.jgit.lib.RefUpdate;
import org.eclipse.jgit.lib.Repository;
-import org.eclipse.jgit.lib.Tree;
-import org.eclipse.jgit.lib.TreeEntry;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.revwalk.filter.RevFilter;
@@ -220,6 +213,7 @@ private static void put(Set<String> set, String relPath,
final FileTreeIterator workTree = new FileTreeIterator(repo.getWorkDir());
final TreeWalk walk = new TreeWalk(repo);
+ DirCache cache = DirCache.read(repo);
walk.reset(); // drop the first empty tree
walk.setRecursive(true);
@@ -242,7 +236,7 @@ private static void put(Set<String> set, String relPath,
index.getModified().contains(path)) {
continue;
}
- Entry entry = repo.getIndex().getEntry(path);
+ DirCacheEntry entry = cache.getEntry(path);
File file = new File(root, path);
int status;
@@ -304,6 +298,8 @@ private static void put(Set<String> set, String relPath,
walk.setRecursive(true);
walk.addTree(workTree);
+ DirCache cache = DirCache.read(repo);
+
while (walk.next()) {
String path = walk.getPathString();
@@ -317,7 +313,7 @@ private static void put(Set<String> set, String relPath,
index.getModified().contains(path)) {
continue;
}
- Entry entry = repo.getIndex().getEntry(path);
+ DirCacheEntry entry = cache.getEntry(path);
if (entry != null) {
continue;
}
View
5 src/org/nbgit/util/HtmlFormatter.java
@@ -277,8 +277,9 @@ private String formatAnnotation(StatusInfo info, File file) {
walk.dispose();
} catch (IOException ex) {
- NotifyDescriptor.Exception e = new NotifyDescriptor.Exception(ex);
- DialogDisplayer.getDefault().notifyLater(e);
+ NotifyDescriptor notification =
+ new NotifyDescriptor.Message(ex, NotifyDescriptor.ERROR_MESSAGE);
+ DialogDisplayer.getDefault().notifyLater(notification);
}
}
}
View
8 src/org/nbgit/util/exclude/FnMatch.java
@@ -189,9 +189,11 @@ private static boolean match(String pattern, int patternPos,
}
private static boolean hasLeadingPeriod(String string, int stringPos, EnumSet<Flag> flags) {
- return string.charAt(stringPos) == '.' && flags.contains(Flag.PERIOD) &&
- (stringPos == 0 ||
- (flags.contains(Flag.PATHNAME) && string.charAt(stringPos - 1) == '/'));
+ if (stringPos > string.length() - 1)
+ return false;
+ return (stringPos == 0
+ || (flags.contains(Flag.PATHNAME) && string.charAt(stringPos - 1) == '/'))
+ && string.charAt(stringPos) == '.' && flags.contains(Flag.PERIOD);
}
private static int matchRange(String pattern, int patternPos, char test, EnumSet<Flag> flags) {
Please sign in to comment.
Something went wrong with that request. Please try again.