示例#1
0
        private void GetHistory()
        {
            if (reversedFileversion != null)
            {
                return;
            }

            using (SvnClient client = new SvnClient())
            {
                client.CleanUp(Path.GetDirectoryName(_excelFilePath));

                Collection <SvnFileVersionEventArgs> fileVersions = new Collection <SvnFileVersionEventArgs>();
                var tt = new SvnFileVersionsArgs();
                tt.Start = new SvnRevision(DateTime.Now.AddDays(-1));
                tt.End   = new SvnRevision(DateTime.Now);

                client.GetFileVersions(
                    new SvnPathTarget(_excelFilePath, DateTime.Now),
                    new SvnFileVersionsArgs(),
                    out fileVersions);

                reversedFileversion = fileVersions.Reverse();
                reversedFileversion = reversedFileversion.OrderByDescending(x => x.Revision);
            }
        }
示例#2
0
        private async Task LoadRevisions(string path)
        {
            Revisions = new List <Revision>();
            SvnTarget target;

            if (path.Contains("://"))
            {
                target = new SvnUriTarget(path);
            }
            else
            {
                target = new SvnPathTarget(path);
            }
            var svnFileVersionsArgs = new SvnFileVersionsArgs {
                Start = SvnRevision.Zero, End = SvnRevision.Head
            };

            svnClient.FileVersions(target, svnFileVersionsArgs, (sender, args) =>
            {
                var revision = new Revision
                {
                    Author       = args.Author,
                    Message      = args.LogMessage,
                    RevisionId   = args.Revision.ToString(CultureInfo.InvariantCulture),
                    RevisionTime = args.Time,
                };

                using (TextReader reader = new StreamReader(args.GetContentStream()))
                {
                    revision.Content = reader.ReadToEnd();
                }

                Revisions.Insert(0, revision); // Put them in newest-to-oldest order
            });
        }
示例#3
0
        public void FileVersions_WalkChange()
        {
            SvnFileVersionsArgs a  = new SvnFileVersionsArgs();
            SvnUriTarget        me = new SvnUriTarget(new Uri("https://ctf.open.collab.net/svn/repos/sharpsvn/trunk/src/SharpSvn.Tests/Commands/FileVersions.cs"), 931);

            a.Start = 927;
            a.End   = 928;
            int n = 0;

            Client.FileVersions(me, a,
                                delegate(object sender, SvnFileVersionEventArgs e)
            {
                GC.KeepAlive(e);
                e.WriteTo(GetTempFile());
                n++;
            });

            Assert.That(n, Is.EqualTo(2));
        }
示例#4
0
        public void FileVersions_ListIndex()
        {
            SvnSandBox sbox = new SvnSandBox(this);

            Uri reposUri = sbox.CreateRepository(SandBoxRepository.DefaultBranched);

            bool touched           = false;
            SvnFileVersionsArgs fa = new SvnFileVersionsArgs();

            fa.RetrieveProperties = true;
            Client.FileVersions(new Uri(reposUri, "trunk/README.txt"),
                                fa,
                                delegate(object sender, SvnFileVersionEventArgs e)
            {
                touched = true;
                Assert.That(e.RevisionProperties, Is.Not.Null, "Revision properties available");
                Assert.That(e.Properties, Is.Not.Null, "Properties available");

                Assert.That(e.RevisionProperties.Contains(SvnPropertyNames.SvnAuthor));
//                    Assert.That(e.Properties.Contains(SvnPropertyNames.SvnEolStyle));

                Assert.That(e.Revision, Is.GreaterThan(0));
                Assert.That(e.Author, Is.Not.Null);
                Assert.That(e.LogMessage, Is.Not.Null);
                Assert.That(e.Time, Is.LessThan(DateTime.UtcNow).And.GreaterThan(DateTime.UtcNow - new TimeSpan(0, 0, 2, 0)));

                using (StreamReader sr = new StreamReader(e.GetContentStream()))
                {
                    string content = sr.ReadToEnd();

                    Assert.That(content, Is.Not.Null);
                    Assert.That(content.Length, Is.GreaterThan(10));
                }
            });

            Assert.That(touched);
        }
