public FileContent GetCvsRevision(FileRevision f) { m_ensureAllDirectories.Wait(); InvokeCvs("-f", "-Q", "update", "-r" + f.Revision.ToString(), f.File.Name); var dataPath = Path.Combine(m_sandboxPath, f.File.Name.Replace('/', '\\')); return new FileContent(f.File.Name, new FileContentData(File.ReadAllBytes(dataPath))); }
public FileContent GetCvsRevision(FileRevision f) { m_ensureAllDirectories.Wait(); InvokeCvs("-f", "-Q", "update", "-r" + f.Revision.ToString(), f.File.Name); var dataPath = Path.Combine(m_sandboxPath, f.File.Name.Replace('/', '\\')); return(new FileContent(f.File.Name, new FileContentData(File.ReadAllBytes(dataPath)))); }
private void CreateHeadOnlyCommit(string branch, BranchStreamCollection streams, FileCollection allFiles, string branchMergeFrom) { var headOnlyState = m_headOnlyState[branch]; var commitId = String.Format("headonly-{0}", branch); var commit = new Commit(commitId); var message = String.Format("Adding head-only files to {0}", m_branchRenamer.Process(branch)); foreach (var file in headOnlyState.LiveFiles.OrderBy(i => i, StringComparer.OrdinalIgnoreCase)) { var fileRevision = new FileRevision(allFiles[file], headOnlyState[file], mergepoint: Revision.Empty, time: DateTime.Now, author: "", commitId: commitId); fileRevision.AddMessage(message); commit.Add(fileRevision); } // check for a merge if (branchMergeFrom != null) { Commit mergeSource = streams.Head(branchMergeFrom); if (mergeSource.CommitId.StartsWith("headonly-")) { commit.MergeFrom = mergeSource; // check for deleted files var fileLookup = new HashSet <string>(commit.Select(r => r.File.Name)); foreach (var r in mergeSource) { if (!fileLookup.Contains(r.File.Name)) { var fileRevision = new FileRevision( file: r.File, revision: Revision.Empty, // a bit lazy, but I think we can get away with it mergepoint: Revision.Empty, time: DateTime.Now, author: "", commitId: commitId, isDead: true); fileRevision.AddMessage(message); commit.Add(fileRevision); } } } } if (commit.Any()) { m_log.WriteLine("Added commit {0}", commitId); streams.AppendCommit(commit); } }
public FileContent GetCvsRevision(FileRevision f) { var cachedPath = GetCachedRevisionPath(f); if (File.Exists(cachedPath)) { var bytes = File.ReadAllBytes(cachedPath); return new FileContent(f.File.Name, new FileContentData(bytes, bytes.Length)); } else { var contents = m_repository.GetCvsRevision(f); UpdateCache(cachedPath, contents); return contents; } }
public void GetCvsRevision_CallsUnderlyingIfFileMissing() { var f = new FileRevision(new FileInfo("file.txt"), Revision.Create("1.1"), mergepoint: Revision.Empty, time: DateTime.Now, author: "fred", commitId: "c1"); var repo = MockRepository.GenerateMock<ICvsRepository>(); repo.Expect(r => r.GetCvsRevision(f)).Return(new FileContent("file.txt", FileContentData.Empty)); var cache = new CvsRepositoryCache(m_temp.Path, repo); cache.GetCvsRevision(f); repo.VerifyAllExpectations(); }
public FileContent GetCvsRevision(FileRevision f) { var cachedPath = GetCachedRevisionPath(f); if (File.Exists(cachedPath)) { var bytes = File.ReadAllBytes(cachedPath); return(new FileContent(f.File.Name, new FileContentData(bytes, bytes.Length))); } else { var contents = m_repository.GetCvsRevision(f); UpdateCache(cachedPath, contents); return(contents); } }
public void GetCvsRevision_ReturnsExistingFileIfPresent() { var f = new FileRevision(new FileInfo("file.txt"), Revision.Create("1.1"), mergepoint: Revision.Empty, time: DateTime.Now, author: "fred", commitId: "c1"); var contents = new FileContentData(new byte[] { 1, 2, 3, 4 }, 4); var repo1 = MockRepository.GenerateStub<ICvsRepository>(); repo1.Stub(r => r.GetCvsRevision(f)).Return(new FileContent("file.txt", contents)); var cache1 = new CvsRepositoryCache(m_temp.Path, repo1); cache1.GetCvsRevision(f); // create a second cache var repo2 = MockRepository.GenerateMock<ICvsRepository>(); var cache2 = new CvsRepositoryCache(m_temp.Path, repo1); var data = cache2.GetCvsRevision(f); repo2.AssertWasNotCalled(r => r.GetCvsRevision(f)); Assert.AreNotSame(data.Data, contents); Assert.IsTrue(data.Data.Equals(contents)); }
private Task <FileContent> StartNextFile(FileRevision r) { return(Task <FileContent> .Factory.StartNew(() => m_repository.GetCvsRevision(r))); }
private string MakeCommitId(FileRevision r) { return String.Format("{0:yyMMdd}-{1}-{2}", r.Time, r.Author, m_nextCommitId++); }
private string GetCachedRevisionPath(FileRevision f) { var filePath = f.File.Name.Replace('/', '\\'); return Path.Combine(m_cacheDir, filePath, f.Revision.ToString()); }
public void Add(FileRevision revision) { m_revisions.Add(revision.Message, revision); }
/// <summary> /// Parse the log returning a list of the individual commits to the individual files. /// </summary> public IEnumerable <FileRevision> Parse() { var state = State.Start; FileInfo currentFile = null; Revision revision = Revision.Empty; FileRevision commit = null; m_repo = GetCvsRepo(); foreach (var line in m_reader) { switch (state) { case State.Start: if (line.StartsWith("RCS file: ")) { currentFile = new FileInfo(ExtractFileName(line)); m_files.Add(currentFile); state = State.InFileHeader; } break; case State.InFileHeader: if (line == LogSeparator) { state = State.ExpectCommitRevision; } else if (line == "symbolic names:") { state = State.InTags; } break; case State.InTags: if (!line.StartsWith("\t")) { state = State.InFileHeader; } else { var tagMatch = Regex.Match(line, @"^\t(\S+): (\S+)"); if (!tagMatch.Success) { throw MakeParseException("Invalid tag line: '{0}'", line); } var tagName = tagMatch.Groups[1].Value; var tagRevision = Revision.Create(tagMatch.Groups[2].Value); if (tagRevision.IsBranch) { if (m_branchMatcher.Match(tagName)) { currentFile.AddBranchTag(tagName, tagRevision); } else { m_excludedBranches.Add(tagName); } } else { currentFile.AddTag(tagName, tagRevision); } } break; case State.ExpectCommitRevision: if (line.StartsWith("revision ")) { revision = Revision.Create(line.Substring(9)); state = State.ExpectCommitInfo; } else { throw MakeParseException("Expected revision line, found '{0}'", line); } break; case State.ExpectCommitInfo: commit = ParseFields(currentFile, revision, line); state = State.ExpectCommitMessage; break; case State.ExpectCommitMessage: if (line == LogSeparator) { if (commit != null) { yield return(commit); } state = State.ExpectCommitRevision; } else if (line == FileSeparator) { if (commit != null) { yield return(commit); } state = State.Start; } else if (!line.StartsWith("branches: ")) { if (commit != null) { commit.AddMessage(line); } } break; } } }
private static FileContent CreateMockContent(FileRevision f) { var data = Encoding.UTF8.GetBytes(String.Format("{0} r{1}", f.File.Name, f.Revision.ToString())); var content = new FileContentData(data, data.Length); return new FileContent(f.File.Name, content); }
private void CreateHeadOnlyCommit(string branch, BranchStreamCollection streams, FileCollection allFiles, string branchMergeFrom) { var headOnlyState = m_headOnlyState[branch]; var commitId = String.Format("headonly-{0}", branch); var commit = new Commit(commitId); var message = String.Format("Adding head-only files to {0}", m_branchRenamer.Process(branch)); foreach (var file in headOnlyState.LiveFiles.OrderBy(i => i, StringComparer.OrdinalIgnoreCase)) { var fileRevision = new FileRevision(allFiles[file], headOnlyState[file], mergepoint: Revision.Empty, time: DateTime.Now, author: "", commitId: commitId); fileRevision.AddMessage(message); commit.Add(fileRevision); } // check for a merge if (branchMergeFrom != null) { Commit mergeSource = streams.Head(branchMergeFrom); if (mergeSource.CommitId.StartsWith("headonly-")) { commit.MergeFrom = mergeSource; // check for deleted files var fileLookup = new HashSet<string>(commit.Select(r => r.File.Name)); foreach (var r in mergeSource) { if (!fileLookup.Contains(r.File.Name)) { var fileRevision = new FileRevision( file: r.File, revision: Revision.Empty, // a bit lazy, but I think we can get away with it mergepoint: Revision.Empty, time: DateTime.Now, author: "", commitId: commitId, isDead: true); fileRevision.AddMessage(message); commit.Add(fileRevision); } } } } if (commit.Any()) { m_log.WriteLine("Added commit {0}", commitId); streams.AppendCommit(commit); } }
private string GetCachedRevisionPath(FileRevision f) { var filePath = f.File.Name.Replace('/', '\\'); return(Path.Combine(m_cacheDir, filePath, f.Revision.ToString())); }
private string MakeCommitId(FileRevision r) { return(String.Format("{0:yyMMdd}-{1}-{2}", r.Time, r.Author, m_nextCommitId++)); }
private Task<FileContent> StartNextFile(FileRevision r) { return Task<FileContent>.Factory.StartNew(() => m_repository.GetCvsRevision(r)); }