Branch: refs/heads/master
Home: https://github.com/mono/mono
Compare: https://github.com/mono/mono/compare/8e037f7ceffa...48266c8b04e2
Commit: b8be8f0e634d6197b49321eed4d7e5cbd429dbb5
Author: Aaron Bockover <[email protected]> (abock)
Date: 2013-10-04 14:26:24 GMT
URL: https://github.com/mono/mono/commit/b8be8f0e634d6197b49321eed4d7e5cbd429dbb5
mdbrebase: fix prefix replacement, add regex & filename modes
Existing prefix replacement was incorrect as
it tested for a prefix but performed a multi
search and replace instead of just a prefix
replace. Fix that.
Add -r|--regex mode to indicate that path
replacement should be performed with regular
expressions.
Add -f|--filename mode to indicate that
replacements should be performed only on
a file name and not the full absolute path.
Add -v|--verbose mode to print the replacements
that are performed.
Changed paths:
M mcs/tools/mdbrebase/mdbrebase.cs
Modified: mcs/tools/mdbrebase/mdbrebase.cs
===================================================================
@@ -2,6 +2,7 @@
using System.Reflection;
using System.Collections;
using System.Collections.Generic;
+using System.Text.RegularExpressions;
using System.IO;
using Mono.CompilerServices.SymbolWriter;
@@ -15,6 +16,11 @@ class Settings
public string OutputDirectory { get; set; }
public string InputPattern { get; set; }
public string OutputPattern { get; set; }
+ public bool InputPatternIsRegex { get; set; }
+ public bool FileNamesOnly { get; set; }
+ public bool Verbose { get; set; }
+
+ Regex inputPatternRegex;
public bool Validate ()
{
@@ -23,8 +29,15 @@ public bool Validate ()
public string Replace (string input)
{
- if (input.StartsWith (InputPattern))
- return input.Replace (InputPattern, OutputPattern);
+ if (InputPatternIsRegex) {
+ if (inputPatternRegex == null)
+ inputPatternRegex = new Regex (InputPattern);
+ return inputPatternRegex.Replace (input, OutputPattern);
+ } else {
+ if (input.StartsWith (InputPattern))
+ return OutputPattern + input.Substring (InputPattern.Length);
+ }
+
return input;
}
}
@@ -46,7 +59,14 @@ public void RewriteMdbFile (string inputFile)
var output = new MonoSymbolFile ();
foreach (var s in input.Sources) {
- s.FileName = settings.Replace (s.FileName);
+ var newFileName = settings.FileNamesOnly
+ ? Path.Combine (Path.GetDirectoryName (s.FileName), settings.Replace (Path.GetFileName (s.FileName)))
+ : settings.Replace (s.FileName);
+
+ if (settings.Verbose)
+ Console.WriteLine ("{0} -> {1}", s.FileName, newFileName);
+
+ s.FileName = newFileName;
output.AddSource (s);
}
@@ -97,6 +117,9 @@ static void Usage (OptionSet options)
var p = new OptionSet () {
{ "d=|output=", "Output directory to the mdb file, replace existing one if ommited", v => s.OutputDirectory = v },
+ { "v|verbose", "Be verbose with output (show individual path rewrites)", v => s.Verbose = true },
+ { "f|filenames", "Only operate on file names, not full absolute paths", v => s.FileNamesOnly = true },
+ { "r|regex", "Input pattern is a regular expression", v => s.InputPatternIsRegex = true },
{ "i=|input-pattern=", "Input pattern to replace (must not be a prefix to output-pattern)(required)", v => s.InputPattern = v },
{ "o=|output-pattern=", "Output pattern to replace (required)", v => s.OutputPattern = v },
{ "h|?|help", v => showHelp = true },
Commit: 48266c8b04e26fe273abe84377132520bbb8f893
Author: Rodrigo Kumpera <[email protected]> (kumpera)
Date: 2013-10-04 16:55:00 GMT
URL: https://github.com/mono/mono/commit/48266c8b04e26fe273abe84377132520bbb8f893
Merge pull request #770 from abock/master
mdbrebase: fix prefix replacement, add regex & filename modes
Changed paths:
M mcs/tools/mdbrebase/mdbrebase.cs
Modified: mcs/tools/mdbrebase/mdbrebase.cs
===================================================================
@@ -2,6 +2,7 @@
using System.Reflection;
using System.Collections;
using System.Collections.Generic;
+using System.Text.RegularExpressions;
using System.IO;
using Mono.CompilerServices.SymbolWriter;
@@ -15,6 +16,11 @@ class Settings
public string OutputDirectory { get; set; }
public string InputPattern { get; set; }
public string OutputPattern { get; set; }
+ public bool InputPatternIsRegex { get; set; }
+ public bool FileNamesOnly { get; set; }
+ public bool Verbose { get; set; }
+
+ Regex inputPatternRegex;
public bool Validate ()
{
@@ -23,8 +29,15 @@ public bool Validate ()
public string Replace (string input)
{
- if (input.StartsWith (InputPattern))
- return input.Replace (InputPattern, OutputPattern);
+ if (InputPatternIsRegex) {
+ if (inputPatternRegex == null)
+ inputPatternRegex = new Regex (InputPattern);
+ return inputPatternRegex.Replace (input, OutputPattern);
+ } else {
+ if (input.StartsWith (InputPattern))
+ return OutputPattern + input.Substring (InputPattern.Length);
+ }
+
return input;
}
}
@@ -46,7 +59,14 @@ public void RewriteMdbFile (string inputFile)
var output = new MonoSymbolFile ();
foreach (var s in input.Sources) {
- s.FileName = settings.Replace (s.FileName);
+ var newFileName = settings.FileNamesOnly
+ ? Path.Combine (Path.GetDirectoryName (s.FileName), settings.Replace (Path.GetFileName (s.FileName)))
+ : settings.Replace (s.FileName);
+
+ if (settings.Verbose)
+ Console.WriteLine ("{0} -> {1}", s.FileName, newFileName);
+
+ s.FileName = newFileName;
output.AddSource (s);
}
@@ -97,6 +117,9 @@ static void Usage (OptionSet options)
var p = new OptionSet () {
{ "d=|output=", "Output directory to the mdb file, replace existing one if ommited", v => s.OutputDirectory = v },
+ { "v|verbose", "Be verbose with output (show individual path rewrites)", v => s.Verbose = true },
+ { "f|filenames", "Only operate on file names, not full absolute paths", v => s.FileNamesOnly = true },
+ { "r|regex", "Input pattern is a regular expression", v => s.InputPatternIsRegex = true },
{ "i=|input-pattern=", "Input pattern to replace (must not be a prefix to output-pattern)(required)", v => s.InputPattern = v },
{ "o=|output-pattern=", "Output pattern to replace (required)", v => s.OutputPattern = v },
{ "h|?|help", v => showHelp = true },
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.