Update email adress and git respository adress.
[hgct.git] / hg.py
blob78506065cba4dcd1a359d9ecc925a814523040da
1 # Copyright (c) 2005 Mark Williamson <mark.williamson@cl.cam.ac.uk>
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License version 2 as
5 # published by the Free Software Foundation.
6 #
7 # This program is distributed in the hope that it will be useful,
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 # GNU General Public License for more details.
12 # You should have received a copy of the GNU General Public License
13 # along with this program; if not, write to the Free Software
14 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 import re
18 from ctcore import *
20 def doCommit(keepFiles, filesToCommit, msg):
21 commitFileNames = []
22 for f in filesToCommit:
23 commitFileNames.append(f.dstName)
24 runProgram(['hg', 'commit', '-A', '-l', '-'] + commitFileNames, msg)
26 class HgFile(File):
27 def __init__(self, unknown=False):
28 File.__init__(self)
30 def getPatchImpl(self):
31 return getPatch(self)
33 def fileSetFactory(addCallback, removeCallback):
34 return FileSet(addCallback, removeCallback)
36 parseDiffRE = re.compile('([AMR?]) (.*)')
38 def getPatch(file, otherFile = None):
39 if file.change == 'M' or \
40 file.change == 'R' or \
41 file.change == 'A':
42 return runProgram(['hg', 'diff', file.dstName])
43 elif file.change == '?':
44 return runProgram(['diff', '-u', '/dev/null', file.dstName],
45 expectedexits=[0,1,2])
46 else:
47 assert(False)
49 def __parseStatus():
50 inp = runProgram(['hg', 'status'])
51 ret = []
52 try:
53 recs = inp.split("\n")
54 recs.pop() # remove last entry (which is '')
55 it = recs.__iter__()
56 while True:
57 rec = it.next()
58 m = parseDiffRE.match(rec)
60 if not m:
61 print "Unknown output from hg status!: " + rec + "\n"
62 continue
64 f = HgFile()
65 f.change = m.group(1)
67 if f.change == '?' and not settings().showUnknown:
68 continue
70 f.srcName = f.dstName = m.group(2)
72 ret.append(f)
73 except StopIteration:
74 pass
75 return ret
78 def updateFiles(fileSet):
79 for f in list([x for x in fileSet]):
80 fileSet.remove(f)
82 files = __parseStatus()
83 for f in files:
84 c = f.change
85 if c == 'A':
86 f.text = 'Added file: ' + f.srcName
87 elif c == '?':
88 f.text = 'New file: ' + f.srcName
89 elif c == 'R':
90 f.text = 'Removed file: ' + f.srcName
91 else:
92 f.text = f.srcName
94 fileSet.add(f)
96 def initialize():
97 def basicsFailed(msg):
98 print "hg status: " + msg
99 print "Make sure that the current working directory contains a '.hg' directory."
100 sys.exit(1)
102 try:
103 runProgram(['hg', 'status'])
104 except OSError, e:
105 basicsFailed(e.strerror)
106 except ProgramError, e:
107 basicsFailed(e.error)
109 def doUpdateCache(file):
110 return
112 def discardFile(file):
113 if file.change == "M":
114 runProgram(['hg', 'revert', file.dstName])
115 elif file.change == "?":
116 runProgram(['rm', '-f', file.dstName])
117 return
119 def ignoreFile(file):
120 hgignore = open('.hgignore', 'a')
121 print >> hgignore, "^" + re.escape(file.dstName) + "$"
122 hgignore.close()
125 # Not yet implemented
126 def commitIsMerge():
127 return False
129 def mergeMessage():
130 return ''
132 # Not yet implemented
133 def getCurrentBranch():
134 return None