Example #1
0
        private FixedFilterTuple BuildFilter(string fileName)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                return(null);
            }

            //Replace windows path separator to Linux path separator.
            //This is needed to keep the file history working when started from file tree in
            //browse dialog.
            fileName = fileName.ToPosixPath();

            // we will need this later to look up proper casing for the file
            var fullFilePath = _fullPathResolver.Resolve(fileName);

            //The section below contains native windows (kernel32) calls
            //and breaks on Linux. Only use it on Windows. Casing is only
            //a Windows problem anyway.
            if (EnvUtils.RunningOnWindows() && File.Exists(fullFilePath))
            {
                // grab the 8.3 file path
                var shortPath = new StringBuilder(4096);
                NativeMethods.GetShortPathName(fullFilePath, shortPath, shortPath.Capacity);

                // use 8.3 file path to get properly cased full file path
                var longPath = new StringBuilder(4096);
                NativeMethods.GetLongPathName(shortPath.ToString(), longPath, longPath.Capacity);

                // remove the working directory and now we have a properly cased file name.
                fileName = longPath.ToString().Substring(Module.WorkingDir.Length);
            }

            if (fileName.StartsWith(Module.WorkingDir, StringComparison.InvariantCultureIgnoreCase))
            {
                fileName = fileName.Substring(Module.WorkingDir.Length);
            }

            FileName = fileName;

            FixedFilterTuple res = new FixedFilterTuple();

            res.PathFilter = " \"" + fileName + "\"";
            if (AppSettings.FollowRenamesInFileHistory && !Directory.Exists(fullFilePath))
            {
                // git log --follow is not working as expected (see  http://kerneltrap.org/mailarchive/git/2009/1/30/4856404/thread)
                //
                // But we can take a more complicated path to get reasonable results:
                //  1. use git log --follow to get all previous filenames of the file we are interested in
                //  2. use git log "list of files names" to get the history graph
                //
                // note: This implementation is quite a quick hack (by someone who does not speak C# fluently).
                //

                string arg = "log --format=\"%n\" --name-only --follow " +
                             GitCommandHelpers.FindRenamesAndCopiesOpts()
                             + " -- \"" + fileName + "\"";
                Process p = Module.RunGitCmdDetached(arg, GitModule.LosslessEncoding);

                // the sequence of (quoted) file names - start with the initial filename for the search.
                var listOfFileNames = new StringBuilder("\"" + fileName + "\"");

                // keep a set of the file names already seen
                var setOfFileNames = new HashSet <string> {
                    fileName
                };

                string line;
                do
                {
                    line = p.StandardOutput.ReadLine();
                    line = GitModule.ReEncodeFileNameFromLossless(line);

                    if (!string.IsNullOrEmpty(line) && setOfFileNames.Add(line))
                    {
                        listOfFileNames.Append(" \"");
                        listOfFileNames.Append(line);
                        listOfFileNames.Append('\"');
                    }
                } while (line != null);
                // here we need --name-only to get the previous filenames in the revision graph
                res.PathFilter      = listOfFileNames.ToString();
                res.RevisionFilter += " --name-only --parents" + GitCommandHelpers.FindRenamesAndCopiesOpts();
            }
            else if (AppSettings.FollowRenamesInFileHistory)
            {
                // history of a directory
                // --parents doesn't work with --follow enabled, but needed to graph a filtered log
                res.RevisionFilter = " " + GitCommandHelpers.FindRenamesOpt() + " --follow --parents";
            }
            else
            {
                // rename following disabled
                res.RevisionFilter = " --parents";
            }

            if (AppSettings.FullHistoryInFileHistory)
            {
                res.RevisionFilter = string.Concat(" --full-history --simplify-merges ", res.RevisionFilter);
            }


            return(res);
        }
