Login | Register
My pages Projects Community openCollabNet

Discussions > commits > [chorns] 408: svn:eol-style=native

sin
Discussion topic

Back to topic list

[chorns] 408: svn:eol-style=native

Reply

Author chorns
Full name Casper Hornstrup
Date 2005-08-11 16:56:30 PDT
Message svn:eol-style=native
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:53:13 UTC (rev 407)
+++ branches/0.1/Sin.Int​egrationManager.Comm​itMailer/SvnCommitMa​iler.cs
2005-08-11 23:56:03 UTC (rev 408)
@@ -1,934 +1,934 @@

-/*
- * Copyright (C) 2004-2005 Casper S. Hornstrup
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-using System;
-using System.Text;
-using System.IO;
-using System.Reflection;
-using System.Resources;
-using System.Collections;
-using System.Diagnostics;
-using System.Web.Mail;
-using Sin.Library;
-
-namespace Sin.IntegrationManag​er.CommitMailer
-{
- public class SvnCommitMailer
- {
- private const string DocumentTemplate =
"DocumentTemplate.html";
- private const int MaxLinesPerChange = 100;
- private const int MaxLinesPerDiff = 1000;
-
- private enum ChangedLineType
- {
- Unknown,
- Added,
- Deleted,
- Updated
- }
-
- private class ChangedLineInformation
- {
- public string Plain;
-
- public ChangedLineType Type
- {
- get
- {
- if (Plain == null ||
Plain.Length < 1)
- {
- return
ChangedLineType.Unknown;
- }
-
- if (Plain.StartsWith("A"))
- {
- return
ChangedLineType.Added;
- }
-
- if (Plain.StartsWith("D"))
- {
- return
ChangedLineType.Deleted;
- }
-
- if (Plain.StartsWith("U"))
- {
- return
ChangedLineType.Updated;
- }
-
- return ChangedLineType.Unknown;
- }
- }
-
- public string Path
- {
- get
- {
- if (Plain.Length > 4)
- {
- return
Plain.Substring(4).Trim();
- }
- else
- {
- return "";
- }
- }
- }
-
- public ChangedLineInformation(string plain)
- {
- Plain = plain;
- }
- }
-
- private enum DiffLineType
- {
- Unknown,
- FileStart,
- Modified,
- Added,
- Deleted,
- Copied,
- Moved,
- FileSpacer,
- FromRevision,
- DiffHeader,
- ToRevision,
- Context,
- Add,
- Remove,
- Ignore
- }
-
- private class DiffLineInformation
- {
- public string Plain;
-
- public bool IsStartOfFile()
- {
- switch (Type)
- {
- case DiffLineType.FileStart:
- return true;
- case DiffLineType.Modified:
- return true;
- case DiffLineType.Added:
- return true;
- case DiffLineType.Deleted:
- return true;
- case DiffLineType.Copied:
- return true;
- case DiffLineType.Moved:
- return true;
- default:
- return false;
- }
- }
-
- public DiffLineType Type
- {
- get
- {
- if (Plain == null ||
Plain.Length < 1)
- return
DiffLineType.Unknown;
-
- if (Plain.StartsWith("Modified:
"))
- return
DiffLineType.Modified;
-
- if (Plain.StartsWith("Added: "))
- return
DiffLineType.Added;
-
- if (Plain.StartsWith("Deleted:
"))
- return
DiffLineType.Deleted;
-
- if (Plain.StartsWith("Copied:
"))
- return
DiffLineType.Copied;
-
- if (Plain.StartsWith("Moved: "))
- return
DiffLineType.Moved;
-
- if (Plain.StartsWith("Index: "))
- return
DiffLineType.FileStart;
-
- if (Plain.StartsWith("--- "))
- return
DiffLineType.FromRevision;
-
- if (Plain.StartsWith("+++ "))
- return
DiffLineType.ToRevision;
-
- if (Plain.StartsWith("@@ "))
- return
DiffLineType.DiffHeader;
-
- if
(Plain.StartsWith("=​====================​====================​============
=============="))
- return
DiffLineType.FileSpacer;
-
- switch (Plain[0])
- {
- case '+':
- return
DiffLineType.Add;
- case '-':
- return
DiffLineType.Remove;
- default:
- return
DiffLineType.Context;
- }
- }
- }
-
- public string Prefix
- {
- get
- {
- switch (Type)
- {
- case
DiffLineType.FileStart:
- return "";
- case
DiffLineType.Modified:
- return
"Modified:";
- case DiffLineType.Added:
- return "Added:";
- case
DiffLineType.Deleted:
- return
"Deleted:";
- case
DiffLineType.Copied:
- return
"Copied:";
- case DiffLineType.Moved:
- return "Moved:";
- default:
- return null;
- }
- }
- }
-
- public string Filename
- {
- get
- {
- if (IsStartOfFile())
- {
- int index =
Plain.IndexOf(": ");
- int index2 =
Plain.IndexOf(" (");
- if (index2 != -1)
- return
Plain.Substring(index + 2, index2 - index - 2).Trim();
- else
- return
Plain.Substring(index + 2).Trim();
- }
- else
- {
- return null;
- }
- }
- }
-
- public string Extra
- {
- get
- {
- if (IsStartOfFile())
- {
- int index =
Plain.IndexOf(": ");
- int index2 =
Plain.IndexOf(" (");
- if (index2 != -1)
- return
Plain.Substring(index2);
- else
- return null;
- }
- else
- {
- return null;
- }
- }
- }
-
- public DiffLineInformation(string plain)
- {
- Plain = plain;
- }
- }
-
- private int GetCommonPrefixLength(string first,
- string second)
- {
- int maxlength = Math.Min(first.Length,
second.Length);
- int commonPrefixLength = 0;
- for (int i = 0; i < maxlength; i++)
- {
- if (first[i] != second[i])
- break;
- commonPrefixLength++;
- }
- return commonPrefixLength;
- }
-
- private string Reverse(string s)
- {
- StringBuilder sb = new StringBuilder();
- for (int i = s.Length - 1; i > 0; i--)
- sb.Append(s[i]);
- return sb.ToString();
- }
-
- private int GetCommonPostfixLength(string first,
- string second)
- {
- return GetCommonPrefixLengt​h(Reverse(first),
- Reverse(second));
- }
-
- private string GetDocumentTemplate()
- {
- string resourceName = "Html.resources";
- Assembly assembly =
Assembly.GetExecutin​gAssembly();
- using (Stream htmlResourceStream =
-
assembly.GetManifest​ResourceStream(resou​rceName))
- {
- if (htmlResourceStream == null)
- throw new
Exception(String.For​mat("Missing resource '{0}'.",
-
resourceName));
- ResourceManager rm = new
ResourceManager("Html",
-
Assembly.GetExecutin​gAssembly());
- byte[] b =
rm.GetObject("Docume​ntTemplate") as byte[];
- return
System.Text.Encoding​.Default.GetString(b​);
- }
- }
-
- private ArrayList ParseChanged(string changed)
- {
- ArrayList changedLineInformation = new
ArrayList();
- string[] lines = changed.Split(new char[] { '\n'
});
- foreach (string line in lines)
- {
- ChangedLineInformation changedLine = new
ChangedLineInformati​on(line.Replace("\r​", ""));
- if (changedLine.Type ==
ChangedLineType.Unknown)
- continue;
- changedLineInformati​on.Add(changedLine);​
- }
- return changedLineInformation;
- }
-
- private ArrayList ParseDiff(string diff)
- {
- ArrayList diffLineInformation = new ArrayList();
- string[] lines = diff.Split(new char[] { '\n'
});
- foreach (string line in lines)
- {
- DiffLineInformation diffLine = new
DiffLineInformation(​line.Replace("\r", ""));
- if (diffLine.Type ==
DiffLineType.Unknown)
- continue;
- if (diffLine.Type ==
DiffLineType.Ignore)
- continue;
- diffLineInformation.​Add(diffLine);
- }
- return diffLineInformation;
- }
-
- private string FormatChange(string change)
- {
- if (change == null)
- return change;
- string htmlEncoded =
System.Web.HttpUtili​ty.HtmlEncode(change​);
- return htmlEncoded.Replace(" ", " &nbsp;");
- }
-
- private string
GetColoredLineMaybeE​dit(DiffLineInformat​ion line1,
-
DiffLineInformation line2)
- {
- // May be an edit, try to highlight the changed
part of the line
- string a = line1.Plain.Substring(1);
- string b = line2.Plain.Substring(1);
- int prefixLen = GetCommonPrefixLength(a, b) + 1;
- int suffixLen = GetCommonPostfixLength(a, b);
- // Prevent prefix/suffix having overlap
- suffixLen = Math.Min(suffixLen,
-
Math.Min(line2.Plain.Length,
-
line1.Plain.Length) - prefixLen);
- int infixSize = line1.Plain.Length - (prefixLen
+ suffixLen);
- string id;
- if (line1.Type == DiffLineType.Add)
- id = "addedchars";
- else
- id = "removedchars";
-
- if ((prefixLen == 1) && (suffixLen == 0) ||
(infixSize <= 0))
- return FormatChange(line1.Plain);
- else
- {
- int changeStart = prefixLen;
- int changeLength = infixSize;
- int changeEnd = line1.Plain.Length -
suffixLen;
- return String.Format("{0}<span
id=\"{1}\">{2}​</span>{3}",
-
FormatChange(line1.P​lain.Substring(0, changeStart)),
- id,
-
FormatChange(line1.P​lain.Substring(chang​eStart,
- changeLength)),
-
FormatChange(line1.P​lain.Substring(chang​eEnd)));
- }
- }
-
- private string GetColoredLine(DiffL​ineInformation
lastLine,
- DiffLineInformation line,
- DiffLineInformation
nextLine)
- {
- if ((line != null) && (nextLine != null) &&
- (line.Type == DiffLineType.Remove) &&
- (nextLine.Type == DiffLineType.Add))
- return GetColoredLineMaybeEdit(line,
-
nextLine);
-
- if ((lastLine != null) && (line != null) &&
- (lastLine.Type == DiffLineType.Remove) &&
- (line.Type == DiffLineType.Add))
- return GetColoredLineMaybeEdit(line,
-
lastLine);
-
- return FormatChange(line.Plain);
- }
-
- private bool SkipPre(DiffLineInformation line)
- {
- if (line.Type == DiffLineType.FromRevision)
- return true;
-
- if (line.Type == DiffLineType.ToRevision)
- return true;
-
- if (line.Type == DiffLineType.DiffHeader)
- return true;
-
- return false;
- }
-
- private void GenerateChangedColor​edContent(StringBuil​der
coloredContent,
- ArrayList
changed)
- {
- int truncatedAtLine = 0;
- bool hasPre = false;
- ChangedLineInformation lastLine = null;
- for (int lineIndex = 0; lineIndex <
changed.Count; lineIndex++)
- {
- ChangedLineInformation line =
changed[lineIndex] as ChangedLineInformation;
- ChangedLineInformation nextLine =
lineIndex < changed.Count - 1 ?
- changed[lineIndex + 1] as
ChangedLineInformation : null;
-
- if (lastLine == null || lastLine.Type !=
line.Type)
- {
- switch (line.Type)
- {
- case
ChangedLineType.Added:
- if (hasPre)
-
coloredContent.Appen​d("</pre>");
-
coloredContent.Append("<pre class=\"diff\" id=\"added\">");
- hasPre = true;
- break;
- case
ChangedLineType.Deleted:
- if (hasPre)
-
coloredContent.Appen​d("</pre>");
-
coloredContent.Append("<pre class=\"diff\" id=\"removed\">");
- hasPre = true;
- break;
- case
ChangedLineType.Updated:
- if (hasPre)
-
coloredContent.Appen​d("</pre>");
-
coloredContent.Append("<pre class=\"diff\" id=\"context\">");
- hasPre = true;
- break;
- }
- }
-
- switch (line.Type)
- {
- case ChangedLineType.Added:
-
coloredContent.Appen​dFormat("Added: {0}\n", line.Path);
- break;
- case ChangedLineType.Deleted:
-
coloredContent.Appen​dFormat("Deleted: {0}\n", line.Path);
- break;
- case ChangedLineType.Updated:
-
coloredContent.Appen​dFormat("Modified: {0}\n", line.Path);
- break;
- }
-
- lastLine = line;
-
- if (lineIndex + 1 >= MaxLinesPerChange)
- {
- truncatedAtLine = lineIndex + 1;
- break;
- }
- }
-
- if (hasPre)
- coloredContent.Appen​d("</pre>");
-
- if (truncatedAtLine != 0 && truncatedAtLine <
changed.Count)
- coloredContent.Appen​dFormat("<strong
class=\"error\">[truncated at {0} lines; {1} more skipped]</strong>\n",
-
truncatedAtLine,
-
changed.Count - truncatedAtLine);
- }
-
- private void GenerateDiffColoredC​ontent(StringBuilder​
coloredContent,
- ArrayList lines)
- {
- DiffLineInformation lastLine = null;
- bool firstLine = true;
- bool firstFile = true;
- bool hasPre = false;
- bool hasSmallInfo = false;
- int truncatedAtLine = 0;
- for (int lineIndex = 0; lineIndex < lines.Count;
lineIndex++)
- {
- DiffLineInformation line =
lines[lineIndex] as DiffLineInformation;
- DiffLineInformation nextLine = lineIndex
< lines.Count - 1 ?
- lines[lineIndex + 1] as
DiffLineInformation : null;
-
- DiffLineType lastDiffLineType = lastLine
!= null ?
- lastLine.Type :
DiffLineType.Unknown;
- bool skipContent = false;
-
- if (line.Type ==
DiffLineType.FileSpacer)
- continue;
-
- if (hasSmallInfo && (line.Type ==
DiffLineType.Add ||
- line.Type ==
DiffLineType.Remove ||
- line.Type ==
DiffLineType.Context))
- {
-
coloredContent.Appen​d("</small>​</pre>");
- hasSmallInfo = false;
- }
-
- if (hasPre && lastDiffLineType !=
line.Type && !SkipPre(line) && !firstLine)
- {
- coloredContent.Appen​d("</pre>");
- hasPre = false;
- }
-
- if (lastDiffLineType != line.Type)
- {
- switch (line.Type)
- {
- case
DiffLineType.Context:
-
coloredContent.Append("<pre class=\"diff\" id=\"context\">");
- hasPre = true;
- break;
- case DiffLineType.Add:
-
coloredContent.Append("<pre class=\"diff\" id=\"added\">");
- hasPre = true;
- break;
- case
DiffLineType.Remove:
-
coloredContent.Append("<pre class=\"diff\" id=\"removed\">");
- hasPre = true;
- break;
- default:
- if
(!line.IsStartOfFile())
- break;
-
- if (!firstFile)
-
coloredContent.Appen​d("</div>\n")​;
-
- firstFile =
false;
-
-
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.Extra));
-
- if ((nextLine ==
null) || (nextLine.Type) != DiffLineType.FileSpacer)
- {
-
coloredContent.Appen​d("</div>\n")​;
-
continue;
- }
-
-
coloredContent.Append("<pre class=\"diff\"><small id=\"info\">");
- hasSmallInfo =
true;
- skipContent =
true;
- break;
- }
- }
-
- if (!skipContent)
-
coloredContent.Appen​dFormat("{0}\n",
-
GetColoredLine(lastLine,
-
line,
-
nextLine));
-
- lastLine = line;
- firstLine = false;
-
- if (lineIndex + 1 >= MaxLinesPerDiff)
- {
- truncatedAtLine = lineIndex + 1;
- break;
- }
- }
-
- coloredContent.Appen​d("</pre>\n")​;
-
- if (truncatedAtLine != 0 && truncatedAtLine <
lines.Count)
- coloredContent.Appen​dFormat("<strong
class=\"error\">[truncated at {0} lines; {1} more skipped]</strong>\n",
-
truncatedAtLine,
- lines.Count
- truncatedAtLine);
-
- coloredContent.Appen​d("</div>\n")​;
- }
-
- private string GenerateColoredContent(string changelog,
- ArrayList changed,
- ArrayList lines)
- {
- StringBuilder coloredContent = new
StringBuilder();
- coloredContent.Appen​dFormat("<pre
class=\"comment\"​>{0}</pre>",​
-
FormatChange(changel​og.Trim()));
- GenerateChangedColor​edContent(coloredCon​tent,
- changed);
- GenerateDiffColoredC​ontent(coloredConten​t,
- lines);
- return coloredContent.ToString();
- }
-
- public string GenerateColoredMail(string changelog,
- string changed,
- string diff)
- {
- string documentTemplate = GetDocumentTemplate();
- string content =
GenerateColoredConte​nt(changelog,
-
ParseChanged(changed),
-
ParseDiff(diff));
- return documentTemplate.Rep​lace("{CONTENT}",
content);
- }
-
- private ArrayList GetChangedEntriesOfT​ype(ArrayList
changed,
- ChangedLineType
type)
- {
- ArrayList result = new ArrayList();
- foreach (ChangedLineInformation line in changed)
- {
- if (line.Type == type)
- result.Add(line);
- }
- return result;
- }
-
- private void GenerateAddedFiles(ArrayList changedList,
- ref StringBuilder
result)
- {
- ArrayList added =
GetChangedEntriesOfT​ype(changedList,
-
ChangedLineType.Added);
- if (added.Count > 0)
- {
- result.AppendFormat("\nAdded files:\n");
- foreach (ChangedLineInformation line in
added)
- {
- result.AppendFormat("{0}\n",
line.Path);
- }
- }
- }
-
- private void GenerateUpdatedFiles(ArrayList changedList,
- ref StringBuilder
result)
- {
- ArrayList updated =
GetChangedEntriesOfT​ype(changedList,
-
ChangedLineType.Updated);
- if (updated.Count > 0)
- {
- result.AppendFormat("\nUpdated
files:\n");
- foreach (ChangedLineInformation line in
updated)
- {
- result.AppendFormat("{0}\n",
line.Path);
- }
- }
- }
-
- private void GenerateDeletedFiles(ArrayList changedList,
- ref StringBuilder
result)
- {
- ArrayList deleted =
GetChangedEntriesOfT​ype(changedList,
-
ChangedLineType.Deleted);
- if (deleted.Count > 0)
- {
- result.AppendFormat("\nDeleted
files:\n");
- foreach (ChangedLineInformation line in
deleted)
- {
- result.AppendFormat("{0}\n",
line.Path);
- }
- }
- }
-
- public string GeneratePlaintextMail(string changelog,
- string changed)
- {
- StringBuilder result = new
StringBuilder(changelog);
- result.Append("\n");
- ArrayList changedList = ParseChanged(changed);
- GenerateAddedFiles(changedList,
- ref result);
- GenerateUpdatedFiles​(changedList,
- ref result);
- GenerateDeletedFiles​(changedList,
- ref result);
- return result.ToString();
- }
-
- public void Commit(string fromEmail,
- string htmlEmail,
- string plaintextEmail,
- string subject,
- string changelog,
- string changed,
- string diff)
- {
- if (htmlEmail != null)
- {
- string coloredMail =
GenerateColoredMail(changelog,
-
changed,
-
diff);
- MailerHelper mailerHelper = new
MailerHelper();
- mailerHelper.SendEma​il(fromEmail,
- htmlEmail,
- subject,
- coloredMail,
- MailFormat.Html);
- }
-
- if (plaintextEmail != null)
- {
- string plaintextMail =
GeneratePlaintextMai​l(changelog,
-
changed);
- MailerHelper mailerHelper = new
MailerHelper();
- mailerHelper.SendEma​il(fromEmail,
- plaintextEmail,
- subject,
- plaintextMail,
- MailFormat.Text);
- }
- }
-
- /// <summary>
- /// Retrieve a list of changed files.
- /// </summary>
- /// <param name="svnlookApplica​tion">Path to svnlook
application.</param>
- /// <param name="subversionRepo​sitoryPath">Subve​rsion
repository path.</param>
- /// <param name="revision">Revision of commit.</param>
- /// <returns>Outpu​t.</returns>
- private static string Changed(string svnlookApplication,
- string
subversionRepositoryPath,
- int revision)
- {
- string args = String.Format("changed -r {0}
\"{1}\"",
- revision.ToString(),
- subversionRepositoryPath);
- ProcessStartInfo runProcessStartInfo = new
ProcessStartInfo(svn​lookApplication,
-
args);
- runProcessStartInfo.​RedirectStandardInpu​t =
true;
- runProcessStartInfo.​RedirectStandardErro​r =
true;
- runProcessStartInfo.​RedirectStandardOutp​ut =
true;
- runProcessStartInfo.​UseShellExecute = false;
- RedirectableProcess redirectableProcess = new
RedirectableProcess(​runProcessStartInfo)​;
- switch (redirectableProcess.ExitCode)
- {
- case 0:
- break;
- default:
- throw new
Exception(String.Format("'{0}' failed with exit code {1}",
-
svnlookApplication,
-
redirectableProcess.ExitCode));
- }
- return redirectableProcess.​ProcessOutput;
- }
-
- /// <summary>
- /// Retrieve a diff of a change.
- /// </summary>
- /// <param name="svnlookApplica​tion">Path to svnlook
application.</param>
- /// <param name="subversionRepo​sitoryPath">Subve​rsion
repository path.</param>
- /// <param name="revision">Revision of commit.</param>
- /// <returns>Outpu​t.</returns>
- private static string DiffChange(string
svnlookApplication,
- string
subversionRepositoryPath,
- int revision)
- {
- string args = String.Format("diff -r {0}
\"{1}\"",
- revision.ToString(),
- subversionRepositoryPath);
- ProcessStartInfo runProcessStartInfo = new
ProcessStartInfo(svn​lookApplication,
-
args);
- runProcessStartInfo.​RedirectStandardInpu​t =
true;
- runProcessStartInfo.​RedirectStandardErro​r =
true;
- runProcessStartInfo.​RedirectStandardOutp​ut =
true;
- runProcessStartInfo.​UseShellExecute = false;
- RedirectableProcess redirectableProcess = new
RedirectableProcess(​runProcessStartInfo)​;
- switch (redirectableProcess.ExitCode)
- {
- case 0:
- break;
- default:
- throw new
Exception(String.Format("'{0}' failed with exit code {1}",
-
svnlookApplication,
-
redirectableProcess.ExitCode));
- }
- return redirectableProcess.​ProcessOutput;
- }
-
- /// <summary>
- /// Retrieve a log of a change.
- /// </summary>
- /// <param name="svnlookApplica​tion">Path to svnlook
application.</param>
- /// <param name="subversionRepo​sitoryPath">Subve​rsion
repository path.</param>
- /// <param name="revision">Revision of commit.</param>
- /// <returns>Outpu​t.</returns>
- private static string Changelog(string
svnlookApplication,
- string
subversionRepositoryPath,
- int revision)
- {
- string args = String.Format("log -r {0}
\"{1}\"",
- revision.ToString(),
- subversionRepositoryPath);
- ProcessStartInfo runProcessStartInfo = new
ProcessStartInfo(svn​lookApplication,
-
args);
- runProcessStartInfo.​RedirectStandardInpu​t =
true;
- runProcessStartInfo.​RedirectStandardErro​r =
true;
- runProcessStartInfo.​RedirectStandardOutp​ut =
true;
- runProcessStartInfo.​UseShellExecute = false;
- RedirectableProcess redirectableProcess = new
RedirectableProcess(​runProcessStartInfo)​;
- switch (redirectableProcess.ExitCode)
- {
- case 0:
- break;
- default:
- throw new
Exception(String.Format("'{0}' failed with exit code {1}",
-
svnlookApplication,
-
redirectableProcess.ExitCode));
- }
- return redirectableProcess.​ProcessOutput;
- }
-
- private string TrimLineEndings(string s)
- {
- return s.Trim().Replace("\r", "").Replace("\n",
"");
- }
-
- private string GetFirstLine(string s)
- {
- if (s == null || s.Trim().Equals(String.Empty))
- return String.Empty;
- string[] lines = s.Split(new char[] { '\n' });
- foreach (string line in lines)
- {
- string trimmedLine =
TrimLineEndings(line);
- if (!trimmedLine.Equals​(String.Empty))
- return trimmedLine;
- }
- return String.Empty;
- }
-
- public string GetSubject(string changelog,
- string username,
- int revision)
- {
- return String.Format("[{0}] {1}: {2}",
- username != null ? username
: "unknown author",
- revision,
- GetFirstLine(changelog));
- }
-
- private string GetFromEmail(string fromEmailServer,
- string author)
- {
- string mailbox = (author != null) ? author :
"svn";
- return String.Format("{0}@{1}",
- mailbox,
- fromEmailServer);
- }
-
- public void Commit(string username,
- string fromEmailServer,
- string htmlEmail,
- string plaintextEmail,
- string svnlookApplication,
- string subversionRepositoryPath,
- int revision)
- {
- string fromEmail = GetFromEmail(fromEmailServer,
- username);
- string changed = Changed(svnlookApplication,
-
subversionRepositoryPath,
- revision);
- string diff = DiffChange(svnlookApplication,
-
subversionRepositoryPath,
- revision);
- string changelog = Changelog(svnlookApplication,
-
subversionRepositoryPath,
- revision);
- string subject = GetSubject(changelog,
- username,
- revision);
- Commit(fromEmail,
- htmlEmail,
- plaintextEmail,
- subject,
- changelog,
- changed,
- diff);
- }
-
- private string GetAuthor(string svnlookApplication,
- string
subversionRepositoryPath,
- int revision)
- {
- string args = String.Format("author -r {0}
\"{1}\"",
- revision.ToString(),
- subversionRepositoryPath);
- ProcessStartInfo runProcessStartInfo = new
ProcessStartInfo(svn​lookApplication,
-
args);
- runProcessStartInfo.​RedirectStandardInpu​t =
true;
- runProcessStartInfo.​RedirectStandardErro​r =
true;
- runProcessStartInfo.​RedirectStandardOutp​ut =
true;
- runProcessStartInfo.​UseShellExecute = false;
- RedirectableProcess redirectableProcess = new
RedirectableProcess(​runProcessStartInfo)​;
- switch (redirectableProcess.ExitCode)
- {
- case 0:
- break;
- default:
- throw new
Exception(String.Format("'{0}' failed with exit code {1}",
-
svnlookApplication,
-
redirectableProcess.ExitCode));
- }
- string author =
redirectableProcess.​ProcessOutput;
- author = author.Replace("\r", "").Replace("\n",
"").Trim();
- if (author.Equals(String.Empty))
- author = null;
- return author;
- }
-
- public void Commit(string fromEmailServer,
- string htmlEmail,
- string plaintextEmail,
- string svnlookApplication,
- string subversionRepositoryPath,
- int revision)
- {
- string author = GetAuthor(svnlookApplication,
-
subversionRepositoryPath,
- revision);
- Commit(author,
- fromEmailServer,
- htmlEmail,
- plaintextEmail,
- svnlookApplication,
- subversionRepositoryPath,
- revision);
- }
- }
-}
+/*
+ * Copyright (C) 2004-2005 Casper S. Hornstrup
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+using System;
+using System.Text;
+using System.IO;
+using System.Reflection;
+using System.Resources;
+using System.Collections;
+using System.Diagnostics;
+using System.Web.Mail;
+using Sin.Library;
+
+namespace Sin.IntegrationManag​er.CommitMailer
+{
+ public class SvnCommitMailer
+ {
+ private const string DocumentTemplate =
"DocumentTemplate.html";
+ private const int MaxLinesPerChange = 100;
+ private const int MaxLinesPerDiff = 1000;
+
+ private enum ChangedLineType
+ {
+ Unknown,
+ Added,
+ Deleted,
+ Updated
+ }
+
+ private class ChangedLineInformation
+ {
+ public string Plain;
+
+ public ChangedLineType Type
+ {
+ get
+ {
+ if (Plain == null ||
Plain.Length < 1)
+ {
+ return
ChangedLineType.Unknown;
+ }
+
+ if (Plain.StartsWith("A"))
+ {
+ return
ChangedLineType.Added;
+ }
+
[truncated at 1000 lines; 1042 more skipped]
Attachments

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

Messages

Show all messages in topic

[chorns] 408: svn:eol-style=native chorns Casper Hornstrup 2005-08-11 16:56:30 PDT
Messages per page: