aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.pgm/src
diff options
context:
space:
mode:
authorShawn O. Pearce <spearce@spearce.org>2011-02-06 17:42:28 -0800
committerChris Aniszczyk <caniszczyk@gmail.com>2011-02-15 13:36:22 -0600
commit6490090f14684b6026a7aa1ad4fd10c5611366b5 (patch)
tree0f74a2edc9b2945eff12e9cf4095b65401841899 /org.eclipse.jgit.pgm/src
parent22abbd338d696574b458fc26dca3f117f4818d11 (diff)
downloadjgit-6490090f14684b6026a7aa1ad4fd10c5611366b5.tar.gz
jgit-6490090f14684b6026a7aa1ad4fd10c5611366b5.zip
pgm: Make --git-dir a string
DHT based repository types don't use a java.io.File to name the repository. Moving the type to a string starts to open up more types of repository names, making the standard pgm package easier to reuse on other storage systems. Change-Id: I262ccc8c01cd6db88f832ef317b0e1e5db2d016a Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
Diffstat (limited to 'org.eclipse.jgit.pgm/src')
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clone.java5
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Init.java3
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java2
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/TextBuiltin.java31
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/DiffAlgorithms.java2
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/TextHashFunctions.java2
6 files changed, 27 insertions, 18 deletions
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clone.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clone.java
index 903f2e889d..73530efca1 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clone.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clone.java
@@ -106,7 +106,7 @@ class Clone extends AbstractFetchCommand {
}
}
if (gitdir == null)
- gitdir = new File(localName, Constants.DOT_GIT);
+ gitdir = new File(localName, Constants.DOT_GIT).getAbsolutePath();
dst = new FileRepository(gitdir);
dst.create();
@@ -116,8 +116,7 @@ class Clone extends AbstractFetchCommand {
db = dst;
out.print(MessageFormat.format(
- CLIText.get().initializedEmptyGitRepositoryIn, gitdir
- .getAbsolutePath()));
+ CLIText.get().initializedEmptyGitRepositoryIn, gitdir));
out.println();
out.flush();
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Init.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Init.java
index c56540a76a..98f086d460 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Init.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Init.java
@@ -47,6 +47,7 @@
package org.eclipse.jgit.pgm;
+import java.io.File;
import java.text.MessageFormat;
import org.eclipse.jgit.api.Git;
@@ -68,7 +69,7 @@ class Init extends TextBuiltin {
protected void run() throws Exception {
InitCommand command = Git.init();
command.setBare(bare);
- command.setDirectory(gitdir);
+ command.setDirectory(new File(gitdir));
Repository repository = command.call().getRepository();
out.println(MessageFormat.format(
CLIText.get().initializedEmptyGitRepositoryIn, repository
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java
index 62ffd8d9ca..654eed2cd9 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java
@@ -186,7 +186,7 @@ public class Main {
if (cmd.requiresRepository())
cmd.init(openGitDir(gitdir), null);
else
- cmd.init(null, gitdir != null ? new File(gitdir) : null);
+ cmd.init(null, gitdir);
try {
cmd.execute(arguments.toArray(new String[arguments.size()]));
} finally {
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/TextBuiltin.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/TextBuiltin.java
index b6f12a1ab1..2988dfc54b 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/TextBuiltin.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/TextBuiltin.java
@@ -49,19 +49,18 @@ import static org.eclipse.jgit.lib.Constants.R_REMOTES;
import static org.eclipse.jgit.lib.Constants.R_TAGS;
import java.io.BufferedWriter;
-import java.io.File;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.text.MessageFormat;
import java.util.ResourceBundle;
-import org.kohsuke.args4j.CmdLineException;
-import org.kohsuke.args4j.Option;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.pgm.opt.CmdLineParser;
import org.eclipse.jgit.revwalk.RevWalk;
+import org.kohsuke.args4j.CmdLineException;
+import org.kohsuke.args4j.Option;
/**
* Abstract command which can be invoked from the command line.
@@ -87,7 +86,7 @@ public abstract class TextBuiltin {
protected Repository db;
/** Directory supplied via --git-dir command line option. */
- protected File gitdir;
+ protected String gitdir;
/** RevWalk used during command line parsing, if it was required. */
protected RevWalk argWalk;
@@ -101,9 +100,19 @@ public abstract class TextBuiltin {
return true;
}
- void init(final Repository repo, final File gd) {
+ /**
+ * Initialize the command to work with a repository.
+ *
+ * @param repository
+ * the opened repository that the command should work on.
+ * @param gitDir
+ * value of the {@code --git-dir} command line option, if
+ * {@code repository} is null.
+ */
+ protected void init(final Repository repository, final String gitDir) {
try {
- final String outputEncoding = repo != null ? repo.getConfig()
+ final String outputEncoding = repository != null ? repository
+ .getConfig()
.getString("i18n", null, "logOutputEncoding") : null;
if (outputEncoding != null)
out = new PrintWriter(new BufferedWriter(
@@ -115,12 +124,12 @@ public abstract class TextBuiltin {
throw die(CLIText.get().cannotCreateOutputStream);
}
- if (repo != null) {
- db = repo;
- gitdir = repo.getDirectory();
+ if (repository != null && repository.getDirectory() != null) {
+ db = repository;
+ gitdir = repository.getDirectory().getAbsolutePath();
} else {
- db = null;
- gitdir = gd;
+ db = repository;
+ gitdir = gitDir;
}
}
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/DiffAlgorithms.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/DiffAlgorithms.java
index 552d704508..60d92d6beb 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/DiffAlgorithms.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/DiffAlgorithms.java
@@ -135,7 +135,7 @@ class DiffAlgorithms extends TextBuiltin {
if (gitDirs.isEmpty()) {
RepositoryBuilder rb = new RepositoryBuilder() //
- .setGitDir(gitdir) //
+ .setGitDir(new File(gitdir)) //
.readEnvironment() //
.findGitDir();
if (rb.getGitDir() == null)
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/TextHashFunctions.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/TextHashFunctions.java
index 5ce9d808c5..61a8ecc383 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/TextHashFunctions.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/TextHashFunctions.java
@@ -266,7 +266,7 @@ class TextHashFunctions extends TextBuiltin {
protected void run() throws Exception {
if (gitDirs.isEmpty()) {
RepositoryBuilder rb = new RepositoryBuilder() //
- .setGitDir(gitdir) //
+ .setGitDir(new File(gitdir)) //
.readEnvironment() //
.findGitDir();
if (rb.getGitDir() == null)