本文整理汇总了C#中LibGit2Sharp.Repository.Lookup方法的典型用法代码示例。如果您正苦于以下问题:C# Repository.Lookup方法的具体用法?C# Repository.Lookup怎么用?C# Repository.Lookup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LibGit2Sharp.Repository
的用法示例。
在下文中一共展示了Repository.Lookup方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
Setup();
using (var repo = new Repository(Environment.CurrentDirectory))
{
if (repo.Index.Conflicts.Any())
Console.WriteLine("Found UASSET conflicts. Building folder for diff");
foreach (var conflict in repo.Index.Conflicts.Where(x => x.Ours.Path.EndsWith(".uasset")))
{
Console.WriteLine("Setting up diff files for " + conflict.Ours.Path);
var a = repo.Lookup<Blob>(conflict.Ours.Id);
var b = repo.Lookup<Blob>(conflict.Theirs.Id);
using (FileStream fileStream = File.Create(Path.Combine(tempDir, Path.GetFileNameWithoutExtension(conflict.Ours.Path) + "_a" + Path.GetExtension(conflict.Ours.Path))))
{
a.GetContentStream().CopyTo(fileStream);
}
using (FileStream fileStream = File.Create(Path.Combine(tempDir, Path.GetFileNameWithoutExtension(conflict.Theirs.Path) + "_b" + Path.GetExtension(conflict.Theirs.Path))))
{
b.GetContentStream().CopyTo(fileStream);
}
}
}
Console.WriteLine();
Console.WriteLine(File.ReadAllText(Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location), "helpfiles", "diffsetupcomplete.txt")));
}
示例2: sha1_of_trees_rocks
public void sha1_of_trees_rocks()
{
var first = TestHelper.TestGitRepository.Commits.First( sc => sc.Message.StartsWith( "First in parallel world." ) );
var modified = TestHelper.TestGitRepository.Commits.First( sc => sc.Message.StartsWith( "Change in parallel-world.txt content (1)." ) );
var reset = TestHelper.TestGitRepository.Commits.First( sc => sc.Message.StartsWith( "Reset change in parallel-world.txt content (2)." ) );
using( var r = new Repository( TestHelper.TestGitRepositoryFolder ) )
{
var cFirst = r.Lookup<Commit>( first.Sha );
var cModified = r.Lookup<Commit>( modified.Sha );
var cReset = r.Lookup<Commit>( reset.Sha );
Assert.That( cFirst.Tree.Sha, Is.Not.EqualTo( cModified.Tree.Sha ) );
Assert.That( cReset.Tree.Sha, Is.Not.EqualTo( cModified.Tree.Sha ) );
Assert.That( cFirst.Tree.Sha, Is.EqualTo( cReset.Tree.Sha ) );
}
}
示例3: BranchWrapper
public BranchWrapper(Repository repo, Branch branch)
{
this.repo = repo;
this.branch = branch;
IsRemote = branch.IsRemote;
if (branch.TrackedBranch != null)
{
TrackedBranch = new BranchWrapper(repo, branch.TrackedBranch);
}
IsTracking = branch.IsTracking;
TrackingDetails = (Func<object, Task<object>>)(async (j) => { return branch.TrackingDetails; });
IsCurrentRepositoryHead = (Func<object, Task<object>>)(async (j) => { return branch.IsCurrentRepositoryHead; });
Tip = async (j) => { return new CommitWrapper(branch.Tip); };
UpstreamBranchCanonicalName = (Func<object, Task<object>>)(async (j) => { return branch.UpstreamBranchCanonicalName; });
Remote = branch.Remote;
CanonicalName = branch.CanonicalName;
Commits = (Func<object, Task<object>>)(async (j) => {
if (j != null)
{
Commit after = repo.Lookup<Commit>((string)j);
Commit until = branch.Tip;
Commit ancestor = repo.Commits.FindMergeBase(after, until) ?? after;
return CommitsAfter(after, until, ancestor).Distinct().Select(c => new CommitWrapper(c));
}
else
{
return branch.Commits.Select(c => new CommitWrapper(c));
}
});
Name = branch.Name;
}
示例4: Commit
internal Commit(ObjectId id, ObjectId treeId, Repository repo)
: base(id)
{
this.tree = new Lazy<Tree>(() => repo.Lookup<Tree>(treeId));
this.parents = new Lazy<IEnumerable<Commit>>(() => RetrieveParentsOfCommit(id.Oid));
this.repo = repo;
}
示例5: Commit
internal Commit(ObjectId id, ObjectId treeId, Repository repo)
: base(id)
{
tree = new Lazy<Tree>(() => repo.Lookup<Tree>(treeId));
parents = new Lazy<IEnumerable<Commit>>(() => RetrieveParentsOfCommit(id));
shortMessage = new Lazy<string>(ExtractShortMessage);
this.repo = repo;
}
示例6: Execute
public override bool Execute()
{
try
{
//if (LocalPath == ".")
//{
// // User didn't define a Path, find the Git path by expecting this Task to be contained in a Git repo
// LocalPath =
//}
using (var repo = new Repository(LocalPath))
{
LastCommitHash = LastCommitShortHash = LastCommitMessage = LastTagName = LastTagMessage = LastTagCommitHash = String.Empty;
RevisionCount = 0;
Commit commit = null;
CommitCollection commits = repo.Commits;
if (!String.IsNullOrEmpty(CommitHash))
{
// We're looking for a from a particular Commit on back
commit = repo.Lookup<Commit>(CommitHash);
commits = commits.StartingAt(CommitHash);
}
else
{
// We're looking from the most recent Commit
commit = repo.Commits.First();
}
if (null == commit)
{
Log.LogError("Can't find a Git Commit with that hash.");
return false;
}
LastCommitShortHash = GetCommitShortHash(commit);
LastCommitHash = commit.Sha;
LastCommitMessage = commit.Message;
Tag tag = GetMostRecentTagByEnumeration(commits, repo.Tags);
if (null != tag)
{
LastTagName = tag.Annotation.Name;
LastTagMessage = tag.Annotation.Message;
LastTagCommitHash = tag.Annotation.TargetId.Sha;
}
}
}
catch (Exception exception)
{
Log.LogMessage("StackTrace: " + exception.StackTrace);
Log.LogErrorFromException(exception);
return false;
}
return true;
}
示例7: GetGitDiffFor
public IEnumerable<HunkRangeInfo> GetGitDiffFor(ITextDocument textDocument, ITextSnapshot snapshot)
{
var content = GetCompleteContent(textDocument, snapshot);
if (content == null) yield break;
var filename = textDocument.FilePath;
var discoveredPath = Repository.Discover(Path.GetFullPath(filename));
if (!Repository.IsValid(discoveredPath)) yield break;
using (var repo = new Repository(discoveredPath))
{
var retrieveStatus = repo.Index.RetrieveStatus(filename);
if (retrieveStatus == FileStatus.Untracked || retrieveStatus == FileStatus.Added) yield break;
content = AdaptCrlf(repo, content, textDocument);
using (var currentContent = new MemoryStream(content))
{
var newBlob = repo.ObjectDatabase.CreateBlob(currentContent);
var directoryInfo = new DirectoryInfo(discoveredPath).Parent;
if (directoryInfo == null) yield break;
var relativeFilepath = filename.Replace(directoryInfo.FullName + "\\", string.Empty);
// Determine 'from' and 'to' trees.
var currentBranch = repo.Head.Name;
var baseCommitEntry = repo.Config.Get<string>(string.Format("branch.{0}.diffmarginbase", currentBranch));
Tree tree = null;
if (baseCommitEntry != null)
{
var baseCommit = repo.Lookup<Commit>(baseCommitEntry.Value);
if (baseCommit != null)
{
// Found a merge base to diff from.
tree = baseCommit.Tree;
}
}
tree = tree ?? repo.Head.Tip.Tree;
var from = TreeDefinition.From(tree);
var treeDefinition = from.Add(relativeFilepath, newBlob, Mode.NonExecutableFile);
var to = repo.ObjectDatabase.CreateTree(treeDefinition);
var treeChanges = repo.Diff.Compare(tree, to, compareOptions: new CompareOptions { ContextLines = ContextLines, InterhunkLines = 0 });
var gitDiffParser = new GitDiffParser(treeChanges.Patch, ContextLines);
var hunkRangeInfos = gitDiffParser.Parse();
foreach (var hunkRangeInfo in hunkRangeInfos)
{
yield return hunkRangeInfo;
}
}
}
}
示例8: UniqueAbbreviation
private string UniqueAbbreviation(Repository repo, string full) {
for (int len = 7; len < 40; ++len) {
try {
repo.Lookup(full.Substring(0, len));
return full.Substring(0, len);
}
catch (AmbiguousSpecificationException) {
continue;
}
}
return full;
}
示例9: BuildFromPtr
internal static TagAnnotation BuildFromPtr(GitObjectSafeHandle obj, ObjectId id, Repository repo)
{
ObjectId targetOid = NativeMethods.git_tag_target_oid(obj).MarshalAsObjectId();
return new TagAnnotation(id)
{
Message = NativeMethods.git_tag_message(obj),
Name = NativeMethods.git_tag_name(obj),
Tagger = new Signature(NativeMethods.git_tag_tagger(obj)),
targetBuilder = new Lazy<GitObject>(() => repo.Lookup<GitObject>(targetOid))
};
}
示例10: BuildFromPtr
internal static TagAnnotation BuildFromPtr(IntPtr obj, ObjectId id, Repository repo)
{
IntPtr oidPtr = NativeMethods.git_tag_target_oid(obj);
var oid = (GitOid)Marshal.PtrToStructure(oidPtr, typeof(GitOid));
return new TagAnnotation(id)
{
Message = NativeMethods.git_tag_message(obj).MarshallAsString(),
Name = NativeMethods.git_tag_name(obj).MarshallAsString(),
Tagger = new Signature(NativeMethods.git_tag_tagger(obj)),
targetBuilder = new Lazy<GitObject>(() => repo.Lookup<GitObject>(new ObjectId(oid)))
};
}
示例11: RepositoryWrapper
public RepositoryWrapper(Repository repo)
{
this.repo = repo;
Head = async (i) => { return new BranchWrapper(repo, repo.Head); };
Config = async (i) => { return repo.Config; };
Index = async (i) => { return repo.Index; };
Ignore = async (i) => { return repo.Ignore; };
Network = async (i) => { return new NetworkWrapper(repo.Network); };
ObjectDatabase = async (i) => { return repo.ObjectDatabase; };
Refs = async (i) => { return repo.Refs; };
Commits = async (i) => { return repo.Commits.Select(c => new CommitWrapper(c)); };
Tags = async (i) => { return repo.Tags; };
Stashes = async (i) => { return repo.Stashes; };
Info = async (i) => { return repo.Info; };
Diff = async (i) => { return repo.Diff; };
Notes = async (i) => { return repo.Notes; };
Submodules = async (i) => { return repo.Submodules; };
Dispose = async (i) => { repo.Dispose(); return null; };
Lookup = async (id) => {
var found = repo.Lookup(id.ToString());
if (found.GetType() == typeof(Commit)) {
return new CommitWrapper((Commit)found);
} else {
return found;
}
};
Branches = async (i) => repo.Branches.Select(b => new BranchWrapper(repo, b)).ToDictionary(b => b.Name);
Reset = async (dynamic i) => {
var modeName = ((string)i.mode).ToLower();
ResetMode mode;
if (modeName == "soft") {
mode = ResetMode.Soft;
} else if (modeName == "mixed") {
mode = ResetMode.Mixed;
} else {
mode = ResetMode.Hard;
}
var committish = (string)i.committish;
repo.Reset(mode, committish, null, null);
return null;
};
Checkout = async (i) => {
var branch = repo.Branches.First(b => b.Name == i.ToString());
repo.Checkout(branch);
return branch;
};
}
示例12: GetPost
public VotedPost GetPost(string id)
{
using (var repo = new Repository(_directory.FullName))
{
Commit commit = repo.Lookup<Commit>(id);
var post = JsonConvert.DeserializeObject<VotedPost>(commit.Message);
post.Id = commit.Sha;
// Get the votes for the post
Commit postTip = repo.Branches[post.Id].Tip;
Tree postTree = postTip.Tree;
Tree votesDir = (Tree)postTree[VOTES_DIR].Target;
post.Votes = votesDir.Where(f => f.Mode == Mode.NonExecutableFile).Select(DecodeVote).ToList();
return post;
}
}
示例13: GetGitDiffFor
public IEnumerable<HunkRangeInfo> GetGitDiffFor(ITextDocument textDocument, ITextSnapshot snapshot)
{
var filename = textDocument.FilePath;
var discoveredPath = Repository.Discover(Path.GetFullPath(filename));
if (!Repository.IsValid(discoveredPath)) yield break;
using (var repo = new Repository(discoveredPath))
{
var retrieveStatus = repo.Index.RetrieveStatus(filename);
if (retrieveStatus == FileStatus.Untracked || retrieveStatus == FileStatus.Added) yield break;
var content = GetCompleteContent(textDocument, snapshot);
if (content == null) yield break;
content = AdaptCrlf(repo, content, textDocument);
using (var currentContent = new MemoryStream(content))
{
var newBlob = repo.ObjectDatabase.CreateBlob(currentContent);
var directoryInfo = new DirectoryInfo(discoveredPath).Parent;
if (directoryInfo == null) yield break;
var relativeFilepath = filename.Replace(directoryInfo.FullName + "\\", string.Empty);
var from = TreeDefinition.From(repo.Head.Tip.Tree);
if (!repo.ObjectDatabase.Contains(@from[relativeFilepath].TargetId)) yield break;
var blob = repo.Lookup<Blob>(@from[relativeFilepath].TargetId);
var treeChanges = repo.Diff.Compare(blob, newBlob, new CompareOptions { ContextLines = ContextLines, InterhunkLines = 0 });
var gitDiffParser = new GitDiffParser(treeChanges.Patch, ContextLines);
var hunkRangeInfos = gitDiffParser.Parse();
foreach (var hunkRangeInfo in hunkRangeInfos)
{
yield return hunkRangeInfo;
}
}
}
}
示例14: GetCheckinDetails
public static CommitDetails GetCheckinDetails(string checkinId)
{
Repository repo = new Repository(ConfigurationManager.AppSettings["RepoRoot"]);
//Commit commit = repo.Lookup<Commit>(checkinId);
//return commit.Message;
string patchDirectory = Path.Combine(repo.Info.Path, "patches");
CommitDetails commitDetails = new CommitDetails();
IEnumerable<string> files = Directory.EnumerateFiles(patchDirectory, checkinId + "*", SearchOption.TopDirectoryOnly);
if (files != null && files.Any())
{
string patchFileName = files.First();
string commitId = Path.GetFileNameWithoutExtension(patchFileName);
commitDetails.Commit = repo.Lookup<Commit>(commitId);
commitDetails.FileChanges = Serializer.Deserialize<List<FileChanges>>(File.OpenRead(patchFileName));
}
return commitDetails;
}
示例15: ObtenerComits
private static void ObtenerComits(Repository repo)
{
/*Obtener dos commits, el comit1 sera el ultimo comit realizado
y el comit2 sera el elemento padre (el anterior) del comit actual
La cola esta de forma inversa, es decir, cuando accedemos a First()
estamos accediendo al ultimo commit guardado
*/
try
{
comit1 = repo.Lookup<Commit>(repo.Commits.First().Id.Sha);
comit2 = comit1.Parents.First();
Console.WriteLine("\r\nCommit: \r\n\tpadre " + comit1.Id + " \r\n\thijo " + comit2.Id + "; ");
}
catch (Exception ex)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Error: " + ex.Message);
}
}