C# Класс GitSharp.Core.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.
  • GIT_DIR
    • objects/ - objects
    • refs/ - tags and heads
    • config - configuration
    • info/ - more configurations
This class is thread-safe. This implementation only handles a subtly undocumented subset of git features.
Наследование: IDisposable
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
Close ( ) : void

Close all resources used by this repository

Create ( ) : void

Create a new Git repository initializing the necessary files and directories.

Create ( bool bare ) : void

Create a new Git repository initializing the necessary files and directories.

Dispose ( ) : void
HasObject ( AnyObjectId objectId ) : bool

IncrementOpen ( ) : void
IsValidRefName ( string refName ) : bool

Check validity of a ref name. It must not contain character that has a special meaning in a Git object reference expression. Some other dangerous characters are also excluded.

Link ( string name, string target ) : void
MapCommit ( ObjectId id ) : Commit

Access a Commit by SHA'1 id.

MapCommit ( string resolveString ) : Commit

Access a Commit object using a symbolic reference. This reference may be a SHA-1 or ref in combination with a number of symbols translating from one ref or SHA1-1 to another, such as HEAD^ etc.

MapObject ( ObjectId id, string refName ) : object

Access any type of Git object by id and

MapTag ( string revstr ) : Tag

Access a tag by symbolic name.

MapTag ( string refName, ObjectId id ) : Tag

Access a Tag by SHA'1 id

MapTree ( ObjectId id ) : Tree

Access a Tree by SHA'1 id.

MapTree ( string revstr ) : Tree

Access a Tree object using a symbolic reference. This reference may be a SHA-1 or ref in combination with a number of symbols translating from one ref or SHA1-1 to another, such as HEAD^{tree} etc.

Open ( DirectoryInfo directory ) : Repository
Open ( string directory ) : Repository
OpenBlob ( ObjectId id ) : ObjectLoader

OpenCommit ( ObjectId id ) : Commit
OpenObject ( AnyObjectId id ) : ObjectLoader

OpenObject ( WindowCursor windowCursor, AnyObjectId id ) : ObjectLoader

OpenObjectInAllPacks ( AnyObjectId objectId, WindowCursor windowCursor ) : IEnumerable

Open object in all packs containing specified object.

OpenObjectInAllPacks ( AnyObjectId objectId, ICollection resultLoaders, WindowCursor windowCursor ) : void

Open object in all packs containing specified object.

OpenPack ( FileInfo pack, FileInfo idx ) : void
OpenTree ( ObjectId id ) : ObjectLoader

Peel ( Ref pRef ) : Ref
ReflogReader ( string refName ) : ReflogReader

RefreshFromDisk ( ) : void

Clean up stale caches.

RenameRef ( string fromRef, string toRef ) : RefRename

Create a command to rename a ref in this repository

Repository ( DirectoryInfo d ) : System

Construct a representation of a Git repository. The work tree, object directory, alternate object directories and index file locations are deduced from the given git directory and the default rules.

Repository ( DirectoryInfo d, DirectoryInfo workTree ) : System

Construct a representation of a Git repository. The work tree, object directory, alternate object directories and index file locations are deduced from the given git directory and the default rules.

Repository ( DirectoryInfo d, DirectoryInfo workTree, DirectoryInfo objectDir, DirectoryInfo alternateObjectDir, FileInfo indexFile ) : System

Construct a representation of a Git repository using the given parameters possibly overriding default conventions..

Resolve ( string revision ) : ObjectId

Parse a git revision string and return an object id. Currently supported is combinations of these.

  • SHA-1 - a SHA-1
  • refs/... - a ref name
  • ref^n - nth parent reference
  • ref~n - distance via parent reference
  • ref@{n} - nth version of ref
  • ref^{tree} - tree references by ref
  • ref^{commit} - commit references by ref
Not supported is
  • timestamps in reflogs, ref@{full or relative timestamp}
  • abbreviated SHA-1's

ShortenRefName ( string refName ) : string

StripWorkDir ( FileSystemInfo workDir, FileSystemInfo file ) : string

Strip work dir and return normalized repository path

ToFile ( AnyObjectId objectId ) : FileInfo

