Esempio n. 1
0
        private void GetDiff(IResource repository, FileChange fileChange)
        {
            if (fileChange.HasProp(Props.Diff))
            {
                return;
            }

            int revision = fileChange.Revision;

            if (revision == 1)
            {
                return;
            }

            string repoRoot = repository.GetProp(Props.RepositoryRoot);

            if (repoRoot == null)
            {
                try
                {
                    repoRoot = GetRunner(repository).GetSvnInfo("Repository Root:");
                    ClearLastError(repository);
                }
                catch (RunnerException ex)
                {
                    SetLastError(repository, ex);
                    return;
                }
                new ResourceProxy(repository).SetPropAsync(Props.RepositoryRoot, repoRoot);
            }

            string    repoPath  = BuildFileName(repository, fileChange);
            SvnRunner svnRunner = GetRunner(repository);

            svnRunner.RepositoryUrl = repoRoot;
            try
            {
                string diff = svnRunner.GetDiff(repoPath, revision - 1, revision);
                fileChange.Diff = diff;
                fileChange.SaveAsync();
                if (diff == "")
                {
                    CheckBinaryFile(repository, repoRoot, repoPath, fileChange);
                }

                ClearLastError(repository);
            }
            catch (RunnerException ex)
            {
                SetLastError(repository, ex);
            }
        }
Esempio n. 2
0
        private static void CheckBinaryFile(IResource repository, string repoRoot, string repoPath, FileChange fileChange)
        {
            SvnRunner svnRunner = GetRunner(repository);

            svnRunner.RepositoryUrl = repoRoot;
            try
            {
                string prop = svnRunner.GetProperty(repoPath, "svn:mime-type");
                ClearLastError(repository);
                // see libsvn_subr/validate.c:svn_mime_type_is_binary() in Subversion source code
                if (!prop.StartsWith("text/") && !prop.StartsWith("image/x-xbitmap") &&
                    !prop.StartsWith("image/x-xpixmap"))
                {
                    fileChange.Binary = true;
                    fileChange.SaveAsync();
                }
            }
            catch (RunnerException ex)
            {
                SetLastError(repository, ex);
            }
        }