예제 #1
0
파일: Tag.cs 프로젝트: openhome/ohGit
        internal Tag(Repository aRepository, string aId, byte[] aBytes)
        {
            iRepository = aRepository;
            iId = aId;

            string id = null;
            string type = null;

            string tag = ASCIIEncoding.ASCII.GetString(aBytes);

            string[] lines = tag.Split(new char[] { '\n' });

            int offset = 1;

            foreach (string line in lines)
            {
                if (line.Length == 0)
                {
                    break;
                }

                offset += line.Length + 1;

                int keyEnd = line.IndexOf(' ');

                CorruptIf(keyEnd < 0);

                string key = line.Substring(0, keyEnd);

                string value = line.Substring(keyEnd + 1);

                switch (key)
                {
                    case "object":
                        id = value;
                        break;

                    case "type":
                        type = value;
                        break;

                    case "tag":
                        iName = value;
                        break;

                    case "tagger":
                        iTagger = PersonTime.Create(value);
                        break;

                    default:
                        CorruptIf(true);
                        break;
                }
            }

            iDescription = tag.Substring(offset);

            CorruptIf(iName == null);
            CorruptIf(iTagger == null);

            CorruptIf(id == null);
            CorruptIf(type == null);

            switch (type)
            {
                case "commit":
                    iType = EObjectType.Commit;
                    break;
                case "blob":
                    iType = EObjectType.Blob;
                    break;
                case "tree":
                    iType = EObjectType.Tree;
                    break;
                case "tag":
                    iType = EObjectType.Tag;
                    break;
                default:
                    CorruptIf(true);
                    break;
            }
        }
예제 #2
0
파일: Commit.cs 프로젝트: openhome/ohGit
        internal void Resolve()
        {
            if (iTree == null)
            {
                iParents = new List<ICommit>();

                string commit = ASCIIEncoding.ASCII.GetString(iReference.Contents);

                string[] lines = commit.Split(new char[] { '\n' });

                int offset = 1;

                foreach (string line in lines)
                {
                    if (line.Length == 0)
                    {
                        break;
                    }

                    offset += line.Length + 1;

                    string[] parts = line.Split(new char[] { ' ' }, 2);

                    CorruptIf(parts.Length != 2);

                    string key = parts[0];
                    string value = parts[1];

                    switch (key)
                    {
                        case "tree":
                            CorruptIf(iTree != null);
                            iTree = new Tree(new TreeRef(iReference.Repository, value));
                            break;

                        case "parent":
                            iParents.Add(new Commit(new CommitRef(iReference.Repository, value)));
                            break;

                        case "author":
                            CorruptIf(iAuthor != null);
                            iAuthor = PersonTime.Create(value);
                            break;

                        case "committer":
                            CorruptIf(iCommitter != null);
                            iCommitter = PersonTime.Create(value);
                            break;

                        default:
                            CorruptIf(true);
                            break;
                    }
                }

                CorruptIf(iTree == null);
                CorruptIf(iAuthor == null);
                CorruptIf(iCommitter == null);

                iDescription = commit.Substring(offset);
            }
        }