Construct a filename where the loose object having a specified SHA-1 should be stored. If the object is stored in a shared repository the path to the alternative repo will be returned. If the object is not yet store a usable path in this repo will be returned. It is assumed that callers will look for objects in a pack first.

ToString ( ) : string
UpdateRef ( string refName ) : RefUpdate

Create a command to update (or create) a ref in this repository.

UpdateRef ( string refName, bool detach ) : RefUpdate

Create a command to update, create or delete a ref in this repository.

WriteSymref ( string name, string target ) : void

Writes a symref (e.g. HEAD) to disk

addAnyRepositoryChangedListener ( RepositoryListener l ) : void
addRepositoryChangedListener ( RepositoryListener l ) : void
getAllRefs ( ) : Ref>.Dictionary
getAllRefsByPeeledObjectId ( ) : List>.Dictionary
getBranch ( ) : string
getIndexFile ( ) : FileInfo
getRef ( string name ) : Ref
getTags ( ) : Ref>.Dictionary
removeAnyRepositoryChangedListener ( RepositoryListener l ) : void
removeRepositoryChangedListener ( RepositoryListener l ) : void
scanForRepoChanges ( ) : void
setWorkDir ( DirectoryInfo workTree ) : void

Override default workdir

Приватные методы

Метод Описание
GitInternalSlash ( byte bytes ) : byte[]

Replaces any windows director separators (backslash) with /

MakeCommit ( ObjectId id, byte raw ) : object
MakeTag ( ObjectId id, string refName, byte raw ) : Tag
MakeTree ( ObjectId id, byte raw ) : Tree
ResolveSimple ( string revstr ) : ObjectId
fireIndexChanged ( ) : void
fireRefsMaybeChanged ( ) : void

Описание методов

Close() публичный Метод

Close all resources used by this repository
public Close ( ) : void
Результат void

Create() публичный Метод

Create a new Git repository initializing the necessary files and directories.
public Create ( ) : void
Результат void

Create() публичный Метод

Create a new Git repository initializing the necessary files and directories.
public Create ( bool bare ) : void
bare bool if true, a bare repository is created.
Результат void

Dispose() публичный Метод

public Dispose ( ) : void
Результат void

HasObject() публичный Метод

public HasObject ( AnyObjectId objectId ) : bool
objectId AnyObjectId
Результат bool

IncrementOpen() публичный Метод

public IncrementOpen ( ) : void
Результат void

IsValidRefName() публичный статический Метод

Check validity of a ref name. It must not contain character that has a special meaning in a Git object reference expression. Some other dangerous characters are also excluded.
public static IsValidRefName ( string refName ) : bool
refName string
Результат bool

Link() публичный Метод

public Link ( string name, string target ) : void
name string
target string
Результат void

MapCommit() публичный Метод

Access a Commit by SHA'1 id.
public MapCommit ( ObjectId id ) : Commit
id ObjectId
Результат Commit

MapCommit() публичный Метод

Access a Commit object using a symbolic reference. This reference may be a SHA-1 or ref in combination with a number of symbols translating from one ref or SHA1-1 to another, such as HEAD^ etc.
public MapCommit ( string resolveString ) : Commit
resolveString string a reference to a git commit object
Результат Commit

MapObject() публичный Метод

Access any type of Git object by id and
public MapObject ( ObjectId id, string refName ) : object
id ObjectId SHA-1 of object to read
refName string optional, only relevant for simple tags
Результат object

MapTag() публичный Метод

Access a tag by symbolic name.
public MapTag ( string revstr ) : Tag
revstr string
Результат Tag

MapTag() публичный Метод

Access a Tag by SHA'1 id
public MapTag ( string refName, ObjectId id ) : Tag
refName string
id ObjectId
Результат Tag

MapTree() публичный Метод

Access a Tree by SHA'1 id.
public MapTree ( ObjectId id ) : Tree
id ObjectId
Результат Tree

MapTree() публичный Метод

Access a Tree object using a symbolic reference. This reference may be a SHA-1 or ref in combination with a number of symbols translating from one ref or SHA1-1 to another, such as HEAD^{tree} etc.
public MapTree ( string revstr ) : Tree
revstr string a reference to a git commit object
Результат Tree