Example #2
0
        private FixedFilterTuple BuildFilter(string fileName)
        {
            if (string.IsNullOrEmpty(fileName))
                return null;

            //Replace windows path separator to Linux path separator.
            //This is needed to keep the file history working when started from file tree in
            //browse dialog.
            fileName = fileName.ToPosixPath();

            // we will need this later to look up proper casing for the file
            var fullFilePath = Path.Combine(Module.WorkingDir, fileName);

            //The section below contains native windows (kernel32) calls
            //and breaks on Linux. Only use it on Windows. Casing is only
            //a Windows problem anyway.
            if (EnvUtils.RunningOnWindows() && File.Exists(fullFilePath))
            {
                // grab the 8.3 file path
                var shortPath = new StringBuilder(4096);
                NativeMethods.GetShortPathName(fullFilePath, shortPath, shortPath.Capacity);

                // use 8.3 file path to get properly cased full file path
                var longPath = new StringBuilder(4096);
                NativeMethods.GetLongPathName(shortPath.ToString(), longPath, longPath.Capacity);

                // remove the working directory and now we have a properly cased file name.
                fileName = longPath.ToString().Substring(Module.WorkingDir.Length);
            }

            if (fileName.StartsWith(Module.WorkingDir, StringComparison.InvariantCultureIgnoreCase))
                fileName = fileName.Substring(Module.WorkingDir.Length);

            FileName = fileName;

            FixedFilterTuple res = new FixedFilterTuple();
            res.PathFilter = " \"" + fileName + "\"";
            if (AppSettings.FollowRenamesInFileHistory && !Directory.Exists(fullFilePath))
            {
                // git log --follow is not working as expected (see  http://kerneltrap.org/mailarchive/git/2009/1/30/4856404/thread)
                //
                // But we can take a more complicated path to get reasonable results:
                //  1. use git log --follow to get all previous filenames of the file we are interested in
                //  2. use git log "list of files names" to get the history graph
                //
                // note: This implementation is quite a quick hack (by someone who does not speak C# fluently).
                //

                string arg = "log --format=\"%n\" --name-only --follow "+
                    GitCommandHelpers.FindRenamesAndCopiesOpts()
                    + " -- \"" + fileName + "\"";
                Process p = Module.RunGitCmdDetached(arg);

                // the sequence of (quoted) file names - start with the initial filename for the search.
                var listOfFileNames = new StringBuilder("\"" + fileName + "\"");

                // keep a set of the file names already seen
                var setOfFileNames = new HashSet<string> { fileName };

                string line;
                do
                {
                    line = p.StandardOutput.ReadLine();

                    if (!string.IsNullOrEmpty(line) && setOfFileNames.Add(line))
                    {
                        listOfFileNames.Append(" \"");
                        listOfFileNames.Append(line);
                        listOfFileNames.Append('\"');
                    }
                } while (line != null);
                // here we need --name-only to get the previous filenames in the revision graph
                res.PathFilter = listOfFileNames.ToString();
                res.RevisionFilter += " --name-only --parents" + GitCommandHelpers.FindRenamesAndCopiesOpts();
            }
            else if (AppSettings.FollowRenamesInFileHistory)
            {
                // history of a directory
                // --parents doesn't work with --follow enabled, but needed to graph a filtered log
                res.RevisionFilter = " " + GitCommandHelpers.FindRenamesOpt() + " --follow --parents";
            }
            else
            {
                // rename following disabled
                res.RevisionFilter = " --parents";
            }

            if (AppSettings.FullHistoryInFileHistory)
            {
                res.RevisionFilter = string.Concat(" --full-history ", res.RevisionFilter);
            }

            return res;
        }
