If anyone is interested, I'm currently trying to resolve issue 457.

The crux of the problem is that directly calling extdiff in a
background thread has the side-effect of changing the process cwd.
This can cause a lot of problems, so we need to spawn each extdiff
call in it's own process.  While I'm at it, I want to make 'hgtk
vdiff' respect the user's 'skip diff window' configuration, and for it
to provide a dialog to the user if there were no diffable files.

Attached is a patch which gets us 80% of the way there.  I still need
to write the code that forks the new process, but the rest looks like
it's in good shape.  This has to go on to the stable branch, so I'm
hoping people can help test the final fix when it's pushed, so we
don't have any surprises when 0.8.2 is released.

Cheers,

--
Steve Borho
diff --git a/hggtk/gdialog.py b/hggtk/gdialog.py
--- a/hggtk/gdialog.py
+++ b/hggtk/gdialog.py
@@ -16,7 +16,6 @@
 import atexit
 
 from mercurial import cmdutil, util, ui, hg, commands
-from hgext import extdiff
 
 from thgutil.i18n import _
 from thgutil import settings, hglib, paths
@@ -403,43 +402,13 @@
 
         return True, textout
 
-    def _do_diff(self, patterns, options, modal=False):
-        from hggtk import visdiff, thgconfig
-        if self.ui.configbool('tortoisehg', 'vdiffnowin'):
-            tools = visdiff.readtools(self.ui)
-            preferred = self.ui.config('tortoisehg', 'vdiff', 'vdiff')
-            if not preferred or preferred not in tools:
-                Prompt(_('No visual diff configured'),
-                       _('Please select a visual diff application.'), self).run()
-                dlg = thgconfig.ConfigDialog(self.repo.root, False)
-                dlg.show_all()
-                dlg.focus_field('tortoisehg.vdiff')
-                dlg.run()
-                dlg.hide()
-                self.ui = ui.ui()
-                self._parse_config()
-                return
-
-            file = len(patterns) == 1 and patterns[0] or ''
-            diffcmd, diffopts = tools[preferred]
-            opts = {'change': options.get('change')}
-            if not opts['change']:
-                opts['rev'] = options.get('rev')
-
-            def dodiff():
-                extdiff.dodiff(self.ui, self.repo, diffcmd, diffopts,
-                               [self.repo.wjoin(file)], opts)
-
-            thread = threading.Thread(target=dodiff, name='diff:' + file)
-            thread.setDaemon(True)
-            thread.start()
-
-        else:
-            dialog = visdiff.FileSelectionDialog(patterns, options)
-            dialog.show_all()
-            if modal:
-                dialog.run()
-                dialog.hide()
+    def _do_diff(self, canonpats, options, modal=False):
+        options['canonpats'] = canonpats
+        dialog = visdiff.run(self.ui, [], **options)
+        dialog.show_all()
+        if modal:
+            dialog.run()
+            dialog.hide()
 
     def _diff_file(self, stat, file):
         self._do_diff(file and [file] or [], self.opts)
diff --git a/hggtk/hgtk.py b/hggtk/hgtk.py
--- a/hggtk/hgtk.py
+++ b/hggtk/hgtk.py
@@ -418,7 +418,10 @@
 def vdiff(ui, *pats, **opts):
     """launch configured visual diff tool"""
     portable_fork()
-    from hggtk.visdiff import run
+    from hggtk.visdiff import run, rawextdiff
+    if opts.get('raw'):
+        rawextdiff(ui, *pats, **opts)
+        return
     gtkrun(run(ui, *pats, **opts))
 
 ### help management, adapted from mercurial.commands.help_()
@@ -691,7 +694,8 @@
         ('hgtk update')),
     "^vdiff": (vdiff,
         [('c', 'change', '', _('changeset to view in diff tool')),
-         ('r', 'rev', [], _('revisions to view in diff tool'))],
+         ('r', 'rev', [], _('revisions to view in diff tool')),
+         ('', 'raw', None, _('directly use raw extdiff command'))],
             _('launch visual diff tool')),
     "^version": (version,
         [('v', 'verbose', None, _('print license'))],
diff --git a/hggtk/visdiff.py b/hggtk/visdiff.py
--- a/hggtk/visdiff.py
+++ b/hggtk/visdiff.py
@@ -273,5 +273,34 @@
             tools[cmd] = [path, diffopts]
     return tools
 
+def rawextdiff(ui, *pats, **opts):
+    'launch raw extdiff command, block until finish'
+    from hgext import extdiff
+    try:
+        repo = hg.repository(ui, path=paths.find_root())
+    except hglib.RepoError:
+        # hgtk should catch this earlier
+        ui.warn(_('No repository found here') + '\n')
+        return
+    tools = readtools(ui)
+    preferred = ui.config('tortoisehg', 'vdiff', 'vdiff')
+    try:
+        diffcmd, diffopts = tools[preferred]
+    except KeyError:
+        ui.warn(_('Extdiff command not recognized\n'))
+        return
+    pats = hglib.canonpaths(pats)
+    ret = extdiff.dodiff(ui, repo, diffcmd, diffopts, pats, opts)
+    if ret == 0:
+        gdialog.Prompt(_('No file changes'),
+                      _('There are no file changes to view'), None).run()
+
 def run(ui, *pats, **opts):
-    return FileSelectionDialog(hglib.canonpaths(pats), opts)
+    if ui.configbool('tortoisehg', 'vdiffnowin'):
+        # TODO: launch 'hgtk vdiff --nofork --raw [OPTIONS] [pats]'
+        return None
+    else:
+        pats = hglib.canonpaths(pats)
+        if opts.get('canonpats'):
+            pats.extend(opts['canonpats'])
+        return FileSelectionDialog(pats, opts)
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Tortoisehg-develop mailing list
Tortoisehg-develop@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tortoisehg-develop

Reply via email to