private string FormatMessage (SparkleChangeSet change_set)
        {
            string message = "added ‘{0}’";

            switch (change_set.Changes [0].Type) {
                case SparkleChangeType.Edited:  message = "edited ‘{0}’"; break;
                case SparkleChangeType.Deleted: message = "deleted ‘{0}’"; break;
                case SparkleChangeType.Moved:   message = "moved ‘{0}’"; break;
            }

            if (change_set.Changes.Count == 1) {
                return message = string.Format (message, change_set.Changes [0].Path);

            } else if (change_set.Changes.Count > 1) {
                message = string.Format (message, change_set.Changes [0].Path);

                if ((change_set.Changes.Count - 1) == 1)
                    return string.Format (message + " and one other event", change_set.Changes.Count - 1);
                else
                    return string.Format (message + " and {0} other events", change_set.Changes.Count - 1);

            } else {
                return "did something magical";
            }
        }
        private string FormatMessage(SparkleChangeSet change_set)
        {
            string message = "";

            if (change_set.Changes [0].Type == SparkleChangeType.Deleted)
                message = string.Format ("moved ‘{0}’", change_set.Changes [0].Path);

            if (change_set.Changes [0].Type == SparkleChangeType.Moved)
                message = string.Format ("moved ‘{0}’", change_set.Changes [0].Path);

            if (change_set.Changes [0].Type == SparkleChangeType.Added)
                message = string.Format ("added ‘{0}’", change_set.Changes [0].Path);

            if (change_set.Changes [0].Type == SparkleChangeType.Edited)
                message = string.Format ("moved ‘{0}’", change_set.Changes [0].Path);

            if (change_set.Changes.Count > 0) {
                string msg = string.Format ("and {0} more", change_set.Changes.Count);
                message    = message + " " + string.Format (msg, change_set.Changes.Count);

            } else {
                message = "did something magical";
            }

            return message;
        }
        private string FormatMessage(SparkleChangeSet change_set)
        {
            string file_name = "";
            string message   = "";

            if (change_set.Added.Count > 0) {
                file_name = change_set.Added [0];
                message = String.Format ("added ‘{0}’", file_name);
            }

            if (change_set.MovedFrom.Count > 0) {
                file_name = change_set.MovedFrom [0];
                message = String.Format ("moved ‘{0}’", file_name);
            }

            if (change_set.Edited.Count > 0) {
                file_name = change_set.Edited [0];
                message = String.Format ("edited ‘{0}’", file_name);
            }

            if (change_set.Deleted.Count > 0) {
                file_name = change_set.Deleted [0];
                message = String.Format ("deleted ‘{0}’", file_name);
            }

            int changes_count = (change_set.Added.Count +
                                 change_set.Edited.Count +
                                 change_set.Deleted.Count +
                                 change_set.MovedFrom.Count) - 1;

            if (changes_count > 0) {
                string msg = string.Format ("and {0} more", changes_count);
                message += " " + String.Format (msg, changes_count);

            } else if (changes_count < 0) {
                message += "did something magical";
            }

            return message;
        }
Example #4
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> ();

            // Console.InputEncoding  = System.Text.Encoding.Unicode;
            // Console.OutputEncoding = System.Text.Encoding.Unicode;

            SparkleGit git_log = new SparkleGit (LocalPath,
                "log -" + count + " --raw -M --date=iso --format=medium --no-color");
            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 line_number = 0;
            bool first_pass = true;
            string entry = "", last_entry = "";
            foreach (string line in lines) {
                if (line.StartsWith ("commit") && !first_pass) {
                    entries.Add (entry);
                    entry = "";
                    line_number = 0;

                } else {
                    first_pass = false;
                }

                // Only parse 250 files to prevent memory issues
                if (line_number < 254) {
                    entry += line + "\n";
                    line_number++;
                }

                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.User      = new SparkleUser (match.Groups [2].Value, match.Groups [3].Value);
                    change_set.IsMagical = is_merge_commit;
                    change_set.Url       = Url;

                    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 (file_path.EndsWith (".empty"))
                                file_path = file_path.Substring (0,
                                    file_path.Length - ".empty".Length);

                            if (change_type.Equals ("A") &&
                                !file_path.Equals (".sparkleshare")) {

                                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);

                                if (file_path.EndsWith (".empty"))
                                    file_path = file_path.Substring (0,
                                        file_path.Length - ".empty".Length);

                                if (to_file_path.EndsWith (".empty"))
                                    to_file_path = to_file_path.Substring (0,
                                        to_file_path.Length - ".empty".Length);

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

                    if ((change_set.Added.Count +
                         change_set.Edited.Count +
                         change_set.Deleted.Count +
                         change_set.MovedFrom.Count) > 0) {

                        change_sets.Add (change_set);
                    }
                }
            }

            return change_sets;
        }