Open() публичный статический Метод

public static Open ( DirectoryInfo directory ) : Repository
directory DirectoryInfo
Результат Repository

Open() публичный статический Метод

public static Open ( string directory ) : Repository
directory string
Результат Repository

OpenBlob() публичный Метод

public OpenBlob ( ObjectId id ) : ObjectLoader
id ObjectId SHA'1 of a blob
Результат ObjectLoader

OpenCommit() публичный Метод

public OpenCommit ( ObjectId id ) : Commit
id ObjectId
Результат Commit

OpenObject() публичный Метод

public OpenObject ( AnyObjectId id ) : ObjectLoader
id AnyObjectId SHA-1 of an object.
Результат ObjectLoader

OpenObject() публичный Метод

public OpenObject ( WindowCursor windowCursor, AnyObjectId id ) : ObjectLoader
windowCursor WindowCursor /// Temporary working space associated with the calling thread. ///
id AnyObjectId SHA-1 of an object.
Результат ObjectLoader

OpenObjectInAllPacks() публичный Метод

Open object in all packs containing specified object.
public OpenObjectInAllPacks ( AnyObjectId objectId, WindowCursor windowCursor ) : IEnumerable
objectId AnyObjectId id of object to search for
windowCursor WindowCursor /// Temporary working space associated with the calling thread. ///
Результат IEnumerable

OpenObjectInAllPacks() публичный Метод

Open object in all packs containing specified object.
public OpenObjectInAllPacks ( AnyObjectId objectId, ICollection resultLoaders, WindowCursor windowCursor ) : void
objectId AnyObjectId of object to search for
resultLoaders ICollection /// Result collection of loaders for this object, filled with /// loaders from all packs containing specified object ///
windowCursor WindowCursor /// Temporary working space associated with the calling thread. ///
Результат void

OpenPack() публичный Метод

public OpenPack ( FileInfo pack, FileInfo idx ) : void
pack FileInfo
idx FileInfo
Результат void

OpenTree() публичный Метод

public OpenTree ( ObjectId id ) : ObjectLoader
id ObjectId SHA'1 of a tree
Результат ObjectLoader

Peel() публичный Метод

public Peel ( Ref pRef ) : Ref
pRef Ref
Результат Ref

ReflogReader() публичный Метод

The could not be accessed.
public ReflogReader ( string refName ) : ReflogReader
refName string
Результат ReflogReader

RefreshFromDisk() публичный Метод

Clean up stale caches.
public RefreshFromDisk ( ) : void
Результат void

RenameRef() публичный Метод

Create a command to rename a ref in this repository
The rename could not be performed.
public RenameRef ( string fromRef, string toRef ) : RefRename
fromRef string Name of ref to rename from.
toRef string Name of ref to rename to.
Результат RefRename

Repository() публичный Метод

Construct a representation of a Git repository. The work tree, object directory, alternate object directories and index file locations are deduced from the given git directory and the default rules.
public Repository ( DirectoryInfo d ) : System
d DirectoryInfo GIT_DIR (the location of the repository metadata).
Результат System

Repository() публичный Метод

Construct a representation of a Git repository. The work tree, object directory, alternate object directories and index file locations are deduced from the given git directory and the default rules.
public Repository ( DirectoryInfo d, DirectoryInfo workTree ) : System
d DirectoryInfo GIT_DIR (the location of the repository metadata).
workTree DirectoryInfo GIT_WORK_TREE (the root of the checkout). May be null for default value.
Результат System

Repository() публичный Метод

Construct a representation of a Git repository using the given parameters possibly overriding default conventions..
public Repository ( DirectoryInfo d, DirectoryInfo workTree, DirectoryInfo objectDir, DirectoryInfo alternateObjectDir, FileInfo indexFile ) : System
d DirectoryInfo GIT_DIR (the location of the repository metadata). May be null for default value in which case it depends on GIT_WORK_TREE.
workTree DirectoryInfo GIT_WORK_TREE (the root of the checkout). May be null for default value if GIT_DIR is
objectDir DirectoryInfo GIT_OBJECT_DIRECTORY (where objects and are stored). May be null for default value. Relative names ares resolved against GIT_WORK_TREE
alternateObjectDir DirectoryInfo GIT_ALTERNATE_OBJECT_DIRECTORIES (where more objects are read from). May be null for default value. Relative names ares resolved against GIT_WORK_TREE
indexFile FileInfo GIT_INDEX_FILE (the location of the index file). May be null for default value. Relative names ares resolved against GIT_WORK_TREE.
Результат System

