Login | Register
My pages Projects Community openCollabNet

Discussions > commits > [chorns] 410: Merge 399:400 from trunk

sin
Discussion topic

Back to topic list

[chorns] 410: Merge 399:400 from trunk

Reply

Author chorns
Full name Casper Hornstrup
Date 2005-08-11 17:02:37 PDT
Message Merge 399:400 from trunk
Modified:
branches/0.1/Sin.Int​egrationManager.Comm​itMailer/SvnCommitMa​iler.cs
Modified: branches/0.1/Sin.Tes​ts/CommitMailerTest.​cs
  _____

Modified:
branches/0.1/Sin.Int​egrationManager.Comm​itMailer/SvnCommitMa​iler.cs
--- branches/0.1/Sin.Int​egrationManager.Comm​itMailer/SvnCommitMa​iler.cs
2005-08-11 23:59:50 UTC (rev 409)
+++ branches/0.1/Sin.Int​egrationManager.Comm​itMailer/SvnCommitMa​iler.cs
2005-08-12 00:02:22 UTC (rev 410)
@@ -17,6 +17,7 @@

  */
 using System;
 using System.Text;
+using System.Text.RegularExpressions;
 using System.IO;
 using System.Reflection;
 using System.Resources;
@@ -33,7 +34,7 @@
         private const int MaxLinesPerChange = 100;
         private const int MaxLinesPerDiff = 1000;
 
- private enum ChangedLineType
+ public enum ChangedLineType
         {
             Unknown,
             Added,
@@ -41,33 +42,33 @@
             Updated
         }
 
