rough Mercurial log implementation and crash fixes on empty repo
This commit is contained in:
parent
5a0c45bc6a
commit
3d286a4b60
|
@ -51,7 +51,7 @@ namespace SparkleLib {
|
||||||
SparkleHg hg = new SparkleHg (LocalPath, "log -r : --limit 1 --template \"{node}\"");
|
SparkleHg hg = new SparkleHg (LocalPath, "log -r : --limit 1 --template \"{node}\"");
|
||||||
hg.Start ();
|
hg.Start ();
|
||||||
hg.WaitForExit ();
|
hg.WaitForExit ();
|
||||||
|
Console.WriteLine ("Identifier" + hg.StandardOutput.ReadToEnd ());
|
||||||
return hg.StandardOutput.ReadToEnd ();
|
return hg.StandardOutput.ReadToEnd ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,12 @@ namespace SparkleLib {
|
||||||
hg.Start ();
|
hg.Start ();
|
||||||
hg.WaitForExit ();
|
hg.WaitForExit ();
|
||||||
|
|
||||||
return hg.StandardOutput.ReadToEnd ();
|
string hash = hg.StandardOutput.ReadToEnd ().Trim ();
|
||||||
|
Console.WriteLine ("CurrentRevision" + hg.StandardOutput.ReadToEnd ());
|
||||||
|
if (hash.Length > 0)
|
||||||
|
return hash;
|
||||||
|
else
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -206,8 +211,7 @@ namespace SparkleLib {
|
||||||
|
|
||||||
List <SparkleChangeSet> change_sets = new List <SparkleChangeSet> ();
|
List <SparkleChangeSet> change_sets = new List <SparkleChangeSet> ();
|
||||||
|
|
||||||
string style_file_path = SparkleHelpers.CombineMore (LocalPath, ".hg", "log.style");
|
SparkleHg hg_log = new SparkleHg (LocalPath, "log --limit " + count + " --style changelog --verbose --stat");
|
||||||
SparkleHg hg_log = new SparkleHg (LocalPath, "log --limit " + count + " --style " + style_file_path);
|
|
||||||
Console.OutputEncoding = System.Text.Encoding.Unicode;
|
Console.OutputEncoding = System.Text.Encoding.Unicode;
|
||||||
hg_log.Start ();
|
hg_log.Start ();
|
||||||
|
|
||||||
|
@ -222,7 +226,7 @@ namespace SparkleLib {
|
||||||
int j = 0;
|
int j = 0;
|
||||||
string entry = "", last_entry = "";
|
string entry = "", last_entry = "";
|
||||||
foreach (string line in lines) {
|
foreach (string line in lines) {
|
||||||
if (line.StartsWith ("changeset:") && j > 0) {
|
if (line.StartsWith ("2") && line.EndsWith (")") && j > 0) {
|
||||||
entries.Add (entry);
|
entries.Add (entry);
|
||||||
entry = "";
|
entry = "";
|
||||||
}
|
}
|
||||||
|
@ -235,10 +239,8 @@ namespace SparkleLib {
|
||||||
|
|
||||||
entries.Add (last_entry);
|
entries.Add (last_entry);
|
||||||
|
|
||||||
Regex regex = new Regex (@"changeset: ([a-z0-9]{40})\n" +
|
Regex regex = new Regex (@"([0-9]{4})-([0-9]{2})-([0-9]{2}).*([0-9]{2}):([0-9]{2}).*.([0-9]{4}).*" +
|
||||||
"(.+) <(.+)>\n" +
|
"(.+).*<(.+)>.*([a-z0-9]{12})", RegexOptions.Compiled);
|
||||||
"([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}) .([0-9]{4})\n" +
|
|
||||||
"", RegexOptions.Compiled);
|
|
||||||
|
|
||||||
// TODO: Need to optimise for speed
|
// TODO: Need to optimise for speed
|
||||||
foreach (string log_entry in entries) {
|
foreach (string log_entry in entries) {
|
||||||
|
@ -247,44 +249,50 @@ namespace SparkleLib {
|
||||||
|
|
||||||
Match match = regex.Match (log_entry);
|
Match match = regex.Match (log_entry);
|
||||||
|
|
||||||
if (match.Success) {
|
if (match.Success) {Console.WriteLine ("f!!!!!!!!!!!!!!!!!!!!!");
|
||||||
SparkleChangeSet change_set = new SparkleChangeSet ();
|
SparkleChangeSet change_set = new SparkleChangeSet ();
|
||||||
|
|
||||||
change_set.Revision = match.Groups [1].Value;
|
change_set.Revision = match.Groups [9].Value;
|
||||||
change_set.UserName = match.Groups [2].Value;
|
change_set.UserName = match.Groups [7].Value;
|
||||||
change_set.UserEmail = match.Groups [3].Value;
|
change_set.UserEmail = match.Groups [8].Value;
|
||||||
change_set.IsMerge = is_merge_commit;
|
change_set.IsMerge = is_merge_commit;
|
||||||
|
|
||||||
change_set.Timestamp = new DateTime (int.Parse (match.Groups [4].Value),
|
change_set.Timestamp = new DateTime (int.Parse (match.Groups [1].Value),
|
||||||
int.Parse (match.Groups [5].Value), int.Parse (match.Groups [6].Value),
|
int.Parse (match.Groups [2].Value), int.Parse (match.Groups [3].Value),
|
||||||
int.Parse (match.Groups [7].Value), int.Parse (match.Groups [8].Value), 0);
|
int.Parse (match.Groups [4].Value), int.Parse (match.Groups [5].Value), 0);
|
||||||
|
|
||||||
string [] entry_lines = log_entry.Split ("\n".ToCharArray ());
|
string [] entry_lines = log_entry.Split ("\n".ToCharArray ());
|
||||||
|
|
||||||
foreach (string entry_line in entry_lines) {
|
foreach (string entry_line in entry_lines) {
|
||||||
if (entry_line.StartsWith (":")) {
|
if (entry_line.StartsWith ("\t* ")) {
|
||||||
|
|
||||||
string change_type = entry_line [37].ToString ();
|
if (entry_line.EndsWith ("new file.")) {
|
||||||
string file_path = entry_line.Substring (39);
|
string files = entry_line.Substring (3, entry_line.Length - 13);
|
||||||
string to_file_path;
|
string [] added_files = files.Split (",".ToCharArray());
|
||||||
|
|
||||||
if (change_type.Equals ("A")) {
|
foreach (string added_file in added_files)
|
||||||
change_set.Added.Add (file_path);
|
change_set.Added.Add (added_file.Trim().TrimEnd (":".ToCharArray()));
|
||||||
} 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);
|
} else if (entry_line.EndsWith ("deleted file.")) {
|
||||||
change_set.MovedTo.Add (to_file_path);
|
string files = entry_line.Substring (3, entry_line.Length - 17);
|
||||||
|
string [] deleted_files = files.Split (",".ToCharArray());
|
||||||
|
|
||||||
|
foreach (string deleted_file in deleted_files)
|
||||||
|
change_set.Deleted.Add (deleted_file.Trim().TrimEnd (":".ToCharArray()));
|
||||||
|
|
||||||
|
} else {
|
||||||
|
string files = entry_line.Substring (3);
|
||||||
|
string [] edited_files = files.Split (",".ToCharArray());
|
||||||
|
foreach (string file in edited_files){
|
||||||
|
|
||||||
|
string edited_file = file.Trim().TrimEnd (":".ToCharArray());
|
||||||
|
Console.WriteLine ("[" + edited_file + "]");
|
||||||
|
if (!change_set.Added.Contains (edited_file) && !change_set.Deleted.Contains (edited_file))
|
||||||
|
change_set.Edited.Add (edited_file);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
change_sets.Add (change_set);
|
change_sets.Add (change_set);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,7 @@ namespace SparkleLib {
|
||||||
|
|
||||||
this.client.OnChannelMessage += delegate (object o, IrcEventArgs args) {
|
this.client.OnChannelMessage += delegate (object o, IrcEventArgs args) {
|
||||||
string message = args.Data.Message.Trim ();
|
string message = args.Data.Message.Trim ();
|
||||||
string folder_id = args.Data.Channel.Substring (1); // remove the #
|
string folder_id = args.Data.Channel.Substring (1); // remove the starting hash
|
||||||
OnRemoteChange (new SparkleAnnouncement (folder_id, message));
|
OnRemoteChange (new SparkleAnnouncement (folder_id, message));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,7 +97,7 @@ namespace SparkleLib {
|
||||||
|
|
||||||
if (CurrentRevision == null) {
|
if (CurrentRevision == null) {
|
||||||
CreateInitialChangeSet ();
|
CreateInitialChangeSet ();
|
||||||
SyncUpBase ();
|
HasUnsyncedChanges = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
CreateWatcher ();
|
CreateWatcher ();
|
||||||
|
|
|
@ -1005,30 +1005,24 @@ namespace SparkleShare {
|
||||||
|
|
||||||
// Needed to do the moving
|
// Needed to do the moving
|
||||||
SparkleHelpers.ClearAttributes (tmp_folder);
|
SparkleHelpers.ClearAttributes (tmp_folder);
|
||||||
|
string target_folder_path = Path.Combine (SparklePaths.SparklePath, target_folder_name);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
string target_folder_path = SparkleHelpers.CombineMore (SparklePaths.SparklePath,
|
|
||||||
target_folder_name);
|
|
||||||
|
|
||||||
Directory.Move (tmp_folder, target_folder_path);
|
Directory.Move (tmp_folder, target_folder_path);
|
||||||
AddRepository (target_folder_path);
|
|
||||||
|
|
||||||
if (FolderListChanged != null)
|
|
||||||
FolderListChanged ();
|
|
||||||
|
|
||||||
FolderSize = GetFolderSize ();
|
|
||||||
|
|
||||||
if (FolderSizeChanged != null)
|
|
||||||
FolderSizeChanged (FolderSize);
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
SparkleHelpers.DebugInfo ("Controller", "Error moving folder: " + e.Message);
|
SparkleHelpers.DebugInfo ("Controller", "Error moving folder: " + e.Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AddRepository (target_folder_path);
|
||||||
|
|
||||||
if (FolderFetched != null)
|
if (FolderFetched != null)
|
||||||
FolderFetched ();
|
FolderFetched ();
|
||||||
|
|
||||||
|
FolderSize = GetFolderSize ();
|
||||||
|
|
||||||
|
if (FolderSizeChanged != null)
|
||||||
|
FolderSizeChanged (FolderSize);
|
||||||
|
|
||||||
if (FolderListChanged != null)
|
if (FolderListChanged != null)
|
||||||
FolderListChanged ();
|
FolderListChanged ();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue