private string isRenamed(string leftcommit, string rightcommit, string filename, bool leftsidename, out bool moved, GitLabSharp.Entities.Comparison comparison) { FileRevision fileRevision = new FileRevision(filename, leftsidename ? leftcommit : rightcommit); string fileRevisionPath = _fileCache.GetFileRevisionPath(fileRevision); string fileContent = System.IO.File.ReadAllText(fileRevisionPath); foreach (GitLabSharp.Entities.DiffStruct diff in comparison.Diffs) { if (leftsidename && filename == diff.Old_Path) { FileRevision oppositeRevision = new FileRevision(diff.New_Path, rightcommit); string oppositeRevisionPath = _fileCache.GetFileRevisionPath(oppositeRevision); string oppositeFileContent = oppositeRevisionPath == String.Empty ? String.Empty : System.IO.File.ReadAllText(oppositeRevisionPath); moved = fileContent == oppositeFileContent && diff.Old_Path != diff.New_Path; return(diff.New_Path); } else if (!leftsidename && filename == diff.New_Path) { FileRevision oppositeRevision = new FileRevision(diff.Old_Path, leftcommit); string oppositeRevisionPath = _fileCache.GetFileRevisionPath(oppositeRevision); string oppositeFileContent = oppositeRevisionPath == String.Empty ? String.Empty : System.IO.File.ReadAllText(oppositeRevisionPath); moved = fileContent == oppositeFileContent && diff.Old_Path != diff.New_Path; return(diff.Old_Path); } } moved = false; return(filename); }
internal string GetFileRevisionPath(FileRevision fileRevision) { if (!doesFileRevisionExist(fileRevision)) { return(string.Empty); } return(getFileRevisionPath(fileRevision)); }
private string getFilePath(string sha, string gitFilepath, bool isDummy) { if (String.IsNullOrEmpty(gitFilepath)) { return(String.Empty); } FileRevision fileRevision = new FileRevision(gitFilepath + (isDummy ? DummyRevisionSuffix : ""), sha); return(_fileStorage.FileCache.GetFileRevisionPath(fileRevision)); }
protected override object runCommand(GitShowRevisionArguments arguments) { FileRevision fileRevision = new FileRevision(arguments.Filename, arguments.Sha); string fileRevisionPath = _fileCache.GetFileRevisionPath(fileRevision); try { string content = System.IO.File.ReadAllText(fileRevisionPath); return(StringUtils.ConvertNewlineWindowsToUnix(content).Split('\n')); } catch (Exception ex) { throw new GitCommandServiceInternalException(ex); } }
private bool createDummyRevision(string sha, string gitFilepath) { FileRevision fileRevision = new FileRevision(gitFilepath, sha); if (!_fileStorage.FileCache.ContainsFileRevision(fileRevision)) { try { _fileStorage.FileCache.WriteFileRevision(gitFilepath + DummyRevisionSuffix, sha, Array.Empty <byte>()); return(true); } catch (FileStorageRevisionCacheException ex) { throw new ArgumentConversionException(String.Format("Cannot create a dummy revision for {0}", gitFilepath), ex); } } return(false); }
public FullContextDiff GetFullContextDiff(string leftSHA, string rightSHA, string leftFileName, string rightFileName) { FileRevision leftRevision = new FileRevision(leftSHA, leftFileName); string leftRevisionPath = _fileCache.GetFileRevisionPath(leftRevision); if (String.IsNullOrEmpty(leftRevisionPath)) { throw new FullContextDiffProviderException("Cannot obtain left file revision path", null); } FileRevision rightRevision = new FileRevision(leftSHA, leftFileName); string rightRevisionPath = _fileCache.GetFileRevisionPath(leftRevision); if (String.IsNullOrEmpty(rightRevisionPath)) { throw new FullContextDiffProviderException("Cannot obtain right file revision path", null); } System.IO.File.ReadLines }
public void writeFileRevision(string path, string sha, byte[] content) { FileRevision fileRevision = new FileRevision(path, sha); string fileRevisionPath = getFileRevisionPath(fileRevision); try { string fileRevisionDirName = System.IO.Path.GetDirectoryName(fileRevisionPath); if (!Directory.Exists(fileRevisionDirName)) { Directory.CreateDirectory(fileRevisionDirName); } } catch (Exception ex) // Any exceptio Path.GetDirectoryName() or Directory.CreateDirectory() { throw new FileStorageRevisionCacheException(String.Format( "Cannot create a directory for revision {0}", fileRevisionPath), ex); } try { bool isBinary = isBinaryData(content); if (isBinary) { File.WriteAllBytes(fileRevisionPath, content); } else { string contentAsString = System.Text.Encoding.UTF8.GetString(content); contentAsString = Common.Tools.StringUtils.ConvertNewlineUnixToWindows(contentAsString); File.WriteAllText(fileRevisionPath, contentAsString); } } catch (Exception ex) // Any exception from File or System.Text.Encoding.UTF8.GetString() or I/O operations { throw new FileStorageRevisionCacheException(String.Format( "Cannot write a file revision at {0}", fileRevisionPath), ex); } }
private bool doesFileRevisionExist(FileRevision fileRevision) { return(File.Exists(getFileRevisionPath(fileRevision))); }
internal bool ContainsFileRevision(FileRevision fileRevision) { return(doesFileRevisionExist(fileRevision)); }
private string getFileRevisionPath(FileRevision fileRevision) { string prefix = getRevisionPath(fileRevision.SHA); return(fileRevision.GitFilePath.ToDiskPath(prefix)); }
private string getFileRevisionPath(FileRevision fileRevision) { return(_fileStorage.FileCache.GetFileRevisionPath(fileRevision)); }