Example #5
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> ();

            SparkleHg hg_log = new SparkleHg (LocalPath, "log --limit " + count + " --style changelog --verbose --stat");
            Console.OutputEncoding = System.Text.Encoding.Unicode;
            hg_log.Start ();

            // Reading the standard output HAS to go before
            // WaitForExit, or it will hang forever on output > 4096 bytes
            string output = hg_log.StandardOutput.ReadToEnd ();
            hg_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 ("2") && line.EndsWith (")") && j > 0) {
                    entries.Add (entry);
                    entry = "";
                }

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

                last_entry = entry;
            }

            entries.Add (last_entry);

            Regex regex = new Regex (@"([0-9]{4})-([0-9]{2})-([0-9]{2}).*([0-9]{2}):([0-9]{2}).*.([0-9]{4})" +
                                      "(.+)<(.+)>.*.([a-z0-9]{12})", RegexOptions.Compiled);

            foreach (string log_entry in entries) {

                bool is_merge_commit = false;

                Match match = regex.Match (log_entry);

                if (!match.Success)
                    continue;

                SparkleChangeSet change_set = new SparkleChangeSet () {
                    Revision  = match.Groups [9].Value,
                    UserName  = match.Groups [7].Value.Trim (),
                    UserEmail = match.Groups [8].Value,
                    IsMerge   = is_merge_commit
                };

                change_set.Timestamp = new DateTime (int.Parse (match.Groups [1].Value),
                    int.Parse (match.Groups [2].Value), int.Parse (match.Groups [3].Value),
                    int.Parse (match.Groups [4].Value), int.Parse (match.Groups [5].Value), 0);

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

                foreach (string entry_line in entry_lines) {
                    if (!entry_line.StartsWith ("\t* "))
                        continue;

                    if (entry_line.EndsWith ("new file.")) {
                        string files = entry_line.Substring (3, entry_line.Length - 13);
                        string [] added_files = files.Split (",".ToCharArray ());

                        foreach (string added_file in added_files) {
                            string file = added_file.TrimEnd (": ".ToCharArray ());
                            change_set.Added.Add (file);
                        }

                    } else if (entry_line.EndsWith ("deleted file.")) {
                        string files = entry_line.Substring (3, entry_line.Length - 17);
                        string [] deleted_files = files.Split (",".ToCharArray ());

                        foreach (string deleted_file in deleted_files) {
                            string file = deleted_file.TrimEnd (": ".ToCharArray ());
                            change_set.Deleted.Add (file);
                        }

                    } else if (!"".Equals (entry_line.Trim ())){
                        string files = entry_line.Substring (3);
                        files = files.TrimEnd (":".ToCharArray());
                        string [] edited_files = files.Split (",".ToCharArray ());

                        foreach (string edited_file in edited_files) {
                            if (!change_set.Added.Contains (edited_file) &&
                                !change_set.Deleted.Contains (edited_file)) {

                                change_set.Edited.Add (edited_file);
                            }
                        }
                    }
                }

                change_sets.Add (change_set);
            }

            return change_sets;
        }
