Exemplo n.º 1
0
        public override void Checkout(string url, string targetLocalPath, MercurialRevision rev, bool recurse, MonoDevelop.Core.IProgressMonitor monitor)
        {
            // TODO: Support this?
            return;

            /*
             * if (null == monitor){ monitor = new MonoDevelop.Core.ProgressMonitoring.NullProgressMonitor (); }
             * string pyrev = "None";
             * string realUrl = url;
             * StringBuilder command = new StringBuilder ();
             *
             * Match match = UrlRegex.Match (url);
             * if(match.Success) {
             *      realUrl = UrlRegex.Replace(url, @"${protocol}://${host}$3${path}");
             * }
             *
             * lock (lockme) {
             *      run (null, "b = branch.Branch.open_containing(url=ur\"{0}\")[0]\n", realUrl);
             * }
             *
             * monitor.Log.WriteLine ("Opened {0}", url);
             *
             * if (null != rev && MercurialRevision.HEAD != rev.Rev && MercurialRevision.NONE != rev.Rev) {
             *      command.AppendFormat ("revspec = revisionspec.RevisionSpec.from_string(spec=\"{0}\")\n", rev.Rev);
             *      pyrev = "revspec.in_history(branch=b).rev_id";
             * }
             * command.AppendFormat ("b.create_checkout(to_location=ur\"{1}\", revision_id={0})\n", pyrev, NormalizePath (targetLocalPath));
             *
             * lock (lockme){ run (null, command.ToString ()); }
             * monitor.Log.WriteLine ("Checkout to {0} completed", targetLocalPath);
             */
        }
Exemplo n.º 2
0
        public override string GetTextAtRevision(FilePath repositoryPath, Revision revision)
        {
            // System.Console.WriteLine ("Got GetTextAtRevision for {0}", repositoryPath);
            MercurialRevision brev = (null == revision)? new MercurialRevision(this, MercurialRevision.HEAD): (MercurialRevision)revision;

            return(Client.GetTextAtRevision(repositoryPath.FullPath, brev));
        }
Exemplo n.º 3
0
        }        // GetKnownBranches

        /*
         * public override string GetPathUrl (string path)
         * {
         *      IntPtr branch = IntPtr.Zero;
         *
         *      lock (lockme) {
         *              branch = run (new List<string>{"mybase"}, "mybranch = branch.Branch.open_containing(url=ur\"{0}\")[0]\nmybase=mybranch.base\n", NormalizePath (Path.GetFullPath (path)))[0];
         *              string baseurl = StringFromPython (branch);
         *              return baseurl.StartsWith ("file://", StringComparison.Ordinal)? baseurl.Substring (7): baseurl;
         *      }
         * }
         */

        public override string GetTextAtRevision(string path, MercurialRevision rev)
        {
            path = NormalizePath(path);
            string tempfile = Path.GetTempFileName();

            RunMercurialRepoCommand(path, "commands.cat(repo.ui,repo,os.path.realpath('{0}'),rev='{1}',output='{2}')", path, rev.Rev, tempfile);
            return(File.ReadAllText(tempfile));
        }        // GetTextAtRevision
Exemplo n.º 4
0
        // public abstract RevisionPath[] GetRevisionChanges (MercurialRepository repo, MercurialRevision revision);
        public virtual RevisionPath[] GetRevisionChanges(MercurialRepository repo, MercurialRevision revision)
        {
            List <RevisionPath> paths = new List <RevisionPath> ();

            foreach (LocalStatus status in Status(repo.LocalBasePath, revision)
                     .Where(s => s.Status != ItemStatus.Unchanged && s.Status != ItemStatus.Unversioned))
            {
                paths.Add(new RevisionPath(Path.Combine(repo.LocalBasePath, status.Filename), ConvertAction(status.Status), status.Status.ToString()));
            }

            return(paths.ToArray());
        }
Exemplo n.º 5
0
        public override string GetTextAtRevision(string path, MercurialRevision rev)
        {
            path = NormalizePath(path);
            string revisionText = null;

            if (null != rev && MercurialRevision.NONE != rev.Rev && MercurialRevision.HEAD != rev.Rev)
            {
                revisionText = rev.Rev;
            }
            IDictionary <string, string> text = client.Cat(revisionText, path);

            if (null == text || !text.ContainsKey(path))
            {
                return(string.Empty);
            }
            return(text [path]);
        }
