Example #1
0
        public void ImplicitConversion_RevisionsToString_ExtractsTheSpecification()
        {
            RevSpec revSpec = RevSpec.Range(17, 42);
            string  value   = revSpec;

            Assert.That(value, Is.EqualTo("17:42"));
        }
Example #2
0
        public void Not_OnSimpleRange_CreatesCorrectExpression()
        {
            string       output   = (!RevSpec.Range(2, 7)).ToString();
            const string expected = "not 2:7";

            Assert.That(output, Is.EqualTo(expected));
        }
Example #3
0
        public void Log_WithMultipleRevisionFilters_OnlyIncludeMatchingChangesets()
        {
            Repo.Init();
            foreach (string filename in new[]
            {
                "test1.txt", "test2.txt", "test3.txt"
            })
            {
                File.WriteAllText(Path.Combine(Repo.Path, filename), "dummy content");
                Repo.Commit(
                    filename + " added", new CommitCommand
                {
                    AddRemove = true,
                });
            }

            Changeset[] log = Repo.Log(
                new LogCommand
            {
                Revisions =
                {
                    RevSpec.Range(RevSpec.Single(0), RevSpec.Single(0)),
                    RevSpec.Range(RevSpec.Single(2), RevSpec.Single(2)),
                },
            }).ToArray();

            Assert.That(log.Length, Is.EqualTo(2));
        }
Example #4
0
        public void Pull_FromOtherWithRevisionSpecification_OnlyPullsInRelevantChanges()
        {
            WriteTextFileAndCommit(Repo1, "test1.txt", "initial contents", "initial commit", true);
            WriteTextFileAndCommit(Repo1, "test1.txt", "changed contents", "2nd commit", false);
            WriteTextFileAndCommit(Repo1, "test1.txt", "changed contents again", "3rd commit", false);

            Repo2.Pull(
                Repo1.Path, new PullCommand
            {
                Revisions =
                {
                    RevSpec.Single(1),
                },
            });

            Changeset[] pulledChangesets   = Repo2.Log().OrderBy(c => c.RevisionNumber).ToArray();
            Changeset[] originalChangesets = Repo1.Log(
                new LogCommand
            {
                Revisions =
                {
                    RevSpec.Range(0, 1),
                },
            }).OrderBy(c => c.RevisionNumber).ToArray();
            CollectionAssert.AreEqual(pulledChangesets, originalChangesets);
        }
Example #5
0
        public void Range_WithTwoRevisionsByRevisionNumber_ProducesCorrectRevisionSpecification()
        {
            string       output   = RevSpec.Range(2, 7).ToString();
            const string expected = "2:7";

            Assert.That(output, Is.EqualTo(expected));
        }
Example #6
0
        public void And_WithOtherRevisions_ProducesCorrectRevisionSpecification()
        {
            RevSpec rev1   = RevSpec.Range(2, 7);
            RevSpec rev2   = RevSpec.Range(10, 14);
            RevSpec result = rev1.And(rev2);

            Assert.That(result.ToString(), Is.EqualTo("2:7 and 10:14"));
        }
Example #7
0
        public void Branches_ForRange_ProducesCorrectRevisionSpecification()
        {
            RevSpec revSpec = RevSpec.Range(2, 17);

            string output = revSpec.Branches.ToString();

            Assert.That(output, Is.EqualTo("branch(2:17)"));
        }
Example #8
0
        public void Except_ProducesCorrectRevisionSpecification()
        {
            RevSpec include = RevSpec.Range(2, 7);
            RevSpec exclude = RevSpec.Single(5);
            RevSpec result  = include.Except(exclude);

            Assert.That(result.ToString(), Is.EqualTo("2:7 - 5"));
        }
Example #9
0
        public void Children_OfRange_ProducesCorrectRevisionSpecification()
        {
            RevSpec revSpec = RevSpec.Range(2, 17);

            string output = revSpec.Children.ToString();

            Assert.That(output, Is.EqualTo("children(2:17)"));
        }
        public RevisionInfo[] GetRevisions(RevisionId fromChangeset, RevisionId toChangeset)
        {
            var from          = new RevSpec(fromChangeset.Value);
            var to            = new RevSpec(toChangeset.Value);
            var command       = new LogCommand().WithRevision(RevSpec.Range(from, to)).WithIncludePathActions();
            var revisionInfos = _repository.Log(command)
                                .Where(ch => ch.Timestamp >= fromChangeset.Time.Value && ch.Timestamp <= toChangeset.Time.Value)
                                .Select(ch => ch.ToRevisionInfo())
                                .ToArray();

            return(revisionInfos);
        }
