public void GetRevision_WithTwoCommits_HasExpectedRevisionValuesForSecondCommit() { using (var testRoot = new TemporaryFolder("RepositoryTests")) { HgRepository.CreateRepositoryInExistingDir(testRoot.Path, _progress); var repo = new HgRepository(testRoot.Path, new NullProgress()); Assert.That(repo.Identifier, Is.Null); var rev = repo.GetAllRevisions().FirstOrDefault(); Assert.That(rev, Is.Null); using (var file1 = testRoot.GetNewTempFile(true)) { repo.AddAndCheckinFile(file1.Path); using (var file2 = testRoot.GetNewTempFile(true)) { repo.AddAndCheckinFile(file2.Path); rev = repo.GetRevisionWorkingSetIsBasedOn(); Assert.That(rev.Number.LocalRevisionNumber, Is.EqualTo("1")); Assert.That(rev.Number.Hash.Length, Is.EqualTo(12)); Assert.That(rev.Number.Hash, Is.EqualTo(rev.Number.LongHash.Substring(0, 12))); // We can't test for the value of rev.Number.LongHash, // since Mercurial makes up a unique hash, // that is not knowable ahead of time. } } } }
void RevisionGetter_DoWork(object sender, DoWorkEventArgs e) { lock (DiscoveredRevisionsQueue) { DiscoveredRevisionsQueue.Clear(); } //NOte: at this point, we're not really getting revisions little by little, //we're getting them all at once. Is it still worth it? Maybe not. //after all, the UI could just request all items, then use a timer to //add them in the background, if needed. In order to actually get them //little by little, we'd have to go all the way down to hg, and see if we //can get it to page its results. Or at least we'd have to "page" the making //of revision objects. //ANother idea: get the first batch of, say 20 fast, queue those up, then get the rest. //This could be done by making a GetFirstNRevisions(20), which would use // the --limit command given to hg log. The trick, then //is when we call GetAllRevisions(), we need to not add those first (up to) 20 again. foreach (var revision in _repository.GetAllRevisions()) { if (_options.RevisionsToShowFilter(revision)) { lock (DiscoveredRevisionsQueue) { this.DiscoveredRevisionsQueue.Enqueue(revision); } } } }
public void GetFilesInRevision_OnlyOneRevisionInRepo_GivesAllFiles() { using (var testRoot = new TemporaryFolder("ChorusRetrieveTest")) using (var f = new TempFileFromFolder(testRoot)) { File.WriteAllText(f.Path, "one"); HgRepository.CreateRepositoryInExistingDir(testRoot.Path, _progress); var repo = new HgRepository(testRoot.Path, _progress); repo.AddAndCheckinFile(f.Path); repo.Commit(true, "initial"); var revisions = repo.GetAllRevisions(); Assert.AreEqual(1, revisions.Count); var files = repo.GetFilesInRevision(revisions[0]); Assert.AreEqual(1, files.Count()); Assert.AreEqual(f.Path, files.First().FullPath); } }
public void Setup() { _progress = new ConsoleProgress(); _testRoot = new TemporaryFolder("ChorusRetrieveTest"); _tempFile = new TempFileFromFolder(_testRoot); File.WriteAllText(_tempFile.Path,"one"); HgRepository.CreateRepositoryInExistingDir(_testRoot.Path,_progress); _repo = new HgRepository(_testRoot.Path, new NullProgress()); _repo.AddAndCheckinFile(_tempFile.Path); _repo.Commit(true, "initial"); File.WriteAllText(_tempFile.Path, "two"); _repo.AddAndCheckinFile(_tempFile.Path); _repo.Commit(true, "changed to two"); _changesets = _repo.GetAllRevisions(); Assert.AreEqual(2, _changesets.Count); }
public void GetFilesInRevision_OnlyOneRevisionInRepo_GivesAllFiles() { using (var testRoot = new TemporaryFolder("ChorusRetrieveTest")) using (var f = new TempFileFromFolder(testRoot)) { File.WriteAllText(f.Path, "one"); HgRepository.CreateRepositoryInExistingDir(testRoot.Path,_progress); var repo = new HgRepository(testRoot.Path, _progress); repo.AddAndCheckinFile(f.Path); repo.Commit(true, "initial"); var revisions = repo.GetAllRevisions(); Assert.AreEqual(1, revisions.Count); var files = repo.GetFilesInRevision(revisions[0]); Assert.AreEqual(1, files.Count()); Assert.AreEqual(f.Path, files.First().FullPath); } }
public void Setup() { _progress = new ConsoleProgress(); _testRoot = new TemporaryFolder("ChorusRetrieveTest"); _tempFile = new TempFileFromFolder(_testRoot); File.WriteAllText(_tempFile.Path, "one"); HgRepository.CreateRepositoryInExistingDir(_testRoot.Path, _progress); _repo = new HgRepository(_testRoot.Path, new NullProgress()); _repo.AddAndCheckinFile(_tempFile.Path); _repo.Commit(true, "initial"); File.WriteAllText(_tempFile.Path, "two"); _repo.AddAndCheckinFile(_tempFile.Path); _repo.Commit(true, "changed to two"); _changesets = _repo.GetAllRevisions(); Assert.AreEqual(2, _changesets.Count); }
public void GetRevision_WithOneCommit_HasExpectedRevisionValues() { using (var testRoot = new TemporaryFolder("RepositoryTests")) { HgRepository.CreateRepositoryInExistingDir(testRoot.Path, _progress); var repo = new HgRepository(testRoot.Path, new NullProgress()); Assert.That(repo.Identifier, Is.Null); var rev = repo.GetAllRevisions().FirstOrDefault(); Assert.That(rev, Is.Null); using (var f = testRoot.GetNewTempFile(true)) { repo.AddAndCheckinFile(f.Path); rev = repo.GetRevisionWorkingSetIsBasedOn(); Assert.That(rev.Number.LocalRevisionNumber, Is.EqualTo("0")); Assert.That(rev.Number.LongHash, Is.EqualTo(repo.Identifier)); Assert.That(rev.Number.Hash.Length, Is.EqualTo(12)); Assert.That(rev.Number.Hash, Is.EqualTo(repo.Identifier.Substring(0, 12))); Assert.That(rev.Number.Hash, Is.EqualTo(rev.Number.LongHash.Substring(0, 12))); } } }
public void GetFilesInRevision_MultipleRevisionsInRepo_GivesCorrectFiles() { using (var testRoot = new TemporaryFolder("ChorusRetrieveTest")) { var temp = testRoot.Combine("filename with spaces"); File.WriteAllText(temp, "one"); using (var f = TempFile.TrackExisting(temp)) { HgRepository.CreateRepositoryInExistingDir(testRoot.Path, _progress); var repo = new HgRepository(testRoot.Path, _progress); repo.AddAndCheckinFile(f.Path); repo.Commit(true, "initial"); File.WriteAllText(f.Path, "one two"); repo.Commit(true, "second"); var revisions = repo.GetAllRevisions(); Assert.AreEqual(2, revisions.Count); var files = repo.GetFilesInRevision(revisions[0]); Assert.AreEqual(1, files.Count()); Assert.AreEqual(f.Path, files.First().FullPath); } } }
public void GetFilesInRevision_MultipleRevisionsInRepo_GivesCorrectFiles() { using (var testRoot = new TemporaryFolder("ChorusRetrieveTest")) { var temp = testRoot.Combine("filename with spaces"); File.WriteAllText(temp, "one"); using (var f = TempFile.TrackExisting(temp)) { HgRepository.CreateRepositoryInExistingDir(testRoot.Path,_progress); var repo = new HgRepository(testRoot.Path, _progress); repo.AddAndCheckinFile(f.Path); repo.Commit(true, "initial"); File.WriteAllText(f.Path, "one two"); repo.Commit(true, "second"); var revisions = repo.GetAllRevisions(); Assert.AreEqual(2, revisions.Count); var files = repo.GetFilesInRevision(revisions[0]); Assert.AreEqual(1, files.Count()); Assert.AreEqual(f.Path, files.First().FullPath); } } }
private List <Revision> GetCommonBaseHashesWithRemoteRepo(bool useCache) { if (useCache && LastKnownCommonBases.Count > 0) { return(LastKnownCommonBases); } int offset = 0; var localRevisions = new MultiMap <string, Revision>(); foreach (var rev in _repo.GetAllRevisions()) { localRevisions.Add(rev.Branch, rev); } //The goal here is to to return the first common revision of each branch. var commonBases = new List <Revision>(); var localBranches = new List <string>(localRevisions.Keys); while (commonBases.Count < localRevisions.Keys.Count()) { var remoteRevisions = GetRemoteRevisions(offset, RevisionRequestQuantity); if (remoteRevisions.Keys.Count() == 1 && remoteRevisions[remoteRevisions.Keys.First()].First().Split(':')[0] == "0") { // special case when remote repo is empty (initialized with no changesets) return(new List <Revision>()); } var branchesMatched = new List <string>(); // track branches that we've already found a common revision for foreach (var branch in localBranches) { var localList = localRevisions[branch]; var remoteList = remoteRevisions[branch]; foreach (var revision in remoteList) { var remoteRevision = revision; //copy to local for use in predicate var commonRevision = localList.Find(localRev => localRev.Number.Hash == remoteRevision); if (commonRevision != null) { commonBases.Add(commonRevision); branchesMatched.Add(branch); // found a common revision for this branch break; } } } localBranches.RemoveAll(branchesMatched.Contains); // stop looking for common revisions in branches we matched if (remoteRevisions.Count() < RevisionRequestQuantity) { //we did not find a common revision for each branch, but we ran out of revisions from the repo break; } offset += RevisionRequestQuantity; } // If we have found no common revisions at this point, the remote repo is unrelated if (commonBases.Count == 0) { return(null); } LastKnownCommonBases = commonBases; return(commonBases); }
public void GetAllRevisionss_BeforeAnySyncing_EmptyHistory() { List <Revision> items = _repository.GetAllRevisions(); Assert.AreEqual(0, items.Count); }
public HgResumeApiResponse Execute(string method, HgResumeApiParameters request, byte[] bytesToWrite, int secondsBeforeTimeout) { ValidateParameters(method, request, bytesToWrite, secondsBeforeTimeout); _executeCount++; if (method == "finishPullBundle") { if (CurrentTip != OriginalTip) { PrepareBundle(HgResumeTransport.GetHashStringsFromRevisions(_repo.BranchingHelper.GetBranches())); return(ApiResponses.Reset()); // repo changed in between pulls } return(ApiResponses.Custom(HttpStatusCode.OK)); } if (method == "getRevisions") { IEnumerable <string> revisions = _repo.GetAllRevisions().Select(rev => rev.Number.Hash + ':' + rev.Branch); return(ApiResponses.Revisions(string.Join("|", revisions.ToArray()))); } if (method == "pullBundleChunk") { if (_cancelCount == _executeCount) { _progress.CancelRequested = true; return(ApiResponses.Failed("")); } if (_failCount == _executeCount) { return(ApiResponses.Failed("")); } if (_timeoutList.Contains(_executeCount)) { return(null); } if (_serverUnavailableList.Any(i => i.ExecuteCount == _executeCount)) { return(ApiResponses.NotAvailable( _serverUnavailableList.Where(i => i.ExecuteCount == _executeCount).First().Message )); } if (Array.BinarySearch(request.BaseHashes, 0, request.BaseHashes.Length, CurrentTip) >= 0) { return(ApiResponses.PullNoChange()); } var bundleFileInfo = new FileInfo(_helper.BundlePath); if (bundleFileInfo.Exists && bundleFileInfo.Length == 0 || !bundleFileInfo.Exists) { PrepareBundle(request.BaseHashes); } //int offset = Convert.ToInt32(request["offset"]); //int chunkSize = Convert.ToInt32(request["chunkSize"]); var bundleFile = new FileInfo(_helper.BundlePath); if (request.StartOfWindow >= bundleFile.Length) { return(ApiResponses.Failed("offset greater than bundleSize")); } var chunk = _helper.GetChunk(request.StartOfWindow, request.ChunkSize); return(ApiResponses.PullOk(Convert.ToInt32(bundleFile.Length), chunk)); } return(ApiResponses.Custom(HttpStatusCode.InternalServerError)); }
public HgResumeApiResponse Execute(string method, HgResumeApiParameters request, byte[] bytesToWrite, int secondsBeforeTimeout) { ValidateParameters(method, request, bytesToWrite, secondsBeforeTimeout); if (method == "getRevisions") { IEnumerable <Revision> revisions = _repo.GetAllRevisions(); if (revisions.Count() == 0) { return(ApiResponses.Revisions("0:default")); } var revisionStrings = _repo.GetAllRevisions().Select(rev => rev.Number.Hash + ':' + rev.Branch); return(ApiResponses.Revisions(string.Join("|", revisionStrings.ToArray()))); } if (method == "finishPushBundle") { return(ApiResponses.PushComplete()); } if (method == "pushBundleChunk") { _executeCount++; if (_cancelCount == _executeCount) { _progress.CancelRequested = true; return(ApiResponses.Failed("")); } if (_failCount == _executeCount) { return(ApiResponses.Failed("")); } if (_timeoutList.Contains(_executeCount)) { return(null); } if (_serverUnavailableList.Any(i => i.ExecuteCount == _executeCount)) { return(ApiResponses.NotAvailable( _serverUnavailableList.Where(i => i.ExecuteCount == _executeCount).First().Message )); } _helper = new PullStorageManager(_localStorage.Path, request.TransId); //int bundleSize = Convert.ToInt32(parameters["bundleSize"]); //int offset = Convert.ToInt32(parameters["offset"]); //int chunkSize = bytesToWrite.Length; _helper.WriteChunk(request.StartOfWindow, bytesToWrite); if (request.StartOfWindow + request.ChunkSize == request.BundleSize) { if (_repo.Unbundle(_helper.BundlePath)) { return(ApiResponses.PushComplete()); } return(ApiResponses.Reset()); } if (request.StartOfWindow + request.ChunkSize < request.BundleSize) { return(ApiResponses.PushAccepted(_helper.StartOfWindow)); } return(ApiResponses.Failed("offset + chunkSize > bundleSize !")); } return(ApiResponses.Custom(HttpStatusCode.InternalServerError)); }