Exemplo n.º 6
0
        public override void RevertToRevision(FilePath localPath, Revision revision, IProgressMonitor monitor)
        {
            if (IsModified(MercurialRepository.GetLocalBasePath(localPath)))
            {
                MessageDialog md = new MessageDialog(MonoDevelop.Ide.IdeApp.Workbench.RootWindow, DialogFlags.Modal,
                                                     MessageType.Question, ButtonsType.YesNo,
                                                     GettextCatalog.GetString("You have uncommitted local changes. Revert anyway?"));
                try {
                    if ((int)ResponseType.Yes != md.Run())
                    {
                        return;
                    }
                } finally {
                    md.Destroy();
                }
            }            // warn about uncommitted changes

            MercurialRevision brev = (null == revision)? new MercurialRevision(this, MercurialRevision.HEAD): (MercurialRevision)revision;

            Client.Revert(localPath.FullPath, true, monitor, brev);
        }
Exemplo n.º 7
0
        public override DiffInfo[] Diff(string path, MercurialRevision fromRevision, MercurialRevision toRevision)
        {
            // Need history for this
            path = NormalizePath(path);
            return(new[] { new DiffInfo(GetLocalBasePath(path), path,
                                        RunMercurialRepoCommand(path, "commands.diff(repo.ui,repo,os.path.realpath('{2}'),rev='{0}:{1}')", fromRevision.Rev, toRevision.Rev, path)) });

            /*
             * List<DiffInfo> results = new List<DiffInfo> ();
             * path = NormalizePath (Path.GetFullPath (path));
             * StringBuilder command = new StringBuilder ();
             *
             * command.AppendFormat ("outfile = StringIO.StringIO()\n");
             * command.AppendFormat ("old_tree = None\n");
             * command.AppendFormat ("new_tree = None\n");
             * command.AppendFormat ("try:\n");
             * command.AppendFormat ("  old_tree,new_tree,old_branch,new_branch,specific_files,extra_trees = diff.get_trees_and_branches_to_diff(path_list=None, revision_specs=[revisionspec.RevisionSpec.from_string(ur\"{0}\"), revisionspec.RevisionSpec.from_string(ur\"{1}\")], old_url=ur\"{2}\", new_url=ur\"{2}\")\n",
             *                    fromRevision, toRevision, path);
             * command.AppendFormat ("  mydiff = bzrlib.diff.DiffTree(old_tree=old_tree, new_tree=new_tree, to_file=outfile)\n");
             * command.AppendFormat ("  old_tree.lock_read()\n");
             * command.AppendFormat ("  new_tree.lock_read()\n");
             * command.AppendFormat ("  mydiff.show_diff(specific_files=specific_files, extra_trees=extra_trees)\n");
             * command.AppendFormat ("  output = outfile.getvalue()\n");
             * command.AppendFormat ("finally:\n");
             * command.AppendFormat ("  outfile.close()\n");
             * command.AppendFormat ("  if(old_tree): old_tree.unlock()\n");
             * command.AppendFormat ("  if(new_tree): new_tree.unlock()\n");
             *
             * lock (lockme) {
             *      string output = StringFromPython (run (new List<string>{"output"}, command.ToString ())[0]);
             *      results.Add (new DiffInfo (Path.GetDirectoryName (path), Path.GetFileName (path),
             *                                 output.Replace ("\r\n", Environment.NewLine)));
             * }
             *
             * return results.ToArray ();
             */
        }
Exemplo n.º 8
0
 public abstract string GetTextAtRevision(string path, MercurialRevision rev);
Exemplo n.º 9
0
 public abstract void Revert(string localPath, bool recurse, IProgressMonitor monitor, MercurialRevision toRevision);
Exemplo n.º 10
0
 public abstract void Checkout(string url, string targetLocalPath, MercurialRevision rev, bool recurse, IProgressMonitor monitor);
 protected override string OnGetTextAtRevision(FilePath repositoryPath, Revision revision)
 {
     var rev = new MercurialRevision(this, revision == null ? MercurialRevision.Head : revision.Name);
     return _mercurialClient.Cat(repositoryPath.FullPath, rev.RevisionNumber);
 }
Exemplo n.º 12
0
 public abstract IEnumerable <LocalStatus> Status(string path, MercurialRevision revision);
