org.eclipse.jgit.lib
Class RepositoryCache.FileKey

java.lang.Object
  extended by org.eclipse.jgit.lib.RepositoryCache.FileKey
All Implemented Interfaces:
RepositoryCache.Key
Enclosing class:
RepositoryCache

public static class RepositoryCache.FileKey
extends Object
implements RepositoryCache.Key

Location of a Repository, using the standard java.io.File API.


Constructor Summary
protected RepositoryCache.FileKey(File directory, FS fs)
           
 
Method Summary
 boolean equals(Object o)
           
static RepositoryCache.FileKey exact(File directory, FS fs)
          Obtain a pointer to an exact location on disk.
 File getFile()
           
 int hashCode()
           
static boolean isGitRepository(File dir, FS fs)
          Guess if a directory contains a Git repository.
static RepositoryCache.FileKey lenient(File directory, FS fs)
          Obtain a pointer to a location on disk.
 Repository open(boolean mustExist)
          Called by RepositoryCache.open(Key) if it doesn't exist yet.
static File resolve(File directory, FS fs)
          Guess the proper path for a Git repository.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RepositoryCache.FileKey

protected RepositoryCache.FileKey(File directory,
                                  FS fs)
Parameters:
directory - exact location of the repository.
fs - the file system abstraction which will be necessary to perform certain file system operations.
Method Detail

exact

public static RepositoryCache.FileKey exact(File directory,
                                            FS fs)
Obtain a pointer to an exact location on disk.

No guessing is performed, the given location is exactly the GIT_DIR directory of the repository.

Parameters:
directory - location where the repository database is.
fs - the file system abstraction which will be necessary to perform certain file system operations.
Returns:
a key for the given directory.
See Also:
lenient(File, FS)

lenient

public static RepositoryCache.FileKey lenient(File directory,
                                              FS fs)
Obtain a pointer to a location on disk.

The method performs some basic guessing to locate the repository. Searched paths are:

  1. directory // assume exact match
  2. directory + "/.git" // assume working directory
  3. directory + ".git" // assume bare

Parameters:
directory - location where the repository database might be.
fs - the file system abstraction which will be necessary to perform certain file system operations.
Returns:
a key for the given directory.
See Also:
exact(File, FS)

getFile

public final File getFile()
Returns:
location supplied to the constructor.

open

public Repository open(boolean mustExist)
                throws IOException
Description copied from interface: RepositoryCache.Key
Called by RepositoryCache.open(Key) if it doesn't exist yet.

If a repository does not exist yet in the cache, the cache will call this method to acquire a handle to it.

Specified by:
open in interface RepositoryCache.Key
Parameters:
mustExist - true if the repository must exist in order to be opened; false if a new non-existent repository is permitted to be created (the caller is responsible for calling create).
Returns:
the new repository instance.
Throws:
IOException - the repository could not be read (likely its core.version property is not supported).
RepositoryNotFoundException - There is no repository at the given location, only thrown if mustExist is true.

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object o)
Overrides:
equals in class Object

toString

public String toString()
Overrides:
toString in class Object

isGitRepository

public static boolean isGitRepository(File dir,
                                      FS fs)
Guess if a directory contains a Git repository.

This method guesses by looking for the existence of some key files and directories.

Parameters:
dir - the location of the directory to examine.
fs - the file system abstraction which will be necessary to perform certain file system operations.
Returns:
true if the directory "looks like" a Git repository; false if it doesn't look enough like a Git directory to really be a Git directory.

resolve

public static File resolve(File directory,
                           FS fs)
Guess the proper path for a Git repository.

The method performs some basic guessing to locate the repository. Searched paths are:

  1. directory // assume exact match
  2. directory + "/.git" // assume working directory
  3. directory + ".git" // assume bare

Parameters:
directory - location to guess from. Several permutations are tried.
fs - the file system abstraction which will be necessary to perform certain file system operations.
Returns:
the actual directory location if a better match is found; null if there is no suitable match.


Copyright © 2012. All Rights Reserved.