Beispiel #1
0
        void ExecuteDiff(CommandEventArgs e, ICollection <SvnOrigin> targets, SvnRevisionRange range)
        {
            if (targets.Count != 1)
            {
                return;
            }

            SvnTarget diffTarget = EnumTools.GetSingle(targets).Target;

            IAnkhDiffHandler diff = e.GetService <IAnkhDiffHandler>();
            AnkhDiffArgs     da   = new AnkhDiffArgs();

            string[] files = diff.GetTempFiles(diffTarget, range.StartRevision, range.EndRevision, true);

            if (files == null)
            {
                return;
            }

            da.BaseFile  = files[0];
            da.MineFile  = files[1];
            da.BaseTitle = diff.GetTitle(diffTarget, range.StartRevision);
            da.MineTitle = diff.GetTitle(diffTarget, range.EndRevision);
            da.ReadOnly  = true;
            diff.RunDiff(da);
        }
Beispiel #2
0
        /// <summary>
        /// Update to revision performs a reverse merge
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="startRevision"></param>
        /// <param name="endRevision"></param>
        /// <returns></returns>
        public bool ReverseMerge(string filePath, long startRevision, long endRevision)
        {
            var svnRange      = new SvnRevisionRange(startRevision, endRevision);
            var svnPathTarget = new SvnPathTarget(filePath);

            return(_svnClient.Merge(filePath, svnPathTarget, svnRange));
        }
Beispiel #3
0
        public static FileChanged[] GetChangeSetFromSvn(DateTime startDateTime, DateTime endDateTime, SvnConfig server)
        {
            SvnRevisionRange range = new SvnRevisionRange(new SvnRevision(startDateTime), new SvnRevision(endDateTime));
            Collection<SvnLogEventArgs> logitems;

            var uri = new Uri(server.Url);
            FileChanged[] changed;
            using (SvnClient client = new SvnClient())
            {
                client.Authentication.Clear(); // Disable all use of the authentication area
                client.Authentication.UserNamePasswordHandlers +=
                    delegate(object sender, SvnUserNamePasswordEventArgs e)
                        {
                            e.UserName = server.UserName;
                            e.Password = server.Password;
                            e.Save = true;
                        };
                client.Authentication.SslServerTrustHandlers += delegate(object sender, SvnSslServerTrustEventArgs e)
                    {
                        e.AcceptedFailures = e.Failures;
                        e.Save = true; // Save acceptance to authentication store
                    };
                client.GetLog(uri, new SvnLogArgs(range), out logitems);
                foreach (var svnLogEventArgse in logitems)
                {
                    Console.WriteLine((string) WriteString(svnLogEventArgse));
                }
                changed = logitems.SelectMany<SvnLogEventArgs, FileChanged>(l => GetChangedFiles(l)).ToArray();
            }
            return changed;
        }
Beispiel #4
0
 private string GetCommitMessage(string parent, string child, SvnRevisionRange mergedRevisions)
 {
     return string.Format(
         "{0} from {1} to {2}",
         GetSuccessMessage(mergedRevisions),
         parent,
         child);
 }
Beispiel #5
0
 private SvnRevisionRange GetMergedRevisions(SvnRevisionRange initialRange, SvnRevisionRange newRange)
 {
     return initialRange != null
         ? new SvnRevisionRange(
             initialRange.EndRevision.Revision + 1,
             newRange.EndRevision)
         : newRange;
 }
Beispiel #6
0
        public override void RevertToRevision(FilePath path, Revision revision, IProgressMonitor monitor)
        {
            SvnMergeArgs args = new SvnMergeArgs();

            BindMonitor(args, monitor);
            SvnRevisionRange range = new SvnRevisionRange(GetRevision(SvnRevision.Head), GetRevision(revision));

            client.Merge(path, new SvnPathTarget(path), range, args);
        }
        private string GetPatchOfChange(long revision, string path)
        {
            if (revision == 1)
            {
                return("");
            }
            path = this.DirectoryPath + path;
            SvnRevisionRange range;

            range = new SvnRevisionRange(revision - 1, revision);
            MemoryStream diffResult = new MemoryStream();
            string       theFile    = String.Empty;
            int          counter    = 0;
            bool         descFlag   = false;

            using (SvnClient client = new SvnClient())
            {
                if (client.Diff(new SvnUriTarget(path), range, diffResult))
                {
                    diffResult.Position = 0;
                    StreamReader strReader = new StreamReader(diffResult);
                    string       diff      = strReader.ReadToEnd();
                    diff = diff.Insert(diff.Length, "\0");
                    if (diff.Length >= 50000)
                    {
                        double size = diff.Length / 500;
                        return(String.Format("File content: {0} kb", size));
                    }
                    foreach (char c in diff)
                    {
                        counter++;
                        if (c != '@' && descFlag == false) //getting past the first description part
                        {
                            continue;
                        }
                        else if (c == '@' && descFlag == false)                                           //we know we are towards the end of it
                        {
                            if (diff.Substring(counter, 1) == "\n" || diff.Substring(counter, 1) == "\r") //at the end of the line with the '@' symbols
                            {
                                descFlag = true;
                            }
                            else
                            {
                                continue;
                            }
                        }
                        else if (descFlag == true) //now reading the actual file
                        {
                            theFile += diff.Substring(counter);
                            break;
                        }
                    }
                }
            }
            return(theFile);
        }
