本文整理汇总了C#中Repository.Open方法的典型用法代码示例。如果您正苦于以下问题:C# Repository.Open方法的具体用法?C# Repository.Open怎么用?C# Repository.Open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Repository
的用法示例。
在下文中一共展示了Repository.Open方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetFileContent
public static string GetFileContent(this RevCommit commit, string path, Repository repository)
{
var treeWalk = new TreeWalk(repository) {Recursive = true, Filter = PathFilter.Create(path)};
treeWalk.AddTree(commit.Tree);
if (!treeWalk.Next())
{
return string.Empty;
}
var objectId = treeWalk.GetObjectId(0);
var loader = repository.Open(objectId);
using (var stream = loader.OpenStream())
{
using (var reader = new StreamReader(stream))
{
return reader.ReadToEnd();
}
}
}
示例2: GetRawText
/// <exception cref="System.IO.IOException"></exception>
private static RawText GetRawText(ObjectId id, Repository db)
{
if (id.Equals(ObjectId.ZeroId))
{
return new RawText(new byte[] { });
}
return new RawText(db.Open(id, Constants.OBJ_BLOB).GetCachedBytes());
}
示例3: Refresh
public void Refresh()
{
this.index = null;
this.commitTree = null;
this.cache.Clear();
this.changedFiles = null;
this.repositoryGraph = null;
this.dirCache = null;
this.head = null;
this.ignoreRules = null;
this.remotes = null;
this.configs = null;
if (!string.IsNullOrEmpty(initFolder))
{
try
{
this.repository = Open(new DirectoryInfo(initFolder));
if (this.repository != null)
{
dirCache = repository.ReadDirCache();
head = repository.Resolve(Constants.HEAD);
if (head == null)
{
this.commitTree = new Tree(repository);
}
else
{
var treeId = ObjectId.FromString(repository.Open(head).GetBytes(), 5);
this.commitTree = new Tree(repository, treeId, repository.Open(treeId).GetBytes());
}
if (repository.IsBare)
throw new NoWorkTreeException();
this.index = new GitIndex(repository);
this.index.Read();
this.index.RereadIfNecessary();
try
{
//load local .gitignore file
var ignoreFile = Path.Combine(this.initFolder,
Constants.GITIGNORE_FILENAME);
if (File.Exists(ignoreFile))
{
ignoreRules = File.ReadAllLines(ignoreFile)
.Where(line => !line.StartsWith("#") && line.Trim().Length > 0)
.Select(line => new IgnoreRule(line)).ToList();
}
}
catch (Exception ex)
{
Log.WriteLine("ReadIgnoreFile: {0}\r\n{1}", this.initFolder, ex.ToString());
}
}
}
catch (Exception ex)
{
this.repository = null;
Log.WriteLine("Refresh: {0}\r\n{1}", this.initFolder, ex.ToString());
}
}
}
示例4: CheckoutEntry
/// <summary>
/// Updates the file in the working tree with content and mode from an entry
/// in the index.
/// </summary>
/// <remarks>
/// Updates the file in the working tree with content and mode from an entry
/// in the index. The new content is first written to a new temporary file in
/// the same directory as the real file. Then that new file is renamed to the
/// final filename.
/// TODO: this method works directly on File IO, we may need another
/// abstraction (like WorkingTreeIterator). This way we could tell e.g.
/// Eclipse that Files in the workspace got changed
/// </remarks>
/// <param name="repo"></param>
/// <param name="f">
/// the file to be modified. The parent directory for this file
/// has to exist already
/// </param>
/// <param name="entry">the entry containing new mode and content</param>
/// <exception cref="System.IO.IOException">System.IO.IOException</exception>
public static void CheckoutEntry(Repository repo, FilePath f, DirCacheEntry entry
)
{
ObjectLoader ol = repo.Open(entry.GetObjectId());
FilePath parentDir = f.GetParentFile();
FilePath tmpFile = FilePath.CreateTempFile("._" + f.GetName(), null, parentDir);
FileOutputStream channel = new FileOutputStream(tmpFile);
try
{
ol.CopyTo(channel);
}
finally
{
channel.Close();
}
FS fs = repo.FileSystem;
WorkingTreeOptions opt = repo.GetConfig().Get(WorkingTreeOptions.KEY);
if (opt.IsFileMode() && fs.SupportsExecute())
{
if (FileMode.EXECUTABLE_FILE.Equals(entry.RawMode))
{
if (!fs.CanExecute(tmpFile))
{
fs.SetExecute(tmpFile, true);
}
}
else
{
if (fs.CanExecute(tmpFile))
{
fs.SetExecute(tmpFile, false);
}
}
}
if (!tmpFile.RenameTo(f))
{
// tried to rename which failed. Let' delete the target file and try
// again
FileUtils.Delete(f);
if (!tmpFile.RenameTo(f))
{
throw new IOException(MessageFormat.Format(JGitText.Get().couldNotWriteFile, tmpFile
.GetPath(), f.GetPath()));
}
}
entry.LastModified = f.LastModified();
entry.SetLength((int)ol.GetSize());
}
示例5: Refresh
public void Refresh()
{
this.cache.Clear();
this.changedFiles = null;
this.repositoryGraph = null;
if (!string.IsNullOrEmpty(initFolder))
{
try
{
this.repository = Git.Open(initFolder).GetRepository();
if (this.repository != null)
{
var id = repository.Resolve(Constants.HEAD);
//var commit = repository.MapCommit(id);
//this.commitTree = (commit != null ? commit.TreeEntry : new Tree(repository));
if (id == null)
{
this.commitTree = new Tree(repository);
}
else
{
var treeId = ObjectId.FromString(repository.Open(id).GetBytes(), 5);
this.commitTree = new Tree(repository, treeId, repository.Open(treeId).GetBytes());
}
this.index = repository.GetIndex();
this.index.RereadIfNecessary();
ignoreRules = File.ReadAllLines(Path.Combine(this.initFolder, Constants.GITIGNORE_FILENAME))
.Where(line => !line.StartsWith("#") && line.Trim().Length > 0)
.Select(line => new IgnoreRule(line)).ToList();
}
}
catch (Exception ex)
{
}
}
}
示例6: Refresh
public void Refresh()
{
this.cache.Clear();
this.changedFiles = null;
if (!string.IsNullOrEmpty(initFolder))
{
try
{
this.repository = Git.Open(initFolder).GetRepository();
if (this.repository != null)
{
var id = repository.Resolve(Constants.HEAD);
//var commit = repository.MapCommit(id);
//this.commitTree = (commit != null ? commit.TreeEntry : new Tree(repository));
if (id == null)
{
this.commitTree = new Tree(repository);
}
else
{
var treeId = ObjectId.FromString(repository.Open(id).GetBytes(), 5);
this.commitTree = new Tree(repository, treeId, repository.Open(treeId).GetBytes());
}
this.index = repository.GetIndex();
this.index.RereadIfNecessary();
}
}
catch (Exception ex)
{
}
}
}