|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.eclipse.jgit.lib.Repository
public class Repository
Represents a Git repository. A repository holds all objects and refs used for managing source code (could by any type of file, but source code is what SCM's are typically used for). In Git terms all data is stored in GIT_DIR, typically a directory called .git. A work tree is maintained unless the repository is a bare repository. Typically the .git directory is located at the root of the work dir.
This class is thread-safe.
This implementation only handles a subtly undocumented subset of git features.
| Constructor Summary | |
|---|---|
Repository(java.io.File d)
Construct a representation of a Git repository. |
|
| Method Summary | |
|---|---|
static void |
addAnyRepositoryChangedListener(RepositoryListener l)
Register a global RepositoryListener which will be notified
when a ref changes in any repository are detected. |
void |
addRepositoryChangedListener(RepositoryListener l)
Register a RepositoryListener which will be notified
when ref changes are detected. |
void |
close()
Close all resources used by this repository |
void |
create()
Create a new Git repository initializing the necessary files and directories. |
void |
create(boolean bare)
Create a new Git repository initializing the necessary files and directories. |
java.util.Map<java.lang.String,Ref> |
getAllRefs()
|
java.util.Map<AnyObjectId,java.util.Set<Ref>> |
getAllRefsByPeeledObjectId()
|
java.lang.String |
getBranch()
|
RepositoryConfig |
getConfig()
|
java.io.File |
getDirectory()
|
java.lang.String |
getFullBranch()
|
GitIndex |
getIndex()
|
ObjectDatabase |
getObjectDatabase()
|
java.io.File |
getObjectsDirectory()
|
Ref |
getRef(java.lang.String name)
Get a ref by name. |
ReflogReader |
getReflogReader(java.lang.String refName)
|
RepositoryState |
getRepositoryState()
|
java.util.Map<java.lang.String,Ref> |
getTags()
|
java.io.File |
getWorkDir()
|
boolean |
hasObject(AnyObjectId objectId)
|
void |
incrementOpen()
Increment the use counter by one, requiring a matched close(). |
static boolean |
isValidRefName(java.lang.String refName)
Check validity of a ref name. |
Commit |
mapCommit(ObjectId id)
Access a Commit by SHA'1 id. |
Commit |
mapCommit(java.lang.String revstr)
Access a Commit object using a symbolic reference. |
java.lang.Object |
mapObject(ObjectId id,
java.lang.String refName)
Access any type of Git object by id and |
Tag |
mapTag(java.lang.String revstr)
Access a tag by symbolic name. |
Tag |
mapTag(java.lang.String refName,
ObjectId id)
Access a Tag by SHA'1 id |
Tree |
mapTree(ObjectId id)
Access a Tree by SHA'1 id. |
Tree |
mapTree(java.lang.String revstr)
Access a Tree object using a symbolic reference. |
ObjectLoader |
openBlob(ObjectId id)
|
ObjectLoader |
openObject(AnyObjectId id)
|
ObjectLoader |
openObject(WindowCursor curs,
AnyObjectId id)
|
java.util.Collection<org.eclipse.jgit.lib.PackedObjectLoader> |
openObjectInAllPacks(AnyObjectId objectId,
WindowCursor curs)
Open object in all packs containing specified object. |
void |
openPack(java.io.File pack,
java.io.File idx)
Add a single existing pack to the list of available pack files. |
ObjectLoader |
openTree(ObjectId id)
|
Ref |
peel(Ref ref)
Peel a possibly unpeeled ref and updates it. |
void |
refreshFromDisk()
Clean up stale caches |
static void |
removeAnyRepositoryChangedListener(RepositoryListener l)
Remove a globally registered RepositoryListener |
void |
removeRepositoryChangedListener(RepositoryListener l)
Remove a registered RepositoryListener |
RefRename |
renameRef(java.lang.String fromRef,
java.lang.String toRef)
Create a command to rename a ref in this repository |
ObjectId |
resolve(java.lang.String revstr)
Parse a git revision string and return an object id. |
void |
scanForRepoChanges()
Force a scan for changed refs. |
java.lang.String |
shortenRefName(java.lang.String refName)
|
static java.lang.String |
stripWorkDir(java.io.File workDir,
java.io.File file)
Strip work dir and return normalized repository path. |
java.io.File |
toFile(AnyObjectId objectId)
Construct a filename where the loose object having a specified SHA-1 should be stored. |
java.lang.String |
toString()
|
RefUpdate |
updateRef(java.lang.String ref)
Create a command to update, create or delete a ref in this repository. |
void |
writeSymref(java.lang.String name,
java.lang.String target)
Writes a symref (e.g. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public Repository(java.io.File d)
throws java.io.IOException
d - GIT_DIR (the location of the repository metadata).
java.io.IOException - the repository appears to already exist but cannot be
accessed.| Method Detail |
|---|
public void create()
throws java.io.IOException
java.io.IOExceptioncreate(boolean)
public void create(boolean bare)
throws java.io.IOException
bare - if true, a bare repository is created.
java.io.IOException - in case of IO problempublic java.io.File getDirectory()
public java.io.File getObjectsDirectory()
public ObjectDatabase getObjectDatabase()
public RepositoryConfig getConfig()
public java.io.File toFile(AnyObjectId objectId)
objectId -
public boolean hasObject(AnyObjectId objectId)
objectId -
public ObjectLoader openObject(AnyObjectId id)
throws java.io.IOException
id - SHA-1 of an object.
ObjectLoader for accessing the data of the named
object, or null if the object does not exist.
java.io.IOException
public ObjectLoader openObject(WindowCursor curs,
AnyObjectId id)
throws java.io.IOException
curs - temporary working space associated with the calling thread.id - SHA-1 of an object.
ObjectLoader for accessing the data of the named
object, or null if the object does not exist.
java.io.IOException
public java.util.Collection<org.eclipse.jgit.lib.PackedObjectLoader> openObjectInAllPacks(AnyObjectId objectId,
WindowCursor curs)
throws java.io.IOException
objectId - id of object to search forcurs - temporary working space associated with the calling thread.
java.io.IOException
public ObjectLoader openBlob(ObjectId id)
throws java.io.IOException
id - SHA'1 of a blob
ObjectLoader for accessing the data of a named blob
java.io.IOException
public ObjectLoader openTree(ObjectId id)
throws java.io.IOException
id - SHA'1 of a tree
ObjectLoader for accessing the data of a named tree
java.io.IOException
public Commit mapCommit(java.lang.String revstr)
throws java.io.IOException
revstr - a reference to a git commit object
java.io.IOException - for I/O error or unexpected object type.resolve(String)
public java.lang.Object mapObject(ObjectId id,
java.lang.String refName)
throws java.io.IOException
id - SHA-1 of object to readrefName - optional, only relevant for simple tags
java.io.IOException
public Commit mapCommit(ObjectId id)
throws java.io.IOException
id -
java.io.IOException - for I/O error or unexpected object type.
public Tree mapTree(java.lang.String revstr)
throws java.io.IOException
revstr - a reference to a git commit object
java.io.IOExceptionresolve(String)
public Tree mapTree(ObjectId id)
throws java.io.IOException
id -
java.io.IOException - for I/O error or unexpected object type.
public Tag mapTag(java.lang.String revstr)
throws java.io.IOException
revstr -
java.io.IOException - on I/O error or unexpected type
public Tag mapTag(java.lang.String refName,
ObjectId id)
throws java.io.IOException
refName - id -
java.io.IOException - for I/O error or unexpected object type.
public RefUpdate updateRef(java.lang.String ref)
throws java.io.IOException
ref - name of the ref the caller wants to modify.
java.io.IOException - a symbolic ref was passed in and could not be resolved back
to the base ref, as the symbolic ref could not be read.
public RefRename renameRef(java.lang.String fromRef,
java.lang.String toRef)
throws java.io.IOException
fromRef - name of ref to rename fromtoRef - name of ref to rename to
java.io.IOException - the rename could not be performed.
public ObjectId resolve(java.lang.String revstr)
throws java.io.IOException
revstr - A git object references expression
java.io.IOException - on serious errorspublic void incrementOpen()
close().
public void close()
public void openPack(java.io.File pack,
java.io.File idx)
throws java.io.IOException
pack - path of the pack file to open.idx - path of the corresponding index file.
java.io.IOException - index file could not be opened, read, or is not recognized as
a Git pack file index.
public void writeSymref(java.lang.String name,
java.lang.String target)
throws java.io.IOException
name - symref nametarget - pointed to ref
java.io.IOExceptionpublic java.lang.String toString()
toString in class java.lang.Object
public java.lang.String getFullBranch()
throws java.io.IOException
java.io.IOException
public java.lang.String getBranch()
throws java.io.IOException
java.io.IOException
public Ref getRef(java.lang.String name)
throws java.io.IOException
name - the name of the ref to lookup. May be a short-hand form, e.g.
"master" which is is automatically expanded to
"refs/heads/master" if "refs/heads/master" already exists.
java.io.IOExceptionpublic java.util.Map<java.lang.String,Ref> getAllRefs()
public java.util.Map<java.lang.String,Ref> getTags()
public Ref peel(Ref ref)
If the ref cannot be peeled (as it does not refer to an annotated tag)
the peeled id stays null, but Ref.isPeeled() will be true.
ref - The ref to peel
ref if ref.isPeeled() is true; else a
new Ref object representing the same data as Ref, but isPeeled()
will be true and getPeeledObjectId will contain the peeled object
(or null).public java.util.Map<AnyObjectId,java.util.Set<Ref>> getAllRefsByPeeledObjectId()
public void refreshFromDisk()
public GitIndex getIndex()
throws java.io.IOException
java.io.IOExceptionpublic RepositoryState getRepositoryState()
public static boolean isValidRefName(java.lang.String refName)
refName -
public static java.lang.String stripWorkDir(java.io.File workDir,
java.io.File file)
workDir - Work dirfile - File whose path shall be stripped of its workdir
public java.io.File getWorkDir()
public void addRepositoryChangedListener(RepositoryListener l)
RepositoryListener which will be notified
when ref changes are detected.
l - public void removeRepositoryChangedListener(RepositoryListener l)
RepositoryListener
l - public static void addAnyRepositoryChangedListener(RepositoryListener l)
RepositoryListener which will be notified
when a ref changes in any repository are detected.
l - public static void removeAnyRepositoryChangedListener(RepositoryListener l)
RepositoryListener
l -
public void scanForRepoChanges()
throws java.io.IOException
java.io.IOExceptionpublic java.lang.String shortenRefName(java.lang.String refName)
refName -
public ReflogReader getReflogReader(java.lang.String refName)
throws java.io.IOException
refName -
ReflogReader for the supplied refname, or null if the
named ref does not exist.
java.io.IOException - the ref could not be accessed.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||