Beispiel #8
0
        public override string[] RetrieveAuthors(DateRange dateRange)
        {
            var startRevision = new SvnRevision(dateRange.StartDate.GetValueOrDefault());
            var endRevision   = new SvnRevision(dateRange.EndDate.GetValueOrDefault());

            var range  = new SvnRevisionRange(startRevision, endRevision);
            var result = GetSvnRevisions(new SvnLogArgs(range));

            return(result.Select(x => x.Author).Where(y => !string.IsNullOrEmpty(y)).Distinct().ToArray());
        }
Beispiel #9
0
        public override void RevertToRevision(FilePath path, Revision revision, ProgressMonitor monitor)
        {
            var args = new SvnMergeArgs();

            BindMonitor(monitor);
            var range = new SvnRevisionRange(GetRevision(SvnRevision.Head), GetRevision(revision));

            lock (client)
                client.Merge(path, new SvnPathTarget(path), range, args);
        }
        public LoadSourcesInfoResult LoadSourcesInfo(SourceControlVersion sourceControlVersion, string path)
        {
            NetworkCredential credentials = new NetworkCredential(
                sourceControlVersion.SourceControl.GetStringProperty("Login"),
                sourceControlVersion.SourceControl.GetStringProperty("Password"));

            Revision latestRevision =
                sourceControlVersion.Revisions.OrderByDescending(r => r.CreatedDate).FirstOrDefault();

            if (latestRevision == null)
            {
                return(new LoadSourcesInfoResult
                {
                    SourcesInfos = new List <SourcesInfo>()
                });
            }

            SvnRevisionRange range = new SvnRevisionRange(long.Parse(latestRevision.Name), long.Parse(latestRevision.Name));

            if (latestRevision.ParentRevision != null)
            {
                range = new SvnRevisionRange(long.Parse(latestRevision.ParentRevision.Name) + 1, long.Parse(latestRevision.Name));
            }

            try
            {
                using (SvnClient client = new SvnClient())
                {
                    client.LoadConfiguration(Path.Combine(Path.GetTempPath(), "Svn"), true);

                    client.Authentication.DefaultCredentials = credentials;

                    Collection <SvnLogEventArgs> logEventArgs;

                    client.GetLog(path, new SvnLogArgs
                    {
                        Range = range
                    }, out logEventArgs);

                    return(new LoadSourcesInfoResult
                    {
                        SourcesInfos = logEventArgs.Select(e => new SourcesInfo
                        {
                            CreatedDate = e.Time,
                            Author = e.Author,
                            Message = e.LogMessage
                        }).ToList()
                    });
                }
            }
            catch (SvnException e)
            {
                throw new AspNetDeployException("SvnClient failed to load sources", e);
            }
        }
Beispiel #11
0
        public override void RevertRevision(FilePath path, Revision revision, IProgressMonitor monitor)
        {
            var args = new SvnMergeArgs();

            BindMonitor(monitor);
            Revision prev  = ((SvnRevision)revision).GetPrevious();
            var      range = new SvnRevisionRange(GetRevision(revision), GetRevision(prev));

            lock (client)
                client.Merge(path, new SvnPathTarget(path), range, args);
        }
Beispiel #12
0
        public override async void RevertRevision(FilePath path, Revision revision, ProgressMonitor monitor)
        {
            var args = new SvnMergeArgs();

            BindMonitor(monitor);
            Revision prev  = await((SvnRevision)revision).GetPreviousAsync(monitor.CancellationToken);
            var      range = new SvnRevisionRange(GetRevision(revision), GetRevision(prev));

            lock (client)
                client.Merge(path, new SvnPathTarget(path), range, args);
        }
Beispiel #13
0
 /// <summary>
 /// Generates the diff from the current selection.
 /// </summary>
 /// <param name="context"></param>
 /// <param name="selection"></param>
 /// <param name="revisions"></param>
 /// <returns>The diff as a string.</returns>
 protected virtual string GetDiff(IAnkhServiceProvider context, ISelectionContext selection, SvnRevisionRange revisions)
 {
     return GetDiff(
         context,
         selection,
         revisions,
         delegate(SvnItem item)
         {
             return item.IsVersioned;
         });
 }
Beispiel #14
0
        private IList <string> GetLatestCommitMessages(Uri repository)
        {
            using (var client = new SvnClient()) {
                System.Collections.ObjectModel.Collection <SvnLogEventArgs> logEntries;

                SvnRevisionRange range = new SvnRevisionRange(new SvnRevision(Start), new SvnRevision(End));
                var args = new SvnLogArgs(range);
                client.GetLog(repository, args, out logEntries);
                return(logEntries.Where(log => log.LogMessage.Contains("#SD-3606")).Select(log => log.LogMessage).ToList());
            }
        }
Beispiel #15
0
        private string GetSuccessMessage(SvnRevisionRange mergedRevisions)
        {
            if (mergedRevisions.StartRevision.Revision == mergedRevisions.EndRevision.Revision)
            {
                return "Merged revision r" + mergedRevisions.StartRevision.Revision;
            }

            return string.Format(
                "Merged revisions r{0}-r{1}",
                mergedRevisions.StartRevision.Revision,
                mergedRevisions.EndRevision.Revision);
        }
Beispiel #16
0
        public static void Merge(string targetPath, string svnSourceURL, string svnUsername, string svnPassword, long revisionNumber)
        {
            using (SvnClient client = InitializeSvnClient(svnUsername, svnPassword))
            {
                SvnMergeArgs mergeArgs = new SvnMergeArgs();
                mergeArgs.Depth = SvnDepth.Infinity;

                SvnUriTarget     svnTargetSource = new SvnUriTarget(new Uri(svnSourceURL));
                SvnRevisionRange svnRange        = new SvnRevisionRange(revisionNumber - 1, revisionNumber);
                bool             success         = client.Merge(targetPath, svnTargetSource, svnRange, mergeArgs);
            }
        }
