コード例 #1
0
        internal ReflogEntry(byte[] raw, int pos)
        {
            oldId = ObjectId.FromString(raw, pos);
            pos  += Constants.OBJECT_ID_STRING_LENGTH;
            if (raw[pos++] != ' ')
            {
                throw new ArgumentException(JGitText.Get().rawLogMessageDoesNotParseAsLogEntry);
            }
            newId = ObjectId.FromString(raw, pos);
            pos  += Constants.OBJECT_ID_STRING_LENGTH;
            if (raw[pos++] != ' ')
            {
                throw new ArgumentException(JGitText.Get().rawLogMessageDoesNotParseAsLogEntry);
            }
            who = RawParseUtils.ParsePersonIdentOnly(raw, pos);
            int p0 = RawParseUtils.Next(raw, pos, '\t');

            if (p0 >= raw.Length)
            {
                comment = string.Empty;
            }
            else
            {
                // personident has no \t, no comment present
                int p1 = RawParseUtils.NextLF(raw, p0);
                comment = p1 > p0?RawParseUtils.Decode(raw, p0, p1 - 1) : string.Empty;
            }
        }
コード例 #2
0
ファイル: ReflogReader.cs プロジェクト: ashmind/ngit
            internal Entry(byte[] raw, int pos)
            {
                oldId = ObjectId.FromString(raw, pos);
                pos  += Constants.OBJECT_ID_STRING_LENGTH;
                if (raw[pos++] != ' ')
                {
                    throw new ArgumentException(JGitText.Get().rawLogMessageDoesNotParseAsLogEntry);
                }
                newId = ObjectId.FromString(raw, pos);
                pos  += Constants.OBJECT_ID_STRING_LENGTH;
                if (raw[pos++] != ' ')
                {
                    throw new ArgumentException(JGitText.Get().rawLogMessageDoesNotParseAsLogEntry);
                }
                who = RawParseUtils.ParsePersonIdentOnly(raw, pos);
                int p0 = RawParseUtils.Next(raw, pos, '\t');

                // personident has no
                // \t
                if (p0 == -1)
                {
                    throw new ArgumentException(JGitText.Get().rawLogMessageDoesNotParseAsLogEntry);
                }
                int p1 = RawParseUtils.NextLF(raw, p0);

                if (p1 == -1)
                {
                    throw new ArgumentException(JGitText.Get().rawLogMessageDoesNotParseAsLogEntry);
                }
                comment = RawParseUtils.Decode(raw, p0, p1 - 1);
            }
コード例 #3
0
        internal DirCacheTree(byte[] @in, MutableInteger off, NGit.Dircache.DirCacheTree
                              myParent)
        {
            parent = myParent;
            int ptr     = RawParseUtils.Next(@in, off.value, '\0');
            int nameLen = ptr - off.value - 1;

            if (nameLen > 0)
            {
                encodedName = new byte[nameLen];
                System.Array.Copy(@in, off.value, encodedName, 0, nameLen);
            }
            else
            {
                encodedName = NO_NAME;
            }
            entrySpan = RawParseUtils.ParseBase10(@in, ptr, off);
            int subcnt = RawParseUtils.ParseBase10(@in, off.value, off);

            off.value = RawParseUtils.Next(@in, off.value, '\n');
            if (entrySpan >= 0)
            {
                // Valid trees have a positive entry count and an id of a
                // tree object that should exist in the object database.
                //
                id         = ObjectId.FromRaw(@in, off.value);
                off.value += Constants.OBJECT_ID_LENGTH;
            }
            if (subcnt > 0)
            {
                bool alreadySorted = true;
                children = new NGit.Dircache.DirCacheTree[subcnt];
                for (int i = 0; i < subcnt; i++)
                {
                    children[i] = new NGit.Dircache.DirCacheTree(@in, off, this);
                    // C Git's ordering differs from our own; it prefers to
                    // sort by length first. This sometimes produces a sort
                    // we do not desire. On the other hand it may have been
                    // created by us, and be sorted the way we want.
                    //
                    if (alreadySorted && i > 0 && TREE_CMP.Compare(children[i - 1], children[i]) > 0)
                    {
                        alreadySorted = false;
                    }
                }
                if (!alreadySorted)
                {
                    Arrays.Sort(children, 0, subcnt, TREE_CMP);
                }
            }
            else
            {
                // Leaf level trees have no children, only (file) entries.
                //
                children = NO_CHILDREN;
            }
            childCnt = subcnt;
        }
