##// END OF EJS Templates
move repo.current to dirstate.parents()...
mpm@selenic.com -
r227:f57519cd default
parent child Browse files
Show More
@@ -66,9 +66,8 b' def diff(files = None, node1 = None, nod'
66 else:
66 else:
67 date2 = time.asctime()
67 date2 = time.asctime()
68 if not node1:
68 if not node1:
69 node1 = repo.current
69 node1 = repo.dirstate.parents()[0]
70 (c, a, d, u) = repo.diffdir(repo.root, node1)
70 (c, a, d, u) = repo.diffdir(repo.root, node1)
71 a = [] # ignore unknown files in repo, by popular request
72 def read(f): return file(os.path.join(repo.root, f)).read()
71 def read(f): return file(os.path.join(repo.root, f)).read()
73
72
74 change = repo.changelog.read(node1)
73 change = repo.changelog.read(node1)
@@ -139,9 +138,9 b' elif cmd == "remove" or cmd == "rm" or c'
139 elif cmd == "commit" or cmd == "checkin" or cmd == "ci":
138 elif cmd == "commit" or cmd == "checkin" or cmd == "ci":
140 if 1:
139 if 1:
141 if len(args) > 0:
140 if len(args) > 0:
142 repo.commit(repo.current, args)
141 repo.commit(args)
143 else:
142 else:
144 repo.commit(repo.current)
143 repo.commit()
145 elif cmd == "rawcommit":
144 elif cmd == "rawcommit":
146 "raw commit interface"
145 "raw commit interface"
147 rc = {}
146 rc = {}
@@ -204,7 +203,7 b' elif cmd == "import" or cmd == "patch":'
204 if files:
203 if files:
205 if os.system("patch -p%d < %s %s" % (strip, pf, quiet)):
204 if os.system("patch -p%d < %s %s" % (strip, pf, quiet)):
206 raise "patch failed!"
205 raise "patch failed!"
207 repo.commit(repo.current, files, text)
206 repo.commit(files, text)
208
207
209 elif cmd == "diff":
208 elif cmd == "diff":
210 revs = []
209 revs = []
@@ -102,7 +102,7 b' def annotate(u, repo, *args, **ops):'
102 ops['number'] = 1
102 ops['number'] = 1
103
103
104 args = relpath(repo, args)
104 args = relpath(repo, args)
105 node = repo.current
105 node = repo.dirstate.parents()[0]
106 if ops['revision']:
106 if ops['revision']:
107 node = repo.changelog.lookup(ops['revision'])
107 node = repo.changelog.lookup(ops['revision'])
108 change = repo.changelog.read(node)
108 change = repo.changelog.read(node)
@@ -142,6 +142,17 b' def heads(ui, repo):'
142 print "description:"
142 print "description:"
143 print changes[4]
143 print changes[4]
144
144
145 def parents(ui, repo, node = None):
146 '''show the parents of the current working dir'''
147 if node:
148 p = repo.changelog.parents(repo.lookup(hg.bin(node)))
149 else:
150 p = repo.dirstate.parents()
151
152 for n in p:
153 if n != hg.nullid:
154 ui.write("%d:%s\n" % (repo.changelog.rev(n), hg.hex(n)))
155
145 def status(ui, repo):
156 def status(ui, repo):
146 '''show changed files in the working directory
157 '''show changed files in the working directory
147
158
@@ -172,6 +183,7 b' table = {'
172 ('n', 'number', None, 'show revision number'),
183 ('n', 'number', None, 'show revision number'),
173 ('c', 'changeset', None, 'show changeset')],
184 ('c', 'changeset', None, 'show changeset')],
174 'hg annotate [-u] [-c] [-n] [-r id] [files]'),
185 'hg annotate [-u] [-c] [-n] [-r id] [files]'),
186 "parents": (parents, [], 'hg parents [node]'),
175 "status": (status, [], 'hg status'),
187 "status": (status, [], 'hg status'),
176 "undo": (undo, [], 'hg undo'),
188 "undo": (undo, [], 'hg undo'),
177 }
189 }
@@ -155,6 +155,7 b' class dirstate:'
155 self.dirty = 0
155 self.dirty = 0
156 self.ui = ui
156 self.ui = ui
157 self.map = None
157 self.map = None
158 self.pl = None
158
159
159 def __del__(self):
160 def __del__(self):
160 if self.dirty:
161 if self.dirty:
@@ -171,6 +172,15 b' class dirstate:'
171 if not self.map: self.read()
172 if not self.map: self.read()
172 return key in self.map
173 return key in self.map
173
174
175 def parents(self):
176 if not self.pl:
177 self.read()
178 return self.pl
179
180 def setparents(self, p1, p2 = nullid):
181 self.dirty = 1
182 self.pl = p1, p2
183
174 def state(self, key):
184 def state(self, key):
175 try:
185 try:
176 return self[key][0]
186 return self[key][0]
@@ -181,11 +191,14 b' class dirstate:'
181 if self.map is not None: return self.map
191 if self.map is not None: return self.map
182
192
183 self.map = {}
193 self.map = {}
194 self.pl = [nullid, nullid]
184 try:
195 try:
185 st = self.opener("dirstate").read()
196 st = self.opener("dirstate").read()
186 except: return
197 except: return
187
198
188 pos = 0
199 self.pl = [st[:20], st[20: 40]]
200
201 pos = 40
189 while pos < len(st):
202 while pos < len(st):
190 e = struct.unpack(">cllll", st[pos:pos+17])
203 e = struct.unpack(">cllll", st[pos:pos+17])
191 l = e[4]
204 l = e[4]
@@ -232,6 +245,7 b' class dirstate:'
232
245
233 def write(self):
246 def write(self):
234 st = self.opener("dirstate", "w")
247 st = self.opener("dirstate", "w")
248 st.write("".join(self.pl))
235 for f, e in self.map.items():
249 for f, e in self.map.items():
236 e = struct.pack(">cllll", e[0], e[1], e[2], e[3], len(f))
250 e = struct.pack(">cllll", e[0], e[1], e[2], e[3], len(f))
237 st.write(e + f)
251 st.write(e + f)
@@ -297,15 +311,7 b' class localrepository:'
297
311
298 if not self.remote:
312 if not self.remote:
299 self.dirstate = dirstate(self.opener, ui)
313 self.dirstate = dirstate(self.opener, ui)
300 try:
301 self.current = bin(self.opener("current").read())
302 except IOError:
303 self.current = None
304
314
305 def setcurrent(self, node):
306 self.current = node
307 self.opener("current", "w").write(hex(node))
308
309 def ignore(self, f):
315 def ignore(self, f):
310 if self.ignorelist is None:
316 if self.ignorelist is None:
311 self.ignorelist = []
317 self.ignorelist = []
@@ -366,7 +372,7 b' class localrepository:'
366 node = self.changelog.tip()
372 node = self.changelog.tip()
367 f.sort()
373 f.sort()
368
374
369 self.setcurrent(node)
375 self.dirstate.setparents(node)
370 self.dirstate.update(f, 'i')
376 self.dirstate.update(f, 'i')
371
377
372 else:
378 else:
@@ -486,7 +492,7 b' class localrepository:'
486 os.makedirs(os.path.dirname(f))
492 os.makedirs(os.path.dirname(f))
487 file(f, "w").write(t)
493 file(f, "w").write(t)
488
494
489 self.setcurrent(node)
495 self.dirstate.setparents(node)
490 self.dirstate.clear()
496 self.dirstate.clear()
491 self.dirstate.update([f for f,n in l], "n")
497 self.dirstate.update([f for f,n in l], "n")
492
498
General Comments 0
You need to be logged in to leave comments. Login now