Beispiel #17
0
        public int MergeItem(MigrationItemStrings mergeItem, int mergeFrom, int mergeTo)
        {
            Trace.TraceInformation("SVNTCAdapter MergeItem {0} {1}", mergeItem.LocalPath, mergeItem.NewLocalPath);
            SvnTarget        sourceTarget = SvnTarget.FromString(mergeItem.LocalPath);
            SvnRevisionRange range        = new SvnRevisionRange(mergeFrom, mergeTo);

            m_client.Merge(mergeItem.NewLocalPath, sourceTarget, range);
            m_client.Commit(mergeItem.NewLocalPath, new SvnCommitArgs()
            {
                LogMessage = MergeComment
            });

            return(GetLatestRevisionNumber());
        }
        public override void OnExecute(CommandEventArgs e)
        {
            PathSelectorResult result = ShowDialog(e);
            if (!result.Succeeded)
                return;

            SvnRevisionRange revRange = new SvnRevisionRange(result.RevisionStart, result.RevisionEnd);

            IAnkhTempFileManager tempfiles = e.GetService<IAnkhTempFileManager>();
            string tempFile = tempfiles.GetTempFile(".patch");

            IAnkhSolutionSettings ss = e.GetService<IAnkhSolutionSettings>();
            string slndir = ss.ProjectRoot;
            string slndirP = slndir + "\\";

            SvnDiffArgs args = new SvnDiffArgs();
            args.IgnoreAncestry = true;
            args.NoDeleted = false;
            args.Depth = result.Depth;

            using (MemoryStream stream = new MemoryStream())
            {
                e.Context.GetService<IProgressRunner>().RunModal("Diffing",
                    delegate(object sender, ProgressWorkerArgs ee)
                    {
                        foreach (SvnItem item in result.Selection)
                        {
                            SvnWorkingCopy wc;
                            if (!string.IsNullOrEmpty(slndir) &&
                                item.FullPath.StartsWith(slndirP, StringComparison.OrdinalIgnoreCase))
                                args.RelativeToPath = slndir;
                            else if ((wc = item.WorkingCopy) != null)
                                args.RelativeToPath = wc.FullPath;
                            else
                                args.RelativeToPath = null;

                            ee.Client.Diff(item.FullPath, revRange, args, stream);
                        }

                        stream.Flush();
                        stream.Position = 0;
                    });
                using (StreamReader sr = new StreamReader(stream))
                {
                    File.WriteAllText(tempFile, sr.ReadToEnd(), Encoding.UTF8);
                    VsShellUtilities.OpenDocument(e.Context, tempFile);
                }
            }
        }
Beispiel #19
0
        void UpdateSVNRevision(string file, string tag)
        {
            if (tag == "src")
            {
                Collection <SvnLogEventArgs> logitems;

                DateTime startDateTime = DateTime.Now.AddDays(-60);
                DateTime endDateTime   = DateTime.Now;
                var      svnRange      = new SvnRevisionRange(new SvnRevision(startDateTime), new SvnRevision(endDateTime));

                List <SvnRevisionCombo> revisions = new List <SvnRevisionCombo>();

                using (SvnClient client = new SvnClient()) {
                    client.Authentication.SslServerTrustHandlers += delegate(object sender, SharpSvn.Security.SvnSslServerTrustEventArgs e) {
                        e.AcceptedFailures = e.Failures;
                        e.Save             = true; // Save acceptance to authentication store
                    };

                    if (client.GetUriFromWorkingCopy(file) != null)
                    {
                        SvnInfoEventArgs info;
                        client.GetInfo(file, out info);
                        var uri = info.Uri;

                        client.GetLog(uri, new SvnLogArgs(svnRange), out logitems);

                        foreach (var logentry in logitems)
                        {
                            var author  = logentry.Author;
                            var message = logentry.LogMessage;
                            var date    = logentry.Time;

                            revisions.Add(new SvnRevisionCombo()
                            {
                                Revision = string.Format("{0}[{1}]", author, message), ID = (int)logentry.Revision
                            });
                        }
                        revisions.Sort((a, b) => {
                            return(b.ID - a.ID);
                        });
                    }
                }
                SVNRevisionCombo.ItemsSource = revisions;
            }
        }
        /// <summary>
        ///     Слияние родительской ветки в ветку фитчи
        /// </summary>
        /// <param name="workingCopyPath">Рабочая папка</param>
        /// <param name="basePathUrl">URL родительской ветки</param>
        /// <returns>Результат слияния</returns>
        private bool MergeBaseBranchIntoFeature(string workingCopyPath, string basePathUrl)
        {
            var svnMergeArgs = new SvnMergeArgs {
                Force = true
            };

            svnMergeArgs.Notify   += OnSvnMergeArgsOnNotify;
            svnMergeArgs.Conflict += OnSvnMergeArgsOnConflict;
            try {
                var mergeRange = new SvnRevisionRange(SvnRevision.One, SvnRevision.Head);
                return(Merge(workingCopyPath, SvnUriTarget.FromString(basePathUrl), mergeRange, svnMergeArgs));
            } catch (SvnException svnException) {
                Logger.LogError(svnException.Message);
            } finally {
                svnMergeArgs.Notify   -= OnSvnMergeArgsOnNotify;
                svnMergeArgs.Conflict -= OnSvnMergeArgsOnConflict;
            }

            return(false);
        }