コード例 #4
0
        internal virtual PersonIdent ParseAuthor(byte[] raw)
        {
            if (raw.Length == 0)
            {
                return(null);
            }
            IDictionary <string, string> keyValueMap = new Dictionary <string, string>();

            for (int p = 0; p < raw.Length;)
            {
                int end = RawParseUtils.NextLF(raw, p);
                if (end == p)
                {
                    break;
                }
                int equalsIndex = RawParseUtils.Next(raw, p, '=');
                if (equalsIndex == end)
                {
                    break;
                }
                string key   = RawParseUtils.Decode(raw, p, equalsIndex - 1);
                string value = RawParseUtils.Decode(raw, equalsIndex + 1, end - 2);
                p = end;
                keyValueMap.Put(key, value);
            }
            string name  = keyValueMap.Get(GIT_AUTHOR_NAME);
            string email = keyValueMap.Get(GIT_AUTHOR_EMAIL);
            string time  = keyValueMap.Get(GIT_AUTHOR_DATE);
            // the time is saved as <seconds since 1970> <timezone offset>
            long   when           = long.Parse(Sharpen.Runtime.Substring(time, 0, time.IndexOf(' '))) * 1000;
            string tzOffsetString = Sharpen.Runtime.Substring(time, time.IndexOf(' ') + 1);
            int    multiplier     = -1;

            if (tzOffsetString[0] == '+')
            {
                multiplier = 1;
            }
            int hours = System.Convert.ToInt32(Sharpen.Runtime.Substring(tzOffsetString, 1, 3
                                                                         ));
            int minutes = System.Convert.ToInt32(Sharpen.Runtime.Substring(tzOffsetString, 3,
                                                                           5));
            // this is in format (+/-)HHMM (hours and minutes)
            // we need to convert into minutes
            int tz = (hours * 60 + minutes) * multiplier;

            if (name != null && email != null)
            {
                return(new PersonIdent(name, email, when, tz));
            }
            return(null);
        }
コード例 #5
0
        /// <exception cref="System.IO.IOException"></exception>
        private IList <RebaseCommand.Step> LoadSteps()
        {
            byte[] buf                   = IOUtil.ReadFully(new FilePath(rebaseDir, GIT_REBASE_TODO));
            int    ptr                   = 0;
            int    tokenBegin            = 0;
            AList <RebaseCommand.Step> r = new AList <RebaseCommand.Step>();

            while (ptr < buf.Length)
            {
                tokenBegin = ptr;
                ptr        = RawParseUtils.NextLF(buf, ptr);
                int nextSpace              = 0;
                int tokenCount             = 0;
                RebaseCommand.Step current = null;
                while (tokenCount < 3 && nextSpace < ptr)
                {
                    switch (tokenCount)
                    {
                    case 0:
                    {
                        nextSpace = RawParseUtils.Next(buf, tokenBegin, ' ');
                        string actionToken = Sharpen.Runtime.GetStringForBytes(buf, tokenBegin, nextSpace
                                                                               - tokenBegin - 1);
                        tokenBegin = nextSpace;
                        if (actionToken[0] == '#')
                        {
                            tokenCount = 3;
                            break;
                        }
                        RebaseCommand.Action action = RebaseCommand.Action.Parse(actionToken);
                        if (action != null)
                        {
                            current = new RebaseCommand.Step(RebaseCommand.Action.Parse(actionToken));
                        }
                        break;
                    }

                    case 1:
                    {
                        if (current == null)
                        {
                            break;
                        }
                        nextSpace = RawParseUtils.Next(buf, tokenBegin, ' ');
                        string commitToken = Sharpen.Runtime.GetStringForBytes(buf, tokenBegin, nextSpace
                                                                               - tokenBegin - 1);
                        tokenBegin     = nextSpace;
                        current.commit = AbbreviatedObjectId.FromString(commitToken);
                        break;
                    }

                    case 2:
                    {
                        if (current == null)
                        {
                            break;
                        }
                        nextSpace = ptr;
                        int length = ptr - tokenBegin;
                        current.shortMessage = new byte[length];
                        System.Array.Copy(buf, tokenBegin, current.shortMessage, 0, length);
                        r.AddItem(current);
                        break;
                    }
                    }
                    tokenCount++;
                }
            }
            return(r);
        }