- private class ChangedLineInformation
- {
- public string Plain;
+ public class ChangedLineInformation
+ {
+ private string plain;
             
+ public string Plain
+ {
+ get
+ {
+ return plain;
+ }
+ }
+
             public ChangedLineType Type
             {
                 get
                 {
- if (Plain == null ||
Plain.Length < 1)
- {
+ if (plain == null ||
plain.Length < 1)
                         return
ChangedLineType.Unknown;
- }
                     
- if (Plain.StartsWith("A"))
- {
+ if (plain.StartsWith("A"))
                         return
ChangedLineType.Added;
- }
 
- if (Plain.StartsWith("D"))
- {
+ if (plain.StartsWith("D"))
                         return
ChangedLineType.Deleted;
- }
 
- if (Plain.StartsWith("U"))
- {
+ if (plain.StartsWith("U"))
                         return
ChangedLineType.Updated;
- }
                     
                     return ChangedLineType.Unknown;
                 }
@@ -77,24 +78,38 @@
             {
                 get
                 {
- if (Plain.Length > 4)
+ if (plain.Length > 4)
+ return
plain.Substring(4).Trim();
+ else
+ return "";
+ }
+ }
+
+ public string DisplayPath
+ {
+ get
+ {
+ string path = Path;
+ if (path != String.Empty)
                     {
- return
Plain.Substring(4).Trim();
+ string checkin =
"checkin/";
+ if
(path.StartsWith(checkin))
+ return
path.Substring(checkin.Length);
+ else
+ return path;
                     }
                     else
- {
                         return "";
- }
                 }
             }
-
+
             public ChangedLineInformation(string plain)
             {
- Plain = plain;
+ this.plain = plain;
             }
         }
 
- private enum DiffLineType
+ public enum DiffLineType
         {
             Unknown,
             FileStart,
@@ -113,10 +128,51 @@
             Ignore
         }
 
- private class DiffLineInformation
+ public class DiffLineInformation
         {
- public string Plain;
+ public string plain;
 
+ public string Plain
+ {
+ get
+ {
+ string newPlain;
+ if (HasPlainCheckinPrefix("---
",
+ plain,
+ out
newPlain))
+ return newPlain;
+ if (HasPlainCheckinPrefix("+++
",
+ plain,
+
out newPlain))
+ return newPlain;
+ if
(HasPlainCheckinPref​ix("Property changes on: ",
+ plain,
+ out
newPlain))
+ return newPlain;
+ return plain;
+ }
+ }
+
+ private bool HasPlainCheckinPrefix(string
prefix,
+ string plain,
+ out string
newPlain)
+ {
+ if (!plain.StartsWith(prefix))
+ {
+ newPlain = null;
+ return false;
+ }
+ plain = plain.Remove(0, prefix.Length);
+ string checkin = "checkin/";
+ if (plain.StartsWith(checkin))
+ {
+ newPlain = prefix +
plain.Remove(0, checkin.Length);
+ return true;
+ }
+ newPlain = null;
+ return false;
+ }
+
             public bool IsStartOfFile()
             {
                 switch (Type)
@@ -142,40 +198,40 @@
             {
                 get
                 {
- if (Plain == null ||
Plain.Length < 1)
+ if (plain == null ||
plain.Length < 1)
                         return
DiffLineType.Unknown;
                     
- if (Plain.StartsWith("Modified:
"))
+ if (plain.StartsWith("Modified:
"))
                         return
DiffLineType.Modified;
 
- if (Plain.StartsWith("Added: "))
+ if (plain.StartsWith("Added: "))
                         return
DiffLineType.Added;
 
- if (Plain.StartsWith("Deleted:
"))
+ if (plain.StartsWith("Deleted:
"))
                         return
DiffLineType.Deleted;
 
- if (Plain.StartsWith("Copied:
"))
+ if (plain.StartsWith("Copied:
"))
                         return
DiffLineType.Copied;
 
- if (Plain.StartsWith("Moved: "))
+ if (plain.StartsWith("Moved: "))
                         return
DiffLineType.Moved;
 
- if (Plain.StartsWith("Index: "))
+ if (plain.StartsWith("Index: "))
                         return
DiffLineType.FileStart;
 
- if (Plain.StartsWith("--- "))
+ if (plain.StartsWith("--- "))
                         return
DiffLineType.FromRevision;
 
- if (Plain.StartsWith("+++ "))
+ if (plain.StartsWith("+++ "))
                         return
DiffLineType.ToRevision;
 
- if (Plain.StartsWith("@@ "))
+ if (plain.StartsWith("@@ "))
                         return
DiffLineType.DiffHeader;
 
- if
(Plain.StartsWith("=​====================​====================​============
=============="))
+ if
(plain.StartsWith("=​====================​====================​============
=============="))
                         return
DiffLineType.FileSpacer;
                     
- switch (Plain[0])
+ switch (plain[0])
                     {
                         case '+':
                             return
DiffLineType.Add;
@@ -217,17 +273,33 @@
                 {
                     if (IsStartOfFile())
                     {
- int index =
Plain.IndexOf(": ");
- int index2 =
Plain.IndexOf(" (");
+ int index =
plain.IndexOf(": ");
+ int index2 =
plain.IndexOf(" (");
                         if (index2 != -1)
- return
Plain.Substring(index + 2, index2 - index - 2).Trim();
+ return
plain.Substring(index + 2, index2 - index - 2).Trim();
                         else
- return
Plain.Substring(index + 2).Trim();
+ return
plain.Substring(index + 2).Trim();
                     }
                     else
+ return null;
+ }
+ }
+
+ public string DisplayFilename
+ {
+ get
+ {
+ string filename = Filename;
+ if (filename != null)
                     {
+ string checkin =
"checkin/";
+ if
(filename.StartsWith(checkin))
+ return
filename.Substring(c​heckin.Length);
+ else
+ return filename;
+ }
+ else
                         return null;
- }
                 }
             }
 
@@ -237,23 +309,65 @@
                 {
                     if (IsStartOfFile())
                     {
- int index =
Plain.IndexOf(": ");
- int index2 =
Plain.IndexOf(" (");
+ int index =
plain.IndexOf(": ");
+ int index2 =
plain.IndexOf(" (");
                         if (index2 != -1)
- return
Plain.Substring(index2);
+ return
plain.Substring(index2);
                         else
                             return null;
                     }
                     else
- {
                         return null;
- }
                 }
             }
             
+ private bool GetRevisionAndPath(out int
revision,
+ out string path)
+ {
+ revision = -1;
+ path = null;
+
+ string extra = Extra;
+ if (extra == null)
+ return false;
+ Match match = Regex.Match(extra,
+ "\\(from rev
(?<Revision>[0-9]+), (?<Path>.+)\\)");
+ if (!match.Success)
+ return false;
+ Group revisionGroup =
match.Groups["Revision"];
+ revision =
Int32.Parse(revision​Group.Value);
+ Group pathGroup = match.Groups["Path"];
+ path = pathGroup.Value;
+ return true;
+ }
+
+ public int Revision
+ {
+ get
+ {
+ int revision;
+ string path;
+ if (!GetRevisionAndPath(out
revision, out path))
+ return -1;
+ return revision;
+ }
+ }
+
+ public string Path
+ {
+ get
+ {
+ int revision;
+ string path;
+ if (!GetRevisionAndPath(out
revision, out path))
+ return null;
+ return path;
+ }
+ }
+
             public DiffLineInformation(string plain)
             {
- Plain = plain;
+ this.plain = plain;
             }
         }
 
@@ -317,7 +431,7 @@
             return changedLineInformation;
         }
         
- private ArrayList ParseDiff(string diff)
+ public ArrayList ParseDiff(string diff)
         {
             ArrayList diffLineInformation = new ArrayList();
             string[] lines = diff.Split(new char[] { '\n'
});
@@ -449,13 +563,13 @@
                 switch (line.Type)
                 {
                     case ChangedLineType.Added:
-
coloredContent.Appen​dFormat("Added: {0}\n", line.Path);
+
coloredContent.Appen​dFormat("Added: {0}\n", line.DisplayPath);
                         break;
                     case ChangedLineType.Deleted:
-
coloredContent.Appen​dFormat("Deleted: {0}\n", line.Path);
+
coloredContent.Appen​dFormat("Deleted: {0}\n", line.DisplayPath);
                         break;
                     case ChangedLineType.Updated:
-
coloredContent.Appen​dFormat("Modified: {0}\n", line.Path);
+
coloredContent.Appen​dFormat("Modified: {0}\n", line.DisplayPath);
                         break;
                 }
 
@@ -541,7 +655,7 @@
 
coloredContent.Append("<hr /><div class=\"file\">\n");
 
coloredContent.Appen​dFormat("<div class=\"fileheader​"><big>​<b>{0}
{1}</b>{2}<​/big></div>​\n",
 
FormatChange(line.Prefix),
-
FormatChange(line.Filename),
+
FormatChange(line.Di​splayFilename),
 
FormatChange(line.Extra));
 
                             if ((nextLine ==
null) || (nextLine.Type) != DiffLineType.FileSpacer)
@@ -599,12 +713,12 @@
         
         public string GenerateColoredMail(string changelog,
                                           string changed,
- string diff)
+ ArrayList diffLines)
         {
             string documentTemplate = GetDocumentTemplate();
             string content =
GenerateColoredConte​nt(changelog,
 
ParseChanged(changed),
-
ParseDiff(diff));
+
diffLines);
             return documentTemplate.Rep​lace("{CONTENT}",
content);
         }
         
@@ -680,19 +794,19 @@
             return result.ToString();
         }
         
- public void Commit(string fromEmail,
- string htmlEmail,
- string plaintextEmail,
- string subject,
- string changelog,
- string changed,
- string diff)
+ private void Commit(string fromEmail,
+ string htmlEmail,
+ string plaintextEmail,
+ string subject,
+ string changelog,
+ string changed,
+ ArrayList diffLines)
         {
             if (htmlEmail != null)
             {
                 string coloredMail =
GenerateColoredMail(changelog,
 
changed,
-
diff);
+
diffLines);
                 MailerHelper mailerHelper = new
MailerHelper();
                 mailerHelper.SendEma​il(fromEmail,
                                        htmlEmail,
@@ -780,7 +894,69 @@
             return redirectableProcess.​ProcessOutput;
         }
 
+ private bool IsDiffLineChildOf(Di​ffLineInformation
parent,
+ DiffLineInformation
child)
+ {
+ if (parent.Path == null || child.Filename ==
null)
+ return false;
+ return child.Filename.Start​sWith(parent.Path);
+ }
+
+ private ArrayList GetChildDiffLines(ArrayList diffLines,
+ DiffLineInformation
parent)
+ {
+ ArrayList list = new ArrayList();
+ for (int i = 0; i < diffLines.Count; i++)
+ {
+ DiffLineInformation line = diffLines[i]
as DiffLineInformation;
+ if (IsDiffLineChildOf(parent, line))
+ {
+ list.Add(line);
+ i++;
+ while (i < diffLines.Count)
+ {
+ line = diffLines[i] as
DiffLineInformation;
+ if
(line.IsStartOfFile())
+ {
+ i--;
+ break;
+ }
+ list.Add(line);
+ i++;
+ }
+ }
+ }
+ return list;
+ }
+
         /// <summary>
+ /// Build a diff which also contain the contents of
added files which are copied from the checkin branch.
+ /// </summary>
+ /// <param name="diffLines">Diff lines.</param>
+ /// <param name="svnlookApplica​tion">Path to svnlook
application.</param>
+ /// <param name="subversionRepo​sitoryPath">Subve​rsion
repository path.</param>
+ private void BuildExtendedDiff(ArrayList diffLines,
+ string
svnlookApplication,
+ string
subversionRepositoryPath)
+ {
+ ArrayList originalLines = diffLines.Clone() as
ArrayList;
+ foreach (DiffLineInformation originalLine in
originalLines)
+ {
+ if (originalLine.Type !=
DiffLineType.Copied &&
+ originalLine.Type !=
DiffLineType.Moved)
+ continue;
+ string diff =
DiffChange(svnlookApplication,
+
subversionRepositoryPath,
+
originalLine.Revision);
+ ArrayList newLines =
GetChildDiffLines(Pa​rseDiff(diff),
+
originalLine);
+ int index =
diffLines.IndexOf(or​iginalLine);
+ diffLines.Remove(originalLine);
+ diffLines.InsertRange(index, newLines);
+ }
+ }
+
+ /// <summary>
         /// Retrieve a log of a change.
         /// </summary>
         /// <param name="svnlookApplica​tion">Path to svnlook
application.</param>
@@ -873,13 +1049,17 @@
             string subject = GetSubject(changelog,
                                         username,
                                         revision);
+ ArrayList diffLines = ParseDiff(diff);
+ BuildExtendedDiff(diffLines,
+ svnlookApplication,
+ subversionRepositoryPath);
             Commit(fromEmail,
                    htmlEmail,
                    plaintextEmail,
                    subject,
                    changelog,
                    changed,
- diff);
+ diffLines);
         }
         
         private string GetAuthor(string svnlookApplication,
  _____

Modified: branches/0.1/Sin.Tes​ts/CommitMailerTest.​cs
--- branches/0.1/Sin.Tes​ts/CommitMailerTest.​cs 2005-08-11 23:59:50 UTC
(rev 409)
+++ branches/0.1/Sin.Tes​ts/CommitMailerTest.​cs 2005-08-12 00:02:22 UTC
(rev 410)
@@ -32,7 +32,7 @@

             string commitMailerTestDiffOutput =
Global.GetResource("​CommitMailerTestHtml​Output");
             string coloredDiff =
svnCommitMailer.Gene​rateColoredMail("My change.",
 
"",
-
commitMailerTestDiffInput);
+
svnCommitMailer.Pars​eDiff(commitMailerTe​stDiffInput));
 
Assert.AreEqual(comm​itMailerTestDiffOutp​ut.Replace("\r", ""),
                             coloredDiff.Replace("\r", ""));
         }
@@ -74,5 +74,30 @@
                                           "My change."),
                             subject);
         }
+
+ [Test]
+ public void DiffLineRevisionTest()
+ {
+ string plain = "Copied:
trunk/Sin.Setup/Sin-4GB.zip (from rev 377,
checkin/trunk/Sin.Se​tup/Sin-4GB.zip)";
+ SvnCommitMailer.Diff​LineInformation dli = new
SvnCommitMailer.Diff​LineInformation(plai​n);
+ Assert.AreEqual(377, dli.Revision);
+
Assert.AreEqual("che​ckin/trunk/Sin.Setup​/Sin-4GB.zip", dli.Path);
+ }
+
+ [Test]
+ public void DiffLinePlainTest()
+ {
+ string plain = "Property changes on:
checkin/trunk/reacto​s/makefile";
+ SvnCommitMailer.Diff​LineInformation dli = new
SvnCommitMailer.Diff​LineInformation(plai​n);
+ Assert.AreEqual("Property changes on:
trunk/reactos/makefile", dli.Plain);
+
+ plain = "--- checkin/trunk/reactos/makefile2
2005-07-14 16:07:22 UTC (rev 11)";
+ dli = new
SvnCommitMailer.Diff​LineInformation(plai​n);
+ Assert.AreEqual("--- trunk/reactos/makefile2
2005-07-14 16:07:22 UTC (rev 11)", dli.Plain);
+
+ plain = "+++ checkin/trunk/reactos/makefile2
2005-07-14 16:07:22 UTC (rev 11)";
+ dli = new
SvnCommitMailer.Diff​LineInformation(plai​n);
+ Assert.AreEqual("+++ trunk/reactos/makefile2
2005-07-14 16:07:22 UTC (rev 11)", dli.Plain);
+ }
     }
 }
Attachments

« Previous message in topic | 1 of 1 | Next message in topic »

Messages

Show all messages in topic

[chorns] 410: Merge 399:400 from trunk chorns Casper Hornstrup 2005-08-11 17:02:37 PDT
Messages per page: