comparison mercurial/hg.py @ 247:863b508c5b36

migrate verify -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 migrate verify Move the bulk of the verify code into the localrepository class and move the command into commands.py manifest hash: 793a8d0094d56ab0a411cd11d7fe7f39c923f209 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (GNU/Linux) iD8DBQFCog33ywK+sNU5EO8RApfBAJ4mCmiMmZE1fEfbR6sA+aP1csPvqQCfXHzY 3XK7yc19AivXf5HGKEOL3eM= =GISf -----END PGP SIGNATURE-----
author mpm@selenic.com
date Sat, 04 Jun 2005 12:24:23 -0800
parents 43105253cf5e
children 619e775aa7f9
comparison
equal deleted inserted replaced
246:96cde50a746f 247:863b508c5b36
991 self.ui.warn("merging %s failed!\n" % f) 991 self.ui.warn("merging %s failed!\n" % f)
992 992
993 os.unlink(b) 993 os.unlink(b)
994 os.unlink(c) 994 os.unlink(c)
995 995
996 def verify(self):
997 filelinkrevs = {}
998 filenodes = {}
999 manifestchangeset = {}
1000 changesets = revisions = files = 0
1001 errors = 0
1002
1003 self.ui.status("checking changesets\n")
1004 for i in range(self.changelog.count()):
1005 changesets += 1
1006 n = self.changelog.node(i)
1007 for p in self.changelog.parents(n):
1008 if p not in self.changelog.nodemap:
1009 self.ui.warn("changeset %s has unknown parent %s\n" %
1010 (short(n), short(p)))
1011 errors += 1
1012 try:
1013 changes = self.changelog.read(n)
1014 except Exception, inst:
1015 self.ui.warn("unpacking changeset %s: %s\n" % (short(n), inst))
1016 errors += 1
1017
1018 manifestchangeset[changes[0]] = n
1019 for f in changes[3]:
1020 filelinkrevs.setdefault(f, []).append(i)
1021
1022 self.ui.status("checking manifests\n")
1023 for i in range(self.manifest.count()):
1024 n = self.manifest.node(i)
1025 for p in self.manifest.parents(n):
1026 if p not in self.manifest.nodemap:
1027 self.ui.warn("manifest %s has unknown parent %s\n" %
1028 (short(n), short(p)))
1029 errors += 1
1030 ca = self.changelog.node(self.manifest.linkrev(n))
1031 cc = manifestchangeset[n]
1032 if ca != cc:
1033 self.ui.warn("manifest %s points to %s, not %s\n" %
1034 (hex(n), hex(ca), hex(cc)))
1035 errors += 1
1036
1037 try:
1038 delta = mdiff.patchtext(self.manifest.delta(n))
1039 except KeyboardInterrupt:
1040 print "aborted"
1041 sys.exit(0)
1042 except Exception, inst:
1043 self.ui.warn("unpacking manifest %s: %s\n"
1044 % (short(n), inst))
1045 errors += 1
1046
1047 ff = [ l.split('\0') for l in delta.splitlines() ]
1048 for f, fn in ff:
1049 filenodes.setdefault(f, {})[bin(fn)] = 1
1050
1051 self.ui.status("crosschecking files in changesets and manifests\n")
1052 for f in filenodes:
1053 if f not in filelinkrevs:
1054 self.ui.warn("file %s in manifest but not in changesets\n" % f)
1055 errors += 1
1056
1057 for f in filelinkrevs:
1058 if f not in filenodes:
1059 self.ui.warn("file %s in changeset but not in manifest\n" % f)
1060 errors += 1
1061
1062 self.ui.status("checking files\n")
1063 ff = filenodes.keys()
1064 ff.sort()
1065 for f in ff:
1066 if f == "/dev/null": continue
1067 files += 1
1068 fl = self.file(f)
1069 nodes = { nullid: 1 }
1070 for i in range(fl.count()):
1071 revisions += 1
1072 n = fl.node(i)
1073
1074 if n not in filenodes[f]:
1075 self.ui.warn("%s: %d:%s not in manifests\n"
1076 % (f, i, short(n)))
1077 print len(filenodes[f].keys()), fl.count(), f
1078 errors += 1
1079 else:
1080 del filenodes[f][n]
1081
1082 flr = fl.linkrev(n)
1083 if flr not in filelinkrevs[f]:
1084 self.ui.warn("%s:%s points to unexpected changeset %d\n"
1085 % (f, short(n), fl.linkrev(n)))
1086 errors += 1
1087 else:
1088 filelinkrevs[f].remove(flr)
1089
1090 # verify contents
1091 try:
1092 t = fl.read(n)
1093 except Exception, inst:
1094 self.ui.warn("unpacking file %s %s: %s\n"
1095 % (f, short(n), inst))
1096 errors += 1
1097
1098 # verify parents
1099 (p1, p2) = fl.parents(n)
1100 if p1 not in nodes:
1101 self.ui.warn("file %s:%s unknown parent 1 %s" %
1102 (f, short(n), short(p1)))
1103 errors += 1
1104 if p2 not in nodes:
1105 self.ui.warn("file %s:%s unknown parent 2 %s" %
1106 (f, short(n), short(p1)))
1107 errors += 1
1108 nodes[n] = 1
1109
1110 # cross-check
1111 for node in filenodes[f]:
1112 self.ui.warn("node %s in manifests not in %s\n"
1113 % (hex(n), f))
1114 errors += 1
1115
1116 self.ui.status("%d files, %d changesets, %d total revisions\n" %
1117 (files, changesets, revisions))
1118
1119 if errors:
1120 self.ui.warn("%d integrity errors encountered!\n" % errors)
1121 return 1
1122
996 class remoterepository: 1123 class remoterepository:
997 def __init__(self, ui, path): 1124 def __init__(self, ui, path):
998 self.url = path 1125 self.url = path
999 self.ui = ui 1126 self.ui = ui
1000 1127