Beispiel #21
0
        /// <summary>
        /// because the library use UTC datetime, so can not believe datetime
        /// </summary>
        /// <param name="startDateTime"></param>
        /// <param name="endDateTime"></param>
        /// <returns></returns>
        private long[] GetVersion(DateTime startDateTime, DateTime endDateTime)
        {
            SvnRevisionRange range   = new SvnRevisionRange(new SvnRevision(startDateTime.AddDays(-1)), new SvnRevision(endDateTime.AddDays(2)));
            SvnLogArgs       logArgs = new SvnLogArgs()
            {
                Limit = 0,
                Range = range,
                RetrieveAllProperties = true,
            };

            Collection <SvnLogEventArgs> logs;

            client.GetLog(new Uri(serverPath), logArgs, out logs);

            long[] revisions = new long[2] {
                -1, -1
            };
            foreach (var log in logs)
            {
                if (log.Time.ToLocalTime().Date >= startDateTime.Date && revisions[0] == -1)
                {
                    revisions[0] = log.Revision;
                }
                revisions[1] = log.Revision;

                if (log.Time.ToLocalTime().Date > endDateTime.Date)
                {
                    break;
                }
            }
            if (revisions[0] == -1)
            {
                return(null);
            }

            return(revisions);
        }
Beispiel #22
0
        public HashSet <string> GetLogByTime(DateTime startDateTime, DateTime endDateTime)
        {
            long[] revisions = GetVersion(startDateTime, endDateTime);

            if (revisions == null)
            {
                return(null);
            }

            SvnRevisionRange range   = new SvnRevisionRange(revisions[0], revisions[1]);
            SvnLogArgs       logArgs = new SvnLogArgs()
            {
                Limit = 0,
                Range = range,
                RetrieveAllProperties = true,
            };

            Collection <SvnLogEventArgs> logs;

            client.GetLog(new Uri(serverPath), logArgs, out logs);

            HashSet <string> fetchFiles = new HashSet <string>();

            foreach (var log in logs)
            {
                foreach (var changeItem in log.ChangedPaths)
                {
                    if (changeItem.Action == SvnChangeAction.Modify ||
                        changeItem.Action == SvnChangeAction.Add ||
                        changeItem.Action == SvnChangeAction.Replace)
                    {
                        fetchFiles.Add(ChangeToLocalPath(changeItem.Path));
                    }
                }
            }
            return(fetchFiles);
        }
Beispiel #23
0
        /// <summary>
        /// Generates the diff from the current selection.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="selection"></param>
        /// <param name="revisions"></param>
        /// <param name="visibleFilter"></param>
        /// <returns>The diff as a string.</returns>
        protected virtual string GetDiff(IAnkhServiceProvider context, ISelectionContext selection, SvnRevisionRange revisions, Predicate<SvnItem> visibleFilter)
        {
            if (selection == null)
                throw new ArgumentNullException("selection");
            if (context == null)
                throw new ArgumentNullException("context");

            IUIShell uiShell = context.GetService<IUIShell>();

            bool foundModified = false;
            foreach (SvnItem item in selection.GetSelectedSvnItems(true))
            {
                if (item.IsModified || item.IsDocumentDirty)
                {
                    foundModified = true;
                    break; // no need (yet) to keep searching
                }
            }

            PathSelectorInfo info = new PathSelectorInfo("Select items for diffing", selection.GetSelectedSvnItems(true));
            info.VisibleFilter += visibleFilter;
            if (foundModified)
                info.CheckedFilter += delegate(SvnItem item) { return item.IsFile && (item.IsModified || item.IsDocumentDirty); };

            info.RevisionStart = revisions == null ? SvnRevision.Base : revisions.StartRevision;
            info.RevisionEnd = revisions == null ? SvnRevision.Working : revisions.EndRevision;

            PathSelectorResult result;
            // should we show the path selector?
            if (!Shift && (revisions == null || !foundModified))
            {
                result = uiShell.ShowPathSelector(info);
                if (!result.Succeeded)
                    return null;
            }
            else
                result = info.DefaultResult;

            if (!result.Succeeded)
                return null;

            SaveAllDirtyDocuments(selection, context);

            return DoExternalDiff(context, result);
        }
Beispiel #24
0
        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;
        }
		public override string[] RetrieveAuthors(DateRange dateRange)
		{
			var startRevision = new SvnRevision(dateRange.StartDate.GetValueOrDefault());
			var endRevision = new SvnRevision(dateRange.EndDate.GetValueOrDefault());

			var range = new SvnRevisionRange(startRevision, endRevision);
			var result = GetSvnRevisions(new SvnLogArgs(range));
			return result.Select(x => x.Author).Where(y => !string.IsNullOrEmpty(y)).Distinct().ToArray();
		}