示例#5
0
        public void FileVersions_ListIndex()
        {
            SvnSandBox sbox = new SvnSandBox(this);

            Uri reposUri = sbox.CreateRepository(SandBoxRepository.DefaultBranched);

            bool touched = false;
            SvnFileVersionsArgs fa = new SvnFileVersionsArgs();
            fa.RetrieveProperties = true;
            Client.FileVersions(new Uri(reposUri, "trunk/README.txt"),
                fa,
                delegate(object sender, SvnFileVersionEventArgs e)
                {
                    touched = true;
                    Assert.That(e.RevisionProperties, Is.Not.Null, "Revision properties available");
                    Assert.That(e.Properties, Is.Not.Null, "Properties available");

                    Assert.That(e.RevisionProperties.Contains(SvnPropertyNames.SvnAuthor));
            //                    Assert.That(e.Properties.Contains(SvnPropertyNames.SvnEolStyle));

                    Assert.That(e.Revision, Is.GreaterThan(0));
                    Assert.That(e.Author, Is.Not.Null);
                    Assert.That(e.LogMessage, Is.Not.Null);
                    Assert.That(e.Time, Is.LessThan(DateTime.UtcNow).And.GreaterThan(DateTime.UtcNow - new TimeSpan(0,0,2,0)));

                    using (StreamReader sr = new StreamReader(e.GetContentStream()))
                    {
                        string content = sr.ReadToEnd();

                        Assert.That(content, Is.Not.Null);
                        Assert.That(content.Length, Is.GreaterThan(10));
                    }
                });

            Assert.That(touched);
        }
示例#6
0
        public string[] GetTempFiles(SvnTarget target, SvnRevision from, SvnRevision to, bool withProgress)
        {
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }
            else if (from == null)
            {
                throw new ArgumentNullException("from");
            }
            else if (to == null)
            {
                throw new ArgumentNullException("to");
            }

            string f1;
            string f2;

            if (from.RevisionType == SvnRevisionType.Number && to.RevisionType == SvnRevisionType.Number && from.Revision + 1 == to.Revision)
            {
                f1 = GetTempPath(target.FileName, from);
                f2 = GetTempPath(target.FileName, to);

                int n = 0;
                ProgressRunnerResult r = Context.GetService <IProgressRunner>().RunModal(ServiceStrings.RetrievingMultipleVersionsOfFile,
                                                                                         delegate(object sender, ProgressWorkerArgs e)
                {
                    SvnFileVersionsArgs ea = new SvnFileVersionsArgs();
                    ea.Start = from;
                    ea.End   = to;
                    ea.AddExpectedError(SvnErrorCode.SVN_ERR_UNSUPPORTED_FEATURE);     // Github

                    e.Client.FileVersions(target, ea,
                                          delegate(object sender2, SvnFileVersionEventArgs e2)
                    {
                        if (n++ == 0)
                        {
                            e2.WriteTo(f1);
                        }
                        else
                        {
                            e2.WriteTo(f2);
                        }
                    });
                });

                if (!r.Succeeded)
                {
                    return(null);
                }

                if (n != 2)
                {
                    // Sloooooow workaround for SvnBridge / Codeplex

                    f1 = GetTempFile(target, from, withProgress);
                    if (f1 == null)
                    {
                        return(null); // Canceled
                    }
                    f2 = GetTempFile(target, to, withProgress);
                }
            }
            else
            {
                f1 = GetTempFile(target, from, withProgress);
                if (f1 == null)
                {
                    return(null); // Canceled
                }
                f2 = GetTempFile(target, to, withProgress);
            }

            if (string.IsNullOrEmpty(f1) || string.IsNullOrEmpty(f2))
            {
                return(null);
            }

            string[] files = new string[] { f1, f2 };

            foreach (string f in files)
            {
                if (File.Exists(f))
                {
                    File.SetAttributes(f, FileAttributes.ReadOnly);
                }
            }

            return(files);
        }
示例#7
0
        public void FileVersions_WalkChange()
        {
            SvnFileVersionsArgs a = new SvnFileVersionsArgs();
            SvnUriTarget me = new SvnUriTarget(new Uri("https://ctf.open.collab.net/svn/repos/sharpsvn/trunk/src/SharpSvn.Tests/Commands/FileVersions.cs"), 931);
            a.Start = 927;
            a.End = 928;
            int n = 0;

            Client.FileVersions(me, a,
                delegate(object sender, SvnFileVersionEventArgs e)
                {
                    GC.KeepAlive(e);
                    e.WriteTo(GetTempFile());
                    n++;
                });

            Assert.That(n, Is.EqualTo(2));
        }