Exemplo n.º 13
0
        public override System.Collections.Generic.IEnumerable <LocalStatus> Status(string path, MercurialRevision revision)
        {
            List <LocalStatus> statuses = new List <LocalStatus> ();
            string             rev      = string.Empty;
            ItemStatus         itemStatus;
            LocalStatus        mystatus = null;
            LocalStatus        tmp;
            bool modified = false;


            path = NormalizePath(Path.GetFullPath(path).Replace("{", "{{").Replace("}", "}}"), false);                // escape for string.format

            if (null != revision && MercurialRevision.HEAD != revision.Rev && MercurialRevision.NONE != revision.Rev)
            {
                rev = string.Format(",change={0}", revision.Rev);
            }

            string statusText = string.Empty;

            try {
                statusText = RunMercurialRepoCommand(path, "commands.status(repo.ui,repo,os.path.realpath('{0}'),all=True{1})\n", path, rev);
            } catch (MercurialClientException) {
                // TODO: This happens on incoming/outgoing - handle this in a better way
                LoggingService.LogWarning("Error getting status for {0} at {1}", path, revision.Rev);
            }

            foreach (string line in statusText.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries))
            {
                string[] tokens = line.Split(new[] { ' ' }, 2);
                itemStatus = (ItemStatus)tokens[0][0];
                // Console.WriteLine ("Got status {0} for path {1}", tokens[0], tokens[1]);
                tmp = new LocalStatus(string.Empty, NormalizePath(tokens[1]), itemStatus);
                statuses.Add(tmp);
                if (itemStatus != ItemStatus.Ignored && itemStatus != ItemStatus.Unversioned && itemStatus != ItemStatus.Unchanged)
                {
                    modified = true;
                }
                if (Path.GetFileName(path).Equals(Path.GetFileName(tokens[1]), StringComparison.OrdinalIgnoreCase))
                {
                    mystatus = tmp;
                }
            }

            string conflictText = RunMercurialRepoCommand(path, "commands.resolve(repo.ui,repo,os.path.realpath('{0}'),list=True)", path);

            // System.Console.WriteLine (conflictText);
            foreach (string line in conflictText.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries))
            {
                string[] tokens = line.Split(new[] { ' ' }, 2);
                itemStatus = (ItemStatus)tokens[0][0];
                if (ItemStatus.Conflicted == itemStatus)
                {
                    LocalStatus status = statuses.Find((s) =>
                                                       s.Filename.EndsWith(tokens[1], StringComparison.OrdinalIgnoreCase)
                                                       );
                    if (null == status)
                    {
                        statuses.Add(new LocalStatus(MercurialRevision.HEAD, tokens[1], ItemStatus.Conflicted));
                    }
                    else
                    {
                        status.Status = ItemStatus.Conflicted;
                    }
                }
//				Console.WriteLine ("Got status {0} for path {1}", tokens[0], tokens[1]);
            }

            if (null == mystatus)
            {
                statuses.Insert(0, new LocalStatus(string.Empty, GetLocalBasePath(path), modified? ItemStatus.Modified: ItemStatus.Unchanged));
            }

            return(statuses);
        }
