~autark/ubuntu/natty/meld/meld-fix-988296

« back to all changes in this revision

Viewing changes to vc/mercurial.py

  • Committer: Bazaar Package Importer
  • Author(s): Balint Reczey, Josselin Mouette, Balint Reczey
  • Date: 2010-06-24 23:54:27 UTC
  • mfrom: (2.1.8 sid)
  • Revision ID: james.westby@ubuntu.com-20100624235427-h5419rmmin36qm8u
Tags: 1.3.2-1
[ Josselin Mouette ]
* vcs-crash.patch: stolen upstream. Fix a crash when using CVS, svn or
  git. Closes: #584554.

[ Balint Reczey ]
* New upstream release
  - Added support for diffing a file and a directory (Closes: #567340)
  - Translation updates (Thanks to Holger Wansing) (Closes: #313985)
  - vcs-crash.patch: removed, included upstream.
* run meld using /usr/bin/python instead of env python (Closes: #551189)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
### Copyright (C) 2002-2005 Stephen Kennedy <stevek@gnome.org>
2
 
 
3
 
### Redistribution and use in source and binary forms, with or without
4
 
### modification, are permitted provided that the following conditions
5
 
### are met:
6
 
### 
7
 
### 1. Redistributions of source code must retain the above copyright
8
 
###    notice, this list of conditions and the following disclaimer.
9
 
### 2. Redistributions in binary form must reproduce the above copyright
10
 
###    notice, this list of conditions and the following disclaimer in the
11
 
###    documentation and/or other materials provided with the distribution.
12
 
 
13
 
### THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14
 
### IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15
 
### OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16
 
### IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17
 
### INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18
 
### NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19
 
### DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20
 
### THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21
 
### (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22
 
### THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
 
 
24
 
import os
25
 
import errno
26
 
import _vc
27
 
 
28
 
class Vc(_vc.Vc):
29
 
 
30
 
    CMD = "hg"
31
 
    NAME = "Mercurial"
32
 
    VC_DIR = ".hg"
33
 
    PATCH_STRIP_NUM = 1
34
 
    # Mercurial diffs can be run in "git" mode
35
 
    PATCH_INDEX_RE = "^diff (?:-r \w+ |--git a/.* b/)(.*)$"
36
 
    DIFF_GIT_MODE = False
37
 
    state_map = {
38
 
        "?": _vc.STATE_NONE,
39
 
        "A": _vc.STATE_NEW,
40
 
        "C": _vc.STATE_NORMAL,
41
 
        "!": _vc.STATE_MISSING,
42
 
        "I": _vc.STATE_IGNORED,
43
 
        "M": _vc.STATE_MODIFIED,
44
 
        "R": _vc.STATE_REMOVED,
45
 
    }
46
 
 
47
 
    def commit_command(self, message):
48
 
        return [self.CMD,"commit","-m",message]
49
 
    def diff_command(self):
50
 
        ret = [self.CMD,"diff"]
51
 
        if self.DIFF_GIT_MODE:
52
 
            ret.append("--git")
53
 
        return ret
54
 
    def update_command(self):
55
 
        return [self.CMD,"update"]
56
 
    def add_command(self, binary=0):
57
 
        return [self.CMD,"add"]
58
 
    def remove_command(self, force=0):
59
 
        return [self.CMD,"rm"]
60
 
    def revert_command(self):
61
 
        return [self.CMD,"revert"]
62
 
    def get_working_directory(self, workdir):
63
 
        return self.root
64
 
 
65
 
    def _get_dirsandfiles(self, directory, dirs, files):
66
 
 
67
 
        while 1:
68
 
            try:
69
 
                entries = _vc.popen([self.CMD, "status", "-A", "."], cwd=directory).read().split("\n")[:-1]
70
 
                break
71
 
            except OSError, e:
72
 
                if e.errno != errno.EAGAIN:
73
 
                    raise
74
 
 
75
 
        retfiles = []
76
 
        retdirs = []
77
 
        hgfiles = {}
78
 
        for statekey, name in [ (entry[0], entry[2:]) for entry in entries if entry.find("/")==-1 ]:
79
 
            path = os.path.join(directory, name)
80
 
            rev, options, tag = "","",""
81
 
            state = self.state_map.get(statekey, _vc.STATE_NONE)
82
 
            retfiles.append( _vc.File(path, name, state, rev, tag, options) )
83
 
            hgfiles[name] = 1
84
 
        for f,path in files:
85
 
            if f not in hgfiles:
86
 
                #state = ignore_re.match(f) == None and _vc.STATE_NONE or _vc.STATE_IGNORED
87
 
                state = _vc.STATE_NORMAL
88
 
                retfiles.append( _vc.File(path, f, state, "") )
89
 
        for d,path in dirs:
90
 
            if d not in hgfiles:
91
 
                #state = ignore_re.match(f) == None and _vc.STATE_NONE or _vc.STATE_IGNORED
92
 
                state = _vc.STATE_NORMAL
93
 
                retdirs.append( _vc.Dir(path, d, state) )
94
 
 
95
 
        return retdirs, retfiles