示例#8
0
        public void FileVersions_WalkKeywords()
        {
            SvnSandBox sbox = new SvnSandBox(this);
            sbox.Create(SandBoxRepository.Empty);

            string wc = sbox.Wc;
            string file = Path.Combine(wc, "myFile.txt");
            string nl = Environment.NewLine;

            File.WriteAllText(file, "Line1 $Id: FileVersions.cs 2139 2012-05-19 10:21:53Z rhuijben $" + nl + "$HeadURL$" + nl + nl);

            Client.Add(file);
            Client.SetProperty(file, SvnPropertyNames.SvnKeywords, "Id\nHeadURL");
            Client.Commit(file);
            File.AppendAllText(file, "Line" + nl);
            Client.Commit(file);
            Client.SetProperty(file, SvnPropertyNames.SvnEolStyle, "native");
            Client.Commit(file);
            File.AppendAllText(file, "Line" + nl + "Line");
            Client.Commit(file);
            Client.SetProperty(file, SvnPropertyNames.SvnEolStyle, "CR");
            Client.Commit(file);

            string f2 = file + "2";
            Client.Copy(file, f2);
            SvnCommitArgs xa = new SvnCommitArgs();
            xa.LogProperties.Add("extra", "value");
            Client.Commit(wc, xa);
            Client.Update(wc);

            SvnFileVersionsArgs va;

            using (SvnClient c2 = new SvnClient())
            {
                Uri fileUri = c2.GetUriFromWorkingCopy(file);
                Uri f2Uri = c2.GetUriFromWorkingCopy(f2);

                for (int L = 0; L < 2; L++)
                {
                    va = new SvnFileVersionsArgs();
                    va.RetrieveProperties = true;
                    switch (L)
                    {
                        case 0:
                            va.Start = SvnRevision.Zero;
                            va.End = SvnRevision.Head;
                            break;
                        default:
                            break;
                    }

                    int i = 0;
                    Client.FileVersions(f2, va,
                        delegate(object sender, SvnFileVersionEventArgs e)
                        {
                            Assert.That(e.Revision, Is.EqualTo(i + 1L));
                            Assert.That(e.RepositoryRoot, Is.Not.Null);
                            Assert.That(e.Uri, Is.EqualTo(i == 5 ? f2Uri : fileUri));
                            Assert.That(e.Author, Is.EqualTo(Environment.UserName));
                            Assert.That(e.Time, Is.GreaterThan(DateTime.UtcNow - new TimeSpan(0, 0, 10, 0, 0)));
                            Assert.That(e.RevisionProperties.Count, Is.GreaterThanOrEqualTo(3));

                            if (i == 5)
                            {
                                Assert.That(e.RevisionProperties.Contains("extra"), "Contains extra property");
                                //Assert.That(e.Properties.Contains(SvnPropertyNames.SvnMergeInfo), Is.True, "Contains merge info in revision 5");
                            }
                            else
                                Assert.That(e.Properties.Contains(SvnPropertyNames.SvnMergeInfo), Is.False, "No mergeinfo");

                            MemoryStream ms1 = new MemoryStream();
                            MemoryStream ms2 = new MemoryStream();

                            e.WriteTo(ms1);
                            c2.Write(new SvnUriTarget(e.Uri, e.Revision), ms2);

                            string s1 = Encoding.UTF8.GetString(ms1.ToArray());
                            string s2 = Encoding.UTF8.GetString(ms2.ToArray());

                            //Assert.That(ms1.Length, Is.EqualTo(ms2.Length), "Export lengths equal");
                            Assert.That(s1, Is.EqualTo(s2));
                            i++;
                        });

                    Assert.That(i, Is.EqualTo(6), "Found 6 versions");
                }
            }
        }
示例#9
0
        public string[] GetTempFiles(SvnTarget target, SvnRevision from, SvnRevision to, bool withProgress)
        {
            if (target == null)
                throw new ArgumentNullException("target");
            else if (from == null)
                throw new ArgumentNullException("from");
            else if (to == null)
                throw new ArgumentNullException("to");

            string f1;
            string f2;

            if (from.RevisionType == SvnRevisionType.Number && to.RevisionType == SvnRevisionType.Number && from.Revision + 1 == to.Revision)
            {
                f1 = GetTempPath(target.FileName, from);
                f2 = GetTempPath(target.FileName, to);

                int n = 0;
                ProgressRunnerResult r = Context.GetService<IProgressRunner>().RunModal("Getting revisions",
                    delegate(object sender, ProgressWorkerArgs e)
                    {
                        SvnFileVersionsArgs ea = new SvnFileVersionsArgs();
                        ea.Start = from;
                        ea.End = to;

                        e.Client.FileVersions(target, ea,
                            delegate(object sender2, SvnFileVersionEventArgs e2)
                            {
                                if (n++ == 0)
                                    e2.WriteTo(f1);
                                else
                                    e2.WriteTo(f2);
                            });
                    });

                if (!r.Succeeded)
                    return null;

                if (n != 2)
                {
                    // Sloooooow workaround for SvnBridge / Codeplex

                    f1 = GetTempFile(target, from, withProgress);
                    if (f1 == null)
                        return null; // Canceled
                    f2 = GetTempFile(target, to, withProgress);
                }
            }
            else
            {
                f1 = GetTempFile(target, from, withProgress);
                if (f1 == null)
                    return null; // Canceled
                f2 = GetTempFile(target, to, withProgress);
            }

            if (string.IsNullOrEmpty(f1) || string.IsNullOrEmpty(f2))
                return null;

            string[] files = new string[] { f1, f2 };

            foreach (string f in files)
            {
                if (File.Exists(f))
                    File.SetAttributes(f, FileAttributes.ReadOnly);
            }

            return files;
        }