Beispiel #26
0
        private IEnumerable <SvnPathInfo> GetSVNFiles(DateTime lastDate, string svnPath)
        {
            IEnumerable <SvnPathInfo> files = new SvnPathInfo[0];

            Uri              uriBase = new Uri(svnPath);
            DateTime         dtBeg   = lastDate.ToUniversalTime();
            DateTime         dtEnd   = DateTime.Now.AddMinutes(5).ToUniversalTime();
            SvnRevisionRange range   = new SvnRevisionRange(dtBeg, dtEnd);
            SvnLogArgs       logArgs = new SvnLogArgs(range);

            logArgs.BaseUri = uriBase;
            SvnClient client = new SvnClient();

            client.Authentication.UserNamePasswordHandlers += new EventHandler <SvnUserNamePasswordEventArgs>(Authentication_UserNamePasswordHandlers);

            Collection <SvnLogEventArgs> lstLogEvent = new Collection <SvnLogEventArgs>();

            if (client.GetLog(uriBase, logArgs, out lstLogEvent))
            {
                Dictionary <string, SvnPathInfo> lstFiles = new Dictionary <string, SvnPathInfo>();
                SvnPathInfo pathInfo = null;
                foreach (SvnLogEventArgs log in lstLogEvent)
                {
                    foreach (SvnChangeItem item in log.ChangedPaths)
                    {
                        if (item.NodeKind == SvnNodeKind.File)
                        {
                            if (ContainsExclude(item.Path))
                            {
                                continue;
                            }

                            if (lstFiles.ContainsKey(item.Path))
                            {
                                pathInfo            = lstFiles[item.Path];
                                pathInfo.ModifyTime = log.Time.ToLocalTime();
                            }
                            else
                            {
                                pathInfo            = new SvnPathInfo();
                                pathInfo.FilePath   = item.Path;
                                pathInfo.Author     = log.Author;
                                pathInfo.ModifyTime = log.Time.ToLocalTime();
                                lstFiles[item.Path] = pathInfo;
                            }

                            if (log.LogMessage != null && log.LogMessage.Trim().Length > 0)
                            {
                                string[] messages = log.LogMessage.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
                                foreach (var msg in messages)
                                {
                                    if (string.IsNullOrWhiteSpace(msg))
                                    {
                                        continue;
                                    }
                                    pathInfo.Log.Append(msg + ";");
                                }
                            }
                        }
                    }
                }

                files = lstFiles.Values.ToArray();
            }

            return(files);
        }
Beispiel #27
0
        public override void OnExecute(CommandEventArgs e)
        {
            List <SvnItem> selectedFiles = new List <SvnItem>();

            if (e.Command == AnkhCommand.DocumentShowChanges)
            {
                SvnItem item = e.Selection.ActiveDocumentSvnItem;

                if (item == null)
                {
                    return;
                }
                selectedFiles.Add(item);
            }
            else
            {
                foreach (SvnItem item in e.Selection.GetSelectedSvnItems(false))
                {
                    if (!item.IsVersioned || (item.Status.LocalNodeStatus == SvnStatus.Added && !item.Status.IsCopied))
                    {
                        continue;
                    }

                    if (e.Command == AnkhCommand.ItemCompareBase ||
                        e.Command == AnkhCommand.ItemShowChanges)
                    {
                        if (!(item.IsModified || item.IsDocumentDirty) ||
                            !item.IsLocalDiffAvailable    // exclude if local diff is not available
                            )
                        {
                            continue;
                        }
                    }

                    if (e.Command == AnkhCommand.DiffLocalItem &&
                        !NotDeletedFilter(item))
                    {
                        continue;
                    }

                    selectedFiles.Add(item);
                }
            }

            SvnRevisionRange revRange = null;

            switch (e.Command)
            {
            case AnkhCommand.DiffLocalItem:
                break;     // revRange null -> show selector

            case AnkhCommand.ItemCompareBase:
            case AnkhCommand.ItemShowChanges:
            case AnkhCommand.DocumentShowChanges:
                revRange = new SvnRevisionRange(SvnRevision.Base, SvnRevision.Working);
                break;

            case AnkhCommand.ItemCompareCommitted:
                revRange = new SvnRevisionRange(SvnRevision.Committed, SvnRevision.Working);
                break;

            case AnkhCommand.ItemCompareLatest:
                revRange = new SvnRevisionRange(SvnRevision.Head, SvnRevision.Working);
                break;

            case AnkhCommand.ItemComparePrevious:
                revRange = new SvnRevisionRange(SvnRevision.Previous, SvnRevision.Working);
                break;
            }

            if (e.PromptUser || selectedFiles.Count > 1 || revRange == null)
            {
                SvnRevision start = revRange == null ? SvnRevision.Base : revRange.StartRevision;
                SvnRevision end   = revRange == null ? SvnRevision.Working : revRange.EndRevision;

                // should we show the path selector?
                if (e.PromptUser || !Shift)
                {
                    using (CommonFileSelectorDialog dlg = new CommonFileSelectorDialog())
                    {
                        dlg.Text          = CommandStrings.CompareFilesTitle;
                        dlg.Items         = selectedFiles;
                        dlg.RevisionStart = start;
                        dlg.RevisionEnd   = end;

                        if (dlg.ShowDialog(e.Context) != DialogResult.OK)
                        {
                            return;
                        }

                        selectedFiles.Clear();
                        selectedFiles.AddRange(dlg.GetCheckedItems());
                        start = dlg.RevisionStart;
                        end   = dlg.RevisionEnd;
                    }
                }

                revRange = new SvnRevisionRange(start, end);
            }

            if (revRange.EndRevision.RevisionType == SvnRevisionType.Working ||
                revRange.StartRevision.RevisionType == SvnRevisionType.Working)
            {
                // Save only the files needed

                IAnkhOpenDocumentTracker tracker = e.GetService <IAnkhOpenDocumentTracker>();
                if (tracker != null)
                {
                    tracker.SaveDocuments(SvnItem.GetPaths(selectedFiles));
                }
            }

            IAnkhDiffHandler diff = e.GetService <IAnkhDiffHandler>();

            foreach (SvnItem item in selectedFiles)
            {
                AnkhDiffArgs da = new AnkhDiffArgs();

                if ((item.Status.IsCopied || item.IsReplaced) &&
                    (!revRange.StartRevision.RequiresWorkingCopy || !revRange.EndRevision.RequiresWorkingCopy))
                {
                    // The file is copied, use its origins history instead of that of the new file
                    SvnUriTarget copiedFrom = diff.GetCopyOrigin(item);

                    // TODO: Maybe handle Previous/Committed as history

                    if (copiedFrom != null && !revRange.StartRevision.RequiresWorkingCopy)
                    {
                        if (null == (da.BaseFile = diff.GetTempFile(copiedFrom, revRange.StartRevision, true)))
                        {
                            return; // Canceled
                        }
                        da.BaseTitle = diff.GetTitle(copiedFrom, revRange.StartRevision);
                    }

                    if (copiedFrom != null && !revRange.EndRevision.RequiresWorkingCopy)
                    {
                        if (null == (da.MineFile = diff.GetTempFile(copiedFrom, revRange.EndRevision, true)))
                        {
                            return; // Canceled
                        }
                        da.MineTitle = diff.GetTitle(copiedFrom, revRange.EndRevision);
                    }
                }

                if (da.BaseFile == null)
                {
                    if (null == (da.BaseFile = (revRange.StartRevision == SvnRevision.Working) ? item.FullPath :
                                               diff.GetTempFile(item, revRange.StartRevision, true)))
                    {
                        return; // Canceled
                    }

                    da.BaseTitle = diff.GetTitle(item, revRange.StartRevision);
                }

                if (da.MineFile == null)
                {
                    if (null == (da.MineFile = (revRange.EndRevision == SvnRevision.Working) ? item.FullPath :
                                               diff.GetTempFile(item, revRange.EndRevision, true)))
                    {
                        return; // Canceled
                    }

                    da.MineTitle = diff.GetTitle(item, revRange.EndRevision);
                }

                if (!String.Equals(da.MineFile, item.FullPath, StringComparison.OrdinalIgnoreCase))
                {
                    da.ReadOnly = true;
                }

                diff.RunDiff(da);
            }
        }
