示例#1
0
        public List <SparkleNote> GetNotes(string revision)
        {
            List <SparkleNote> notes = new List <SparkleNote> ();

            string notes_path = Path.Combine(LocalPath, ".notes");

            if (!Directory.Exists(notes_path))
            {
                Directory.CreateDirectory(notes_path);
            }

            Regex regex_notes = new Regex(@"<name>(.+)</name>.*" +
                                          "<email>(.+)</email>.*" +
                                          "<timestamp>([0-9]+)</timestamp>.*" +
                                          "<body>(.+)</body>", RegexOptions.Compiled);

            foreach (string file_path in Directory.GetFiles(notes_path))
            {
                if (Path.GetFileName(file_path).StartsWith(revision))
                {
                    string note_xml = String.Join("", File.ReadAllLines(file_path));

                    Match match_notes = regex_notes.Match(note_xml);

                    if (match_notes.Success)
                    {
                        SparkleNote note = new SparkleNote()
                        {
                            User = new SparkleUser(match_notes.Groups [1].Value,
                                                   match_notes.Groups [2].Value),
                            Timestamp = new DateTime(1970, 1, 1).AddSeconds(int.Parse(match_notes.Groups [3].Value)),
                            Body      = match_notes.Groups [4].Value
                        };

                        notes.Add(note);
                    }
                }
            }

            return(notes);
        }
示例#2
0
        public List<SparkleNote> GetNotes(string revision)
        {
            List<SparkleNote> notes = new List<SparkleNote> ();

            string notes_path = Path.Combine (LocalPath, ".notes");

            if (!Directory.Exists (notes_path))
                Directory.CreateDirectory (notes_path);

            Regex regex_notes = new Regex (@"<name>(.+)</name>.*" +
                                "<email>(.+)</email>.*" +
                                "<timestamp>([0-9]+)</timestamp>.*" +
                                "<body>(.+)</body>", RegexOptions.Compiled);

            foreach (string file_path in Directory.GetFiles (notes_path)) {
                if (Path.GetFileName (file_path).StartsWith (revision)) {
                    string note_xml = String.Join ("", File.ReadAllLines (file_path));

                    Match match_notes = regex_notes.Match (note_xml);

                    if (match_notes.Success) {
                        SparkleNote note = new SparkleNote () {
                            User = new SparkleUser (match_notes.Groups [1].Value,
                                match_notes.Groups [2].Value),
                            Timestamp = new DateTime (1970, 1, 1).AddSeconds (int.Parse (match_notes.Groups [3].Value)),
                            Body      = match_notes.Groups [4].Value
                        };

                        notes.Add (note);
                    }
                }
            }

            return notes;
        }