Exemplo n.º 14
0
        protected override string OnGetTextAtRevision(FilePath repositoryPath, Revision revision)
        {
            var rev = new MercurialRevision(this, revision == null ? MercurialRevision.Head : revision.Name);

            return(_mercurialClient.Cat(repositoryPath.FullPath, rev.RevisionNumber));
        }
        VersionInfo[] GetDirectoryVersionInfo(FilePath localDirectory, IEnumerable<FilePath> localFileNames, bool getRemoteStatus, bool recursive)
        {
            List<VersionInfo> versions = new List<VersionInfo> ();
            HashSet<FilePath> existingFiles = new HashSet<FilePath> ();
            HashSet<FilePath> nonVersionedMissingFiles = new HashSet<FilePath> ();

            if (localFileNames != null) {
                var localFiles = new List<FilePath> ();
                var arev = new MercurialRevision (this, "");
                foreach (var p in localFileNames) {
                    if (Directory.Exists (p)) {
                        if (recursive)
                            versions.AddRange (GetDirectoryVersionInfo (p, getRemoteStatus, true));
                        else
                            versions.Add (new VersionInfo (p, "", true, VersionStatus.Versioned, arev, VersionStatus.Versioned, null));
                    }
                    else {
                        localFiles.Add (p);
                        if (File.Exists (p))
                            existingFiles.Add (p.CanonicalPath);
                        else
                            nonVersionedMissingFiles.Add (p.CanonicalPath);
                    }
                }
                // No files to check, we are done
                if (localFiles.Count == 0)
                    return versions.ToArray ();

                localFileNames = localFiles;
            } else {
                CollectFiles (existingFiles, localDirectory, recursive);
            }

            MercurialRevision rev;
            var headCommit = RootRepository.Tip ();
            if (headCommit != null)
                rev = new MercurialRevision (this, headCommit.Hash);
            else
                rev = null;

            IEnumerable<string> paths;
            if (localFileNames == null) {
                if (recursive)
                paths = new [] { (string) localDirectory };
                else
                    paths = Directory.GetFiles (localDirectory);
            } else {
                paths = localFileNames.Select (f => (string)f);
            }
            paths = paths.Select (f => ToMercurialPath (f));

            var statcmd = new StatusCommand ();
            foreach (var p in paths) statcmd.AddArgument (p);
            var status = RootRepository.Status (statcmd);
            HashSet<string> added = new HashSet<string> ();
            Action<IEnumerable<FileStatus>, VersionStatus> AddFiles = delegate(IEnumerable<FileStatus> files, VersionStatus fstatus) {
                foreach (FileStatus file in files) {
                    if (!added.Add (file.Path))
                        continue;
                    FilePath statFile = FromMercurialPath (file.Path);
                    existingFiles.Remove (statFile.CanonicalPath);
                    nonVersionedMissingFiles.Remove (statFile.CanonicalPath);
                    versions.Add (new VersionInfo (statFile, "", false, fstatus, rev, VersionStatus.Versioned, null));
                }
            };

            AddFiles (status.Where (fs => fs.State == FileState.Added), VersionStatus.Versioned | VersionStatus.ScheduledAdd);
            AddFiles (status.Where (fs => fs.State == FileState.Modified), VersionStatus.Versioned | VersionStatus.Modified);
            AddFiles (status.Where (fs => fs.State == FileState.Removed), VersionStatus.Versioned | VersionStatus.ScheduledDelete);
            AddFiles (status.Where (fs => fs.State == FileState.Missing), VersionStatus.Versioned | VersionStatus.ScheduledDelete);
            // mercurial-FIXME: how can I get conflicts?
            //AddFiles (status.GetConflicting (), VersionStatus.Versioned | VersionStatus.Conflicted);
            AddFiles (status.Where (fs => fs.State == FileState.Unknown), VersionStatus.Unversioned);

            // Existing files for which hg did not report an status are supposed to be tracked
            foreach (FilePath file in existingFiles) {
                VersionInfo vi = new VersionInfo (file, "", false, VersionStatus.Versioned, rev, VersionStatus.Versioned, null);
                versions.Add (vi);
            }

            // Non existing files for which hg did not report an status are unversioned
            foreach (FilePath file in nonVersionedMissingFiles)
                versions.Add (VersionInfo.CreateUnversioned (file, false));

            return versions.ToArray ();
        }
Exemplo n.º 16
0
        public override void Revert(string localPath, bool recurse, MonoDevelop.Core.IProgressMonitor monitor, MercurialRevision toRevision)
        {
            try {
                client.Revert(null, NormalizePath(localPath));
            } catch (CommandException ce) {
                monitor.ReportError(ce.Message, ce);
            }

            monitor.ReportSuccess(string.Empty);
        }
Exemplo n.º 17
0
 public override void Checkout(string url, string targetLocalPath, MercurialRevision rev, bool recurse, MonoDevelop.Core.IProgressMonitor monitor)
 {
     // Remap to clone? or stop caring?
     throw new NotImplementedException();
 }
Exemplo n.º 18
0
 public abstract MercurialRevision[] GetHistory(MercurialRepository repo, string localFile, MercurialRevision since);
Exemplo n.º 19
0
        public override MercurialRevision[] GetHistory(MercurialRepository repo, string localFile, MercurialRevision since)
        {
            string revisions = null;

            if (since != null && since.Rev != MercurialRevision.NONE)
            {
                revisions = since.Rev;
            }
            return(client.Log(revisions, NormalizePath(localFile)).Select(r => FromCommandRevision(repo, r)).ToArray());
        }
Exemplo n.º 20
0
 public override DiffInfo[] Diff(string path, MercurialRevision fromRevision, MercurialRevision toRevision)
 {
     return(new[] { new DiffInfo(client.Root, NormalizePath(path).Substring(client.Root.Length), client.Diff(string.Format("{0}:{1}", fromRevision, toRevision), NormalizePath(path))) });
 }
Exemplo n.º 21
0
        public override void Checkout(FilePath targetLocalPath, Revision rev, bool recurse, IProgressMonitor monitor)
        {
            MercurialRevision brev = (null == rev)? new MercurialRevision(this, MercurialRevision.HEAD): (MercurialRevision)rev;

            Client.Checkout(Url, targetLocalPath.FullPath, brev, recurse, monitor);
        }