Example #11
0
        public IEnumerable <ChangeSet> GetChanges(int index, int limit)
        {
            int max = Repository.Tip().RevisionNumber;

            if (index > max)
            {
                return(Enumerable.Empty <ChangeSet>());
            }

            int from = max - index;
            int to   = Math.Max(0, from - limit);
            var spec = RevSpec.Range(from, to);

            return(Repository.Log(spec).Select(CreateChangeSet));
        }
Example #12
0
        private static void CheckRevSpecMethod(PropertyInfo property, Type type, MethodInfo method)
        {
            var input = new[]
            {
                RevSpec.Single(42), RevSpec.Range(RevSpec.Single(17), RevSpec.Single(42))
            };

            foreach (RevSpec value in input)
            {
                object instance = CreateInstance(type);
                method.Invoke(
                    instance, new object[]
                {
                    value
                });
                object output = property.GetValue(instance, null);

                Assert.That(output, Is.EqualTo(value));
            }
        }
        public IEnumerable <RevisionRange> GetFromAndBefore(RevisionId fromRevision, RevisionId toRevision, int pageSize)
        {
            var command = new LogCommand();

            if (string.IsNullOrEmpty(fromRevision.Value))
            {
                if (string.IsNullOrEmpty(toRevision.Value))
                {
                    command = command.WithAdditionalArgument("-d {0:yyyy-MM-dd} to {1:yyyy-MM-dd}".Fmt(fromRevision.Time.Value, toRevision.Time.Value));
                }
                else
                {
                    var to = new RevSpec(toRevision.Value);
                    command = command.WithRevision(RevSpec.To(to));
                    command = command.WithAdditionalArgument("-d >{0:yyyy-MM-dd}".Fmt(fromRevision.Time.Value));
                }
            }
            else
            {
                var from = new RevSpec(fromRevision.Value);
                if (string.IsNullOrEmpty(toRevision.Value))
                {
                    command = command.WithAdditionalArgument("-d <{0:yyyy-MM-dd}".Fmt(toRevision.Time.Value));
                    command = command.WithRevision(RevSpec.From(from));
                }
                else
                {
                    var to = new RevSpec(toRevision.Value);
                    command = command.WithRevision(RevSpec.Range(from, to));
                }
            }

            var pages = _repository.Log(command)
                        .OrderBy(ch => ch.Timestamp)
                        .ToArray()
                        .Split(pageSize);

            var result = pages.Select(page => new RevisionRange(page.First().ToRevisionId(), page.Last().ToRevisionId()));

            return(result);
        }
Example #14
0
        private static void CheckRevSpecCollectionMethod(PropertyInfo property, Type type, MethodInfo method)
        {
            var input = new[]
            {
                RevSpec.Single(42), RevSpec.Range(RevSpec.Single(17), RevSpec.Single(42))
            };

            foreach (RevSpec value in input)
            {
                object instance = CreateInstance(type);
                method.Invoke(
                    instance, new object[]
                {
                    value
                });
                var output = (Collection <RevSpec>)property.GetValue(instance, null);

                CollectionAssert.AreEqual(
                    output, new[]
                {
                    value
                });
            }
        }
Example #15
0
 public void Range_WithNullFromRevision_ThrowsArgumentNullException()
 {
     Assert.Throws <ArgumentNullException>(() => RevSpec.Range(null, 7));
 }
 /// <summary>
 /// Create a <see cref="HgLogQuery" /> that includes a range
 /// of commits between <paramref name="fromHash"/> and <paramref name="toHash"/>.
 /// </summary>
 /// <param name="fromHash">Hash of first commit to include.</param>
 /// <param name="toHash">Hash of last commit to include.</param>
 public HgLogQuery Range(string fromHash, string toHash)
 {
     return(RevSpec.Range(
                RevSpec.Single(fromHash),
                RevSpec.Single(toHash)));
 }
Example #17
0
        public void Except_WithNullRevisions_ThrowsArgumentNullException()
        {
            RevSpec include = RevSpec.Range(2, 7);

            Assert.Throws <ArgumentNullException>(() => include.Except(null));
        }
Example #18
0
 public void Range_WithNullToRevision_ThrowsArgumentNullException()
 {
     Assert.Throws <ArgumentNullException>(() => RevSpec.Range(2, null));
 }
Example #19
0
        public void And_WithNullRevisions_ThrowsArgumentNullException()
        {
            RevSpec rev = RevSpec.Range(2, 7);

            Assert.Throws <ArgumentNullException>(() => rev.And(null));
        }