LibGit2Sharp.Repository.Lookup C# (CSharp) Метод

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

Try to lookup an object by its ObjectId and GitObjectType. If no matching object is found, null will be returned.
public Lookup ( ObjectId id, GitObjectType type = GitObjectType.Any ) : GitObject
id ObjectId The id to lookup.
type GitObjectType The kind of GitObject being looked up
Результат GitObject
        public GitObject Lookup(ObjectId id, GitObjectType type = GitObjectType.Any)
        {
            Ensure.ArgumentNotNull(id, "id");

            GitOid oid = id.Oid;
            IntPtr obj;
            int res;

            if (id is AbbreviatedObjectId)
            {
                res = NativeMethods.git_object_lookup_prefix(out obj, handle, ref oid, (uint)((AbbreviatedObjectId)id).Length, type);
            }
            else
            {
                res = NativeMethods.git_object_lookup(out obj, handle, ref oid, type);
            }

            if (res == (int)GitErrorCode.GIT_ENOTFOUND || res == (int)GitErrorCode.GIT_EINVALIDTYPE)
            {
                return null;
            }

            Ensure.Success(res);

            if (id is AbbreviatedObjectId)
            {
                id = GitObject.ObjectIdOf(obj);
            }

            return GitObject.CreateFromPtr(obj, id, this);
        }

Same methods

Repository::Lookup ( string shaOrReferenceName, GitObjectType type = GitObjectType.Any ) : GitObject

Usage Example

Пример #1
0
        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")));
        }
All Usage Examples Of LibGit2Sharp.Repository::Lookup