public bool ApplyChanges(IEnumerable <PendingChange> changes, PendingChangeApplyArgs args) { using (PendingCommitState state = new PendingCommitState(Context, changes)) { if (!PreCommit_SaveDirty(state)) { return(false); } if (!PreCommit_AddNewFiles(state)) { return(false); } if (!PreCommit_HandleMissingFiles(state)) { return(false); } state.FlushState(); if (!PreCommit_AddNeededParents(state)) { return(false); } return(true); } }
public bool CreatePatch(IEnumerable <PendingChange> changes, PendingChangeCreatePatchArgs args) { using (PendingCommitState state = new PendingCommitState(Context, changes)) { if (!PreCommit_VerifySingleRoot(state)) // Verify single root 'first' { return(false); } if (!PreCommit_SaveDirty(state)) { return(false); } if (args.AddUnversionedFiles) { if (!PreCommit_AddNewFiles(state)) { return(false); } if (!PreCommit_HandleMissingFiles(state)) { return(false); } } state.FlushState(); if (!PreCommit_AddNeededParents(state)) { return(false); } if (!PreCommit_VerifySingleRoot(state)) // Verify single root 'again' { return(false); } } string relativeToPath = args.RelativeToPath; string relativeToPathP = relativeToPath.EndsWith("\\") ? relativeToPath : (relativeToPath + "\\"); string fileName = args.FileName; SvnRevisionRange revRange = new SvnRevisionRange(SvnRevision.Base, SvnRevision.Working); SvnDiffArgs a = new SvnDiffArgs(); a.IgnoreAncestry = true; a.NoDeleted = false; a.Depth = SvnDepth.Empty; using (MemoryStream stream = new MemoryStream()) { GetService <IProgressRunner>().RunModal(PccStrings.DiffTitle, delegate(object sender, ProgressWorkerArgs e) { foreach (PendingChange pc in changes) { SvnItem item = pc.SvnItem; SvnWorkingCopy wc; if (!string.IsNullOrEmpty(relativeToPath) && item.FullPath.StartsWith(relativeToPathP, StringComparison.OrdinalIgnoreCase)) { a.RelativeToPath = relativeToPath; } else if ((wc = item.WorkingCopy) != null) { a.RelativeToPath = wc.FullPath; } else { a.RelativeToPath = null; } e.Client.Diff(item.FullPath, revRange, a, stream); } stream.Flush(); stream.Position = 0; }); using (StreamReader sr = new StreamReader(stream)) { string line; // Parse to lines to resolve EOL issues using (StreamWriter sw = File.CreateText(fileName)) { while (null != (line = sr.ReadLine())) { sw.WriteLine(line); } } } } return(true); }