Example #6
0
        private List<SparkleChangeSet> GetChangeSetsInternal(string path)
        {
            List <SparkleChangeSet> change_sets = new List <SparkleChangeSet> ();
            SparkleGit git;

            if (path == null) {
                git = new SparkleGit (LocalPath, "log --since=1.month --raw --find-renames --date=iso " +
                    "--format=medium --no-color --no-merges");

            } else {
                path = path.Replace ("\\", "/");

                git = new SparkleGit (LocalPath, "log --raw --find-renames --date=iso " +
                    "--format=medium --no-color --no-merges -- \"" + path + "\"");
            }

            string output = git.StartAndReadStandardOutput ();

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

            int line_number = 0;
            bool first_pass = true;
            string entry = "", last_entry = "";
            foreach (string line in lines) {
                if (line.StartsWith ("commit") && !first_pass) {
                    entries.Add (entry);
                    entry = "";
                    line_number = 0;

                } else {
                    first_pass = false;
                }

                // Only parse 250 files to prevent memory issues
                if (line_number < 254) {
                    entry += line + "\n";
                    line_number++;
                }

                last_entry = entry;
            }

            entries.Add (last_entry);

            foreach (string log_entry in entries) {
                Match match = this.log_regex.Match (log_entry);

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

                    change_set.Folder    = new SparkleFolder (Name);
                    change_set.Revision  = match.Groups [1].Value;
                    change_set.User      = new SparkleUser (match.Groups [2].Value, match.Groups [3].Value);
                    change_set.RemoteUrl = RemoteUrl;

                    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 type_letter = entry_line [37].ToString ();
                            string file_path   = entry_line.Substring (39);
                            bool change_is_folder = false;

                            if (file_path.Equals (".sparkleshare"))
                                continue;

                            if (file_path.EndsWith (".empty")) {
                                file_path        = file_path.Substring (0, file_path.Length - ".empty".Length);
                                change_is_folder = true;
                            }

                            file_path = EnsureSpecialCharacters (file_path);
                            file_path = file_path.Replace ("\\\"", "\"");

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

                                file_path    = EnsureSpecialCharacters (file_path);
                                to_file_path = EnsureSpecialCharacters (to_file_path);

                                file_path = file_path.Replace ("\\\"", "\"");
                                to_file_path = to_file_path.Replace ("\\\"", "\"");

                                if (file_path.EndsWith (".empty")) {
                                    file_path = file_path.Substring (0, file_path.Length - 6);
                                    change_is_folder = true;
                                }

                                if (to_file_path.EndsWith (".empty")) {
                                    to_file_path = to_file_path.Substring (0, to_file_path.Length - 6);
                                    change_is_folder = true;
                                }

                                change_set.Changes.Add (
                                    new SparkleChange () {
                                        Path        = file_path,
                                        IsFolder    = change_is_folder,
                                        MovedToPath = to_file_path,
                                        Timestamp   = change_set.Timestamp,
                                        Type        = SparkleChangeType.Moved
                                    }
                                );

                            } else {
                                SparkleChangeType change_type = SparkleChangeType.Added;

                                if (type_letter.Equals ("M")) {
                                    change_type = SparkleChangeType.Edited;

                                } else if (type_letter.Equals ("D")) {
                                   change_type = SparkleChangeType.Deleted;
                                }

                                change_set.Changes.Add (
                                    new SparkleChange () {
                                        Path      = file_path,
                                        IsFolder  = change_is_folder,
                                        Timestamp = change_set.Timestamp,
                                        Type      = change_type
                                    }
                                );
                            }
                        }
                    }

                    if (change_sets.Count > 0 && path == null) {
                        SparkleChangeSet last_change_set = change_sets [change_sets.Count - 1];

                        if (change_set.Timestamp.Year  == last_change_set.Timestamp.Year &&
                            change_set.Timestamp.Month == last_change_set.Timestamp.Month &&
                            change_set.Timestamp.Day   == last_change_set.Timestamp.Day &&
                            change_set.User.Name.Equals (last_change_set.User.Name)) {

                            last_change_set.Changes.AddRange (change_set.Changes);

                            if (DateTime.Compare (last_change_set.Timestamp, change_set.Timestamp) < 1) {
                                last_change_set.FirstTimestamp = last_change_set.Timestamp;
                                last_change_set.Timestamp      = change_set.Timestamp;
                                last_change_set.Revision       = change_set.Revision;

                            } else {
                                last_change_set.FirstTimestamp = change_set.Timestamp;
                            }

                        } else {
                            change_sets.Add (change_set);
                        }

                    } else {
                        if (path != null) {
                            bool skip_change_set = false;;

                            foreach (SparkleChange change in change_set.Changes) {
                                if ((change.Type == SparkleChangeType.Deleted ||
                                     change.Type == SparkleChangeType.Moved) && change.Path.Equals (path)) {

                                     skip_change_set = true;
                                }
                            }

                            if (skip_change_set)
                                continue;
                        }

                        change_sets.Add (change_set);
                    }
                }
            }

            return change_sets;
        }
