annotate hggit/verify.py @ 694:1e3e4ff9a25a

verify: drop broken and unused import statement
author Augie Fackler <raf@durin42.com>
date Sat, 01 Mar 2014 09:37:26 -0500
parents 9b194d7c9c03
children 705f0a2a7c18
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
693
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
1 # verify.py - verify Mercurial revisions
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
2 #
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
3 # Copyright 2014 Facebook.
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
4 #
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
5 # This software may be used and distributed according to the terms
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
6 # of the GNU General Public License, incorporated herein by reference.
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
7
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
8 import stat
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
9
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
10 from mercurial import error
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
11 from mercurial import util as hgutil
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
12 from mercurial.node import hex, bin, nullid
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
13 from mercurial.i18n import _
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
14 from mercurial import scmutil
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
15
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
16 from dulwich import diff_tree
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
17 from dulwich.objects import Commit, S_IFGITLINK
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
18
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
19 def verify(ui, repo, **opts):
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
20 '''verify that a Mercurial rev matches the corresponding Git rev
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
21
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
22 Given a Mercurial revision that has a corresponding Git revision in the map,
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
23 this attempts to answer whether that revision has the same contents as the
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
24 corresponding Git revision.
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
25
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
26 '''
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
27 hgctx = scmutil.revsingle(repo, opts.get('rev'), '.')
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
28
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
29 handler = repo.githandler
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
30
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
31 gitsha = handler.map_git_get(hgctx.hex())
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
32 if not gitsha:
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
33 # TODO deal better with commits in the middle of octopus merges
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
34 raise hgutil.Abort(_('no git commit found for rev %s') % hgctx,
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
35 hint=_('if this is an octopus merge, verify against the last rev'))
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
36
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
37 try:
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
38 gitcommit = handler.git.get_object(gitsha)
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
39 except KeyError:
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
40 raise hgutil.Abort(_('git equivalent %s for rev %s not found!') %
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
41 (gitsha, hgctx))
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
42 if not isinstance(gitcommit, Commit):
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
43 raise hgutil.Abort(_('git equivalent %s for rev %s is not a commit!') %
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
44 (gitsha, hgctx))
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
45
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
46 ui.status(_('verifying rev %s against git commit %s\n') % (hgctx, gitsha))
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
47 failed = False
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
48
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
49 # TODO check commit message and other metadata
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
50
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
51 dirkind = stat.S_IFDIR
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
52
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
53 hgfiles = set(hgctx)
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
54 # TODO deal with submodules
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
55 hgfiles.discard('.hgsubstate')
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
56 hgfiles.discard('.hgsub')
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
57 gitfiles = set()
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
58
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
59 i = 0
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
60 for gitfile, dummy in diff_tree.walk_trees(handler.git.object_store,
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
61 gitcommit.tree, None):
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
62 if gitfile.mode == dirkind:
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
63 continue
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
64 # TODO deal with submodules
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
65 if (gitfile.mode == S_IFGITLINK or gitfile.path == '.hgsubstate'
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
66 or gitfile.path == '.hgsub'):
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
67 continue
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
68 ui.progress('verify', i, total=len(hgfiles))
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
69 i += 1
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
70 gitfiles.add(gitfile.path)
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
71
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
72 try:
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
73 fctx = hgctx[gitfile.path]
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
74 except error.LookupError:
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
75 # we'll deal with this at the end
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
76 continue
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
77
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
78 hgflags = fctx.flags()
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
79 gitflags = handler.convert_git_int_mode(gitfile.mode)
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
80 if hgflags != gitflags:
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
81 ui.write(_("file has different flags: %s (hg '%s', git '%s')\n") %
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
82 (gitfile.path, hgflags, gitflags))
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
83 failed = True
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
84 if fctx.data() != handler.git[gitfile.sha].data:
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
85 ui.write(_('difference in: %s\n') % gitfile.path)
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
86 failed = True
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
87
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
88 ui.progress('verify', None, total=len(hgfiles))
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
89
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
90 if hgfiles != gitfiles:
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
91 failed = True
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
92 missing = gitfiles - hgfiles
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
93 for f in sorted(missing):
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
94 ui.write(_('file found in git but not hg: %s\n') % f)
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
95 unexpected = hgfiles - gitfiles
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
96 for f in sorted(unexpected):
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
97 ui.write(_('file found in hg but not git: %s\n') % f)
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
98
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
99 if failed:
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
100 return 1
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
101 else:
9b194d7c9c03 verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
102 return 0