private MemoryStream GetSVNFileStream(SvnRevisionId changeset, string path) { var memoryStream = new MemoryStream(); SvnTarget target; //If you use Uri you should encode '#' as %23, as Uri's define the # as Fragment separator. //And in this case the fragment is not send to the server. path = path.Replace("#", "%23"); if (SvnTarget.TryParse(GetPath(path).AbsolutePath, out target)) { if (FileWasDeleted(path, changeset)) { return(new MemoryStream()); } var uriTarget = new SvnUriTarget(_root + path, changeset.Value); var svnWriteArgs = new SvnWriteArgs { Revision = changeset.Value }; Client.Write(uriTarget, memoryStream, svnWriteArgs); return(memoryStream); } return(new MemoryStream()); }
public void DiffUri(long revision, long revisionto, Uri uri) { using (SvnClient client = new SvnClient()) { var tempDir = System.IO.Path.GetTempPath(); var filename = System.IO.Path.GetFileName(uri.LocalPath); var file1 = tempDir + revision + "_" + filename; var checkoutArgs = new SvnWriteArgs() { Revision = revision }; using (var fs = System.IO.File.Create(file1)) { client.Write(uri, fs, checkoutArgs); } var file2 = tempDir + revisionto + "_" + filename; var checkoutArgs2 = new SvnWriteArgs() { Revision = revisionto }; using (var fs = System.IO.File.Create(file2)) { client.Write(uri, fs, checkoutArgs2); } _tempFiles.Add(file1); _tempFiles.Add(file2); Diff(file1, file2, false); } }
public void Diff(long revision, long revisionto) { using (SvnClient client = new SvnClient()) { string file = SrcFile; SvnInfoEventArgs info; client.GetInfo(file, out info); var uri = info.Uri; var tempDir = System.IO.Path.GetTempPath(); var filename = System.IO.Path.GetFileName(SrcFile); var file1 = tempDir + revision + "_" + filename; var checkoutArgs = new SvnWriteArgs() { Revision = revision }; using (var fs = System.IO.File.Create(file1)) { client.Write(uri, fs, checkoutArgs); } var file2 = tempDir + revisionto + "_" + filename; var checkoutArgs2 = new SvnWriteArgs() { Revision = revisionto }; using (var fs = System.IO.File.Create(file2)) { client.Write(uri, fs, checkoutArgs2); } _tempFiles.Add(file1); _tempFiles.Add(file2); Diff(file1, file2, false); } }
public void TestCatPeg() { SvnSandBox sbox = new SvnSandBox(this); Uri reposUri = new Uri(sbox.CreateRepository(SandBoxRepository.AnkhSvnCases), "trunk/"); Uri path = new Uri(reposUri, "Form.cs"); Uri toPath = new Uri(reposUri, "Moo.cs"); SvnCommitResult ci; this.Client.RemoteMove(path, toPath, out ci); string clientOutput = this.RunCommand("svn", string.Format("cat {0}@{1} -r {2}", toPath, ci.Revision, ci.Revision - 1)); MemoryStream stream = new MemoryStream(); SvnWriteArgs a = new SvnWriteArgs(); a.Revision = ci.Revision - 1; this.Client.Write(new SvnUriTarget(toPath, ci.Revision), stream); string wrapperOutput = Encoding.ASCII.GetString(stream.ToArray()); Assert.That(wrapperOutput, Is.EqualTo(clientOutput), "String from wrapper not the same as string from client"); }
private static string GetPath(IAnkhServiceProvider context, SvnRevision revision, SvnItem item, string tempDir) { if (revision == SvnRevision.Working) { return(item.FullPath); } string strRevision; if (revision.RevisionType == SvnRevisionType.Time) { strRevision = revision.Time.ToLocalTime().ToString("yyyyMMdd_hhmmss"); } else { strRevision = revision.ToString(); } string tempFile = Path.GetFileNameWithoutExtension(item.Name) + "." + strRevision + Path.GetExtension(item.Name); tempFile = Path.Combine(tempDir, tempFile); // we need to get it from the repos context.GetService <IProgressRunner>().RunModal(CommandStrings.RetrievingFileForComparison, delegate(object o, ProgressWorkerArgs ee) { SvnTarget target; switch (revision.RevisionType) { case SvnRevisionType.Head: case SvnRevisionType.Number: case SvnRevisionType.Time: target = item.Uri; break; default: target = item.FullPath; break; } SvnWriteArgs args = new SvnWriteArgs(); args.Revision = revision; args.AddExpectedError(SvnErrorCode.SVN_ERR_CLIENT_UNRELATED_RESOURCES); using (FileStream stream = File.Create(tempFile)) { ee.Client.Write(target, stream, args); } }); return(tempFile); }
protected static bool SaveFile(CommandEventArgs e, ISvnRepositoryItem ri, string toFile) { ProgressRunnerResult r = e.GetService<IProgressRunner>().RunModal( "Saving File", delegate(object sender, ProgressWorkerArgs ee) { using (FileStream fs = File.Create(toFile)) { SvnWriteArgs args = new SvnWriteArgs(); if(ri.Revision != null) args.Revision = ri.Revision; ee.Client.Write(ri.Origin.Target, fs, args); } }); return r.Succeeded; }
protected static bool SaveFile(CommandEventArgs e, ISvnRepositoryItem ri, string toFile) { ProgressRunnerResult r = e.GetService <IProgressRunner>().RunModal(CommandStrings.RetrievingFileForComparison, delegate(object sender, ProgressWorkerArgs ee) { using (FileStream fs = File.Create(toFile)) { SvnWriteArgs args = new SvnWriteArgs(); if (ri.Revision != null) { args.Revision = ri.Revision; } ee.Client.Write(ri.Origin.Target, fs, args); } }); return(r.Succeeded); }
public string GetTempFile(SharpSvn.SvnTarget target, SharpSvn.SvnRevision revision, bool withProgress) { if (target == null) { throw new ArgumentNullException("target"); } else if (revision == null) { throw new ArgumentNullException("revision"); } string file = GetTempPath(target.FileName, revision); bool unrelated = false; ProgressRunnerResult r = GetService <IProgressRunner>().RunModal(ServiceStrings.RetrievingFileForComparison, delegate(object sender, ProgressWorkerArgs aa) { SvnWriteArgs wa = new SvnWriteArgs(); wa.Revision = revision; wa.AddExpectedError(SvnErrorCode.SVN_ERR_CLIENT_UNRELATED_RESOURCES); using (Stream s = File.Create(file)) if (!aa.Client.Write(target, s, wa)) { if (wa.LastException.SvnErrorCode == SvnErrorCode.SVN_ERR_CLIENT_UNRELATED_RESOURCES) { unrelated = true; } } }); if (!r.Succeeded || unrelated) { return(null); // User canceled } if (File.Exists(file)) { File.SetAttributes(file, FileAttributes.ReadOnly); // A readonly file does not allow editting from many diff tools } return(file); }
public string GetTempFile(SvnItem target, SharpSvn.SvnRevision revision, bool withProgress) { if (target == null) { throw new ArgumentNullException("target"); } else if (revision == null) { throw new ArgumentNullException("revision"); } string file = GetTempPath(target.Name, revision); if (target.NodeKind != SvnNodeKind.File) { throw new InvalidOperationException("Can't create a tempfile from a directory"); } ProgressRunnerResult r = GetService <IProgressRunner>().RunModal(ServiceStrings.RetrievingFileForComparison, delegate(object sender, ProgressWorkerArgs aa) { SvnWriteArgs wa = new SvnWriteArgs(); wa.Revision = revision; using (Stream s = File.Create(file)) aa.Client.Write(target.FullPath, s, wa); }); if (!r.Succeeded) { return(null); // User canceled } if (File.Exists(file)) { File.SetAttributes(file, FileAttributes.ReadOnly); // A readonly file does not allow editting from many diff tools } return(file); }
static void DoBlame(CommandEventArgs e, SvnOrigin item, SvnRevision revisionStart, SvnRevision revisionEnd, bool ignoreEols, SvnIgnoreSpacing ignoreSpacing, bool retrieveMergeInfo) { SvnWriteArgs wa = new SvnWriteArgs(); wa.Revision = revisionEnd; SvnBlameArgs ba = new SvnBlameArgs(); ba.Start = revisionStart; ba.End = revisionEnd; ba.IgnoreLineEndings = ignoreEols; ba.IgnoreSpacing = ignoreSpacing; ba.RetrieveMergedRevisions = retrieveMergeInfo; SvnTarget target = item.Target; IAnkhTempFileManager tempMgr = e.GetService<IAnkhTempFileManager>(); string tempFile = tempMgr.GetTempFileNamed(target.FileName); Collection<SvnBlameEventArgs> blameResult = null; Dictionary<long, string> logMessages = new Dictionary<long, string>(); ba.Notify += delegate(object sender, SvnNotifyEventArgs ee) { if (ee.Action == SvnNotifyAction.BlameRevision && ee.RevisionProperties != null) { if (ee.RevisionProperties.Contains(SvnPropertyNames.SvnLog)) logMessages[ee.Revision] = ee.RevisionProperties[SvnPropertyNames.SvnLog].StringValue; } }; bool retry = false; ProgressRunnerResult r = e.GetService<IProgressRunner>().RunModal(CommandStrings.Annotating, delegate(object sender, ProgressWorkerArgs ee) { using (FileStream fs = File.Create(tempFile)) { ee.Client.Write(target, fs, wa); } ba.SvnError += delegate(object errorSender, SvnErrorEventArgs errorEventArgs) { if (errorEventArgs.Exception is SvnClientBinaryFileException) { retry = true; errorEventArgs.Cancel = true; } }; ee.Client.GetBlame(target, ba, out blameResult); }); if (retry) { using (AnkhMessageBox mb = new AnkhMessageBox(e.Context)) { if (DialogResult.Yes == mb.Show( CommandStrings.AnnotateBinaryFileContinueAnywayText, CommandStrings.AnnotateBinaryFileContinueAnywayTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Information)) { r = e.GetService<IProgressRunner>() .RunModal(CommandStrings.Annotating, delegate(object sender, ProgressWorkerArgs ee) { ba.IgnoreMimeType = true; ee.Client.GetBlame(target, ba, out blameResult); }); } } } if (!r.Succeeded) return; AnnotateEditorControl annEditor = new AnnotateEditorControl(); IAnkhEditorResolver er = e.GetService<IAnkhEditorResolver>(); annEditor.Create(e.Context, tempFile); annEditor.LoadFile(tempFile); annEditor.AddLines(item, blameResult, logMessages); // Detect and set the language service Guid language; if (er.TryGetLanguageService(Path.GetExtension(target.FileName), out language)) { // Extension is mapped -> user annEditor.SetLanguageService(language); } else if (blameResult != null && blameResult.Count > 0 && blameResult[0].Line != null) { // Extension is not mapped -> Check if this is xml (like project files) string line = blameResult[0].Line.Trim(); if (line.StartsWith("<?xml") || (line.StartsWith("<") && line.Contains("xmlns=\"http://schemas.microsoft.com/developer/msbuild/"))) { if (er.TryGetLanguageService(".xml", out language)) { annEditor.SetLanguageService(language); } } } }
public string GetTempFile(SvnItem target, SharpSvn.SvnRevision revision, bool withProgress) { if (target == null) throw new ArgumentNullException("target"); else if (revision == null) throw new ArgumentNullException("revision"); string file = GetTempPath(target.Name, revision); if (target.NodeKind != SvnNodeKind.File) throw new InvalidOperationException("Can't create a tempfile from a directory"); ProgressRunnerResult r = GetService<IProgressRunner>().RunModal("Getting file", delegate(object sender, ProgressWorkerArgs aa) { SvnWriteArgs wa = new SvnWriteArgs(); wa.Revision = revision; using (Stream s = File.Create(file)) aa.Client.Write(new SvnPathTarget(target.FullPath), s, wa); }); if (!r.Succeeded) return null; // User canceled if (File.Exists(file)) File.SetAttributes(file, FileAttributes.ReadOnly); // A readonly file does not allow editting from many diff tools return file; }
/*private void TryObtainBlock(CommandEventArgs e) * { * ISelectionContextEx ex = e.GetService<ISelectionContextEx>(typeof(ISelectionContext)); * * if (ex == null) * return; * * IVsTextView view = ex.ActiveDocumentFrameTextView; * IVsTextLines lines; * Guid languageService; * IVsLanguageInfo info; * * if (view != null * && VSErr.Succeeded(view.GetBuffer(out lines)) * && VSErr.Succeeded(lines.GetLanguageServiceID(out languageService)) * && null != (info = e.QueryService<IVsLanguageInfo>(languageService))) * { * GC.KeepAlive(info); * IVsLanguageBlock b = info as IVsLanguageBlock; * if (b != null) * { * GC.KeepAlive(b); * } * } * //IVsLanguageBlock * * * GC.KeepAlive(ex); * }*/ static void DoBlame(CommandEventArgs e, SvnOrigin item, SvnRevision revisionStart, SvnRevision revisionEnd, bool ignoreEols, SvnIgnoreSpacing ignoreSpacing, bool retrieveMergeInfo) { SvnWriteArgs wa = new SvnWriteArgs(); wa.Revision = revisionEnd; SvnBlameArgs ba = new SvnBlameArgs(); ba.Start = revisionStart; ba.End = revisionEnd; ba.IgnoreLineEndings = ignoreEols; ba.IgnoreSpacing = ignoreSpacing; ba.RetrieveMergedRevisions = retrieveMergeInfo; SvnTarget target = item.Target; IAnkhTempFileManager tempMgr = e.GetService <IAnkhTempFileManager>(); string tempFile = tempMgr.GetTempFileNamed(target.FileName); Collection <SvnBlameEventArgs> blameResult = null; bool retry = false; ProgressRunnerResult r = e.GetService <IProgressRunner>().RunModal(CommandStrings.Annotating, delegate(object sender, ProgressWorkerArgs ee) { using (FileStream fs = File.Create(tempFile)) { ee.Client.Write(target, fs, wa); } ba.SvnError += delegate(object errorSender, SvnErrorEventArgs errorEventArgs) { if (errorEventArgs.Exception is SvnClientBinaryFileException) { retry = true; errorEventArgs.Cancel = true; } }; ee.Client.GetBlame(target, ba, out blameResult); }); if (retry) { using (AnkhMessageBox mb = new AnkhMessageBox(e.Context)) { if (DialogResult.Yes != mb.Show( CommandStrings.AnnotateBinaryFileContinueAnywayText, CommandStrings.AnnotateBinaryFileContinueAnywayTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Information)) { return; } r = e.GetService <IProgressRunner>() .RunModal(CommandStrings.Annotating, delegate(object sender, ProgressWorkerArgs ee) { ba.IgnoreMimeType = true; ee.Client.GetBlame(target, ba, out blameResult); }); } } if (!r.Succeeded) { return; } AnnotateEditorControl annEditor = new AnnotateEditorControl(); IAnkhEditorResolver er = e.GetService <IAnkhEditorResolver>(); annEditor.Create(e.Context, tempFile); annEditor.LoadFile(tempFile); annEditor.AddLines(item, blameResult); // Detect and set the language service Guid language; if (er.TryGetLanguageService(Path.GetExtension(target.FileName), out language)) { // Extension is mapped -> user annEditor.SetLanguageService(language); } else if (blameResult != null && blameResult.Count > 0 && blameResult[0].Line != null) { // Extension is not mapped -> Check if this is xml (like project files) string line = blameResult[0].Line.Trim(); if (line.StartsWith("<?xml") || (line.StartsWith("<") && line.Contains("xmlns=\"http://schemas.microsoft.com/developer/msbuild/"))) { if (er.TryGetLanguageService(".xml", out language)) { annEditor.SetLanguageService(language); } } } }
private MemoryStream GetSVNFileStream(SvnRevisionId changeset, string path) { var memoryStream = new MemoryStream(); SvnTarget target; //If you use Uri you should encode '#' as %23, as Uri's define the # as Fragment separator. //And in this case the fragment is not send to the server. path = path.Replace("#", "%23"); if (SvnTarget.TryParse(GetPath(path).AbsolutePath, out target)) { if (FileWasDeleted(path, changeset)) { return new MemoryStream(); } var uriTarget = new SvnUriTarget(_root + path, changeset.Value); var svnWriteArgs = new SvnWriteArgs {Revision = changeset.Value}; Client.Write(uriTarget, memoryStream, svnWriteArgs); return memoryStream; } return new MemoryStream(); }
public string GetTempFile(SharpSvn.SvnTarget target, SharpSvn.SvnRevision revision, bool withProgress) { if (target == null) throw new ArgumentNullException("target"); else if (revision == null) throw new ArgumentNullException("revision"); string file = GetTempPath(target.FileName, revision); bool unrelated = false; ProgressRunnerResult r = GetService<IProgressRunner>().RunModal("Getting file", delegate(object sender, ProgressWorkerArgs aa) { SvnWriteArgs wa = new SvnWriteArgs(); wa.Revision = revision; wa.AddExpectedError(SvnErrorCode.SVN_ERR_CLIENT_UNRELATED_RESOURCES); using (Stream s = File.Create(file)) if (!aa.Client.Write(target, s, wa)) { if (wa.LastException.SvnErrorCode == SvnErrorCode.SVN_ERR_CLIENT_UNRELATED_RESOURCES) unrelated = true; } }); if (!r.Succeeded || unrelated) return null; // User canceled if (File.Exists(file)) File.SetAttributes(file, FileAttributes.ReadOnly); // A readonly file does not allow editting from many diff tools return file; }
public void DoBlame(CommandEventArgs e, SvnOrigin origin, SvnRevision revisionStart, SvnRevision revisionEnd, bool ignoreEols, SvnIgnoreSpacing ignoreSpacing, bool retrieveMergeInfo) { // There are two SVN related operations: // [1] Getting the file at revisionEnd, which will be displayed in the editor // [2] Getting the blame information, which will be displayed in the margin // This is the parameter structure for [1] getting the file SvnWriteArgs wa = new SvnWriteArgs(); wa.Revision = revisionEnd; // This is the parameter structure for [2] getting the blame information SvnBlameArgs ba = new SvnBlameArgs(); ba.Start = revisionStart; ba.End = revisionEnd; ba.IgnoreLineEndings = ignoreEols; ba.IgnoreSpacing = ignoreSpacing; ba.RetrieveMergedRevisions = retrieveMergeInfo; SvnTarget target = origin.Target; // Can we make this an MEF service? IAnkhTempFileManager tempMgr = e.GetService <IAnkhTempFileManager>(); string tempFile = tempMgr.GetTempFileNamed(target.FileName); Collection <SvnBlameEventArgs> blameResult = null; bool retry = false; ProgressRunnerResult r = e.GetService <IProgressRunner>().RunModal("Annotating", delegate(object sender, ProgressWorkerArgs ee) { // Here we [1] get the file at revisionEnd using (FileStream fs = File.Create(tempFile)) { ee.Client.Write(target, fs, wa); } // Here we [2] get the blame information ba.SvnError += delegate(object errorSender, SvnErrorEventArgs errorEventArgs) { if (errorEventArgs.Exception is SvnClientBinaryFileException) { retry = true; errorEventArgs.Cancel = true; } }; ee.Client.GetBlame(target, ba, out blameResult); }); if (retry) { using (AnkhMessageBox mb = new AnkhMessageBox(e.Context)) { // Move to resources later :) if (DialogResult.Yes != mb.Show("You are trying to annotate a binary file. Are you sure you want to continue?", "Binary file detected", MessageBoxButtons.YesNo, MessageBoxIcon.Information)) { return; } r = e.GetService <IProgressRunner>() .RunModal("Annotating", delegate(object sender, ProgressWorkerArgs ee) { ba.IgnoreMimeType = true; ee.Client.GetBlame(target, ba, out blameResult); }); } } if (!r.Succeeded) { return; } // Create a parameter struture and add it to our internal map. // Creating the actual view model class is now deferred to the GetModel method. var annParam = new AnnotateMarginParameters { Context = e.Context, Origin = origin, BlameResult = blameResult }; _ViewModelMap.Add(tempFile, annParam); // Open the editor. // ToDo: Open files like resx as code. var dte = e.GetService <DTE> (typeof(SDTE)); dte.ItemOperations.OpenFile(tempFile, EnvDTE.Constants.vsViewKindTextView); }
private static string GetPath(IAnkhServiceProvider context, SvnRevision revision, SvnItem item, string tempDir) { if (revision == SvnRevision.Working) { return item.FullPath; } string strRevision; if (revision.RevisionType == SvnRevisionType.Time) strRevision = revision.Time.ToLocalTime().ToString("yyyyMMdd_hhmmss"); else strRevision = revision.ToString(); string tempFile = Path.GetFileNameWithoutExtension(item.Name) + "." + strRevision + Path.GetExtension(item.Name); tempFile = Path.Combine(tempDir, tempFile); // we need to get it from the repos context.GetService<IProgressRunner>().RunModal("Retrieving file for diffing", delegate(object o, ProgressWorkerArgs ee) { SvnTarget target; switch(revision.RevisionType) { case SvnRevisionType.Head: case SvnRevisionType.Number: case SvnRevisionType.Time: target = new SvnUriTarget(item.Uri); break; default: target = new SvnPathTarget(item.FullPath); break; } SvnWriteArgs args = new SvnWriteArgs(); args.Revision = revision; args.AddExpectedError(SvnErrorCode.SVN_ERR_CLIENT_UNRELATED_RESOURCES); using (FileStream stream = File.Create(tempFile)) { ee.Client.Write(target, stream, args); } }); return tempFile; }
public void TestCatPeg() { SvnSandBox sbox = new SvnSandBox(this); Uri reposUri = new Uri(sbox.CreateRepository(SandBoxRepository.AnkhSvnCases), "trunk/"); Uri path = new Uri(reposUri, "Form.cs"); Uri toPath = new Uri(reposUri, "Moo.cs"); SvnCommitResult ci; this.Client.RemoteMove(path, toPath, out ci); string clientOutput = this.RunCommand("svn", string.Format("cat {0}@{1} -r {2}", toPath, ci.Revision, ci.Revision - 1)); MemoryStream stream = new MemoryStream(); SvnWriteArgs a = new SvnWriteArgs(); a.Revision = ci.Revision - 1; this.Client.Write(new SvnUriTarget(toPath, ci.Revision), stream); string wrapperOutput = Encoding.ASCII.GetString(stream.ToArray()); Assert.That(wrapperOutput, Is.EqualTo(clientOutput), "String from wrapper not the same as string from client"); }