Example #7
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;
        }
Example #8
0
        private void SyncDownBase()
        {
            SparkleHelpers.DebugInfo("SyncDown", "[" + Name + "] Initiated");
            this.remote_timer.Stop();
            DisableWatching();

            if (SyncStatusChanged != null)
            {
                SyncStatusChanged(SyncStatus.SyncDown);
            }

            string pre_sync_revision = CurrentRevision;

            if (SyncDown())
            {
                SparkleHelpers.DebugInfo("SyncDown", "[" + Name + "] Done");
                this.server_online = true;

                if (SyncStatusChanged != null)
                {
                    SyncStatusChanged(SyncStatus.Idle);
                }

                if (!pre_sync_revision.Equals(CurrentRevision))
                {
                    List <SparkleChangeSet> change_sets = GetChangeSets(1);

                    if (change_sets != null && change_sets.Count > 0)
                    {
                        SparkleChangeSet change_set = change_sets [0];

                        bool note_added = false;
                        foreach (string added in change_set.Added)
                        {
                            if (added.Contains(".notes"))
                            {
                                if (NewNote != null)
                                {
                                    NewNote(change_set.User);
                                }

                                note_added = true;
                                break;
                            }
                        }

                        if (!note_added)
                        {
                            if (NewChangeSet != null)
                            {
                                NewChangeSet(change_set);
                            }
                        }
                    }
                }

                // There could be changes from a resolved
                // conflict. Tries only once, then lets
                // the timer try again periodically
                if (HasUnsyncedChanges)
                {
                    SyncUp();
                }
            }
            else
            {
                SparkleHelpers.DebugInfo("SyncDown", "[" + Name + "] Error");
                this.server_online = false;

                if (SyncStatusChanged != null)
                {
                    SyncStatusChanged(SyncStatus.Error);
                }
            }

            if (SyncStatusChanged != null)
            {
                SyncStatusChanged(SyncStatus.Idle);
            }

            this.remote_timer.Start();
            EnableWatching();

            this.progress_percentage = 0.0;
            this.progress_speed      = "";
        }
        private List<SparkleChangeSet> GetChangeSetsInternal(string path)
        {
            List <SparkleChangeSet> change_sets = new List <SparkleChangeSet> ();
            SparkleGit git;

            if (path == null) {
                git = new SparkleGit (LocalPath, "log --since=1.month --raw --find-renames --date=iso " +
                    "--format=medium --no-color -m --first-parent");

            } else {
                path = path.Replace ("\\", "/");

                git = new SparkleGit (LocalPath, "log --raw --find-renames --date=iso " +
                    "--format=medium --no-color --no-merges -- \"" + path + "\"");
            }

            string output = git.StartAndReadStandardOutput ();

            if (path == null && string.IsNullOrWhiteSpace (output)) {
                git = new SparkleGit (LocalPath, "log -n 75 --raw --find-renames --date=iso " +
                    "--format=medium --no-color -m --first-parent");

                output = git.StartAndReadStandardOutput ();
            }

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

            // Split up commit entries
            int line_number = 0;
            bool first_pass = true;
            string entry = "", last_entry = "";
            foreach (string line in lines) {
                if (line.StartsWith ("commit") && !first_pass) {
                    entries.Add (entry);
                    entry = "";
                    line_number = 0;

                } else {
                    first_pass = false;
                }

                // Only parse first 250 files to prevent memory issues
                if (line_number < 250) {
                    entry += line + "\n";
                    line_number++;
                }

                last_entry = entry;
            }

            entries.Add (last_entry);

            // Parse commit entries
            foreach (string log_entry in entries) {
                Match match = this.log_regex.Match (log_entry);

                if (!match.Success) {
                    match = this.merge_regex.Match (log_entry);

                    if (!match.Success)
                        continue;
                }

                SparkleChangeSet change_set = new SparkleChangeSet ();

                change_set.Folder    = new SparkleFolder (Name);
                change_set.Revision  = match.Groups [1].Value;
                change_set.User      = new SparkleUser (match.Groups [2].Value, match.Groups [3].Value);
                change_set.RemoteUrl = RemoteUrl;

                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 ());

                // Parse file list. Lines containing file changes start with ":"
                foreach (string entry_line in entry_lines) {
                    // Skip lines containing backspace characters
                    if (!entry_line.StartsWith (":") || entry_line.Contains ("\\177"))
                        continue;

                    string file_path = entry_line.Substring (39);

                    if (file_path.Equals (".sparkleshare"))
                        continue;

                    string type_letter    = entry_line [37].ToString ();
                    bool change_is_folder = false;

                    if (file_path.EndsWith (".empty")) {
                        file_path        = file_path.Substring (0, file_path.Length - ".empty".Length);
                        change_is_folder = true;
                    }

                    try {
                        file_path = EnsureSpecialCharacters (file_path);

                    } catch (Exception e) {
                        SparkleLogger.LogInfo ("Local", "Error parsing file name '" + file_path + "'", e);
                        continue;
                    }

                    file_path = file_path.Replace ("\\\"", "\"");

                    SparkleChange change = new SparkleChange () {
                        Path      = file_path,
                        IsFolder  = change_is_folder,
                        Timestamp = change_set.Timestamp,
                        Type      = SparkleChangeType.Added
                    };

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

                        try {
                            file_path = EnsureSpecialCharacters (file_path);

                        } catch (Exception e) {
                            SparkleLogger.LogInfo ("Local", "Error parsing file name '" + file_path + "'", e);
                            continue;
                        }

                        try {
                            to_file_path = EnsureSpecialCharacters (to_file_path);

                        } catch (Exception e) {
                            SparkleLogger.LogInfo ("Local", "Error parsing file name '" + to_file_path + "'", e);
                            continue;
                        }

                        file_path    = file_path.Replace ("\\\"", "\"");
                        to_file_path = to_file_path.Replace ("\\\"", "\"");

                        if (file_path.EndsWith (".empty")) {
                            file_path = file_path.Substring (0, file_path.Length - 6);
                            change_is_folder = true;
                        }

                        if (to_file_path.EndsWith (".empty")) {
                            to_file_path = to_file_path.Substring (0, to_file_path.Length - 6);
                            change_is_folder = true;
                        }

                        change.Path        = file_path;
                        change.MovedToPath = to_file_path;
                        change.Type        = SparkleChangeType.Moved;

                    } else if (type_letter.Equals ("M")) {
                        change.Type = SparkleChangeType.Edited;

                    } else if (type_letter.Equals ("D")) {
                        change.Type = SparkleChangeType.Deleted;
                    }

                    change_set.Changes.Add (change);
                }

                // Group commits per user, per day
                if (change_sets.Count > 0 && path == null) {
                    SparkleChangeSet last_change_set = change_sets [change_sets.Count - 1];

                    if (change_set.Timestamp.Year  == last_change_set.Timestamp.Year &&
                        change_set.Timestamp.Month == last_change_set.Timestamp.Month &&
                        change_set.Timestamp.Day   == last_change_set.Timestamp.Day &&
                        change_set.User.Name.Equals (last_change_set.User.Name)) {

                        last_change_set.Changes.AddRange (change_set.Changes);

                        if (DateTime.Compare (last_change_set.Timestamp, change_set.Timestamp) < 1) {
                            last_change_set.FirstTimestamp = last_change_set.Timestamp;
                            last_change_set.Timestamp      = change_set.Timestamp;
                            last_change_set.Revision       = change_set.Revision;

                        } else {
                            last_change_set.FirstTimestamp = change_set.Timestamp;
                        }

                    } else {
                        change_sets.Add (change_set);
                    }

                } else {
                    // Don't show removals or moves in the revision list of a file
                    if (path != null) {
                        List<SparkleChange> changes_to_skip = new List<SparkleChange> ();

                        foreach (SparkleChange change in change_set.Changes) {
                            if ((change.Type == SparkleChangeType.Deleted || change.Type == SparkleChangeType.Moved)
                                && change.Path.Equals (path)) {

                                changes_to_skip.Add (change);
                            }
                        }

                        foreach (SparkleChange change_to_skip in changes_to_skip)
                            change_set.Changes.Remove (change_to_skip);
                    }

                    change_sets.Add (change_set);
                }
            }

            return change_sets;
        }