Exemplo n.º 22
0
 public abstract DiffInfo[] Diff(string path, MercurialRevision fromRevision, MercurialRevision toRevision);
Exemplo n.º 23
0
        public override MercurialRevision[] GetHistory(MercurialRepository repo, string localFile, MercurialRevision since)
        {
            localFile = NormalizePath(localFile);
            List <MercurialRevision> revisions = new List <MercurialRevision> ();
            string logText = RunMercurialRepoCommand(localFile, "commands.log(repo.ui,repo,os.path.realpath('{0}'),date=None,user=None{1},style='xml')", localFile, ",rev=None");

            XmlDocument doc = new XmlDocument();

            try {
                doc.LoadXml(logText);
            } catch (XmlException xe) {
                LoggingService.LogError("Error getting history for " + localFile, xe);
                return(revisions.ToArray());
            }

            foreach (XmlNode node in doc.SelectNodes("/log/logentry"))
            {
                revisions.Add(NodeToRevision(repo, node));
            }

            return(revisions.ToArray());
        }        // GetHistory
 // mercurial-FIXME: GetStashes() not supported
 protected override Revision[] OnGetHistory(FilePath localFile, Revision since)
 {
     List<Revision> revs = new List<Revision> ();
     var commits = RootRepository.Log (new global::Mercurial.LogCommand ().WithIncludePattern (ToMercurialPath (localFile)));
     foreach (var commit in commits) {
         MercurialRevision rev = new MercurialRevision (this, commit.Hash, commit.Timestamp, commit.AuthorName, commit.CommitMessage) {
             Email = commit.AuthorEmailAddress,
             ShortMessage = commit.CommitMessage.Split (line_sep).FirstOrDefault (),
             Commit = commit,
             FileForChanges = localFile
         };
         revs.Add (rev);
     }
     return revs.ToArray ();
 }
Exemplo n.º 25
0
        public override void Revert(string localPath, bool recurse, MonoDevelop.Core.IProgressMonitor monitor, MercurialRevision toRevision)
        {
            string rev = string.Empty;

            localPath = NormalizePath(localPath);
            if (null != toRevision && MercurialRevision.HEAD != toRevision.Rev && MercurialRevision.NONE != toRevision.Rev)
            {
                rev = string.Format(",rev='{0}',date=None", toRevision.Rev);
            }
            else
            {
                rev = ",rev='tip',date=None";
            }

            RunMercurialRepoCommand(localPath, "commands.revert(repo.ui,repo,os.path.realpath('{0}'){1})", localPath, rev);
        }
 internal MercurialRevision GetPreviousRevisionFor(MercurialRevision revision)
 {
     var cmd = new global::Mercurial.LogCommand ().WithRevision (revision.Name + ":0");
     if (revision.FileForChanges != null)
         cmd.WithIncludePattern (ToMercurialPath (revision.FileForChanges));
     var prev = RootRepository.Log (cmd).Skip (1).FirstOrDefault ();
     return prev == null ? null : new MercurialRevision (this, prev.Hash);
 }
Exemplo n.º 27
0
        public override System.Collections.Generic.IEnumerable <LocalStatus> Status(string path, MercurialRevision revision)
        {
            string normalizedPath   = NormalizePath(path);
            string rootRelativePath = ((FilePath)normalizedPath).ToRelative(client.Root);
            string revString        = null;

            if (null != revision && MercurialRevision.HEAD != revision.Rev && MercurialRevision.NONE != revision.Rev)
            {
                revString = revision.Rev;
            }

            IDictionary <string, global::Mercurial.Status> statuses = client.Status(new[] { normalizedPath }, onlyRevision: revString);

            if (!statuses.ContainsKey(path))
            {
                if (statuses.ContainsKey(rootRelativePath))
                {
                    statuses [path] = statuses [rootRelativePath];
                    statuses.Remove(rootRelativePath);
                }
                else if (statuses.ContainsKey(normalizedPath))
                {
                    statuses [path] = statuses [normalizedPath];
                    statuses.Remove(normalizedPath);
                }
                else
                {
                    statuses [path] = global::Mercurial.Status.Clean;
                }
            }

            // Convert relative paths to absolute
            return(statuses.Select(pair => new LocalStatus(MercurialRevision.NONE,
                                                           Path.IsPathRooted(pair.Key)? pair.Key: (string)((FilePath)Path.Combine(client.Root, pair.Key)),
                                                           ConvertCommandStatus(pair.Value))));
        }