Resolve() публичный Метод

Parse a git revision string and return an object id. Currently supported is combinations of these.
  • SHA-1 - a SHA-1
  • refs/... - a ref name
  • ref^n - nth parent reference
  • ref~n - distance via parent reference
  • ref@{n} - nth version of ref
  • ref^{tree} - tree references by ref
  • ref^{commit} - commit references by ref
Not supported is
  • timestamps in reflogs, ref@{full or relative timestamp}
  • abbreviated SHA-1's
On serious errors.
public Resolve ( string revision ) : ObjectId
revision string A git object references expression.
Результат ObjectId

ShortenRefName() публичный статический Метод

public static ShortenRefName ( string refName ) : string
refName string
Результат string

StripWorkDir() публичный статический Метод

Strip work dir and return normalized repository path
public static StripWorkDir ( FileSystemInfo workDir, FileSystemInfo file ) : string
workDir FileSystemInfo Work directory
file FileSystemInfo File whose path shall be stripp off it's workdir
Результат string

ToFile() публичный Метод

Construct a filename where the loose object having a specified SHA-1 should be stored. If the object is stored in a shared repository the path to the alternative repo will be returned. If the object is not yet store a usable path in this repo will be returned. It is assumed that callers will look for objects in a pack first.
public ToFile ( AnyObjectId objectId ) : FileInfo
objectId AnyObjectId
Результат FileInfo

ToString() публичный Метод

public ToString ( ) : string
Результат string

UpdateRef() публичный Метод

Create a command to update (or create) a ref in this repository.
public UpdateRef ( string refName ) : RefUpdate
refName string /// name of the ref the caller wants to modify. ///
Результат RefUpdate

UpdateRef() публичный Метод

Create a command to update, create or delete a ref in this repository.
public UpdateRef ( string refName, bool detach ) : RefUpdate
refName string name of the ref the caller wants to modify.
detach bool true to create a detached head
Результат RefUpdate

WriteSymref() публичный Метод

Writes a symref (e.g. HEAD) to disk
public WriteSymref ( string name, string target ) : void
name string symref name
target string pointed to ref
Результат void

addAnyRepositoryChangedListener() публичный статический Метод

public static addAnyRepositoryChangedListener ( RepositoryListener l ) : void
l RepositoryListener
Результат void

addRepositoryChangedListener() публичный Метод

public addRepositoryChangedListener ( RepositoryListener l ) : void
l RepositoryListener
Результат void

getAllRefs() публичный Метод

public getAllRefs ( ) : Ref>.Dictionary
Результат Ref>.Dictionary

getAllRefsByPeeledObjectId() публичный Метод

public getAllRefsByPeeledObjectId ( ) : List>.Dictionary
Результат List>.Dictionary

getBranch() публичный Метод

public getBranch ( ) : string
Результат string

getIndexFile() публичный Метод

public getIndexFile ( ) : FileInfo
Результат FileInfo

getRef() публичный Метод

public getRef ( string name ) : Ref
name string
Результат Ref

getTags() публичный Метод

public getTags ( ) : Ref>.Dictionary
Результат Ref>.Dictionary

removeAnyRepositoryChangedListener() публичный статический Метод

public static removeAnyRepositoryChangedListener ( RepositoryListener l ) : void
l RepositoryListener
Результат void

removeRepositoryChangedListener() публичный Метод

public removeRepositoryChangedListener ( RepositoryListener l ) : void
l RepositoryListener
Результат void

scanForRepoChanges() публичный Метод

public scanForRepoChanges ( ) : void
Результат void

setWorkDir() публичный Метод

Override default workdir
public setWorkDir ( DirectoryInfo workTree ) : void
workTree DirectoryInfo the work tree directory
Результат void