كيف يمكنني الوصول إلى رسالة SVN قبل الالتزام باستخدام SharpSVN؟
-
21-09-2019 - |
سؤال
أرى أن كل ما يمكنني ضبطه هو ٪ repos ٪ و ٪ TXN ٪
كيف يمكنني استخدام هؤلاء للوصول إلى رسالة الالتزام (في حالتي ، حتى أتمكن من تحليل رقم التذكرة حتى أتمكن من معرفة ما إذا كانت موجودة في قاعدة بيانات الأخطاء قبل الالتزام بها)
المحلول
باستخدام حديث Sharpsvn التحرير يمكنك استخدامه
SvnHookArguments ha;
if (!SvnHookArguments.ParseHookArguments(args, SvnHookType.PreCommit, false, out ha))
{
Console.Error.WriteLine("Invalid arguments");
Environment.Exit(1);
}
لتحليل حجج خطاف ما قبل الالتزام ثم الاستخدام
using (SvnLookClient cl = new SvnLookClient())
{
SvnChangeInfoEventArgs ci;
cl.GetChangeInfo(ha.LookOrigin, out ci);
// ci contains information on the commit e.g.
Console.WriteLine(ci.LogMessage); // Has log message
foreach (SvnChangeItem i in ci.ChangedPaths)
{
}
}
للوصول إلى رسالة السجل ، تم تغيير الملفات ، إلخ.
نصائح أخرى
لا أعرف Sharpsvn ، ولكن إذا قمت بإنشاء برنامج نصي خطاف كما تصف ، فستحصل على حجج ٪ repos ٪ و ٪ txn ٪
مع هذه البيانات ، يمكنك البحث في المعاملة (٪ TXN ٪) من المستودع المحدد. عادة ما تفعل هذا باستخدام
svnlook -t %txn% %repo%
ثم سوف تحصل على log-message.
لذلك يجب أن تبحث عن ما يعادل SVNlook في واجهة Sharpsvn.
منذ بعض الوقت كتبت مجموعة C# لـ svnlook.exe. لقد استخدمت هذا واحد لإرسال رسائل الالتزام إلى تعقب الأخطاء (إذا تم توفير معرف تذكرة). ابحث عنه أدناه ، ربما يكون مفيدًا لك.
/// <summary>
/// Encapsulates the SVNLook command in all of it's flavours
/// </summary>
public static class SvnLookCommand
{
/// <summary>
/// The string "" used as parameter for the svnlook.exe
/// </summary>
private static readonly string AUTHOR = "author";
/// <summary>
/// The string "cat" used as parameter for the svnlook.exe
/// </summary>
private static readonly string CAT = "cat";
/// <summary>
/// The string "changed" used as parameter for the svnlook.exe
/// </summary>
private static readonly string CHANGED = "changed";
/// <summary>
/// The string "date" used as parameter for the svnlook.exe
/// </summary>
private static readonly string DATE = "date";
/// <summary>
/// The string "diff" used as parameter for the svnlook.exe
/// </summary>
private static readonly string DIFF = "diff";
/// <summary>
/// The string "dirs-changed" used as parameter for the svnlook.exe
/// </summary>
private static readonly string DIRSCHANGED = "dirs-changed";
/// <summary>
/// The string "history" used as parameter for the svnlook.exe
/// </summary>
private static readonly string HISTORY = "history";
/// <summary>
/// The string "info" used as parameter for the svnlook.exe
/// </summary>
private static readonly string INFO = "info";
/// <summary>
/// The string "lock" used as parameter for the svnlook.exe
/// </summary>
private static readonly string LOCK = "lock";
/// <summary>
/// The string "log" used as parameter for the svnlook.exe
/// </summary>
private static readonly string LOG = "log";
/// <summary>
/// The string "tree" used as parameter for the svnlook.exe
/// </summary>
private static readonly string TREE = "tree";
/// <summary>
/// The string "uuid" used as parameter for the svnlook.exe
/// </summary>
private static readonly string UUID = "uuid";
/// <summary>
/// The string "youngest" used as parameter for the svnlook.exe
/// </summary>
private static readonly string YOUNGEST = "youngest";
/// <summary>
/// The full path of the svnlook.exe binary
/// </summary>
private static string commandPath = String.Empty;
/// <summary>
/// Initializes static members of the <see cref="SvnLookCommand"/> class.
/// </summary>
static SvnLookCommand()
{
commandPath = Settings.Default.SvnDirectoryPath;
if (!Path.IsPathRooted(commandPath))
{
Assembly entryAssembly = Assembly.GetEntryAssembly();
if (entryAssembly != null)
{
commandPath = new FileInfo(entryAssembly.Location).Directory.ToString() + Path.DirectorySeparatorChar + commandPath;
}
}
if (!commandPath.EndsWith(Path.DirectorySeparatorChar.ToString()))
{
commandPath = commandPath + Path.DirectorySeparatorChar;
}
commandPath += "svnlook.exe";
}
/// <summary>
/// Gets the process info to start a svnlook.exe command with parameter "author"
/// </summary>
/// <param name="repository">The repository.</param>
/// <param name="revision">The revision.</param>
/// <returns>Gets the author of the revision in scope</returns>
public static ProcessStartInfo GetAuthor(string repository, string revision)
{
ProcessStartInfo svnLookProcessStartInfo = new ProcessStartInfo(commandPath);
svnLookProcessStartInfo.Arguments = String.Format("{0} {1} -r {2}", AUTHOR, repository, revision);
return svnLookProcessStartInfo;
}
/// <summary>
/// Gets the process info to start a svnlook.exe command with parameter "log"
/// </summary>
/// <param name="repository">The repository.</param>
/// <param name="revision">The revision.</param>
/// <returns>The svn log of the revision in scope</returns>
public static ProcessStartInfo GetLog(string repository, string revision)
{
ProcessStartInfo svnLookProcessStartInfo = new ProcessStartInfo(commandPath);
svnLookProcessStartInfo.Arguments = String.Format("{0} {1} -r {2}", LOG, repository, revision);
return svnLookProcessStartInfo;
}
/// <summary>
/// Gets the process info to start a svnlook.exe command with parameter "changed"
/// </summary>
/// <param name="repository">The repository.</param>
/// <param name="revision">The revision.</param>
/// <returns>The change log of the revision in scope</returns>
public static ProcessStartInfo GetChangeLog(string repository, string revision)
{
ProcessStartInfo svnLookProcessStartInfo = new ProcessStartInfo(commandPath);
svnLookProcessStartInfo.Arguments = String.Format("{0} {1} -r {2}", CHANGED, repository, revision);
return svnLookProcessStartInfo;
}
/// <summary>
/// Gets the process info to start a svnlook.exe command with parameter "info"
/// </summary>
/// <param name="repository">The repository.</param>
/// <param name="revision">The revision.</param>
/// <returns>The info of the revision in scope</returns>
public static ProcessStartInfo GetInfo(string repository, string revision)
{
ProcessStartInfo svnLookProcessStartInfo = new ProcessStartInfo(commandPath);
svnLookProcessStartInfo.Arguments = String.Format("{0} {1} -r {2}", INFO, repository, revision);
return svnLookProcessStartInfo;
}
}
لقد مررت للتو بعملية إنشاء تطبيق Hooks بنفسي و SharpSVN غير مطلوب للنظر في رسائل الالتزام. على افتراض أنك قمت ببناء تطبيق وحدة تحكم بالفعل ، جرب هذا الرمز الذي يستدعي svnlook.exe مباشرة:
string repos = args[0];
string txn = args[1];
var processStartInfo = new ProcessStartInfo
{
FileName = "svnlook.exe",
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardOutput = true,
RedirectStandardError = true,
Arguments = String.Format("log -t \"{0}\" \"{1}\"", txn, repos)
};
Process process = Process.Start(processStartInfo);
string message = process.StandardOutput.ReadToEnd();
process.WaitForExit();
return message;
تأكد من إضافة موقع svnlook.exe إلى متغير بيئة المسار في جهازك حتى يمكن تنفيذ ما سبق من أي مكان.