Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 55 additions & 2 deletions Vss2Git/GitExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml.Linq;
using System.Threading;
using System.Windows.Forms;
using Hpdi.VssLogicalLib;
Expand All @@ -40,6 +41,20 @@ class GitExporter : Worker
private bool ignoreErrors = false;
private string defaultComment = "";

private string emailMapFile = "emailmap.xml";
public string EmailMapFile
{
get { return emailMapFile; }
set { emailMapFile = value; }
}

private Dictionary<string, string> emailMap = new Dictionary<string, string>();
public System.Collections.Generic.Dictionary<string, string> EmailMap
{
get { return emailMap; }
set { emailMap = value; }
}

private string emailDomain = "localhost";
public string EmailDomain
{
Expand Down Expand Up @@ -82,6 +97,23 @@ public GitExporter(WorkQueue workQueue, Logger logger,
this.changesetBuilder = changesetBuilder;
}

public bool ReadEmailMap()
{
try
{
XDocument xdoc = XDocument.Load(emailMapFile);
foreach (var map in xdoc.Elements("map"))
{
emailMap.Add(map.Attribute("name").Value.ToLower(), map.Attribute("email").Value);
}
}
catch (FileNotFoundException)
{
return false;
}
return true;
}

public void ExportToGit(string repoPath)
{
workQueue.AddLast(delegate(object work)
Expand All @@ -97,6 +129,19 @@ public void ExportToGit(string repoPath)
Directory.CreateDirectory(repoPath);
}

while(!ReadEmailMap())
{
var button = MessageBox.Show("Email map file not found. ",
"Error", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error);
if (button == DialogResult.Abort)
{
workQueue.Abort();
return;
}
if (button == DialogResult.Ignore)
break;
}

var git = new GitWrapper(repoPath, logger);
git.CommitEncoding = commitEncoding;

Expand Down Expand Up @@ -638,8 +683,16 @@ private bool AbortRetryIgnore(ThreadStart work, MessageBoxButtons buttons)

private string GetEmail(string user)
{
// TODO: user-defined mapping of user names to email addresses
return user.ToLower().Replace(' ', '.') + "@" + emailDomain;
// check user-defined mapping of user names to email addresses
string username = user.ToLower();
string email;
if (emailMap.TryGetValue(username, out email))
{
if (!email.Contains("@"))
email += "@" + emailDomain;
return email;
}
return username.Replace(' ', '.') + "@" + emailDomain;
}

private string GetTagFromLabel(string label)
Expand Down
50 changes: 37 additions & 13 deletions Vss2Git/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Vss2Git/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ private void goButton_Click(object sender, EventArgs e)
{
gitExporter.EmailDomain = domainTextBox.Text;
}
if (!string.IsNullOrEmpty(emailMapFileTextBox.Text))
{
gitExporter.EmailMapFile = emailMapFileTextBox.Text;
}
if (!string.IsNullOrEmpty(commentTextBox.Text))
{
gitExporter.DefaultComment = commentTextBox.Text;
Expand Down Expand Up @@ -234,6 +238,7 @@ private void ReadSettings()
excludeTextBox.Text = settings.VssExcludePaths;
outDirTextBox.Text = settings.GitDirectory;
domainTextBox.Text = settings.DefaultEmailDomain;
emailMapFileTextBox.Text = settings.EmailMapFile;
commentTextBox.Text = settings.DefaultComment;
logTextBox.Text = settings.LogFile;
transcodeCheckBox.Checked = settings.TranscodeComments;
Expand All @@ -250,6 +255,7 @@ private void WriteSettings()
settings.VssExcludePaths = excludeTextBox.Text;
settings.GitDirectory = outDirTextBox.Text;
settings.DefaultEmailDomain = domainTextBox.Text;
settings.EmailMapFile = emailMapFileTextBox.Text;
settings.LogFile = logTextBox.Text;
settings.TranscodeComments = transcodeCheckBox.Checked;
settings.ForceAnnotatedTags = forceAnnotatedCheckBox.Checked;
Expand Down
12 changes: 12 additions & 0 deletions Vss2Git/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Vss2Git/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,8 @@
<Setting Name="DefaultComment" Type="System.String" Scope="User">
<Value Profile="(Default)"></Value>
</Setting>
<Setting Name="EmailMapFile" Type="System.String" Scope="User">
<Value Profile="(Default)">emailmap.xml</Value>
</Setting>
</Settings>
</SettingsFile>
2 changes: 2 additions & 0 deletions Vss2Git/Vss2Git.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
</Reference>
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.XML" />
<Reference Include="System.Xml.Linq" />
</ItemGroup>
<ItemGroup>
<Compile Include="AsyncLineReader.cs" />
Expand Down
3 changes: 3 additions & 0 deletions Vss2Git/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
<setting name="DefaultComment" serializeAs="String">
<value></value>
</setting>
<setting name="EmailMapFile" serializeAs="String">
<value>emailmap.xml</value>
</setting>
</Hpdi.Vss2Git.Properties.Settings>
</userSettings>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/></startup></configuration>