Esempio n. 1
0
        public static List<FileNameAndRev> ParseDiffOut(string diffTxt)
        {
            var al = new List<FileNameAndRev>();
            StringReader    reader = new StringReader(diffTxt);
            string          l;

            while (true)
            {
                l = reader.ReadLine();
                if (null == l)
                    break;
                // parse lines like:
                // :100755 100755 6ca2624... 0000000... M  src/WordNetConverter/Program.cs
                string[] parts = l.Split();

                /* Console.WriteLine("line: '{0}'", l);
                int n = 0;
                foreach (var p in parts)
                {
                    Console.WriteLine("part {0}: {1}", n, p);
                    n += 1;
                } */
                var cfi = new FileNameAndRev();
                cfi.Revision = parts[2];
                cfi.FileName = parts[5];
                al.Add(cfi);
            }
            return al;
        }
Esempio n. 2
0
        public static List <FileNameAndRev> ParseDiffOut(string diffTxt)
        {
            var          al     = new List <FileNameAndRev>();
            StringReader reader = new StringReader(diffTxt);
            string       l;

            while (true)
            {
                l = reader.ReadLine();
                if (null == l)
                {
                    break;
                }
                // parse lines like:
                // :100755 100755 6ca2624... 0000000... M  src/WordNetConverter/Program.cs
                string[] parts = l.Split();

                /* Console.WriteLine("line: '{0}'", l);
                 * int n = 0;
                 * foreach (var p in parts)
                 * {
                 *  Console.WriteLine("part {0}: {1}", n, p);
                 *  n += 1;
                 * } */
                var cfi = new FileNameAndRev();
                cfi.Revision = parts[2];
                cfi.FileName = parts[5];
                al.Add(cfi);
            }
            return(al);
        }
Esempio n. 3
0
        // Given an output of 'cvs diff -u' command, return an array of strings, 2 strings for each
        // file that contains a diff, first string is a file name, second is a revision against which
        // the local copy diff is made
        public static List <FileNameAndRev> ParseDiffOutput(string diffTxt)
        {
            StringReader reader = new StringReader(diffTxt);
            var          res    = new List <FileNameAndRev>();
            ParseState   state  = ParseState.EXPECT_INDEX;
            string       txt;
            string       fileName = null;

            while (true)
            {
                txt = reader.ReadLine();
                if (null == txt)
                {
                    break;
                }

                switch (state)
                {
                case ParseState.EXPECT_INDEX:
                    // that's how non-cvs files are marked
                    if (txt.StartsWith("? "))
                    {
                        // file unknown to CVS
                        break;
                    }

                    if (!txt.StartsWith(indexTxt))
                    {
                        // shouldn't happen
                        return(res);
                    }
                    fileName = txt.Substring(indexTxt.Length);
                    state    = ParseState.AFTER_INDEX;
                    break;

                case ParseState.AFTER_INDEX:
                    if (!txt.StartsWith(sepTxt))
                    {
                        // assumption: we might get indexTxt in the body of the diff
                        // so we allow it to not be followed by sepTxt. If it's not
                        // then we'll go into diff skipping mode
                        // this should be very rare, thought!
                        Debug.Assert(false, "Did we really get this in the diff?");
                        state = ParseState.SKIP_DIFF;
                        break;
                    }
                    state = ParseState.AFTER_SEP;
                    break;

                case ParseState.AFTER_SEP:
                    Debug.Assert(txt.StartsWith("RCS file:"));
                    Debug.Assert(-1 != txt.IndexOf(fileName));
                    state = ParseState.AFTER_REV;
                    break;

                case ParseState.AFTER_REV:
                    Debug.Assert(txt.StartsWith("retrieving revision"));
                    Match  match = Regex.Match(txt, @"retrieving revision[^\d]+([\d\.]+)");
                    string rev   = match.Groups[1].Value;
                    var    fi    = new FileNameAndRev();
                    fi.FileName = fileName;
                    fi.Revision = rev;
                    res.Add(fi);
                    // TODO: should also make sure that this is followed by:
                    // diff -u -r...
                    // --- FileName ...
                    // +++ FileName ...
                    state = ParseState.SKIP_DIFF;
                    break;

                case ParseState.SKIP_DIFF:
                    if (txt.StartsWith(indexTxt))
                    {
                        state    = ParseState.AFTER_INDEX;
                        fileName = txt.Substring(indexTxt.Length);
                    }
                    break;

                default:
                    Debug.Assert(false, String.Format("Unkown state {0}", state));
                    break;
                }
            }
            return(res);
        }
Esempio n. 4
0
        // Given an output of 'cvs diff -u' command, return an array of strings, 2 strings for each
        // file that contains a diff, first string is a file name, second is a revision against which
        // the local copy diff is made
        public static List<FileNameAndRev> ParseDiffOutput(string diffTxt)
        {
            StringReader    reader = new StringReader(diffTxt);
            var             res = new List<FileNameAndRev>();
            ParseState      state = ParseState.EXPECT_INDEX;
            string          txt;
            string          fileName = null;

            while (true)
            {
                txt = reader.ReadLine();
                if (null==txt)
                    break;

                switch(state)
                {
                    case ParseState.EXPECT_INDEX:
                        // that's how non-cvs files are marked
                        if ( txt.StartsWith("? ") )
                        {
                            // file unknown to CVS
                            break;
                        }

                        if (! txt.StartsWith(indexTxt))
                        {
                            // shouldn't happen
                            return res;
                        }
                        fileName = txt.Substring(indexTxt.Length);
                        state = ParseState.AFTER_INDEX;
                        break;
                    case ParseState.AFTER_INDEX:
                        if (! txt.StartsWith(sepTxt))
                        {
                            // assumption: we might get indexTxt in the body of the diff
                            // so we allow it to not be followed by sepTxt. If it's not
                            // then we'll go into diff skipping mode
                            // this should be very rare, thought!
                            Debug.Assert(false, "Did we really get this in the diff?");
                            state = ParseState.SKIP_DIFF;
                            break;
                        }
                        state = ParseState.AFTER_SEP;
                        break;
                    case ParseState.AFTER_SEP:
                        Debug.Assert( txt.StartsWith("RCS file:") );
                        Debug.Assert( -1 != txt.IndexOf(fileName) );
                        state = ParseState.AFTER_REV;
                        break;
                    case ParseState.AFTER_REV:
                        Debug.Assert( txt.StartsWith("retrieving revision") );
                        Match match = Regex.Match(txt, @"retrieving revision[^\d]+([\d\.]+)");
                        string rev = match.Groups[1].Value;
                        var fi = new FileNameAndRev();
                        fi.FileName = fileName;
                        fi.Revision = rev;
                        res.Add(fi);
                        // TODO: should also make sure that this is followed by:
                        // diff -u -r...
                        // --- FileName ...
                        // +++ FileName ...
                        state = ParseState.SKIP_DIFF;
                        break;
                    case ParseState.SKIP_DIFF:
                        if (txt.StartsWith(indexTxt))
                        {
                            state = ParseState.AFTER_INDEX;
                            fileName = txt.Substring(indexTxt.Length);
                        }
                        break;
                    default:
                        Debug.Assert(false, String.Format("Unkown state {0}",state));
                        break;
                }
            }
            return res;
        }