Ejemplo n.º 1
0
        public RepositoryChange[] Changes(string since = null, string until = null, string filename = null)
        {
            string revset = null;
            if (!String.IsNullOrEmpty(since) || !String.IsNullOrEmpty(until))
            {
                revset = String.Join(String.Empty,
                                     "--rev (", since, "..", until, ")",
                                     String.IsNullOrEmpty(since) ? null : "-" + since,
                                     String.IsNullOrEmpty(until) ? null : "-" + until);
            }

            var logArgs = new[]
                        {
                            "log --template \"changeset: {node}\nuser: {author}\ndate: {date|rfc3339date}\ndescription: \n{desc}\n\"",
                            revset,
                            filename,
                        };
            ProcessManager logCmd = new ProcessManager("hg", logArgs, this.LocalRepositoryPath).Run();
            if (logCmd.ExitCode != (int)GitReturnCode.Success)
            {
                throw new ApplicationException(String.Format("hg exit code: {0}\r\nstdout:{1}\r\nstderr:{2}", logCmd.ExitCode, logCmd.StandardOutput, logCmd.StandardError));
            }

            List<RepositoryChange> changes = new List<RepositoryChange>();
            RepositoryChange change = null;
            bool description = false;
            foreach (var line in logCmd.StandardOutput.Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries))
            {
                if (line.StartsWith("changeset:"))
                {
                    description = false;

                    change = new RepositoryChange()
                    {
                        Id = line.Substring(10).Trim(),
                    };

                    changes.Add(change);
                }
                else if (line.StartsWith("user:"******"date:"))
                {
                    change.Date = Convert.ToDateTime(line.Substring(6).Trim());
                }
                else if (line.StartsWith("description:"))
                {
                    description = true;
                }
                else if (description)
                {
                    change.Message = change.Message + (String.IsNullOrEmpty(change.Message) ? String.Empty : "\r\n") + line;
                }
            }

            return changes.ToArray();
        }
Ejemplo n.º 2
0
        public RepositoryChange[] Changes(string since = null, string until = null, string filename = null)
        {
            var logArgs = new[]
                        {
                            "log",
                            "--date=rfc",
                            String.IsNullOrEmpty(since) ? String.Empty : since + "..",
                            until ?? String.Empty,
                            filename ?? String.Empty,
                        };
            ProcessManager logCmd = new ProcessManager("git", logArgs, this.LocalRepositoryPath).Run();
            if (logCmd.ExitCode != (int)GitReturnCode.Success)
            {
                throw new ApplicationException(String.Format("git exit code: {0}\r\nstdout:{1}\r\nstderr:{2}", logCmd.ExitCode, logCmd.StandardOutput, logCmd.StandardError));
            }

            List<RepositoryChange> changes = new List<RepositoryChange>();
            RepositoryChange change = null;
            foreach (var line in logCmd.StandardOutput.Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries))
            {
                if (line.StartsWith("commit "))
                {
                    change = new RepositoryChange()
                    {
                        Id = line.Substring(7),
                    };

                    changes.Add(change);
                }
                else if (line.StartsWith("Author: "))
                {
                    change.Author = line.Substring(8);
                }
                else if (line.StartsWith("Date:   "))
                {
                    change.Date = Convert.ToDateTime(line.Substring(8));
                }
                else if (line.StartsWith("    "))
                {
                    change.Message = change.Message + (String.IsNullOrEmpty(change.Message) ? String.Empty : "\r\n") + line.Substring(4);
                }
            }

            return changes.ToArray();
        }