示例#3
0
        // Returns a list of the latest change sets
        public override List<SparkleChangeSet> GetChangeSets(int count)
        {
            if (count < 1)
                count = 30;

            List <SparkleChangeSet> change_sets = new List <SparkleChangeSet> ();

            SparkleGit git_log = new SparkleGit (LocalPath, "log -" + count + " --raw -M --date=iso --show-notes=*");
            Console.OutputEncoding = System.Text.Encoding.Unicode;
            git_log.Start ();

            // Reading the standard output HAS to go before
            // WaitForExit, or it will hang forever on output > 4096 bytes
            string output = git_log.StandardOutput.ReadToEnd ();
            git_log.WaitForExit ();

            string [] lines       = output.Split ("\n".ToCharArray ());
            List <string> entries = new List <string> ();

            int j = 0;
            string entry = "", last_entry = "";
            foreach (string line in lines) {
                if (line.StartsWith ("commit") && j > 0) {
                    entries.Add (entry);
                    entry = "";
                }

                entry += line + "\n";
                j++;

                last_entry = entry;
            }

            entries.Add (last_entry);

            Regex merge_regex = new Regex (@"commit ([a-z0-9]{40})\n" +
                                "Merge: .+ .+\n" +
                                "Author: (.+) <(.+)>\n" +
                                "Date:   ([0-9]{4})-([0-9]{2})-([0-9]{2}) " +
                                "([0-9]{2}):([0-9]{2}):([0-9]{2}) .([0-9]{4})\n" +
                                "*", RegexOptions.Compiled);

            Regex non_merge_regex = new Regex (@"commit ([a-z0-9]{40})\n" +
                                "Author: (.+) <(.+)>\n" +
                                "Date:   ([0-9]{4})-([0-9]{2})-([0-9]{2}) " +
                                "([0-9]{2}):([0-9]{2}):([0-9]{2}) (.[0-9]{4})\n" +
                                "*", RegexOptions.Compiled);

            foreach (string log_entry in entries) {
                Regex regex;
                bool is_merge_commit = false;

                if (log_entry.Contains ("\nMerge: ")) {
                    regex = merge_regex;
                    is_merge_commit = true;
                } else {
                    regex = non_merge_regex;
                }

                Match match = regex.Match (log_entry);

                if (match.Success) {
                    SparkleChangeSet change_set = new SparkleChangeSet ();

                    change_set.Folder        = Name;
                    change_set.Revision      = match.Groups [1].Value;
                    change_set.UserName      = match.Groups [2].Value;
                    change_set.UserEmail     = match.Groups [3].Value;
                    change_set.IsMerge       = is_merge_commit;
                    change_set.SupportsNotes = true;

                    change_set.Timestamp = new DateTime (int.Parse (match.Groups [4].Value),
                        int.Parse (match.Groups [5].Value), int.Parse (match.Groups [6].Value),
                        int.Parse (match.Groups [7].Value), int.Parse (match.Groups [8].Value),
                        int.Parse (match.Groups [9].Value));

                    string time_zone     = match.Groups [10].Value;
                    int our_offset       = TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now).Hours;
                    int their_offset     = int.Parse (time_zone.Substring (0, 3));
                    change_set.Timestamp = change_set.Timestamp.AddHours (their_offset * -1);
                    change_set.Timestamp = change_set.Timestamp.AddHours (our_offset);

                    string [] entry_lines = log_entry.Split ("\n".ToCharArray ());

                    foreach (string entry_line in entry_lines) {
                        if (entry_line.StartsWith (":")) {

                            string change_type = entry_line [37].ToString ();
                            string file_path   = entry_line.Substring (39);
                            string to_file_path;

                            if (change_type.Equals ("A")) {
                                change_set.Added.Add (file_path);

                            } else if (change_type.Equals ("M")) {
                                change_set.Edited.Add (file_path);

                            } else if (change_type.Equals ("D")) {
                                change_set.Deleted.Add (file_path);

                            } else if (change_type.Equals ("R")) {
                                int tab_pos  = entry_line.LastIndexOf ("\t");
                                file_path    = entry_line.Substring (42, tab_pos - 42);
                                to_file_path = entry_line.Substring (tab_pos + 1);

                                change_set.MovedFrom.Add (file_path);
                                change_set.MovedTo.Add (to_file_path);
                            }

                        } else if (entry_line.StartsWith ("    <note>")) {

                            Regex regex_notes = new Regex (@"<name>(.+)</name>.*" +
                                                            "<email>(.+)</email>.*" +
                                                            "<timestamp>([0-9]+)</timestamp>.*" +
                                                            "<body>(.+)</body>", RegexOptions.Compiled);

                            Match match_notes = regex_notes.Match (entry_line);

                            if (match_notes.Success) {
                                SparkleNote note = new SparkleNote () {
                                    UserName  = match_notes.Groups [1].Value,
                                    UserEmail = match_notes.Groups [2].Value,
                                    Timestamp = new DateTime (1970, 1, 1).AddSeconds (int.Parse (match_notes.Groups [3].Value)),
                                    Body      = match_notes.Groups [4].Value
                                };

                                change_set.Notes.Add (note);
                            }
                        }
                    }

                    change_sets.Add (change_set);
                }
            }

            return change_sets;
        }