public void GetFile(string svnFileUrl, string destinationFolder, bool force, string versionSpec) { SvnExportArgs args = new SvnExportArgs(); args.Overwrite = force; args.Revision = ConvertToRevsion(versionSpec); try { if (!Directory.Exists(destinationFolder)) { Directory.CreateDirectory(destinationFolder); } _svn.Export(new Uri(svnFileUrl), destinationFolder, args); } catch (SvnIllegalTargetException) { //if force = false, the exisiting file should not be overwritten and no error should be shown if (force) { throw; } } }
public override void OnExecute(CommandEventArgs e) { using (ExportDialog dlg = new ExportDialog(e.Context)) { dlg.OriginPath = EnumTools.GetSingle(e.Selection.GetSelectedSvnItems(false)).FullPath; if (dlg.ShowDialog(e.Context) != DialogResult.OK) { return; } SvnDepth depth = dlg.NonRecursive ? SvnDepth.Empty : SvnDepth.Infinity; e.GetService <IProgressRunner>().RunModal(CommandStrings.Exporting, delegate(object sender, ProgressWorkerArgs wa) { SvnExportArgs args = new SvnExportArgs(); args.Depth = depth; args.Revision = dlg.Revision; args.Overwrite = true; wa.Client.Export(dlg.ExportSource, dlg.LocalPath, args); }); } }
/// <summary> /// Extract a file from svn and write it locally (and overwrite what was already taken out!). /// </summary> /// <param name="ds"></param> /// <param name="outfile"></param> public static void ExtractFile(SvnTarget ds, FileInfo outfile) { var args = new SvnExportArgs() { Overwrite = true }; _client.Value.Export(ds, outfile.FullName, args); }
public bool exportFileFromLog(SvnLogEventArgs log, string expdir, bool excDel) { Console.WriteLine(string.Format(@"リビジョン:{0} を抽出します。", log.Revision)); var revname = retPadLeftZero(log.Revision); var toRevPath = expdir + @"\" + @"r" + revname; this._exlStm.addRevSht(@"r" + revname, log.LogMessage); var trgtFlLst = this.filterLogFiles(log.ChangedPaths, this._filterList, revname, excDel); if (trgtFlLst.Count == 0) { Directory.CreateDirectory(toRevPath + @"_対象なし"); return(false); } var root = this._reporoot; var args = new SvnExportArgs() { Depth = SvnDepth.Files }; var addCmd = @"echo F | xcopy /v /y ""{0}"" ""{1}"" " + Environment.NewLine + @"svn add ""{1}"" "; var delCmd = @"if exist ""{0}"" ( " + Environment.NewLine + @" svn delete ""{0}"" " + Environment.NewLine + @")"; Directory.CreateDirectory(toRevPath); var sw = createCopyBatStrm(expdir, revname); foreach (var i in trgtFlLst) { var flPth = getFilePath(i.Path); var topath = toRevPath + flPth; if (i.Action != SvnChangeAction.Delete) { var srcp = Path.Combine(root.ToString() , i.RepositoryPath.ToString()); var todir = Path.GetDirectoryName(topath); if (!Directory.Exists(todir)) { Directory.CreateDirectory(todir); } _svncl.Export(new SvnUriTarget(srcp, log.Revision), topath, args); sw.WriteLine(string.Format(addCmd, topath, @"%dstRoot%" + flPth)); } else { sw.WriteLine(string.Format(delCmd, @"%dstRoot" + flPth)); } } this.setCommitComment(expdir, sw, log, revname); sw.Close(); return(true); }
public void Export_ExportNonRecursive() { SvnSandBox sbox = new SvnSandBox(this); sbox.Create(SandBoxRepository.AnkhSvnCases); string WcPath = sbox.Wc; string wc = Path.Combine(sbox.GetTempDir(), "wc"); SvnExportArgs a = new SvnExportArgs(); a.Depth = SvnDepth.Empty; SvnUpdateResult r; this.Client.Export(WcPath, wc, a, out r); Assert.That(Directory.GetDirectories(wc).Length, Is.EqualTo(0)); }
private void Diff() { using (SvnClient client = new SvnClient()) { string filePath = REPO_URL + @"test\test.txt"; string temp = @"F:\svn"; SvnExportArgs args = new SvnExportArgs(); args.Overwrite = true; client.Export(new SvnUriTarget(new Uri(filePath), SvnRevision.Head), temp, args); string argu = WORKSPACE + @"test\test.txt" + " " + temp + @"\test.txt"; Process tmerger = new Process(); tmerger.StartInfo.FileName = DIFF_TOOLS; tmerger.StartInfo.Arguments = argu; tmerger.Start(); } }
/// <summary> /// 将SVN中某文件的某个版本保存到本地指定路径 /// </summary> public static bool ExportSvnFileToLocal(string svnFilePath, string savePath, SvnRevision svnRevision, out Exception exception) { SvnExportArgs exportArgs = new SvnExportArgs(); exportArgs.Overwrite = true; exportArgs.Revision = svnRevision; try { bool result = _svnClient.Export(svnFilePath, savePath, exportArgs); exception = null; return(result); } catch (Exception e) { exception = e; return(false); } }
public override void OnExecute(CommandEventArgs e) { using (ExportDialog dlg = new ExportDialog(e.Context)) { dlg.OriginPath = EnumTools.GetSingle(e.Selection.GetSelectedSvnItems(false)).FullPath; if (dlg.ShowDialog(e.Context) != DialogResult.OK) return; SvnDepth depth = dlg.NonRecursive ? SvnDepth.Empty : SvnDepth.Infinity; e.GetService<IProgressRunner>().RunModal(CommandStrings.Exporting, delegate(object sender, ProgressWorkerArgs wa) { SvnExportArgs args = new SvnExportArgs(); args.Depth = depth; args.Revision = dlg.Revision; wa.Client.Export(dlg.ExportSource, dlg.LocalPath, args); }); } }
static void Main(string[] args) { Console.WriteLine("Добро пожаловать в установщик продуктов компании \"Правильные измерения\"!"); string userName = "******"; string gitPublicApiUrl = "https://api.github.com/orgs/" + userName + "/repos?per_page=1000"; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; LBL_START: Console.WriteLine("Список продуктов загружается...\n"); using (WebClient webClient = new WebClient()) { webClient.Headers["User-Agent"] = "Mozilla/5.0"; var json = webClient.DownloadString(gitPublicApiUrl); var repositoryList = RepositoryList.FromJson(json); int i = 0; foreach (var repository in repositoryList) { Console.WriteLine(i.ToString() + ": " + repository.Name); i++; } Console.WriteLine(); INPUT_IDX: Console.Write("Введите индекс репозитория для копирования: "); string inpStr = Console.ReadLine().Trim(); int selectedIdx = 0; bool res = int.TryParse(inpStr, out selectedIdx); if (!res || selectedIdx < 0 || selectedIdx > repositoryList.Count) { goto INPUT_IDX; } string repositoryName = repositoryList[selectedIdx].Name; string projectName = repositoryList[selectedIdx].Description; string remoteURL = "https://github.com/" + userName + "/" + repositoryName + "/trunk/"; bool bFullProject = false; if (projectName != null && projectName.Length > 0) { Console.Write("Введите [1] для копирования всего проекта, если нужен лишь исполнимый файл, нажмите ввод: "); inpStr = Console.ReadLine().Trim(); if (inpStr.Length == 0) { remoteURL = $"https://github.com/{userName}/{repositoryName}/trunk/{projectName}/bin/Debug/"; } else { bFullProject = true; } } LBL_REPEAT: string targetDirectory = @"C:\" + userName + @"\" + repositoryName; Console.WriteLine("\nURL: " + remoteURL); Console.WriteLine("Дирректория установки: " + targetDirectory); Console.WriteLine("Копировать весь проект: " + bFullProject); if (Directory.Exists(targetDirectory)) { Console.Write("\nУдаляем старые файлы..."); Directory.Delete(targetDirectory, true); Console.Write("Готово!\n"); } else { Console.WriteLine(""); } Console.Write("Ожидайте..."); SvnClient svnClient = new SvnClient(); SvnUriTarget target = new SvnUriTarget(remoteURL); SvnExportArgs svnExpArgs = new SvnExportArgs(); try { svnClient.Export(target, targetDirectory, svnExpArgs, out SvnUpdateResult svnUpdRes); Console.Write("Завершено!\n"); if (Directory.Exists(targetDirectory)) { Process.Start(targetDirectory); } } catch (Exception ex) { Console.Write("ОШИБКА:\n" + ex.Message + "\n"); } Console.WriteLine("Выход - ESC, Повтор - SPACE, начать заново - любая клавиша"); ConsoleKeyInfo cki = Console.ReadKey(); if (cki.Key == ConsoleKey.Escape) { Environment.Exit(-1); } else if (cki.Key == ConsoleKey.Spacebar) { Console.Clear(); goto LBL_REPEAT; } else { Console.Clear(); goto LBL_START; } } }
public void Copy() { long lastSyncRevision = 0; if (_args.Incremental) { SvnLogParser logParser = new SvnLogParser(_args.Destination); lastSyncRevision = logParser.GetLastSyncedRevisionFromDestination(); Console.WriteLine("Last revision synched: {0}", lastSyncRevision); } Console.Write("Collecting svn log: "); if (_args.RevisionRange != null) { Console.Write("{0}:{1} ", _args.RevisionRange.StartRevision, _args.RevisionRange.EndRevision); } // fetch the source svn respository and SvnInfo sourceInfo = new SvnInfo(_args.Source); Console.WriteLine("Source SVN root: {0}", sourceInfo.Info.RepositoryRoot); Console.WriteLine("Source SVN uri: {0}", sourceInfo.Info.Uri); string sourceRelativePath = sourceInfo.Info.Uri.ToString().Remove( 0, sourceInfo.Info.RepositoryRoot.ToString().Length - 1); Console.WriteLine("Relative path: {0}", sourceRelativePath); if (!string.IsNullOrEmpty(_args.Root)) { sourceRelativePath = _args.Root; Console.WriteLine("Substituting relative path: {0}", sourceRelativePath); } SvnLogArgs logArgs = new SvnLogArgs(); logArgs.StrictNodeHistory = _args.StopOnCopy; logArgs.ThrowOnError = true; logArgs.Range = _args.RevisionRange; logArgs.RetrieveChangedPaths = true; _client.Log(_args.Source, logArgs, new EventHandler <SvnLogEventArgs>(OnLog)); Console.WriteLine(); Console.WriteLine("Collected {0} revisions.", _revisions.Count); SvnTarget fromSvnTarget = SvnTarget.FromString(_args.Source); foreach (KeyValuePair <long, SvnLogEventArgs> revisionPair in _revisions) { SvnLogEventArgs revision = revisionPair.Value; if (_args.Incremental && lastSyncRevision != 0 && lastSyncRevision >= revision.Revision) { Console.WriteLine("Skipping revision {0} ({1})", revision.Revision, revision.Time); continue; } Console.WriteLine("Revision {0} ({1})", revision.Revision, revision.Time); if (_args.SimulationOnly) { continue; } SvnExportArgs exportArgs = new SvnExportArgs(); exportArgs.Overwrite = true; exportArgs.ThrowOnError = true; exportArgs.Revision = revision.Revision; SvnUpdateResult exportResult = null; _client.Export(fromSvnTarget, _args.Destination, exportArgs, out exportResult); if (revision.ChangedPaths == null) { throw new Exception(string.Format("No changed paths in rev. {0}", revision.Revision)); } SortedList <string, SvnChangeItem> changeItems = new SortedList <string, SvnChangeItem>(); foreach (SvnChangeItem changeItem in revision.ChangedPaths) { changeItems.Add(changeItem.Path, changeItem); } List <string> filesAdd = new List <string>(); List <string> filesDelete = new List <string>(); List <string> filesModify = new List <string>(); // add files in forward order (add directories first) // delete files in reverse order (delete files first) foreach (SvnChangeItem changeItem in changeItems.Values) { // anything above (outside) of the source path is ignored, we didn't export that if (!changeItem.Path.StartsWith(sourceRelativePath)) { Console.WriteLine("Skipping {0}. Did you need to specify /root:<path>?)", changeItem.Path); continue; } string targetSvnPath = changeItem.Path.Remove(0, sourceRelativePath.Length); string targetOSPath = targetSvnPath.Replace("/", @"\"); string targetPath = Path.Combine(_args.Destination, targetOSPath); Console.WriteLine(" {0} {1}", changeItem.Action, changeItem.Path); switch (changeItem.Action) { case SvnChangeAction.Add: case SvnChangeAction.Replace: filesAdd.Add(targetPath); break; case SvnChangeAction.Delete: filesDelete.Insert(0, targetPath); break; case SvnChangeAction.Modify: filesModify.Add(targetPath); break; } } Console.WriteLine("Applying changes @ rev. {0} ...", revision.Revision); foreach (string targetPath in filesModify) { Console.WriteLine(" M {0}", targetPath); } foreach (string targetPath in filesAdd) { if (!File.Exists(targetPath)) { throw new Exception(string.Format("Added file '{0}' doesn't exist. Did you need to specify /root:<path>?", targetPath)); } Console.WriteLine(" A {0}", targetPath); SvnAddArgs svnAddArgs = new SvnAddArgs(); svnAddArgs.ThrowOnError = true; svnAddArgs.Depth = SvnDepth.Empty; _client.Add(targetPath, svnAddArgs); } foreach (string targetPath in filesDelete) { Console.WriteLine(" D {0}", targetPath); SvnDeleteArgs svnDeleteArgs = new SvnDeleteArgs(); svnDeleteArgs.ThrowOnError = true; svnDeleteArgs.Force = true; _client.Delete(targetPath, svnDeleteArgs); } SvnCommitArgs commitArgs = new SvnCommitArgs(); commitArgs.LogMessage = revision.LogMessage; commitArgs.LogMessage += string.Format("\nCopied from {0}, rev. {1} by {2} @ {3} {4}", sourceInfo.Info.Uri, revision.Revision, revision.Author, revision.Time.ToShortDateString(), revision.Time.ToShortTimeString()); commitArgs.ThrowOnError = true; Console.WriteLine("Committing changes @ rev. {0} in {1}", revision.Revision, _args.Destination); Console.WriteLine("----------------------------------------------------------------------------"); Console.WriteLine(commitArgs.LogMessage); Console.WriteLine("----------------------------------------------------------------------------"); if (_args.Prompt) { while (true) { Console.Write("Commit? [Y/N] "); char k = Char.ToLower(Console.ReadKey().KeyChar); Console.WriteLine(); if (k == 'y') { break; } if (k == 'n') { throw new Exception("Aborted by user."); } } } SvnCommitResult commitResult = null; _client.Commit(_args.Destination, commitArgs, out commitResult); if (commitResult != null) { Console.WriteLine("Commited revision {0}.", commitResult.Revision); } else { Console.WriteLine("There were no committable changes."); Console.WriteLine("Subversion property changes are not supported."); } } }
public override void OnExecute(CommandEventArgs e) { ISvnRepositoryItem item = EnumTools.GetSingle(e.Selection.GetSelection<ISvnRepositoryItem>()); if (item == null) return; string copyTo; bool copyBelow = false; bool suggestExport = false; IFileStatusCache cache = e.GetService<IFileStatusCache>(); if (item.NodeKind == SharpSvn.SvnNodeKind.Directory) { using (FolderBrowserDialog fd = new FolderBrowserDialog()) { fd.ShowNewFolderButton = false; if (DialogResult.OK != fd.ShowDialog(e.Context.DialogOwner)) return; copyTo = fd.SelectedPath; copyBelow = true; SvnItem dirItem = cache[copyTo]; if (dirItem == null || !dirItem.IsVersioned) suggestExport = true; } } else { using (SaveFileDialog sfd = new SaveFileDialog()) { sfd.CheckPathExists = true; sfd.OverwritePrompt = true; string name = item.Origin.Target.FileName; string ext = Path.GetExtension(item.Origin.Target.FileName); sfd.Filter = string.Format("{0} files|*.{0}|All files (*.*)|*", ext.TrimStart('.')); sfd.FileName = name; if (DialogResult.OK != sfd.ShowDialog(e.Context.DialogOwner)) return; copyTo = SvnTools.GetNormalizedFullPath(sfd.FileName); SvnItem fileItem = cache[copyTo]; if (File.Exists(copyTo)) { // We prompted to confirm; remove the file! if (fileItem.IsVersioned) e.GetService<IProgressRunner>().RunModal("Copying", delegate(object sender, ProgressWorkerArgs a) { SvnDeleteArgs da = new SvnDeleteArgs(); da.Force = true; a.Client.Delete(copyTo, da); }); else File.Delete(copyTo); } SvnItem dir = fileItem.Parent; if (dir == null || !(dir.IsVersioned && dir.IsVersionable)) suggestExport = true; } } if (!suggestExport) { e.GetService<IProgressRunner>().RunModal("Copying", delegate(object sender, ProgressWorkerArgs a) { SvnCopyArgs ca = new SvnCopyArgs(); ca.CreateParents = true; if (copyBelow) ca.AlwaysCopyAsChild = true; a.Client.Copy(item.Origin.Target, copyTo, ca); }); } else { AnkhMessageBox mb = new AnkhMessageBox(e.Context); if (DialogResult.Yes == mb.Show("The specified path is not in a workingcopy; would you like to export the file instead?", "No Working Copy", MessageBoxButtons.YesNo, MessageBoxIcon.Information)) { e.GetService<IProgressRunner>().RunModal("Exporting", delegate(object sender, ProgressWorkerArgs a) { SvnExportArgs ea = new SvnExportArgs(); ea.Revision = item.Revision; a.Client.Export(item.Origin.Target, copyTo, ea); }); } } }
public XmlDocument getSVNDifferFiles() { //获取最大的版本号 this.getLastVersion(); // diff xml XmlDocument newDoc = new XmlDocument(); XmlDeclaration xmldecl = newDoc.CreateXmlDeclaration("1.0", "UTF-8", null); newDoc.AppendChild(xmldecl); XmlElement newRoot = newDoc.CreateElement("files"); newDoc.AppendChild(newRoot); newRoot.SetAttribute("version", PackageSubVM.Instance.Version); long fileSizes = 0; int index = 0; string[] szFilter = PackageSubVM.Instance.Filter.Split(new char[1] { ':' }); SvnClient svnClient = new SvnClient(); //List<SvnDiffSummaryEventArgs> list; System.Collections.ObjectModel.Collection <SvnDiffSummaryEventArgs> list; svnClient.GetDiffSummary(new SvnUriTarget(PackageSubVM.Instance.SVNPath, Int32.Parse(PackageSubVM.Instance.BeginVersion)), new SvnUriTarget(PackageSubVM.Instance.SVNPath, Int32.Parse(PackageSubVM.Instance.EndVersion)), out list); foreach (SvnDiffSummaryEventArgs item in list) { if (szFilter.Contains(Path.GetExtension(item.Path)) || szFilter.Contains(Path.GetFileName(item.Path))) { continue; } string fullFileName = szResourceOutPath + "\\" + item.Path; if (item.NodeKind == SvnNodeKind.Directory) { if (Directory.Exists(fullFileName) == false) { DirectoryInfo info = Directory.CreateDirectory(fullFileName); } continue; } string outPath = Path.GetDirectoryName(fullFileName); if (Directory.Exists(outPath) == false) { DirectoryInfo info = Directory.CreateDirectory(outPath); } try { SvnClient exportSVN = new SvnClient(); SvnExportArgs ex = new SvnExportArgs(); ex.Overwrite = true; long size = 0; if (item.DiffKind != SvnDiffKind.Deleted) { exportSVN.Export(new SvnUriTarget(item.ToUri, Int32.Parse(PackageSubVM.Instance.EndVersion)), fullFileName, ex); index = index + 1; this.createXmlNode(newDoc, newRoot, item.Path, this.createFileMD5(fullFileName, out size), "1", index); fileSizes += size; } else { this.createXmlNode(newDoc, newRoot, item.Path, "this is a delete file.", "0", index); } } catch (Exception ee) { MessageBox.Show(ee.Message); Console.WriteLine(ee.Message); } } newRoot.SetAttribute("lastVersion", szLastVersion); newRoot.SetAttribute("size", fileSizes.ToString()); return(newDoc); }
public override void OnExecute(CommandEventArgs e) { ISvnRepositoryItem item = EnumTools.GetSingle(e.Selection.GetSelection <ISvnRepositoryItem>()); if (item == null) { return; } string copyTo; bool copyBelow = false; bool suggestExport = false; ISvnStatusCache cache = e.GetService <ISvnStatusCache>(); if (item.NodeKind == SharpSvn.SvnNodeKind.Directory) { using (FolderBrowserDialog fd = new FolderBrowserDialog()) { fd.ShowNewFolderButton = false; if (DialogResult.OK != fd.ShowDialog(e.Context.DialogOwner)) { return; } copyTo = fd.SelectedPath; copyBelow = true; SvnItem dirItem = cache[copyTo]; if (dirItem == null || !dirItem.IsVersioned) { suggestExport = true; } } } else { using (SaveFileDialog sfd = new SaveFileDialog()) { sfd.CheckPathExists = true; sfd.OverwritePrompt = true; string name = item.Origin.Target.FileName; string ext = Path.GetExtension(item.Origin.Target.FileName); sfd.Filter = string.Format("{0} files|*.{0}|All files (*.*)|*", ext.TrimStart('.')); sfd.FileName = name; if (DialogResult.OK != sfd.ShowDialog(e.Context.DialogOwner)) { return; } copyTo = SvnTools.GetNormalizedFullPath(sfd.FileName); SvnItem fileItem = cache[copyTo]; if (File.Exists(copyTo)) { // We prompted to confirm; remove the file! if (fileItem.IsVersioned) { e.GetService <IProgressRunner>().RunModal(CommandStrings.Copying, delegate(object sender, ProgressWorkerArgs a) { SvnDeleteArgs da = new SvnDeleteArgs(); da.Force = true; a.Client.Delete(copyTo, da); }); } else { SvnItem.DeleteNode(copyTo); } } SvnItem dir = fileItem.Parent; if (dir == null || !(dir.IsVersioned && dir.IsVersionable)) { suggestExport = true; } } } if (!suggestExport) { e.GetService <IProgressRunner>().RunModal(CommandStrings.Copying, delegate(object sender, ProgressWorkerArgs a) { SvnCopyArgs ca = new SvnCopyArgs(); ca.CreateParents = true; if (copyBelow) { ca.AlwaysCopyAsChild = true; } a.Client.Copy(item.Origin.Target, copyTo, ca); }); } else { AnkhMessageBox mb = new AnkhMessageBox(e.Context); if (DialogResult.Yes == mb.Show(CommandStrings.NotInWorkingCopyExportInstead, CommandStrings.NotInWorkingCopyTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Information)) { e.GetService <IProgressRunner>().RunModal(CommandStrings.Exporting, delegate(object sender, ProgressWorkerArgs a) { SvnExportArgs ea = new SvnExportArgs(); ea.Revision = item.Revision; ea.Overwrite = true; a.Client.Export(item.Origin.Target, copyTo, ea); }); } } }
public void Copy() { Console.Write("Collecting svn log: "); if (_args.RevisionRange != null) { Console.Write("{0}:{1} ", _args.RevisionRange.StartRevision, _args.RevisionRange.EndRevision); } // fetch the source svn respository and SvnInfo sourceInfo = new SvnInfo(_args.Source); Console.WriteLine("Source SVN root: {0}", sourceInfo.Info.RepositoryRoot); Console.WriteLine("Source SVN uri: {0}", sourceInfo.Info.Uri); string sourceRelativePath = sourceInfo.Info.Uri.ToString().Remove( 0, sourceInfo.Info.RepositoryRoot.ToString().Length - 1); Console.WriteLine("Relative path: {0}", sourceRelativePath); SvnLogArgs logArgs = new SvnLogArgs(); logArgs.StrictNodeHistory = true; logArgs.ThrowOnError = true; logArgs.Range = _args.RevisionRange; logArgs.RetrieveChangedPaths = true; _client.Log(_args.Source, logArgs, new EventHandler<SvnLogEventArgs>(OnLog)); Console.WriteLine(); Console.WriteLine("Collected {0} revisions.", _revisions.Count); SvnTarget fromSvnTarget = SvnTarget.FromString(_args.Source); foreach (KeyValuePair<long, SvnLogEventArgs> revisionPair in _revisions) { SvnLogEventArgs revision = revisionPair.Value; Console.WriteLine("Revision {0} ({1})", revision.Revision, revision.Time); if (_args.simulationOnly) continue; SvnExportArgs exportArgs = new SvnExportArgs(); exportArgs.Overwrite = true; exportArgs.ThrowOnError = true; exportArgs.Revision = revision.Revision; SvnUpdateResult exportResult = null; _client.Export(fromSvnTarget, _args.Destination, exportArgs, out exportResult); if (revision.ChangedPaths == null) { throw new Exception(string.Format("No changed paths in rev. {0}", revision.Revision)); } SortedList<string, SvnChangeItem> changeItems = new SortedList<string, SvnChangeItem>(); foreach (SvnChangeItem changeItem in revision.ChangedPaths) { changeItems.Add(changeItem.Path, changeItem); } foreach (SvnChangeItem changeItem in changeItems.Values) { string targetSvnPath = changeItem.Path.Remove(0, sourceRelativePath.Length); string targetOSPath = targetSvnPath.Replace("/", @"\"); string targetPath = Path.Combine(_args.Destination, targetOSPath); Console.WriteLine("{0} {1}", changeItem.Action, changeItem.Path); switch (changeItem.Action) { case SvnChangeAction.Add: { Console.WriteLine(" A {0}", targetPath); SvnAddArgs svnAddArgs = new SvnAddArgs(); svnAddArgs.ThrowOnError = true; svnAddArgs.Depth = SvnDepth.Empty; _client.Add(targetPath, svnAddArgs); } break; case SvnChangeAction.Delete: { Console.WriteLine(" D {0}", targetPath); SvnDeleteArgs svnDeleteArgs = new SvnDeleteArgs(); svnDeleteArgs.ThrowOnError = true; _client.Delete(targetPath, svnDeleteArgs); } break; } } SvnCommitArgs commitArgs = new SvnCommitArgs(); commitArgs.LogMessage = revision.LogMessage; commitArgs.LogMessage += string.Format("\nCopied from {0}, rev. {1} by {2} @ {3} {4}", sourceInfo.Info.Uri, revision.Revision, revision.Author, revision.Time.ToShortDateString(), revision.Time.ToShortTimeString()); commitArgs.ThrowOnError = true; Console.WriteLine("Commiting {0}", _args.Destination); Console.WriteLine("----------------------------------------------------------------------------"); Console.WriteLine(commitArgs.LogMessage); Console.WriteLine("----------------------------------------------------------------------------"); if (_args.prompt) { while (true) { Console.Write("Commit? [Y/N] "); char k = Char.ToLower(Console.ReadKey().KeyChar); Console.WriteLine(); if (k == 'y') break; if (k == 'n') throw new Exception("Aborted by user."); } } _client.Commit(_args.Destination, commitArgs); } }
public XmlDocument getSVNDifferFiles() { //获取最大的版本号 this.getLastVersion(); // diff xml XmlDocument newDoc = new XmlDocument(); XmlDeclaration xmldecl = newDoc.CreateXmlDeclaration("1.0", "UTF-8", null); newDoc.AppendChild(xmldecl); XmlElement newRoot = newDoc.CreateElement("files"); newDoc.AppendChild(newRoot); newRoot.SetAttribute("version", PackageSubVM.Instance.Version); long fileSizes = 0; int index = 0; string[] szFilter = PackageSubVM.Instance.Filter.Split(new char[1] { ':' }); SvnClient svnClient = new SvnClient(); //List<SvnDiffSummaryEventArgs> list; System.Collections.ObjectModel.Collection<SvnDiffSummaryEventArgs> list; svnClient.GetDiffSummary(new SvnUriTarget(PackageSubVM.Instance.SVNPath, Int32.Parse(PackageSubVM.Instance.BeginVersion)), new SvnUriTarget(PackageSubVM.Instance.SVNPath, Int32.Parse(PackageSubVM.Instance.EndVersion)), out list); foreach (SvnDiffSummaryEventArgs item in list) { if (szFilter.Contains(Path.GetExtension(item.Path)) || szFilter.Contains(Path.GetFileName(item.Path))) { continue; } string fullFileName = szResourceOutPath + "\\" + item.Path; if (item.NodeKind == SvnNodeKind.Directory) { if (Directory.Exists(fullFileName) == false) { DirectoryInfo info = Directory.CreateDirectory(fullFileName); } continue; } string outPath = Path.GetDirectoryName(fullFileName); if (Directory.Exists(outPath) == false) { DirectoryInfo info = Directory.CreateDirectory(outPath); } try { SvnClient exportSVN = new SvnClient(); SvnExportArgs ex = new SvnExportArgs(); ex.Overwrite = true; long size = 0; if (item.DiffKind != SvnDiffKind.Deleted) { exportSVN.Export(new SvnUriTarget(item.ToUri, Int32.Parse(PackageSubVM.Instance.EndVersion)), fullFileName, ex); index = index + 1; this.createXmlNode(newDoc, newRoot, item.Path, this.createFileMD5(fullFileName, out size), "1", index); fileSizes += size; } else { this.createXmlNode(newDoc, newRoot, item.Path, "this is a delete file.", "0", index); } } catch (Exception ee) { MessageBox.Show(ee.Message); Console.WriteLine(ee.Message); } } newRoot.SetAttribute("lastVersion", szLastVersion); newRoot.SetAttribute("size", fileSizes.ToString()); return newDoc; }
public void Copy() { long lastSyncRevision = 0; if (_args.Incremental) { SvnLogParser logParser = new SvnLogParser(_args.Destination); lastSyncRevision = logParser.GetLastSyncedRevisionFromDestination(); Console.WriteLine("Last revision synched: {0}", lastSyncRevision); } Console.Write("Collecting svn log: "); if (_args.RevisionRange != null) { Console.Write("{0}:{1} ", _args.RevisionRange.StartRevision, _args.RevisionRange.EndRevision); } // fetch the source svn respository and SvnInfo sourceInfo = new SvnInfo(_args.Source); Console.WriteLine("Source SVN root: {0}", sourceInfo.Info.RepositoryRoot); Console.WriteLine("Source SVN uri: {0}", sourceInfo.Info.Uri); string sourceRelativePath = sourceInfo.Info.Uri.ToString().Remove( 0, sourceInfo.Info.RepositoryRoot.ToString().Length - 1); Console.WriteLine("Relative path: {0}", sourceRelativePath); if (!string.IsNullOrEmpty(_args.Root)) { sourceRelativePath = _args.Root; Console.WriteLine("Substituting relative path: {0}", sourceRelativePath); } SvnLogArgs logArgs = new SvnLogArgs(); logArgs.StrictNodeHistory = _args.StopOnCopy; logArgs.ThrowOnError = true; logArgs.Range = _args.RevisionRange; logArgs.RetrieveChangedPaths = true; _client.Log(_args.Source, logArgs, new EventHandler<SvnLogEventArgs>(OnLog)); Console.WriteLine(); Console.WriteLine("Collected {0} revisions.", _revisions.Count); SvnTarget fromSvnTarget = SvnTarget.FromString(_args.Source); foreach (KeyValuePair<long, SvnLogEventArgs> revisionPair in _revisions) { SvnLogEventArgs revision = revisionPair.Value; if (_args.Incremental && lastSyncRevision != 0 && lastSyncRevision >= revision.Revision ) { Console.WriteLine("Skipping revision {0} ({1})", revision.Revision, revision.Time); continue; } Console.WriteLine("Revision {0} ({1})", revision.Revision, revision.Time); if (_args.SimulationOnly) continue; SvnExportArgs exportArgs = new SvnExportArgs(); exportArgs.Overwrite = true; exportArgs.ThrowOnError = true; exportArgs.Revision = revision.Revision; SvnUpdateResult exportResult = null; _client.Export(fromSvnTarget, _args.Destination, exportArgs, out exportResult); if (revision.ChangedPaths == null) { throw new Exception(string.Format("No changed paths in rev. {0}", revision.Revision)); } SortedList<string, SvnChangeItem> changeItems = new SortedList<string, SvnChangeItem>(); foreach (SvnChangeItem changeItem in revision.ChangedPaths) { changeItems.Add(changeItem.Path, changeItem); } List<string> filesAdd = new List<string>(); List<string> filesDelete = new List<string>(); List<string> filesModify = new List<string>(); // add files in forward order (add directories first) // delete files in reverse order (delete files first) foreach (SvnChangeItem changeItem in changeItems.Values) { // anything above (outside) of the source path is ignored, we didn't export that if (! changeItem.Path.StartsWith(sourceRelativePath)) { Console.WriteLine("Skipping {0}. Did you need to specify /root:<path>?)", changeItem.Path); continue; } string targetSvnPath = changeItem.Path.Remove(0, sourceRelativePath.Length); string targetOSPath = targetSvnPath.Replace("/", @"\"); string targetPath = Path.Combine(_args.Destination, targetOSPath); Console.WriteLine(" {0} {1}", changeItem.Action, changeItem.Path); switch (changeItem.Action) { case SvnChangeAction.Add: case SvnChangeAction.Replace: filesAdd.Add(targetPath); break; case SvnChangeAction.Delete: filesDelete.Insert(0, targetPath); break; case SvnChangeAction.Modify: filesModify.Add(targetPath); break; } } Console.WriteLine("Applying changes @ rev. {0} ...", revision.Revision); foreach (string targetPath in filesModify) { Console.WriteLine(" M {0}", targetPath); } foreach (string targetPath in filesAdd) { if (! File.Exists(targetPath)) { throw new Exception(string.Format("Added file '{0}' doesn't exist. Did you need to specify /root:<path>?", targetPath)); } Console.WriteLine(" A {0}", targetPath); SvnAddArgs svnAddArgs = new SvnAddArgs(); svnAddArgs.ThrowOnError = true; svnAddArgs.Depth = SvnDepth.Empty; _client.Add(targetPath, svnAddArgs); } foreach (string targetPath in filesDelete) { Console.WriteLine(" D {0}", targetPath); SvnDeleteArgs svnDeleteArgs = new SvnDeleteArgs(); svnDeleteArgs.ThrowOnError = true; svnDeleteArgs.Force = true; _client.Delete(targetPath, svnDeleteArgs); } SvnCommitArgs commitArgs = new SvnCommitArgs(); commitArgs.LogMessage = revision.LogMessage; commitArgs.LogMessage += string.Format("\nCopied from {0}, rev. {1} by {2} @ {3} {4}", sourceInfo.Info.Uri, revision.Revision, revision.Author, revision.Time.ToShortDateString(), revision.Time.ToShortTimeString()); commitArgs.ThrowOnError = true; Console.WriteLine("Committing changes @ rev. {0} in {1}", revision.Revision, _args.Destination); Console.WriteLine("----------------------------------------------------------------------------"); Console.WriteLine(commitArgs.LogMessage); Console.WriteLine("----------------------------------------------------------------------------"); if (_args.Prompt) { while (true) { Console.Write("Commit? [Y/N] "); char k = Char.ToLower(Console.ReadKey().KeyChar); Console.WriteLine(); if (k == 'y') break; if (k == 'n') throw new Exception("Aborted by user."); } } SvnCommitResult commitResult = null; _client.Commit(_args.Destination, commitArgs, out commitResult); if (commitResult != null) { Console.WriteLine("Commited revision {0}.", commitResult.Revision); } else { Console.WriteLine("There were no committable changes."); Console.WriteLine("Subversion property changes are not supported."); } } }
protected void ReadConfigFile(string secmVersion) { string tempurl = GetSvnUri().ToString() + "/" + secmVersion + "/DependentVersions.xml"; Uri absolute = new Uri(tempurl); Debug.WriteLine(absolute.ToString()); string temppath = @"C:\Users\athakur\Documents\Visual Studio 2010\WebSites\SvnWebsite_Test\Temp\"; string xmlLoadPath = temppath + @"\DependentVersions.xml"; SvnExportArgs exportargs = new SvnExportArgs { Overwrite = true }; client.Export(absolute, temppath, exportargs); XElement xe = XElement.Load(xmlLoadPath); if (!xe.IsEmpty) { IEnumerable<XElement> rad = xe.Elements("RAD"); foreach (XElement ra in rad) { radVersion = new List<string>(); XAttribute tempatt = ra.Attribute("version"); string[] str = tempatt.Value.Split(','); Debug.Write("RAD Versions :"); foreach (string s in str) { radVersion.Add(s); } } IEnumerable<XElement> refm = xe.Elements("RefMaster"); foreach (XElement re in refm) { refMasterVersion = new List<string>(); XAttribute tempatt = re.Attribute("version"); string[] str = tempatt.Value.Split(','); Debug.Write("RefMaster Versions :"); foreach (string s in str) { refMasterVersion.Add(s); } } } ddlRefMasterVersion.DataSource = refMasterVersion; ddlRefMasterVersion.DataBind(); ddlRadVersion.DataSource = radVersion; ddlRadVersion.DataBind(); }
protected void btnSubmit_Click(object sender, EventArgs e) { reposUri = GetAbsoluteUri(ddlSecMasterVersion.SelectedValue); radioButtonSelectedItem = optionList.SelectedValue; if (radioButtonSelectedItem == "Updates") { Collection<SvnLogEventArgs> logcollection = null; SvnLogArgs logargs = null; logargs = new SvnLogArgs { Range = new SvnRevisionRange(Int32.Parse(txtRevision.Text), SvnRevisionType.Head) }; client.GetLog(reposUri, logargs, out logcollection); int i = 1; foreach (SvnLogEventArgs logEventArgs in logcollection) { Debug.WriteLine("Entry " + i); foreach (var changedpaths in logEventArgs.ChangedPaths) { Uri absolute = GetAbsoluteUri(reposUri.ToString() + changedpaths.RepositoryPath.ToString()); if (changedpaths.Action.ToString() != "Delete") { SvnExportArgs exportargs = new SvnExportArgs(); exportargs.Overwrite = true; System.Diagnostics.Debug.WriteLine(changedpaths.Action); string[] directorytemp = changedpaths.RepositoryPath.ToString().Split('/'); string directorypath = null; for (int j = 0; j < directorytemp.Length - 1; j++) { directorypath = directorypath + directorytemp[j] + '\\'; } string temptarget = "C:\\Back Up\\Crap\\svnexport\\Updates" + directorypath; Directory.CreateDirectory(temptarget); string target = temptarget + directorytemp[directorytemp.Length - 1]; Collection<SvnInfoEventArgs> info = null; bool flag = client.GetInfo(absolute, new SvnInfoArgs { ThrowOnError = false }, out info); if (flag) { client.Export(absolute, target, exportargs); Debug.WriteLine("File Created"); } } Debug.WriteLine(changedpaths.RepositoryPath); } i++; Debug.WriteLine("\n\n"); } } else if (radioButtonSelectedItem == "Install") { string storepath = "C:\\Back Up\\Crap\\svnexport\\Install"; SvnUpdateResult exportResult = null; client.Export(reposUri, storepath, new SvnExportArgs { Overwrite = true, Revision = SvnRevision.Head },out exportResult); Debug.WriteLine(exportResult.Revision); } else if (radioButtonSelectedItem == "Batch") { string storepath = "C:\\Back Up\\Crap\\svnexport\\Batch"; SvnUpdateResult exportResult = null; client.Export(reposUri, storepath, new SvnExportArgs { Overwrite = true, Revision = new SvnRevision(long.Parse(txtRevision.Text))}, out exportResult); Debug.WriteLine(exportResult.Revision); } }
public void Copy() { Console.Write("Collecting svn log: "); if (_args.RevisionRange != null) { Console.Write("{0}:{1} ", _args.RevisionRange.StartRevision, _args.RevisionRange.EndRevision); } // fetch the source svn respository and SvnInfo sourceInfo = new SvnInfo(_args.Source); Console.WriteLine("Source SVN root: {0}", sourceInfo.Info.RepositoryRoot); Console.WriteLine("Source SVN uri: {0}", sourceInfo.Info.Uri); string sourceRelativePath = sourceInfo.Info.Uri.ToString().Remove( 0, sourceInfo.Info.RepositoryRoot.ToString().Length - 1); Console.WriteLine("Relative path: {0}", sourceRelativePath); SvnLogArgs logArgs = new SvnLogArgs(); logArgs.StrictNodeHistory = true; logArgs.ThrowOnError = true; logArgs.Range = _args.RevisionRange; logArgs.RetrieveChangedPaths = true; _client.Log(_args.Source, logArgs, new EventHandler <SvnLogEventArgs>(OnLog)); Console.WriteLine(); Console.WriteLine("Collected {0} revisions.", _revisions.Count); SvnTarget fromSvnTarget = SvnTarget.FromString(_args.Source); foreach (KeyValuePair <long, SvnLogEventArgs> revisionPair in _revisions) { SvnLogEventArgs revision = revisionPair.Value; Console.WriteLine("Revision {0} ({1})", revision.Revision, revision.Time); if (_args.simulationOnly) { continue; } SvnExportArgs exportArgs = new SvnExportArgs(); exportArgs.Overwrite = true; exportArgs.ThrowOnError = true; exportArgs.Revision = revision.Revision; SvnUpdateResult exportResult = null; _client.Export(fromSvnTarget, _args.Destination, exportArgs, out exportResult); if (revision.ChangedPaths == null) { throw new Exception(string.Format("No changed paths in rev. {0}", revision.Revision)); } SortedList <string, SvnChangeItem> changeItems = new SortedList <string, SvnChangeItem>(); foreach (SvnChangeItem changeItem in revision.ChangedPaths) { changeItems.Add(changeItem.Path, changeItem); } foreach (SvnChangeItem changeItem in changeItems.Values) { string targetSvnPath = changeItem.Path.Remove(0, sourceRelativePath.Length); string targetOSPath = targetSvnPath.Replace("/", @"\"); string targetPath = Path.Combine(_args.Destination, targetOSPath); Console.WriteLine("{0} {1}", changeItem.Action, changeItem.Path); switch (changeItem.Action) { case SvnChangeAction.Add: { Console.WriteLine(" A {0}", targetPath); SvnAddArgs svnAddArgs = new SvnAddArgs(); svnAddArgs.ThrowOnError = true; svnAddArgs.Depth = SvnDepth.Empty; _client.Add(targetPath, svnAddArgs); } break; case SvnChangeAction.Delete: { Console.WriteLine(" D {0}", targetPath); SvnDeleteArgs svnDeleteArgs = new SvnDeleteArgs(); svnDeleteArgs.ThrowOnError = true; _client.Delete(targetPath, svnDeleteArgs); } break; } } SvnCommitArgs commitArgs = new SvnCommitArgs(); commitArgs.LogMessage = revision.LogMessage; commitArgs.LogMessage += string.Format("\nCopied from {0}, rev. {1} by {2} @ {3} {4}", sourceInfo.Info.Uri, revision.Revision, revision.Author, revision.Time.ToShortDateString(), revision.Time.ToShortTimeString()); commitArgs.ThrowOnError = true; Console.WriteLine("Commiting {0}", _args.Destination); Console.WriteLine("----------------------------------------------------------------------------"); Console.WriteLine(commitArgs.LogMessage); Console.WriteLine("----------------------------------------------------------------------------"); if (_args.prompt) { while (true) { Console.Write("Commit? [Y/N] "); char k = Char.ToLower(Console.ReadKey().KeyChar); Console.WriteLine(); if (k == 'y') { break; } if (k == 'n') { throw new Exception("Aborted by user."); } } } _client.Commit(_args.Destination, commitArgs); } }