Mercurial > public > mercurial-scm > hg-stable
diff hgext/extdiff.py @ 5137:2be225ea5722
extdiff: do single file diffs from the wc with no copy
Extdiff was always making a temporary directory and copying files even when not required. This change makes extdiff avoid the copy when diffing a single file that lives in the wc. This lets external diff tools edit the working copy file directly. It also lets other extensions resuse the functions in extdiff and get in-place diffs.
author | Brad Schick <schickb@gmail.com> |
---|---|
date | Mon, 06 Aug 2007 14:50:57 -0700 |
parents | 841568ccc09d |
children | d4fa6bafc43a |
line wrap: on
line diff
--- a/hgext/extdiff.py Mon Aug 06 14:42:11 2007 -0700 +++ b/hgext/extdiff.py Mon Aug 06 14:50:57 2007 -0700 @@ -113,12 +113,34 @@ return 0 tmproot = tempfile.mkdtemp(prefix='extdiff.') + dir2root = '' try: + # Always make a copy of node1 dir1 = snapshot_node(ui, repo, modified + removed, node1, tmproot) + changes = len(modified) + len(removed) + len(added) + + # If node2 in not the wc or there is >1 change, copy it if node2: dir2 = snapshot_node(ui, repo, modified + added, node2, tmproot) + elif changes > 1: + dir2 = snapshot_wdir(ui, repo, modified + added, tmproot) else: - dir2 = snapshot_wdir(ui, repo, modified + added, tmproot) + # This lets the diff tool open the changed file directly + dir2 = '' + dir2root = repo.root + + # If only one change, diff the files instead of the directories + if changes == 1 : + if len(modified): + dir1 = os.path.join(dir1, util.localpath(modified[0])) + dir2 = os.path.join(dir2root, dir2, util.localpath(modified[0])) + elif len(removed) : + dir1 = os.path.join(dir1, util.localpath(removed[0])) + dir2 = os.devnull + else: + dir1 = os.devnull + dir2 = os.path.join(dir2root, dir2, util.localpath(added[0])) + cmdline = ('%s %s %s %s' % (util.shellquote(diffcmd), ' '.join(diffopts), util.shellquote(dir1), util.shellquote(dir2)))