Beispiel #28
0
		public override void RevertToRevision (FilePath path, Revision revision, IProgressMonitor monitor)
		{
			SvnMergeArgs args = new SvnMergeArgs ();
			BindMonitor (args, monitor);
			SvnRevisionRange range = new SvnRevisionRange (GetRevision (SvnRevision.Head), GetRevision (revision));
			lock (client) 
				client.Merge (path, new SvnPathTarget (path), range, args);
		}
Beispiel #29
0
		public override void RevertRevision (FilePath path, Revision revision, IProgressMonitor monitor)
		{
			var args = new SvnMergeArgs ();
			BindMonitor (monitor);
			Revision prev = ((SvnRevision) revision).GetPrevious ();
			var range = new SvnRevisionRange (GetRevision (revision), GetRevision (prev));
			lock (client) 
				client.Merge (path, new SvnPathTarget (path), range, args);
		}
Beispiel #30
0
        public override void OnExecute(CommandEventArgs e)
        {
            List <string>  toAdd = new List <string>();
            List <SvnItem> items = new List <SvnItem>();

            foreach (SvnItem item in e.Selection.GetSelectedSvnItems(true))
            {
                if (item.IsVersioned)
                {
                    items.Add(item);
                }
                else if (item.IsFile && item.IsVersionable && item.InSolution && !item.IsIgnored && !item.IsSccExcluded)
                {
                    toAdd.Add(item.FullPath); // Add new files  ### Alternative: Show them as added
                    items.Add(item);
                }
            }

            if (items.Count == 0)
            {
                return;
            }

            SvnRevision start = SvnRevision.Base;
            SvnRevision end   = SvnRevision.Working;

            // should we show the path selector?
            if (e.ShouldPrompt(true))
            {
                using (CommonFileSelectorDialog dlg = new CommonFileSelectorDialog())
                {
                    dlg.Text          = CommandStrings.UnifiedDiffTitle;
                    dlg.Items         = items;
                    dlg.RevisionStart = start;
                    dlg.RevisionEnd   = end;

                    if (dlg.ShowDialog(e.Context) != DialogResult.OK)
                    {
                        return;
                    }

                    items.Clear();
                    items.AddRange(dlg.GetCheckedItems());
                    start = dlg.RevisionStart;
                    end   = dlg.RevisionEnd;
                }
            }

            if (items.Count == 0)
            {
                return;
            }

            SvnRevisionRange revRange = new SvnRevisionRange(start, end);

            IAnkhTempFileManager tempfiles = e.GetService <IAnkhTempFileManager>();
            string tempFile = tempfiles.GetTempFile(".patch");

            IAnkhSolutionSettings ss = e.GetService <IAnkhSolutionSettings>();
            string slndir            = ss.ProjectRoot;

            using (MemoryStream stream = new MemoryStream())
            {
                e.Context.GetService <IProgressRunner>().RunModal(CommandStrings.RunningDiff,
                                                                  delegate(object sender, ProgressWorkerArgs ee)
                {
                    SvnAddArgs aa   = new SvnAddArgs();
                    aa.ThrowOnError = false;
                    aa.AddParents   = false;
                    foreach (string item in toAdd)
                    {
                        ee.Client.Add(item, aa);
                    }

                    SvnDiffArgs diffArgs    = new SvnDiffArgs();
                    diffArgs.IgnoreAncestry = true;
                    diffArgs.NoDeleted      = false;
                    diffArgs.ThrowOnError   = false;

                    foreach (SvnItem item in items)
                    {
                        SvnWorkingCopy wc;
                        if (!string.IsNullOrEmpty(slndir) && item.IsBelowPath(slndir))
                        {
                            diffArgs.RelativeToPath = slndir;
                        }
                        else if ((wc = item.WorkingCopy) != null)
                        {
                            diffArgs.RelativeToPath = wc.FullPath;
                        }
                        else
                        {
                            diffArgs.RelativeToPath = null;
                        }

                        if (!ee.Client.Diff(item.FullPath, revRange, diffArgs, stream))
                        {
                            if (diffArgs.LastException != null)
                            {
                                StreamWriter sw = new StreamWriter(stream);
                                sw.WriteLine();
                                sw.WriteLine(string.Format("# {0}: {1}", item.FullPath, diffArgs.LastException.Message));
                                sw.Flush();
                                // Don't dispose the writer as that might close the stream
                            }

                            if (diffArgs.IsLastInvocationCanceled)
                            {
                                break;
                            }
                        }
                    }

                    stream.Flush();
                });

                stream.Position = 0;
                using (StreamReader sr = new StreamReader(stream))
                {
                    File.WriteAllText(tempFile, sr.ReadToEnd(), Encoding.UTF8);
                    VsShellUtilities.OpenDocument(e.Context, tempFile);
                }
            }
        }
        private void DoVersionDiff_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(FilterCommits.Text))
            {
                TextTip.Content = "需要填写单号,多个单号空格隔开";
                return;
            }
            if (src.files.Count <= 0)
            {
                TextTip.Content = "拖目标文件夹进来,或目标文件夹下没有xls";
                return;
            }

            Collection <SvnLogEventArgs> logitems;

            DateTime startDateTime = DateTime.Now.AddDays(-60);
            DateTime endDateTime   = DateTime.Now;
            var      svnRange      = new SvnRevisionRange(new SvnRevision(startDateTime), new SvnRevision(endDateTime));

            List <SvnRevisionCombo> revisions = new List <SvnRevisionCombo>();

            var files = new Dictionary <string, RevisionRange>();

            var filter = FilterCommits.Text.Split(" #".ToArray(), StringSplitOptions.RemoveEmptyEntries);

            var sfilter   = string.Join("|", filter);
            var regfilter = new Regex(sfilter);

            using (SvnClient client = new SvnClient()) {
                client.Authentication.SslServerTrustHandlers += delegate(object _sender, SharpSvn.Security.SvnSslServerTrustEventArgs _e) {
                    _e.AcceptedFailures = _e.Failures;
                    _e.Save             = true; // Save acceptance to authentication store
                };

                if (client.GetUriFromWorkingCopy(src.root) != null)
                {
                    SvnInfoEventArgs info;
                    client.GetInfo(src.root, out info);
                    var uri = info.Uri;

                    var rootPath = info.Path;

                    client.GetLog(uri, new SvnLogArgs(svnRange), out logitems);

                    foreach (var logentry in logitems)
                    {
                        var author   = logentry.Author;
                        var message  = logentry.LogMessage;
                        var date     = logentry.Time;
                        var revision = logentry.Revision;

                        if (regfilter.IsMatch(message))
                        {
                            foreach (var filepath in logentry.ChangedPaths)
                            {
                                var path = filepath.Path;

                                RevisionRange minmax = null;
                                if (!files.TryGetValue(path, out minmax))
                                {
                                    minmax = new RevisionRange()
                                    {
                                        min = revision, max = revision, file = path
                                    };
                                    files[path] = minmax;
                                }
                                if (revision > minmax.max)
                                {
                                    minmax.max = revision;
                                }
                                if (revision < minmax.min)
                                {
                                    minmax.min = revision;
                                }
                            }
                        }
                    }
                }
            }

            results.Clear();
            resultRevisions.Clear();

            foreach (var file in files.Keys)
            {
                var range = files[file];
                var res   = new DiffResult <string>(file + "-" + range.min, file + "-" + range.max, DiffStatus.Modified);

                results.Add(res);
                resultRevisions.Add(range);
            }

            DstDataGrid.refreshData();
            SrcDataGrid.refreshData();
        }
