示例#1
0
        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);
        }
示例#2
0
        internal string GetFileRevisionPath(FileRevision fileRevision)
        {
            if (!doesFileRevisionExist(fileRevision))
            {
                return(string.Empty);
            }

            return(getFileRevisionPath(fileRevision));
        }
示例#3
0
        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));
        }
示例#4
0
        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);
            }
        }
示例#5
0
        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
        }
示例#7
0
        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);
            }
        }
示例#8
0
 private bool doesFileRevisionExist(FileRevision fileRevision)
 {
     return(File.Exists(getFileRevisionPath(fileRevision)));
 }
示例#9
0
 internal bool ContainsFileRevision(FileRevision fileRevision)
 {
     return(doesFileRevisionExist(fileRevision));
 }
示例#10
0
        private string getFileRevisionPath(FileRevision fileRevision)
        {
            string prefix = getRevisionPath(fileRevision.SHA);

            return(fileRevision.GitFilePath.ToDiskPath(prefix));
        }
示例#11
0
 private string getFileRevisionPath(FileRevision fileRevision)
 {
     return(_fileStorage.FileCache.GetFileRevisionPath(fileRevision));
 }