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>
tags/v0.12.1
Shawn O. Pearce 13 years ago
parent
commit
6490090f14

+ 2
- 3
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clone.java View File

@@ -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();


+ 2
- 1
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Init.java View File

@@ -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

+ 1
- 1
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java View File

@@ -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 {

+ 20
- 11
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/TextBuiltin.java View File

@@ -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;
}
}


+ 1
- 1
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/DiffAlgorithms.java View File

@@ -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)

+ 1
- 1
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/TextHashFunctions.java View File

@@ -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)

Loading…
Cancel
Save