Example #10
0
        protected List<SparkleChangeSet> GetChangesSetsInternal(string path, int count)
        {
            SparkleUser user = new SparkleUser(local_config.User.Name, local_config.User.Email);
            List<SparkleChangeSet> sparkleChangeSets = new List<SparkleChangeSet> ();
            SparkleChangeSet schange = new SparkleChangeSet(){
                FirstTimestamp = DateTime.Now,
                Timestamp = DateTime.Now,
                Revision = "Fetch",
                Folder = new SparkleFolder("folder"),
                RemoteUrl = new Uri("http://s.greenqloud.com"),
                User = user
            };
            schange.Changes.Add(new SparkleChange(){
                Path        = "remote",
                MovedToPath = "Local",
                Timestamp   = DateTime.Now,
                Type        = SparkleChangeType.Moved
            });
            sparkleChangeSets.Add(schange);

            base.ChangeSets = sparkleChangeSets;
            return sparkleChangeSets;
        }
Example #11
0
        // Returns a list of the latest change sets
        public override List<SparkleChangeSet> GetChangeSets(int count)
        {
            if (count < 1)
                count = 30;

            count = 150;

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

            SparkleGit git_log = new SparkleGit (LocalPath,
                "log -" + count + " --raw -M --date=iso --format=medium --no-color --no-merges");

            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 line_number = 0;
            bool first_pass = true;
            string entry = "", last_entry = "";
            foreach (string line in lines) {
                if (line.StartsWith ("commit") && !first_pass) {
                    entries.Add (entry);
                    entry = "";
                    line_number = 0;

                } else {
                    first_pass = false;
                }

                // Only parse 250 files to prevent memory issues
                if (line_number < 254) {
                    entry += line + "\n";
                    line_number++;
                }

                last_entry = entry;
            }

            entries.Add (last_entry);

            Regex 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) {
                Match match = regex.Match (log_entry);

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

                    change_set.Folder    = new SparkleFolder (Name);
                    change_set.Revision  = match.Groups [1].Value;
                    change_set.User      = new SparkleUser (match.Groups [2].Value, match.Groups [3].Value);
                    change_set.RemoteUrl = RemoteUrl;

                    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 (file_path.EndsWith (".empty"))
                                file_path = file_path.Substring (0,
                                    file_path.Length - ".empty".Length);

                            if (file_path.Equals (".sparkleshare"))
                                continue;

                            if (change_type.Equals ("A")) {
                                change_set.Changes.Add (
                                    new SparkleChange () {
                                        Path      = file_path,
                                        Timestamp = change_set.Timestamp,
                                        Type      = SparkleChangeType.Added
                                    }
                                );

                            } else if (change_type.Equals ("M")) {
                                change_set.Changes.Add (
                                    new SparkleChange () {
                                        Path      = file_path,
                                        Timestamp = change_set.Timestamp,
                                        Type      = SparkleChangeType.Edited
                                    }
                                );

                            } else if (change_type.Equals ("D")) {
                                change_set.Changes.Add (
                                    new SparkleChange () {
                                        Path      = file_path,
                                        Timestamp = change_set.Timestamp,
                                        Type      = SparkleChangeType.Deleted
                                    }
                                );

                            } 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);

                                if (file_path.EndsWith (".empty"))
                                    file_path = file_path.Substring (0, file_path.Length - 6);

                                if (to_file_path.EndsWith (".empty"))
                                    to_file_path = to_file_path.Substring (0, to_file_path.Length - 6);

                                change_set.Changes.Add (
                                    new SparkleChange () {
                                        Path        = file_path,
                                        MovedToPath = to_file_path,
                                        Timestamp   = change_set.Timestamp,
                                        Type        = SparkleChangeType.Moved
                                    }
                                );
                            }
                        }
                    }

                    if (change_set.Changes.Count > 0) {
                        if (change_sets.Count > 0) {
                            SparkleChangeSet last_change_set = change_sets [change_sets.Count - 1];

                            if (change_set.Timestamp.Year  == last_change_set.Timestamp.Year &&
                                change_set.Timestamp.Month == last_change_set.Timestamp.Month &&
                                change_set.Timestamp.Day   == last_change_set.Timestamp.Day &&
                                change_set.User.Name.Equals (last_change_set.User.Name)) {

                                last_change_set.Changes.AddRange (change_set.Changes);

                                if (DateTime.Compare (last_change_set.Timestamp, change_set.Timestamp) < 1) {
                                    last_change_set.FirstTimestamp = last_change_set.Timestamp;
                                    last_change_set.Timestamp      = change_set.Timestamp;
                                    last_change_set.Revision       = change_set.Revision;

                                } else {
                                    last_change_set.FirstTimestamp = change_set.Timestamp;
                                }

                            } else {
                                change_sets.Add (change_set);
                            }

                        } else {
                            change_sets.Add (change_set);
                        }
                    }
                }
            }

            return change_sets;
        }
