Mercurial > hg-git
annotate hggit/verify.py @ 1116:bd1a01f98154
cleanup: wrap to 80 chars
author | Sean Farley <sean@farley.io> |
---|---|
date | Mon, 27 Nov 2017 19:05:08 -0500 |
parents | 8ed6c0cae9b8 |
children | 6141895a53c9 |
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.i18n import _ |
9b194d7c9c03
verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
13 |
9b194d7c9c03
verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
14 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
|
15 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
|
16 |
1115 | 17 |
731
705f0a2a7c18
verify: add a wrapper function in __init__.py
Siddharth Agarwal <sid0@fb.com>
parents:
694
diff
changeset
|
18 def verify(ui, repo, hgctx): |
693
9b194d7c9c03
verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
19 '''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
|
20 |
1116 | 21 Given a Mercurial revision that has a corresponding Git revision in the |
22 map, this attempts to answer whether that revision has the same contents as | |
23 the corresponding Git revision. | |
693
9b194d7c9c03
verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
24 |
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 handler = repo.githandler |
9b194d7c9c03
verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
27 |
9b194d7c9c03
verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
28 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
|
29 if not gitsha: |
9b194d7c9c03
verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
30 # 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
|
31 raise hgutil.Abort(_('no git commit found for rev %s') % hgctx, |
892 | 32 hint=_('if this is an octopus merge, ' |
33 'verify against the last rev')) | |
693
9b194d7c9c03
verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
34 |
9b194d7c9c03
verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
35 try: |
9b194d7c9c03
verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
36 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
|
37 except KeyError: |
9b194d7c9c03
verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
38 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
|
39 (gitsha, hgctx)) |
9b194d7c9c03
verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
40 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
|
41 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
|
42 (gitsha, hgctx)) |
9b194d7c9c03
verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
43 |
9b194d7c9c03
verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
44 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
|
45 failed = False |
9b194d7c9c03
verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
46 |
9b194d7c9c03
verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
47 # 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
|
48 |
9b194d7c9c03
verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
49 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
|
50 |
9b194d7c9c03
verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
51 hgfiles = set(hgctx) |
9b194d7c9c03
verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
52 # 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
|
53 hgfiles.discard('.hgsubstate') |
9b194d7c9c03
verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
54 hgfiles.discard('.hgsub') |
9b194d7c9c03
verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
55 gitfiles = set() |
9b194d7c9c03
verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
56 |
9b194d7c9c03
verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
57 i = 0 |
9b194d7c9c03
verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
58 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
|
59 gitcommit.tree, None): |
9b194d7c9c03
verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
60 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
|
61 continue |
9b194d7c9c03
verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
62 # TODO deal with submodules |
892 | 63 if (gitfile.mode == S_IFGITLINK or gitfile.path == '.hgsubstate' or |
64 gitfile.path == '.hgsub'): | |
693
9b194d7c9c03
verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
65 continue |
9b194d7c9c03
verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
66 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
|
67 i += 1 |
9b194d7c9c03
verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
68 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
|
69 |
9b194d7c9c03
verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
70 try: |
9b194d7c9c03
verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
71 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
|
72 except error.LookupError: |
9b194d7c9c03
verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
73 # 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
|
74 continue |
9b194d7c9c03
verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
75 |
9b194d7c9c03
verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
76 hgflags = fctx.flags() |
9b194d7c9c03
verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
77 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
|
78 if hgflags != gitflags: |
9b194d7c9c03
verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
79 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
|
80 (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
|
81 failed = True |
9b194d7c9c03
verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
82 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
|
83 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
|
84 failed = True |
9b194d7c9c03
verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
85 |
9b194d7c9c03
verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
86 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
|
87 |
9b194d7c9c03
verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
88 if hgfiles != gitfiles: |
9b194d7c9c03
verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
89 failed = True |
9b194d7c9c03
verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
90 missing = gitfiles - hgfiles |
9b194d7c9c03
verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
91 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
|
92 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
|
93 unexpected = hgfiles - gitfiles |
9b194d7c9c03
verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
94 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
|
95 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
|
96 |
9b194d7c9c03
verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
97 if failed: |
9b194d7c9c03
verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
98 return 1 |
9b194d7c9c03
verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
99 else: |
9b194d7c9c03
verify: add new command to verify the contents of a Mercurial rev
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
100 return 0 |