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
} | } | ||||
} | } | ||||
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(); | ||||
db = dst; | db = dst; | ||||
out.print(MessageFormat.format( | out.print(MessageFormat.format( | ||||
CLIText.get().initializedEmptyGitRepositoryIn, gitdir | |||||
.getAbsolutePath())); | |||||
CLIText.get().initializedEmptyGitRepositoryIn, gitdir)); | |||||
out.println(); | out.println(); | ||||
out.flush(); | out.flush(); | ||||
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; | ||||
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 |
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 { |
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. | ||||
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; | ||||
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( | ||||
throw die(CLIText.get().cannotCreateOutputStream); | 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 { | } else { | ||||
db = null; | |||||
gitdir = gd; | |||||
db = repository; | |||||
gitdir = gitDir; | |||||
} | } | ||||
} | } | ||||
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) |
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) |