Example #3
0
        private FixedFilterTuple BuildFilter(string fileName)
        {
            if (string.IsNullOrEmpty(fileName))
                return null;

            //Replace windows path separator to Linux path separator.
            //This is needed to keep the file history working when started from file tree in
            //browse dialog.
            fileName = fileName.ToPosixPath();

            // we will need this later to look up proper casing for the file
            var fullFilePath = Path.Combine(Module.WorkingDir, fileName);

            //The section below contains native windows (kernel32) calls
            //and breaks on Linux. Only use it on Windows. Casing is only
            //a Windows problem anyway.
            if (EnvUtils.RunningOnWindows() && File.Exists(fullFilePath))
            {
                // grab the 8.3 file path
                var shortPath = new StringBuilder(4096);
                NativeMethods.GetShortPathName(fullFilePath, shortPath, shortPath.Capacity);

                // use 8.3 file path to get properly cased full file path
                var longPath = new StringBuilder(4096);
                NativeMethods.GetLongPathName(shortPath.ToString(), longPath, longPath.Capacity);

                // remove the working directory and now we have a properly cased file name.
                fileName = longPath.ToString().Substring(Module.WorkingDir.Length);
            }

            if (fileName.StartsWith(Module.WorkingDir, StringComparison.InvariantCultureIgnoreCase))
                fileName = fileName.Substring(Module.WorkingDir.Length);

            FileName = fileName;

            FixedFilterTuple res = new FixedFilterTuple();
            if (AppSettings.FollowRenamesInFileHistory && !Directory.Exists(fullFilePath))
            {
                // git log --follow is not working as expected (see  http://kerneltrap.org/mailarchive/git/2009/1/30/4856404/thread)
                FollowParentRewriter hrw = new FollowParentRewriter(fileName, delegate(string arg){
                    Process p = Module.RunGitCmdDetached(arg);
                    return p.StandardOutput;
                });
                // here we need --name-only to get the previous filenames in the revision graph
                if (hrw.RewriteNecessary)
                {
                    res.Rewriter = hrw;
                    res.RevisionFilter = " " + GitCommandHelpers.FindRenamesAndCopiesOpts() + " --name-only --follow";
                }
                else
                {
                    res.RevisionFilter = " " + GitCommandHelpers.FindRenamesAndCopiesOpts() + " --name-only --parents";
                }
            }
            else if (AppSettings.FollowRenamesInFileHistory)
            {
                // history of a directory
                // --parents doesn't work with --follow enabled, but needed to graph a filtered log
                res.RevisionFilter = " " + GitCommandHelpers.FindRenamesOpt() + " --follow --parents";
            }
            else
            {
                // rename following disabled
                res.RevisionFilter = " --parents";
            }

            if (AppSettings.FullHistoryInFileHistory)
            {
                res.RevisionFilter = string.Concat(" --full-history ", res.RevisionFilter);
            }

            res.PathFilter = " \"" + fileName + "\"";

            return res;
        }
        private FixedFilterTuple BuildFilter(string fileName)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                return(null);
            }

            //Replace windows path separator to Linux path separator.
            //This is needed to keep the file history working when started from file tree in
            //browse dialog.
            fileName = fileName.Replace('\\', '/');

            // we will need this later to look up proper casing for the file
            var fullFilePath = Path.Combine(Module.WorkingDir, fileName);

            //The section below contains native windows (kernel32) calls
            //and breaks on Linux. Only use it on Windows. Casing is only
            //a Windows problem anyway.
            if (EnvUtils.RunningOnWindows() && File.Exists(fullFilePath))
            {
                // grab the 8.3 file path
                var shortPath = new StringBuilder(4096);
                NativeMethods.GetShortPathName(fullFilePath, shortPath, shortPath.Capacity);

                // use 8.3 file path to get properly cased full file path
                var longPath = new StringBuilder(4096);
                NativeMethods.GetLongPathName(shortPath.ToString(), longPath, longPath.Capacity);

                // remove the working directory and now we have a properly cased file name.
                fileName = longPath.ToString().Substring(Module.WorkingDir.Length);
            }

            if (fileName.StartsWith(Module.WorkingDir, StringComparison.InvariantCultureIgnoreCase))
            {
                fileName = fileName.Substring(Module.WorkingDir.Length);
            }

            FileName = fileName;

            FixedFilterTuple res = new FixedFilterTuple();

            if (AppSettings.FollowRenamesInFileHistory && !Directory.Exists(fullFilePath))
            {
                // git log --follow is not working as expected (see  http://kerneltrap.org/mailarchive/git/2009/1/30/4856404/thread)
                FollowParentRewriter hrw = new FollowParentRewriter(fileName, delegate(string arg){
                    Process p = Module.RunGitCmdDetached(arg);
                    return(p.StandardOutput);
                });
                // here we need --name-only to get the previous filenames in the revision graph
                if (hrw.RewriteNecessary)
                {
                    res.Rewriter = hrw;
                    res.Filter   = " -M -C --name-only --follow -- \"" + fileName + "\"";
                }
                else
                {
                    res.Filter = " -M -C --name-only --parents -- \"" + fileName + "\"";
                }
            }
            else
            {
                // --parents doesn't work with --follow enabled, but needed to graph a filtered log
                res.Filter = " --follow --parents -- \"" + fileName + "\"";
            }

            if (AppSettings.FullHistoryInFileHistory)
            {
                res.Filter = string.Concat(" --full-history --simplify-by-decoration ", res.Filter);
            }

            return(res);
        }