Example #1
0
        List <VersionControlLogEntry> GetGitLog(string dir, string fromRevision)
        {
            //Sample output

            /*
             * commit d34362948c6d2a40527c2b77dc270da61e9f40fb
             * Author: Sebastian Loncar <*****@*****.**>
             * Date:   2013-11-23 17:30:12 +0100
             *     (empty line)
             * commit test
             *     (empty line)
             * line1
             * line2
             * "line3"
             *     (empty line)
             */

            //git --no-pager log fromRevision..HEAD --pretty=format:"COMMIT=%h;AUTHOR=%an;DATE=%ad;COMMENT=%s" --date=iso //Has no extended descriptions!
            //git --no-pager log fromRevision..HEAD --date=iso //contains also the extended descriptions
            //git --no-pager log --date=iso
            var cmd   = String.Format("--no-pager log {0}..HEAD --date=iso", fromRevision);
            var res   = Execute(dir, GitExecutable, cmd);
            var lines = res.Output.Select(t => t == null ? "" : t).ToArray();

            var list = new List <VersionControlLogEntry>();

            VersionControlLogEntry entry = null;
            var comments = new List <string>();

            foreach (var line in lines)
            {
                if (line.StartsWith("commit "))
                {
                    if (entry != null)
                    {
                        entry.msg = string.Join(Environment.NewLine, comments.Where(t => t.IsNotNullOrEmpty()));
                        list.Add(entry);
                    }
                    entry = new VersionControlLogEntry();
                    comments.Clear();

                    entry.revision = line.Substring("commit ".Length);
                }
                else if (line.StartsWith("Author: "))
                {
                    entry.author = line.Substring("Author: ".Length);
                }
                else if (line.StartsWith("Date: "))
                {
                    entry.date = DateTime.Parse(line.Substring("Date: ".Length));
                }
                else if (line.StartsWith("    "))
                {
                    comments.Add(line.Trim());
                }
            }

            if (entry != null)
            {
                entry.msg = string.Join(Environment.NewLine, comments.Where(t => t.IsNotNullOrEmpty()));
                list.Add(entry);
            }

            //var list = doc.Root.Elements().Select(el => new SvnLogEntry
            //{
            //    author = el.GetChildValue<string>("author"),
            //    date = el.GetChildValue<DateTime>("date"),
            //    msg = el.GetChildValue<string>("msg"),
            //    revision = el.GetChildValue<string>("revision"),
            //}).ToList();

            list.Where(t => t.msg != null && t.msg.EndsWith("\n")).ForEach(t => t.msg = t.msg.RemoveLast(1));
            return(list);
        }
        List<VersionControlLogEntry> GetGitLog(string dir, string fromRevision)
        {
            //Sample output
            /*
             * commit d34362948c6d2a40527c2b77dc270da61e9f40fb
             * Author: Sebastian Loncar <*****@*****.**>
             * Date:   2013-11-23 17:30:12 +0100
             *     (empty line)
             * commit test
             *     (empty line)
             * line1
             * line2
             * "line3"
             *     (empty line)
             */

            //git --no-pager log fromRevision..HEAD --pretty=format:"COMMIT=%h;AUTHOR=%an;DATE=%ad;COMMENT=%s" --date=iso //Has no extended descriptions!
            //git --no-pager log fromRevision..HEAD --date=iso //contains also the extended descriptions
            //git --no-pager log --date=iso
            var res = Execute(dir, GitExecutable, String.Format("--no-pager log {0}..HEAD --date=iso", fromRevision));
            var lines = res.Output.Select(t => t == null ? "" : t).ToArray();

            var list = new List<VersionControlLogEntry>();

            VersionControlLogEntry entry = null;
            var comments = new List<string>();

            foreach (var line in lines)
            {
                if (line.StartsWith("commit "))
                {
                    if (entry != null)
                    {
                        entry.msg = string.Join(Environment.NewLine, comments.Where(t => t.IsNotNullOrEmpty()));
                        list.Add(entry);
                    }
                    entry = new VersionControlLogEntry();
                    comments.Clear();

                    entry.revision = line.Substring("commit ".Length);
                }
                else if (line.StartsWith("Author: "))
                {
                    entry.author = line.Substring("Author: ".Length);
                }
                else if (line.StartsWith("Date: "))
                {
                    entry.date = DateTime.Parse(line.Substring("Date: ".Length));
                }
                else if (line.StartsWith("    "))
                {
                    comments.Add(line.Trim());
                }
            }

            if (entry != null)
            {
                entry.msg = string.Join(Environment.NewLine, comments.Where(t => t.IsNotNullOrEmpty()));
                list.Add(entry);
            }

            //var list = doc.Root.Elements().Select(el => new SvnLogEntry
            //{
            //    author = el.GetChildValue<string>("author"),
            //    date = el.GetChildValue<DateTime>("date"),
            //    msg = el.GetChildValue<string>("msg"),
            //    revision = el.GetChildValue<string>("revision"),
            //}).ToList();

            list.Where(t => t.msg != null && t.msg.EndsWith("\n")).ForEach(t => t.msg = t.msg.RemoveLast(1));
            return list;
        }