Beispiel #32
0
        public override void OnExecute(CommandEventArgs e)
        {
            List<SvnItem> selectedFiles = new List<SvnItem>();
            bool selectionHasDeleted = false;

            if (e.Command == AnkhCommand.DocumentShowChanges)
            {
                SvnItem item = e.Selection.ActiveDocumentItem;

                if(item == null)
                    return;
                selectedFiles.Add(item);
            }
            else
                foreach (SvnItem item in e.Selection.GetSelectedSvnItems(false))
                {
                    if (!item.IsVersioned || (item.Status.CombinedStatus == SvnStatus.Added && !item.Status.IsCopied))
                        continue;

                    if ( e.Command == AnkhCommand.ItemCompareBase
                         || e.Command == AnkhCommand.ItemShowChanges)
                    {
                        if (!(item.IsModified || item.IsDocumentDirty)
                            || !item.IsLocalDiffAvailable // exclude if local diff is not available
                            )
                            continue;
                    }

                    if (e.Command == AnkhCommand.DiffLocalItem)
                    {
                        selectionHasDeleted |= !NotDeletedFilter(item);
                    }

                    selectedFiles.Add(item);
                }

            SvnRevisionRange revRange = null;
            switch (e.Command)
            {
                case AnkhCommand.DiffLocalItem:
                    break; // revRange null -> show selector
                case AnkhCommand.ItemCompareBase:
                case AnkhCommand.ItemShowChanges:
                case AnkhCommand.DocumentShowChanges:
                    revRange = new SvnRevisionRange(SvnRevision.Base, SvnRevision.Working);
                    break;
                case AnkhCommand.ItemCompareCommitted:
                    revRange = new SvnRevisionRange(SvnRevision.Committed, SvnRevision.Working);
                    break;
                case AnkhCommand.ItemCompareLatest:
                    revRange = new SvnRevisionRange(SvnRevision.Head, SvnRevision.Working);
                    break;
                case AnkhCommand.ItemComparePrevious:
                    revRange = new SvnRevisionRange(SvnRevision.Previous, SvnRevision.Working);
                    break;
            }

            if (e.PromptUser || selectedFiles.Count > 1 || revRange == null)
            {
                PathSelectorInfo info = new PathSelectorInfo("Select item for Diff", selectedFiles);
                info.SingleSelection = false;
                info.RevisionStart = revRange == null ? SvnRevision.Base : revRange.StartRevision;
                info.RevisionEnd = revRange == null ? SvnRevision.Working : revRange.EndRevision;
                if (selectionHasDeleted)
                {
                    // do not allow selecting deleted items if the revision combination includes SvnRevision.Working
                    info.CheckableFilter += new PathSelectorInfo.SelectableFilter(delegate(SvnItem item, SvnRevision from, SvnRevision to)
                    {
                        if (item != null
                            && (from == SvnRevision.Working
                                || to == SvnRevision.Working
                                )
                            )
                        {
                            return NotDeletedFilter(item);
                        }
                        return true;
                    });
                }
                info.EnableRecursive = false;
                info.Depth = SvnDepth.Infinity;

                PathSelectorResult result;
                // should we show the path selector?
                if (e.PromptUser || !Shift)
                {
                    IUIShell ui = e.GetService<IUIShell>();

                    result = ui.ShowPathSelector(info);
                    if (!result.Succeeded)
                        return;
                }
                else
                    result = info.DefaultResult;

                selectedFiles.Clear();
                selectedFiles.AddRange(result.Selection);
                revRange = new SvnRevisionRange(result.RevisionStart, result.RevisionEnd);
            }

            if (revRange.EndRevision.RevisionType == SvnRevisionType.Working ||
                revRange.StartRevision.RevisionType == SvnRevisionType.Working)
            {
                // Save only the files needed

                IAnkhOpenDocumentTracker tracker = e.GetService<IAnkhOpenDocumentTracker>();
                if (tracker != null)
                    tracker.SaveDocuments(SvnItem.GetPaths(selectedFiles));
            }

            IAnkhDiffHandler diff = e.GetService<IAnkhDiffHandler>();
            foreach (SvnItem item in selectedFiles)
            {
                AnkhDiffArgs da = new AnkhDiffArgs();

                if ((item.Status.IsCopied || item.IsReplaced) &&
                    (!revRange.StartRevision.RequiresWorkingCopy || !revRange.EndRevision.RequiresWorkingCopy))
                {
                    // The file is copied, use its origins history instead of that of the new file
                    SvnUriTarget copiedFrom = diff.GetCopyOrigin(item);

                    // TODO: Maybe handle Previous/Committed as history

                    if (copiedFrom != null && !revRange.StartRevision.RequiresWorkingCopy)
                    {
                        if (null == (da.BaseFile = diff.GetTempFile(copiedFrom, revRange.StartRevision, true)))
                            return; // Canceled
                        da.BaseTitle = diff.GetTitle(copiedFrom, revRange.StartRevision);
                    }

                    if (copiedFrom != null && !revRange.EndRevision.RequiresWorkingCopy)
                    {
                        if (null == (da.MineFile = diff.GetTempFile(copiedFrom, revRange.EndRevision, true)))
                            return; // Canceled
                        da.MineTitle = diff.GetTitle(copiedFrom, revRange.EndRevision);
                    }
                }

                if (da.BaseFile == null)
                {
                    if (null == (da.BaseFile = (revRange.StartRevision == SvnRevision.Working) ? item.FullPath :
                        diff.GetTempFile(item, revRange.StartRevision, true)))
                    {
                        return; // Canceled
                    }

                    da.BaseTitle = diff.GetTitle(item, revRange.StartRevision);
                }

                if (da.MineFile == null)
                {
                    if (null == (da.MineFile = (revRange.EndRevision == SvnRevision.Working) ? item.FullPath :
                        diff.GetTempFile(item, revRange.EndRevision, true)))
                    {
                        return; // Canceled
                    }

                    da.MineTitle = diff.GetTitle(item, revRange.EndRevision);
                }

                if (!String.Equals(da.MineFile, item.FullPath, StringComparison.OrdinalIgnoreCase))
                    da.ReadOnly = true;

                diff.RunDiff(da);
            }
        }
Beispiel #33
0
        private SvnRevisionRange GetRevisionRange()
        {
            if (!RevisionRange.Contains(":"))
            {
                throw new ArgumentException("Revision range must have the format r1:r2");
            }

            string[] revisions = RevisionRange.Split(':');

            if (revisions.Length != 2)
            {
                throw new ArgumentException("Revision range must have the format r1:r2");
            }

            SvnRevisionRange range = new SvnRevisionRange(
                RevisionParser.SafeParse(revisions[0]),
                RevisionParser.SafeParse(revisions[1]));

            return range;
        }
Beispiel #34
0
        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);
        }