4 # |
4 # |
5 # This software may be used and distributed according to the terms |
5 # This software may be used and distributed according to the terms |
6 # of the GNU General Public License, incorporated herein by reference. |
6 # of the GNU General Public License, incorporated herein by reference. |
7 |
7 |
8 from demandload import demandload |
8 from demandload import demandload |
|
9 from node import * |
9 demandload(globals(), "os re sys signal shutil imp") |
10 demandload(globals(), "os re sys signal shutil imp") |
10 demandload(globals(), "fancyopts ui hg util lock") |
11 demandload(globals(), "fancyopts ui hg util lock") |
11 demandload(globals(), "fnmatch hgweb mdiff random signal time traceback") |
12 demandload(globals(), "fnmatch hgweb mdiff random signal time traceback") |
12 demandload(globals(), "errno socket version struct atexit sets") |
13 demandload(globals(), "errno socket version struct atexit sets") |
13 |
14 |
161 yield str(fix(spec, None)) |
162 yield str(fix(spec, None)) |
162 |
163 |
163 def make_filename(repo, r, pat, node=None, |
164 def make_filename(repo, r, pat, node=None, |
164 total=None, seqno=None, revwidth=None): |
165 total=None, seqno=None, revwidth=None): |
165 node_expander = { |
166 node_expander = { |
166 'H': lambda: hg.hex(node), |
167 'H': lambda: hex(node), |
167 'R': lambda: str(r.rev(node)), |
168 'R': lambda: str(r.rev(node)), |
168 'h': lambda: hg.short(node), |
169 'h': lambda: short(node), |
169 } |
170 } |
170 expander = { |
171 expander = { |
171 '%': lambda: '%', |
172 '%': lambda: '%', |
172 'b': lambda: os.path.basename(repo.root), |
173 'b': lambda: os.path.basename(repo.root), |
173 } |
174 } |
240 return repo.wfile(f).read() |
241 return repo.wfile(f).read() |
241 |
242 |
242 if ui.quiet: |
243 if ui.quiet: |
243 r = None |
244 r = None |
244 else: |
245 else: |
245 hexfunc = ui.verbose and hg.hex or hg.short |
246 hexfunc = ui.verbose and hex or short |
246 r = [hexfunc(node) for node in [node1, node2] if node] |
247 r = [hexfunc(node) for node in [node1, node2] if node] |
247 |
248 |
248 change = repo.changelog.read(node1) |
249 change = repo.changelog.read(node1) |
249 mmap = repo.manifest.read(change[0]) |
250 mmap = repo.manifest.read(change[0]) |
250 date1 = date(change) |
251 date1 = date(change) |
271 changenode = log.node(rev) |
272 changenode = log.node(rev) |
272 elif not rev: |
273 elif not rev: |
273 rev = log.rev(changenode) |
274 rev = log.rev(changenode) |
274 |
275 |
275 if ui.quiet: |
276 if ui.quiet: |
276 ui.write("%d:%s\n" % (rev, hg.short(changenode))) |
277 ui.write("%d:%s\n" % (rev, short(changenode))) |
277 return |
278 return |
278 |
279 |
279 changes = log.read(changenode) |
280 changes = log.read(changenode) |
280 |
281 |
281 t, tz = changes[2].split(' ') |
282 t, tz = changes[2].split(' ') |
284 tz = int(tz) |
285 tz = int(tz) |
285 except ValueError: |
286 except ValueError: |
286 tz = 0 |
287 tz = 0 |
287 date = time.asctime(time.localtime(float(t))) + " %+05d" % (int(tz)/-36) |
288 date = time.asctime(time.localtime(float(t))) + " %+05d" % (int(tz)/-36) |
288 |
289 |
289 parents = [(log.rev(p), ui.verbose and hg.hex(p) or hg.short(p)) |
290 parents = [(log.rev(p), ui.verbose and hex(p) or short(p)) |
290 for p in log.parents(changenode) |
291 for p in log.parents(changenode) |
291 if ui.debugflag or p != hg.nullid] |
292 if ui.debugflag or p != nullid] |
292 if not ui.debugflag and len(parents) == 1 and parents[0][0] == rev-1: |
293 if not ui.debugflag and len(parents) == 1 and parents[0][0] == rev-1: |
293 parents = [] |
294 parents = [] |
294 |
295 |
295 if ui.verbose: |
296 if ui.verbose: |
296 ui.write("changeset: %d:%s\n" % (rev, hg.hex(changenode))) |
297 ui.write("changeset: %d:%s\n" % (rev, hex(changenode))) |
297 else: |
298 else: |
298 ui.write("changeset: %d:%s\n" % (rev, hg.short(changenode))) |
299 ui.write("changeset: %d:%s\n" % (rev, short(changenode))) |
299 |
300 |
300 for tag in repo.nodetags(changenode): |
301 for tag in repo.nodetags(changenode): |
301 ui.status("tag: %s\n" % tag) |
302 ui.status("tag: %s\n" % tag) |
302 for parent in parents: |
303 for parent in parents: |
303 ui.write("parent: %d:%s\n" % parent) |
304 ui.write("parent: %d:%s\n" % parent) |
305 if brinfo and changenode in brinfo: |
306 if brinfo and changenode in brinfo: |
306 br = brinfo[changenode] |
307 br = brinfo[changenode] |
307 ui.write("branch: %s\n" % " ".join(br)) |
308 ui.write("branch: %s\n" % " ".join(br)) |
308 |
309 |
309 ui.debug("manifest: %d:%s\n" % (repo.manifest.rev(changes[0]), |
310 ui.debug("manifest: %d:%s\n" % (repo.manifest.rev(changes[0]), |
310 hg.hex(changes[0]))) |
311 hex(changes[0]))) |
311 ui.status("user: %s\n" % changes[1]) |
312 ui.status("user: %s\n" % changes[1]) |
312 ui.status("date: %s\n" % date) |
313 ui.status("date: %s\n" % date) |
313 |
314 |
314 if ui.debugflag: |
315 if ui.debugflag: |
315 files = repo.changes(log.parents(changenode)[0], changenode) |
316 files = repo.changes(log.parents(changenode)[0], changenode) |
700 " nodeid p1 p2\n") |
701 " nodeid p1 p2\n") |
701 for i in range(r.count()): |
702 for i in range(r.count()): |
702 e = r.index[i] |
703 e = r.index[i] |
703 ui.write("% 6d % 9d % 7d % 6d % 7d %s %s %s\n" % ( |
704 ui.write("% 6d % 9d % 7d % 6d % 7d %s %s %s\n" % ( |
704 i, e[0], e[1], e[2], e[3], |
705 i, e[0], e[1], e[2], e[3], |
705 hg.short(e[6]), hg.short(e[4]), hg.short(e[5]))) |
706 short(e[6]), short(e[4]), short(e[5]))) |
706 |
707 |
707 def debugindexdot(ui, file_): |
708 def debugindexdot(ui, file_): |
708 """dump an index DAG as a .dot file""" |
709 """dump an index DAG as a .dot file""" |
709 r = hg.revlog(file, file_, "") |
710 r = hg.revlog(file, file_, "") |
710 ui.write("digraph G {\n") |
711 ui.write("digraph G {\n") |
711 for i in range(r.count()): |
712 for i in range(r.count()): |
712 e = r.index[i] |
713 e = r.index[i] |
713 ui.write("\t%d -> %d\n" % (r.rev(e[4]), i)) |
714 ui.write("\t%d -> %d\n" % (r.rev(e[4]), i)) |
714 if e[5] != hg.nullid: |
715 if e[5] != nullid: |
715 ui.write("\t%d -> %d\n" % (r.rev(e[5]), i)) |
716 ui.write("\t%d -> %d\n" % (r.rev(e[5]), i)) |
716 ui.write("}\n") |
717 ui.write("}\n") |
717 |
718 |
718 def debugwalk(ui, repo, *pats, **opts): |
719 def debugwalk(ui, repo, *pats, **opts): |
719 """show how files match on given patterns""" |
720 """show how files match on given patterns""" |
759 if fp != sys.stdout: |
760 if fp != sys.stdout: |
760 ui.note("%s\n" % fp.name) |
761 ui.note("%s\n" % fp.name) |
761 |
762 |
762 fp.write("# HG changeset patch\n") |
763 fp.write("# HG changeset patch\n") |
763 fp.write("# User %s\n" % change[1]) |
764 fp.write("# User %s\n" % change[1]) |
764 fp.write("# Node ID %s\n" % hg.hex(node)) |
765 fp.write("# Node ID %s\n" % hex(node)) |
765 fp.write("# Parent %s\n" % hg.hex(prev)) |
766 fp.write("# Parent %s\n" % hex(prev)) |
766 if other != hg.nullid: |
767 if other != nullid: |
767 fp.write("# Parent %s\n" % hg.hex(other)) |
768 fp.write("# Parent %s\n" % hex(other)) |
768 fp.write(change[4].rstrip()) |
769 fp.write(change[4].rstrip()) |
769 fp.write("\n\n") |
770 fp.write("\n\n") |
770 |
771 |
771 dodiff(fp, ui, repo, prev, node, text=opts['text']) |
772 dodiff(fp, ui, repo, prev, node, text=opts['text']) |
772 if fp != sys.stdout: |
773 if fp != sys.stdout: |
900 for n in repo.changelog.heads(): |
901 for n in repo.changelog.heads(): |
901 show_changeset(ui, repo, changenode=n, brinfo=br) |
902 show_changeset(ui, repo, changenode=n, brinfo=br) |
902 |
903 |
903 def identify(ui, repo): |
904 def identify(ui, repo): |
904 """print information about the working copy""" |
905 """print information about the working copy""" |
905 parents = [p for p in repo.dirstate.parents() if p != hg.nullid] |
906 parents = [p for p in repo.dirstate.parents() if p != nullid] |
906 if not parents: |
907 if not parents: |
907 ui.write("unknown\n") |
908 ui.write("unknown\n") |
908 return |
909 return |
909 |
910 |
910 hexfunc = ui.verbose and hg.hex or hg.short |
911 hexfunc = ui.verbose and hex or short |
911 (c, a, d, u) = repo.changes() |
912 (c, a, d, u) = repo.changes() |
912 output = ["%s%s" % ('+'.join([hexfunc(parent) for parent in parents]), |
913 output = ["%s%s" % ('+'.join([hexfunc(parent) for parent in parents]), |
913 (c or a or d) and "+" or "")] |
914 (c or a or d) and "+" or "")] |
914 |
915 |
915 if not ui.quiet: |
916 if not ui.quiet: |
1075 mf = repo.manifest.readflags(n) |
1076 mf = repo.manifest.readflags(n) |
1076 files = m.keys() |
1077 files = m.keys() |
1077 files.sort() |
1078 files.sort() |
1078 |
1079 |
1079 for f in files: |
1080 for f in files: |
1080 ui.write("%40s %3s %s\n" % (hg.hex(m[f]), mf[f] and "755" or "644", f)) |
1081 ui.write("%40s %3s %s\n" % (hex(m[f]), mf[f] and "755" or "644", f)) |
1081 |
1082 |
1082 def outgoing(ui, repo, dest="default-push"): |
1083 def outgoing(ui, repo, dest="default-push"): |
1083 """show changesets not found in destination""" |
1084 """show changesets not found in destination""" |
1084 dest = ui.expandpath(dest) |
1085 dest = ui.expandpath(dest) |
1085 other = hg.repository(ui, dest) |
1086 other = hg.repository(ui, dest) |
1095 p = repo.changelog.parents(repo.lookup(rev)) |
1096 p = repo.changelog.parents(repo.lookup(rev)) |
1096 else: |
1097 else: |
1097 p = repo.dirstate.parents() |
1098 p = repo.dirstate.parents() |
1098 |
1099 |
1099 for n in p: |
1100 for n in p: |
1100 if n != hg.nullid: |
1101 if n != nullid: |
1101 show_changeset(ui, repo, changenode=n) |
1102 show_changeset(ui, repo, changenode=n) |
1102 |
1103 |
1103 def paths(ui, search=None): |
1104 def paths(ui, search=None): |
1104 """show definition of symbolic path names""" |
1105 """show definition of symbolic path names""" |
1105 try: |
1106 try: |
1258 cmd = fin.readline()[:-1] |
1259 cmd = fin.readline()[:-1] |
1259 if cmd == '': |
1260 if cmd == '': |
1260 return |
1261 return |
1261 if cmd == "heads": |
1262 if cmd == "heads": |
1262 h = repo.heads() |
1263 h = repo.heads() |
1263 respond(" ".join(map(hg.hex, h)) + "\n") |
1264 respond(" ".join(map(hex, h)) + "\n") |
1264 if cmd == "lock": |
1265 if cmd == "lock": |
1265 lock = repo.lock() |
1266 lock = repo.lock() |
1266 respond("") |
1267 respond("") |
1267 if cmd == "unlock": |
1268 if cmd == "unlock": |
1268 if lock: |
1269 if lock: |
1269 lock.release() |
1270 lock.release() |
1270 lock = None |
1271 lock = None |
1271 respond("") |
1272 respond("") |
1272 elif cmd == "branches": |
1273 elif cmd == "branches": |
1273 arg, nodes = getarg() |
1274 arg, nodes = getarg() |
1274 nodes = map(hg.bin, nodes.split(" ")) |
1275 nodes = map(bin, nodes.split(" ")) |
1275 r = [] |
1276 r = [] |
1276 for b in repo.branches(nodes): |
1277 for b in repo.branches(nodes): |
1277 r.append(" ".join(map(hg.hex, b)) + "\n") |
1278 r.append(" ".join(map(hex, b)) + "\n") |
1278 respond("".join(r)) |
1279 respond("".join(r)) |
1279 elif cmd == "between": |
1280 elif cmd == "between": |
1280 arg, pairs = getarg() |
1281 arg, pairs = getarg() |
1281 pairs = [map(hg.bin, p.split("-")) for p in pairs.split(" ")] |
1282 pairs = [map(bin, p.split("-")) for p in pairs.split(" ")] |
1282 r = [] |
1283 r = [] |
1283 for b in repo.between(pairs): |
1284 for b in repo.between(pairs): |
1284 r.append(" ".join(map(hg.hex, b)) + "\n") |
1285 r.append(" ".join(map(hex, b)) + "\n") |
1285 respond("".join(r)) |
1286 respond("".join(r)) |
1286 elif cmd == "changegroup": |
1287 elif cmd == "changegroup": |
1287 nodes = [] |
1288 nodes = [] |
1288 arg, roots = getarg() |
1289 arg, roots = getarg() |
1289 nodes = map(hg.bin, roots.split(" ")) |
1290 nodes = map(bin, roots.split(" ")) |
1290 |
1291 |
1291 cg = repo.changegroup(nodes) |
1292 cg = repo.changegroup(nodes) |
1292 while 1: |
1293 while 1: |
1293 d = cg.read(4096) |
1294 d = cg.read(4096) |
1294 if not d: |
1295 if not d: |
1366 " please use -m or --message instead.\n") |
1367 " please use -m or --message instead.\n") |
1367 if name == "tip": |
1368 if name == "tip": |
1368 ui.warn("abort: 'tip' is a reserved name!\n") |
1369 ui.warn("abort: 'tip' is a reserved name!\n") |
1369 return -1 |
1370 return -1 |
1370 if rev: |
1371 if rev: |
1371 r = hg.hex(repo.lookup(rev)) |
1372 r = hex(repo.lookup(rev)) |
1372 else: |
1373 else: |
1373 r = hg.hex(repo.changelog.tip()) |
1374 r = hex(repo.changelog.tip()) |
1374 |
1375 |
1375 if name.find(revrangesep) >= 0: |
1376 if name.find(revrangesep) >= 0: |
1376 ui.warn("abort: '%s' cannot be used in a tag name\n" % revrangesep) |
1377 ui.warn("abort: '%s' cannot be used in a tag name\n" % revrangesep) |
1377 return -1 |
1378 return -1 |
1378 |
1379 |
1451 for x in found: |
1452 for x in found: |
1452 show_changeset(ui, repo, changenode=x, brinfo=br) |
1453 show_changeset(ui, repo, changenode=x, brinfo=br) |
1453 return 1 |
1454 return 1 |
1454 if len(found) == 1: |
1455 if len(found) == 1: |
1455 node = found[0] |
1456 node = found[0] |
1456 ui.warn("Using head %s for branch %s\n" % (hg.short(node), branch)) |
1457 ui.warn("Using head %s for branch %s\n" % (short(node), branch)) |
1457 else: |
1458 else: |
1458 ui.warn("branch %s not found\n" % (branch)) |
1459 ui.warn("branch %s not found\n" % (branch)) |
1459 return 1 |
1460 return 1 |
1460 else: |
1461 else: |
1461 node = node and repo.lookup(node) or repo.changelog.tip() |
1462 node = node and repo.lookup(node) or repo.changelog.tip() |