Skip to content

Commit

Permalink
Update Chorus to use Mercurial 6.5.1 and Python 3 (#329)
Browse files Browse the repository at this point in the history
* ChorusMerge: no more need to change input encoding

With the changes in Mercurial 6.5.1 and Python3, ChorusMerge now gets
correctly-encoded Unicode filenames as input, without needing to go
through a step where UTF-8 is double-encoded as CP1252.

* Change/delete prompt text is different in hg 6.5.1
* Mercurial ignores stdin unless ui.interactive true
* Add hg username to four unit tests

A behavior change between Mercurial 3.3 and 6.5.1 means that these four
tests now fail due to Mercurial complaining that the username isn't set.
Since the absence of a username has nothing to do with the matter under
test, we should just change how these four tests are set up to include a
username so that Mercurial is satisfied.

* Update SIL.Chorus.Mercurial from 3.0.3 to 6.5.1
* Update GeneratedMercurial.wxs file
* Update GeneratedMercurialExtensions.wxs file
* Update CHANGELOG to mention Mercurial 6.5.1

+semver: major
  • Loading branch information
rmunn authored Dec 14, 2023
1 parent 74871cb commit 3de3771
Show file tree
Hide file tree
Showing 10 changed files with 536 additions and 177 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Use UTF-8 in conflict details view
- [SIL.Chorus.LibChorus] Add ChorusStorage (the bundle cache) as an Excluded folder
- [SIL.Chorus.LibChorus] Changed HgResumeTransport LastKnownCommonBases to use Json serialization instead of BinaryFormatter
- Update SIL.Chorus.Mercurial dependency to version 6.5.1 which uses Python 3

### Fixed

Expand Down
27 changes: 27 additions & 0 deletions src/ChorusHub/ChorusHub.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
<PackageId>SIL.Chorus.ChorusHub</PackageId>
<OutputType>WinExe</OutputType>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<RootDir Condition="'$(teamcity_build_checkoutDir)' == '' And '$(RootDir)'==''">$(MSBuildProjectDirectory)/../..</RootDir>
<RootDir Condition="'$(teamcity_build_checkoutDir)' != ''">$(teamcity_build_checkoutDir)</RootDir>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="GitVersion.MsBuild" Version="5.10.3" PrivateAssets="All" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="SIL.ReleaseTasks" Version="2.5.0" PrivateAssets="All" />
<PackageReference Include="SIL.BuildTasks" Version="2.5.0" PrivateAssets="All" />
</ItemGroup>

<ItemGroup>
Expand All @@ -28,4 +31,28 @@
<AssemblySearchPaths>$(AssemblySearchPaths);{GAC}</AssemblySearchPaths>
</PropertyGroup>

<UsingTask TaskName="MakeWixForDirTree" AssemblyFile="$(PkgSIL_BuildTasks)\tools\SIL.BuildTasks.dll" />
<Target Name="MakeWixForDistFiles" DependsOnTargets="Compile" Condition="'$(OS)'=='Windows_NT'">
<!-- NB: The Exclude argument doesn't seem to be working so you may need to hand edit the GeneratedMercurial.wxs -->
<MakeWixForDirTree
DirectoryReferenceId="mercurial"
ComponentGroupId="Mercurial"
RootDirectory="$(RootDir)\mercurial"
OutputFilePath="$(RootDir)\src\Installer\GeneratedMercurial.wxs"
IgnoreRegExPattern="IGNOREME|\.gitignore"
Exclude="$(RootDir)\mercurial\mercurial.ini;$(RootDir)\mercurial\default.d\cacerts.rc"
MatchRegExPattern=".*">
<Output TaskParameter="OutputFilePath" ItemName="Compile" />
</MakeWixForDirTree>
<MakeWixForDirTree
DirectoryReferenceId="MercurialExtensions"
ComponentGroupId="MercurialExtensions"
RootDirectory="$(RootDir)\MercurialExtensions"
OutputFilePath="$(RootDir)\src\Installer\GeneratedMercurialExtensions.wxs"
IgnoreRegExPattern="IGNOREME|\.gitignore"
MatchRegExPattern=".*">
<Output TaskParameter="OutputFilePath" ItemName="Compile" />
</MakeWixForDirTree>
</Target>

</Project>
8 changes: 1 addition & 7 deletions src/ChorusMerge.Tests/ChorusMergeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ private int DoMerge(GroupOfConflictingLiftFiles group)
}

[Test]
[Platform(Exclude = "Linux", Reason = "This test assumes Windows file system behavior.")]
public void Main_Utf8FilePaths_FileNamesOk()
{
using (var e = new TemporaryFolder("ChorusMergeTest"))
Expand All @@ -77,14 +76,9 @@ public void Main_Utf8FilePaths_FileNamesOk()
var filePath3 = Path.Combine(e.Path, "aaa.chorusTest");
File.WriteAllText(filePath3, @"aaa");

var encoding = Encoding.GetEncoding(1252);
string filePath1Cp1252 = encoding.GetString(Encoding.UTF8.GetBytes(filePath1));
string filePath2Cp1252 = encoding.GetString(Encoding.UTF8.GetBytes(filePath2));
string filePath3Cp1252 = encoding.GetString(Encoding.UTF8.GetBytes(filePath3));

MergeSituation.PushRevisionsToEnvironmentVariables("bob", "-123", "sally", "-456");
MergeOrder.PushToEnvironmentVariables(p.Path);
var result = Program.Main(new[] { filePath1Cp1252, filePath2Cp1252, filePath3Cp1252 });
var result = Program.Main(new[] { filePath1, filePath2, filePath3 });

Assert.That(result, Is.EqualTo(0));
}
Expand Down
25 changes: 3 additions & 22 deletions src/ChorusMerge/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ namespace ChorusMerge
/// See MergeOrder and MergeSituation for a description of those variables and their possible values.
/// </summary>
/// <remarks>
/// The arguments are presumed to be presented in utf-8 encoding presented via CP1252. This is a departure
/// from the norm on Windows of UCS2. However, python has issues in calling out to processes using UCS2
/// so gives utf8, which is then mangled via CP1252. This can all be decoded to give ChorusMerge the
/// ucs2 args it expects.
/// The arguments used to be presented in utf-8 encoding presented via CP1252, but Mercurial 6.5.1 and
/// Python 3 have made that unnecessary. Unicode arguments are now passed correctly without needing
/// to play games with encoding.
/// </remarks>
public class Program
{
Expand All @@ -40,24 +39,6 @@ public static int Main(string[] args)
string commonFilePath = args[1];
string theirFilePath = args[2];

if (Platform.IsWindows)
{
if (!RuntimeInformation.FrameworkDescription.Contains("Framework"))
{
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); // required for .NET6
}

// Convert the input arguments from cp1252 -> utf8 -> ucs2
// It always seems to be 1252, even when the input code page is actually something else. CP 2012-03
// var inputEncoding = Console.InputEncoding;
var inputEncoding = Encoding.GetEncoding(1252);
ourFilePath = Encoding.UTF8.GetString(inputEncoding.GetBytes(args[0]));
commonFilePath = Encoding.UTF8.GetString(inputEncoding.GetBytes(args[1]));
theirFilePath = Encoding.UTF8.GetString(inputEncoding.GetBytes(args[2]));
Console.WriteLine("ChorusMerge: Input encoding {0}",
inputEncoding.EncodingName);
}

//this was originally put here to test if console writes were making it out to the linux log or not
Console.WriteLine("ChorusMerge: {0}, {1}, {2}", ourFilePath, commonFilePath, theirFilePath);

Expand Down
Loading

0 comments on commit 3de3771

Please sign in to comment.