当前位置: 首页>>代码示例>>C#>>正文


C# Repository.Lookup方法代码示例

本文整理汇总了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")));
        }
开发者ID:ruba1987,项目名称:UDiff,代码行数:28,代码来源:Program.cs

示例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 ) );
     }
 }
开发者ID:gep13,项目名称:SGV-Net,代码行数:15,代码来源:SimpleMiscTests.cs

示例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;
 }
开发者ID:itsananderson,项目名称:edge-git,代码行数:31,代码来源:BranchWrapper.cs

示例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;
 }
开发者ID:paulcbetts,项目名称:libgit2sharp,代码行数:7,代码来源:Commit.cs

示例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;
 }
开发者ID:kcomkar,项目名称:libgit2sharp,代码行数:8,代码来源:Commit.cs

示例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;
        }
开发者ID:kumichou,项目名称:GitMSBuildTasks,代码行数:58,代码来源:GitCommitInfo.cs

示例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;
                    }
                }
            }
        }
开发者ID:ricksladkey,项目名称:GitDiffMargin,代码行数:55,代码来源:GitCommands.cs

示例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;
 }
开发者ID:chenjide,项目名称:Aegisub,代码行数:12,代码来源:GitVersion.cs

示例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))
                       };
        }
开发者ID:kcomkar,项目名称:libgit2sharp,代码行数:12,代码来源:TagAnnotation.cs

示例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)))
                       };
        }
开发者ID:tclem,项目名称:libgit2sharp,代码行数:13,代码来源:TagAnnotation.cs

示例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;
     };
 }
开发者ID:itsananderson,项目名称:edge-git,代码行数:47,代码来源:RepositoryWrapper.cs

示例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;
            }
        }
开发者ID:rmichela,项目名称:BastionPrototype,代码行数:17,代码来源:Bastion.cs

示例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;
                    }
                }
            }
        }
开发者ID:275208498,项目名称:GitDiffMargin,代码行数:44,代码来源:GitCommands.cs

示例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;
        }
开发者ID:ZanyGnu,项目名称:GitRepoStats,代码行数:20,代码来源:CommitController.cs

示例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);
            }
        }
开发者ID:arkadoel,项目名称:CodigoGitCSharp,代码行数:20,代码来源:Program.cs


注:本文中的LibGit2Sharp.Repository.Lookup方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。