From 35f686bf5edafff7a5585f4b12e352be3ccbfd48 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Sun, 29 Aug 2010 13:04:44 +0100 Subject: [PATCH] [log] detect moves/renames and present them nicer than an remove+add in the recent events --- SparkleLib/SparkleRepo.cs | 2 +- SparkleShare/SparkleLog.cs | 97 +++++++++++++++++++++++++++++++++----- 2 files changed, 87 insertions(+), 12 deletions(-) diff --git a/SparkleLib/SparkleRepo.cs b/SparkleLib/SparkleRepo.cs index 81e34e06..67c47571 100644 --- a/SparkleLib/SparkleRepo.cs +++ b/SparkleLib/SparkleRepo.cs @@ -757,7 +757,7 @@ namespace SparkleLib { if (line.StartsWith ("R")) { - file_action = "renamed"; + file_action = "moved"; message = file_action + " ā€˜" + line.Substring (3).Replace (" -> ", "ā€™ to\nā€˜") + "ā€™"; } diff --git a/SparkleShare/SparkleLog.cs b/SparkleShare/SparkleLog.cs index 9b22efec..40b94867 100644 --- a/SparkleShare/SparkleLog.cs +++ b/SparkleShare/SparkleLog.cs @@ -155,7 +155,9 @@ namespace SparkleShare { ChangeSet change_set = new ChangeSet (user_name, user_email, message, date_time, hash); - process.StartInfo.Arguments = "show " + hash + " --name-status"; + // --name-status lists affected files with the modification type, + // -C detects renames + process.StartInfo.Arguments = "show " + hash + " --name-status -C"; process.Start (); @@ -179,7 +181,20 @@ namespace SparkleShare { if (file_line.StartsWith ("D\t")) change_set.Deleted.Add (file_path); - + + if (file_line.StartsWith ("R")) { + + file_path = file_line.Substring (5); + string [] paths = Regex.Split (file_path, "\t"); + + change_set.MovedFrom.Add (paths [0]); + change_set.MovedTo.Add (paths [1]); + + Console.WriteLine (paths [0]); + Console.WriteLine (paths [1]); + + } + } @@ -253,10 +268,12 @@ namespace SparkleShare { foreach (ChangeSet change_set in activity_day) { - VBox log_entry = new VBox (false, 0); + VBox log_entry = new VBox (false, 0); VBox deleted_files = new VBox (false, 0); VBox edited_files = new VBox (false, 0); VBox added_files = new VBox (false, 0); + VBox moved_files = new VBox (false, 0); + foreach (string file_path in change_set.Edited) { @@ -269,7 +286,6 @@ namespace SparkleShare { } - foreach (string file_path in change_set.Added) { SparkleLink link = new SparkleLink (file_path, @@ -301,11 +317,52 @@ namespace SparkleShare { } + for (int i = 0; i < change_set.MovedFrom.Count; i++) { - log_entry.PackStart (new Label ("" + change_set.UserName + "\n" + - "" + - "at " + change_set.DateTime.ToString ("HH:mm") + - "") { UseMarkup = true, Xalign = 0 }); + SparkleLink from_link = new SparkleLink (change_set.MovedFrom [i], + SparkleHelpers.CombineMore (LocalPath, change_set.MovedFrom [i])); + + from_link.ModifyBg (StateType.Normal, background_color); + + from_link.ButtonPressEvent += delegate { + Destroy (); + }; + + SparkleLink to_link = new SparkleLink (change_set.MovedTo [i], + SparkleHelpers.CombineMore (LocalPath, change_set.MovedTo [i])); + + to_link.ModifyBg (StateType.Normal, background_color); + + to_link.ButtonPressEvent += delegate { + Destroy (); + }; + + Label to_label = new Label ("" + + "to ") { + UseMarkup = true, + Xalign = 0 + }; + + HBox link_wrapper = new HBox (false, 0); + link_wrapper.PackStart (to_label, false, false, 0); + link_wrapper.PackStart (to_link, true, true, 0); + + + moved_files.PackStart (from_link, false, false, 0); + moved_files.PackStart (link_wrapper, false, false, 0); + moved_files.PackStart (new Label (""), false, false, 0); + + } + + Label change_set_info = new Label ("" + change_set.UserName + "\n" + + "" + + "at " + change_set.DateTime.ToString ("HH:mm") + + "") { + UseMarkup = true, + Xalign = 0 + }; + + log_entry.PackStart (change_set_info); if (edited_files.Children.Length > 0) { @@ -349,6 +406,20 @@ namespace SparkleShare { } + if (moved_files.Children.Length > 0) { + + Label moved_label = new Label ("\n" + + "Moved" + + "") { + UseMarkup=true, + Xalign = 0 + }; + + log_entry.PackStart (moved_label, false, false, 0); + log_entry.PackStart (moved_files, false, false, 0); + + } + HBox hbox = new HBox (false, 0); Image avatar = new Image (SparkleHelpers.GetAvatar (change_set.UserEmail, 32)) { @@ -429,6 +500,8 @@ namespace SparkleShare { public List Added; public List Deleted; public List Edited; + public List MovedFrom; + public List MovedTo; public DateTime DateTime; public string Hash; @@ -441,9 +514,11 @@ namespace SparkleShare { DateTime = date_time; Hash = hash; - Edited = new List (); - Added = new List (); - Deleted = new List (); + Edited = new List (); + Added = new List (); + Deleted = new List (); + MovedFrom = new List (); + MovedTo = new List (); }