Browse Source

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>
stable-0.12
Shawn O. Pearce 14 years ago committed by Chris Aniszczyk
parent
commit
6490090f14
  1. 5
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clone.java
  2. 3
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Init.java
  3. 2
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java
  4. 31
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/TextBuiltin.java
  5. 2
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/DiffAlgorithms.java
  6. 2
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/TextHashFunctions.java

5
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clone.java

@ -106,7 +106,7 @@ class Clone extends AbstractFetchCommand {
} }
} }
if (gitdir == null) if (gitdir == null)
gitdir = new File(localName, Constants.DOT_GIT); gitdir = new File(localName, Constants.DOT_GIT).getAbsolutePath();
dst = new FileRepository(gitdir); dst = new FileRepository(gitdir);
dst.create(); dst.create();
@ -116,8 +116,7 @@ class Clone extends AbstractFetchCommand {
db = dst; db = dst;
out.print(MessageFormat.format( out.print(MessageFormat.format(
CLIText.get().initializedEmptyGitRepositoryIn, gitdir CLIText.get().initializedEmptyGitRepositoryIn, gitdir));
.getAbsolutePath()));
out.println(); out.println();
out.flush(); out.flush();

3
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Init.java

@ -47,6 +47,7 @@
package org.eclipse.jgit.pgm; package org.eclipse.jgit.pgm;
import java.io.File;
import java.text.MessageFormat; import java.text.MessageFormat;
import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.Git;
@ -68,7 +69,7 @@ class Init extends TextBuiltin {
protected void run() throws Exception { protected void run() throws Exception {
InitCommand command = Git.init(); InitCommand command = Git.init();
command.setBare(bare); command.setBare(bare);
command.setDirectory(gitdir); command.setDirectory(new File(gitdir));
Repository repository = command.call().getRepository(); Repository repository = command.call().getRepository();
out.println(MessageFormat.format( out.println(MessageFormat.format(
CLIText.get().initializedEmptyGitRepositoryIn, repository CLIText.get().initializedEmptyGitRepositoryIn, repository

2
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java

@ -186,7 +186,7 @@ public class Main {
if (cmd.requiresRepository()) if (cmd.requiresRepository())
cmd.init(openGitDir(gitdir), null); cmd.init(openGitDir(gitdir), null);
else else
cmd.init(null, gitdir != null ? new File(gitdir) : null); cmd.init(null, gitdir);
try { try {
cmd.execute(arguments.toArray(new String[arguments.size()])); cmd.execute(arguments.toArray(new String[arguments.size()]));
} finally { } finally {

31
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 static org.eclipse.jgit.lib.Constants.R_TAGS;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.ResourceBundle; 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.ObjectId;
import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.pgm.opt.CmdLineParser; import org.eclipse.jgit.pgm.opt.CmdLineParser;
import org.eclipse.jgit.revwalk.RevWalk; 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. * Abstract command which can be invoked from the command line.
@ -87,7 +86,7 @@ public abstract class TextBuiltin {
protected Repository db; protected Repository db;
/** Directory supplied via --git-dir command line option. */ /** Directory supplied via --git-dir command line option. */
protected File gitdir; protected String gitdir;
/** RevWalk used during command line parsing, if it was required. */ /** RevWalk used during command line parsing, if it was required. */
protected RevWalk argWalk; protected RevWalk argWalk;
@ -101,9 +100,19 @@ public abstract class TextBuiltin {
return true; 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 { try {
final String outputEncoding = repo != null ? repo.getConfig() final String outputEncoding = repository != null ? repository
.getConfig()
.getString("i18n", null, "logOutputEncoding") : null; .getString("i18n", null, "logOutputEncoding") : null;
if (outputEncoding != null) if (outputEncoding != null)
out = new PrintWriter(new BufferedWriter( out = new PrintWriter(new BufferedWriter(
@ -115,12 +124,12 @@ public abstract class TextBuiltin {
throw die(CLIText.get().cannotCreateOutputStream); throw die(CLIText.get().cannotCreateOutputStream);
} }
if (repo != null) { if (repository != null && repository.getDirectory() != null) {
db = repo; db = repository;
gitdir = repo.getDirectory(); gitdir = repository.getDirectory().getAbsolutePath();
} else { } else {
db = null; db = repository;
gitdir = gd; gitdir = gitDir;
} }
} }

2
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/DiffAlgorithms.java

@ -135,7 +135,7 @@ class DiffAlgorithms extends TextBuiltin {
if (gitDirs.isEmpty()) { if (gitDirs.isEmpty()) {
RepositoryBuilder rb = new RepositoryBuilder() // RepositoryBuilder rb = new RepositoryBuilder() //
.setGitDir(gitdir) // .setGitDir(new File(gitdir)) //
.readEnvironment() // .readEnvironment() //
.findGitDir(); .findGitDir();
if (rb.getGitDir() == null) if (rb.getGitDir() == null)

2
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 { protected void run() throws Exception {
if (gitDirs.isEmpty()) { if (gitDirs.isEmpty()) {
RepositoryBuilder rb = new RepositoryBuilder() // RepositoryBuilder rb = new RepositoryBuilder() //
.setGitDir(gitdir) // .setGitDir(new File(gitdir)) //
.readEnvironment() // .readEnvironment() //
.findGitDir(); .findGitDir();
if (rb.getGitDir() == null) if (rb.getGitDir() == null)

Loading…
Cancel
Save