Ejemplo n.º 1
0
        // ------------------------------------------------------------------------
        /// Add a root directory and query the status of the contining files
        /// by a QueryRootStatus call.
        // ------------------------------------------------------------------------
        public bool AddRootDirectory(string directory)
        {
            if (directory == string.Empty)
            {
                return(false);
            }

            string root = HG.FindRootDirectory(directory);

            if (root != string.Empty && !_rootDirMap.ContainsKey(root))
            {
                _rootDirMap[root] = new RootInfo()
                {
                    _Branch = HG.GetCurrentBranchName(root)
                };

                if (!_directoryWatcherMap.ContainsDirectory(root))
                {
                    _directoryWatcherMap.WatchDirectory(root);
                }

                Dictionary <string, char> fileStatusDictionary;
                if (HG.QueryRootStatus(root, out fileStatusDictionary))
                {
                    _fileStatusDictionary.Add(fileStatusDictionary);
                }
            }

            return(true);
        }
Ejemplo n.º 2
0
        // ------------------------------------------------------------------------
        // build the argument sting from the given files and call invoke the hg command
        // ------------------------------------------------------------------------
        static void InvokeCommand(string command, string[] fileList, bool directoriesAllowed)
        {
            string        workingDirectory = fileList[0].Substring(0, fileList[0].LastIndexOf('\\'));
            string        rootDirectory    = HG.FindRootDirectory(workingDirectory);
            List <string> list;
            string        commandString = command;
            int           counter       = 0;

            foreach (var file in fileList)
            {
                ++counter;

                if (!directoriesAllowed && file.EndsWith("\\"))
                {
                    continue;
                }

                commandString += " \"" + file.Substring(rootDirectory.Length + 1) + "\" ";

                if (counter > 20 || commandString.Length > 1024)
                {
                    HG.InvokeCommand(rootDirectory, commandString, out list);
                    commandString = command;
                }
            }


            HG.InvokeCommand(rootDirectory, commandString, out list);
        }
Ejemplo n.º 3
0
        // ------------------------------------------------------------------------
        // query the files status and get them to the fileStatusDictionary
        // ------------------------------------------------------------------------
        static public bool QueryFileStatus(string[] fileList, out Dictionary <string, char> fileStatusDictionary, out Dictionary <string, string> renamedToOrgFileDictionary)
        {
            fileStatusDictionary       = new Dictionary <string, char>();
            renamedToOrgFileDictionary = new Dictionary <string, string>();
            Dictionary <string, string> commandLines = new Dictionary <string, string>();

            try
            {
                if (fileList.Length > 0)
                {
                    for (int iFile = 0; iFile < fileList.Length; ++iFile)
                    {
                        string file          = fileList[iFile];
                        string rootDirectory = HG.FindRootDirectory(file);

                        string commandLine = "";
                        commandLines.TryGetValue(rootDirectory, out commandLine);
                        commandLine += " \"" + file.Substring(rootDirectory.Length + 1) + "\" ";

                        if (commandLine.Length >= (2000))
                        {
                            List <string> resultList;
                            InvokeCommand(rootDirectory, "status -A " + commandLine, out resultList);
                            UpdateStatusDictionary(resultList, rootDirectory, fileStatusDictionary, renamedToOrgFileDictionary);

                            // reset cmd line and filecounter for the next run
                            commandLine = "";
                        }

                        commandLines[rootDirectory] = commandLine;
                    }

                    foreach (KeyValuePair <string, string> directoryCommandLine in commandLines)
                    {
                        string rootDirectory = directoryCommandLine.Key;
                        string commandLine   = directoryCommandLine.Value;
                        if (commandLine.Length > 0)
                        {
                            List <string> resultList;
                            InvokeCommand(rootDirectory, "status -A " + commandLine, out resultList);
                            UpdateStatusDictionary(resultList, rootDirectory, fileStatusDictionary, renamedToOrgFileDictionary);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine("HGProcess.QueryFileStatus: " + ex.Message);
                return(false);
            }

            return(fileStatusDictionary != null);
        }
Ejemplo n.º 4
0
        // ------------------------------------------------------------------------
        // detect moved files
        // ------------------------------------------------------------------------
        public bool FileMoved(string fileName, out string newName)
        {
            string root = HG.FindRootDirectory(fileName);
            string name = Path.GetFileName(fileName);

            foreach (HGFileStatusInfo value in _dictionary.Values)
            {
                if (value.status == HGLib.HGFileStatus.scsAdded)
                {
                    if (name.Equals(value.fileName, StringComparison.CurrentCultureIgnoreCase))
                    {
                        string root2 = HG.FindRootDirectory(value.fullPath);
                        if (root.Equals(root2, StringComparison.CurrentCultureIgnoreCase))
                        {
                            newName = value.fullPath;
                            return(true);
                        }
                    }
                }
            }
            newName = "";
            return(false);
        }
Ejemplo n.º 5
0
        // ------------------------------------------------------------------------
        // enter file renamed to hg repository
        // ------------------------------------------------------------------------
        static public bool EnterFileRenamed(string[] orgFileName, string[] newFileName)
        {
            try
            {
                for (int pos = 0; pos < orgFileName.Length; ++pos)
                {
                    string workingDirectory = orgFileName[pos].Substring(0, orgFileName[pos].LastIndexOf('\\'));
                    string rootDirectory    = HG.FindRootDirectory(workingDirectory);

                    string        ofile = orgFileName[pos].Substring(rootDirectory.Length + 1);
                    string        nfile = newFileName[pos].Substring(rootDirectory.Length + 1);
                    List <string> list;
                    HG.InvokeCommand(rootDirectory,
                                     "rename  -A \"" + ofile + "\" \"" + nfile + "\"", out list);
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine("HG.EnterFileRenamed exception- " + ex.Message);
                return(false);
            }

            return(true);
        }