示例#10
0
        public void FileVersions_WalkKeywords()
        {
            SvnSandBox sbox = new SvnSandBox(this);

            sbox.Create(SandBoxRepository.Empty);

            string wc   = sbox.Wc;
            string file = Path.Combine(wc, "myFile.txt");
            string nl   = Environment.NewLine;

            File.WriteAllText(file, "Line1 $Id: FileVersions.cs 2139 2012-05-19 10:21:53Z rhuijben $" + nl + "$HeadURL$" + nl + nl);

            Client.Add(file);
            Client.SetProperty(file, SvnPropertyNames.SvnKeywords, "Id\nHeadURL");
            Client.Commit(file);
            File.AppendAllText(file, "Line" + nl);
            Client.Commit(file);
            Client.SetProperty(file, SvnPropertyNames.SvnEolStyle, "native");
            Client.Commit(file);
            File.AppendAllText(file, "Line" + nl + "Line");
            Client.Commit(file);
            Client.SetProperty(file, SvnPropertyNames.SvnEolStyle, "CR");
            Client.Commit(file);

            string f2 = file + "2";

            Client.Copy(file, f2);
            SvnCommitArgs xa = new SvnCommitArgs();

            xa.LogProperties.Add("extra", "value");
            Client.Commit(wc, xa);
            Client.Update(wc);

            SvnFileVersionsArgs va;

            using (SvnClient c2 = new SvnClient())
            {
                Uri fileUri = c2.GetUriFromWorkingCopy(file);
                Uri f2Uri   = c2.GetUriFromWorkingCopy(f2);

                for (int L = 0; L < 2; L++)
                {
                    va = new SvnFileVersionsArgs();
                    va.RetrieveProperties = true;
                    switch (L)
                    {
                    case 0:
                        va.Start = SvnRevision.Zero;
                        va.End   = SvnRevision.Head;
                        break;

                    default:
                        break;
                    }

                    int i = 0;
                    Client.FileVersions(f2, va,
                                        delegate(object sender, SvnFileVersionEventArgs e)
                    {
                        Assert.That(e.Revision, Is.EqualTo(i + 1L));
                        Assert.That(e.RepositoryRoot, Is.Not.Null);
                        Assert.That(e.Uri, Is.EqualTo(i == 5 ? f2Uri : fileUri));
                        Assert.That(e.Author, Is.EqualTo(Environment.UserName));
                        Assert.That(e.Time, Is.GreaterThan(DateTime.UtcNow - new TimeSpan(0, 0, 10, 0, 0)));
                        Assert.That(e.RevisionProperties.Count, Is.GreaterThanOrEqualTo(3));

                        if (i == 5)
                        {
                            Assert.That(e.RevisionProperties.Contains("extra"), "Contains extra property");
                            //Assert.That(e.Properties.Contains(SvnPropertyNames.SvnMergeInfo), Is.True, "Contains merge info in revision 5");
                        }
                        else
                        {
                            Assert.That(e.Properties.Contains(SvnPropertyNames.SvnMergeInfo), Is.False, "No mergeinfo");
                        }

                        MemoryStream ms1 = new MemoryStream();
                        MemoryStream ms2 = new MemoryStream();

                        e.WriteTo(ms1);
                        c2.Write(new SvnUriTarget(e.Uri, e.Revision), ms2);

                        string s1 = Encoding.UTF8.GetString(ms1.ToArray());
                        string s2 = Encoding.UTF8.GetString(ms2.ToArray());

                        //Assert.That(ms1.Length, Is.EqualTo(ms2.Length), "Export lengths equal");
                        Assert.That(s1, Is.EqualTo(s2));
                        i++;
                    });

                    Assert.That(i, Is.EqualTo(6), "Found 6 versions");
                }
            }
        }