Example #12
0
        // Returns a list of the latest change sets
        // TODO: Method needs to be made a lot faster
        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");
            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);

            // TODO: Need to optimise for speed
            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.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.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 [] 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);
                            }
                        }
                    }

                    change_sets.Add (change_set);
                }
            }

            return change_sets;
        }
 //http://samba.anu.edu.au/ftp/rsync/rsync.html
 //see entry for -i (--itemize) this describes how rsync reports changes
 public override List<SparkleChangeSet> GetChangeSets(int count)
 {
     //parse the rsync log here?
     List <SparkleChangeSet> change_sets = new List <SparkleChangeSet> ();
     SparkleChangeSet change_set = new SparkleChangeSet ();
             change_set.Revision   = "test";
             change_set.User.Name  = "test";
             change_set.User.Email = "test";
     change_sets.Add (change_set);
     return change_sets;
 }
Example #14
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> ();

            // Console.InputEncoding  = System.Text.Encoding.Unicode;
            Console.OutputEncoding = System.Text.Encoding.Unicode;

            SparkleGit git_log = new SparkleGit(LocalPath, "log -" + count + " --raw -M --date=iso");

            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.User.Name  = match.Groups [2].Value;
                    change_set.User.Email = match.Groups [3].Value;
                    change_set.IsMagical  = is_merge_commit;

                    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 (file_path.EndsWith(".empty"))
                            {
                                file_path = file_path.Substring(0, file_path.Length - ".empty".Length);
                            }

                            if (change_type.Equals("A") && !file_path.Contains(".notes"))
                            {
                                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);
                            }
                        }
                    }

                    if ((change_set.Added.Count +
                         change_set.Edited.Count +
                         change_set.Deleted.Count +
                         change_set.MovedFrom.Count) > 0)
                    {
                        change_set.Notes.AddRange(GetNotes(change_set.Revision));
                        change_sets.Add(change_set);
                    }
                }
            }

            return(change_sets);
        }