Mercurial > hg-git
annotate hggit/git_handler.py @ 1135:c4703246f350
compat: mark all compat-checking locations outside hggit.compat with "COMPAT:"
The format is:
# COMPAT: hg X.Y - description of change that affects this block
author | Kevin Bullock <kbullock@ringworld.org> |
---|---|
date | Fri, 02 Feb 2018 13:41:42 -0600 |
parents | 6141895a53c9 |
children | 7fd9ee0f7b66 |
rev | line source |
---|---|
883
4d67686c0e64
git_handler: remove dead imports and put them on multiple lines
Sean Farley <sean@farley.io>
parents:
882
diff
changeset
|
1 import collections |
4d67686c0e64
git_handler: remove dead imports and put them on multiple lines
Sean Farley <sean@farley.io>
parents:
882
diff
changeset
|
2 import itertools |
4d67686c0e64
git_handler: remove dead imports and put them on multiple lines
Sean Farley <sean@farley.io>
parents:
882
diff
changeset
|
3 import os |
4d67686c0e64
git_handler: remove dead imports and put them on multiple lines
Sean Farley <sean@farley.io>
parents:
882
diff
changeset
|
4 import urllib |
4d67686c0e64
git_handler: remove dead imports and put them on multiple lines
Sean Farley <sean@farley.io>
parents:
882
diff
changeset
|
5 import urllib2 |
4d67686c0e64
git_handler: remove dead imports and put them on multiple lines
Sean Farley <sean@farley.io>
parents:
882
diff
changeset
|
6 import re |
4d67686c0e64
git_handler: remove dead imports and put them on multiple lines
Sean Farley <sean@farley.io>
parents:
882
diff
changeset
|
7 import cStringIO |
4d67686c0e64
git_handler: remove dead imports and put them on multiple lines
Sean Farley <sean@farley.io>
parents:
882
diff
changeset
|
8 import StringIO |
224
80d67ae190df
port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
222
diff
changeset
|
9 |
883
4d67686c0e64
git_handler: remove dead imports and put them on multiple lines
Sean Farley <sean@farley.io>
parents:
882
diff
changeset
|
10 from dulwich.errors import HangupException, GitProtocolError |
4d67686c0e64
git_handler: remove dead imports and put them on multiple lines
Sean Farley <sean@farley.io>
parents:
882
diff
changeset
|
11 from dulwich.objects import Blob, Commit, Tag, Tree, parse_timezone |
225
cde57730faa7
store non utf-8 encoded author/commit message as deltas
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
224
diff
changeset
|
12 from dulwich.pack import create_delta, apply_delta |
601
65d8a43bc5ee
git_handler: skip exporting hg tags whose names are not valid as git tag name
nsuke <nsukeg@gmail.com>
parents:
596
diff
changeset
|
13 from dulwich.repo import Repo, check_ref_format |
285
5e5aee9b32d4
git_handler: slight style cleanup
Augie Fackler <durin42@gmail.com>
parents:
284
diff
changeset
|
14 from dulwich import client |
476
b9ede5f91701
Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
475
diff
changeset
|
15 from dulwich import config as dul_config |
838
f6f84d51a154
git_handler.get_files_changed: switch to diff_tree's tree_changes
Siddharth Agarwal <sid0@fb.com>
parents:
837
diff
changeset
|
16 from dulwich import diff_tree |
224
80d67ae190df
port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
222
diff
changeset
|
17 |
5
d6c443a91b18
refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
18 from mercurial.i18n import _ |
188
5d48a2310e16
Use mercurial.node.bin instead of dulwich.objects.hex_to_sha
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
187
diff
changeset
|
19 from mercurial.node import hex, bin, nullid |
958
f2391790aaf6
git_handler: regularize mercurial imports
Siddharth Agarwal <sid0@fb.com>
parents:
957
diff
changeset
|
20 from mercurial import ( |
f2391790aaf6
git_handler: regularize mercurial imports
Siddharth Agarwal <sid0@fb.com>
parents:
957
diff
changeset
|
21 bookmarks, |
f2391790aaf6
git_handler: regularize mercurial imports
Siddharth Agarwal <sid0@fb.com>
parents:
957
diff
changeset
|
22 commands, |
f2391790aaf6
git_handler: regularize mercurial imports
Siddharth Agarwal <sid0@fb.com>
parents:
957
diff
changeset
|
23 context, |
974
afea0e32db20
git_handler: work around dulwich using unicode for ref names
Augie Fackler <raf@durin42.com>
parents:
965
diff
changeset
|
24 encoding, |
1128
6141895a53c9
compat: switch from hgutil.Abort to error.Abort
Kevin Bullock <kbullock@ringworld.org>
parents:
1127
diff
changeset
|
25 error, |
1078
a70c1f6caead
fetch: mark remote HEAD as public phase
Sean Farley <sean@farley.io>
parents:
1073
diff
changeset
|
26 phases, |
958
f2391790aaf6
git_handler: regularize mercurial imports
Siddharth Agarwal <sid0@fb.com>
parents:
957
diff
changeset
|
27 util as hgutil, |
f2391790aaf6
git_handler: regularize mercurial imports
Siddharth Agarwal <sid0@fb.com>
parents:
957
diff
changeset
|
28 ) |
222
e414c72d3ec9
fix compatibility with mercurial 1.1
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
221
diff
changeset
|
29 |
369
e5c743cd0da1
pass hg's ui.ssh config to dulwich
Tay Ray Chuan <rctay89@gmail.com>
parents:
368
diff
changeset
|
30 import _ssh |
992
05c8aa7d3edc
git_handler: use compat.passwordmgr for hg < 3.9 support
Sean Farley <sean@farley.io>
parents:
987
diff
changeset
|
31 import compat |
788
e734d71cc558
git_handler: move get_git_incoming to a separate module
Siddharth Agarwal <sid0@fb.com>
parents:
787
diff
changeset
|
32 import git2hg |
596
d6b9c30a3e0f
Export Git objects from incremental Mercurial changes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
593
diff
changeset
|
33 import hg2git |
320
6eded2e4c616
Un-break hg 1.3 by adding a compat layer for progress.
Augie Fackler <durin42@gmail.com>
parents:
317
diff
changeset
|
34 import util |
408 | 35 from overlay import overlayrepo |
24
41f4e0a85d15
fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents:
23
diff
changeset
|
36 |
596
d6b9c30a3e0f
Export Git objects from incremental Mercurial changes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
593
diff
changeset
|
37 |
537
6e05aa1b536d
Optimize get_git_author
Gregory Szorc <gregory.szorc@gmail.com>
parents:
523
diff
changeset
|
38 RE_GIT_AUTHOR = re.compile('^(.*?) ?\<(.*?)(?:\>(.*))?$') |
6e05aa1b536d
Optimize get_git_author
Gregory Szorc <gregory.szorc@gmail.com>
parents:
523
diff
changeset
|
39 |
539
7bf60690386c
Precompile Git username sanitizing regular expression
Gregory Szorc <gregory.szorc@gmail.com>
parents:
538
diff
changeset
|
40 RE_GIT_SANITIZE_AUTHOR = re.compile('[<>\n]') |
7bf60690386c
Precompile Git username sanitizing regular expression
Gregory Szorc <gregory.szorc@gmail.com>
parents:
538
diff
changeset
|
41 |
540
3fb942852b1c
Precompile Git author extra data regular expression
Gregory Szorc <gregory.szorc@gmail.com>
parents:
539
diff
changeset
|
42 RE_GIT_AUTHOR_EXTRA = re.compile('^(.*?)\ ext:\((.*)\) <(.*)\>$') |
3fb942852b1c
Precompile Git author extra data regular expression
Gregory Szorc <gregory.szorc@gmail.com>
parents:
539
diff
changeset
|
43 |
764
70aba6b2fe7b
git_handler: export hg extra metadata as git extra metadata (issue121)
Siddharth Agarwal <sid0@fb.com>
parents:
763
diff
changeset
|
44 RE_GIT_EXTRA_KEY = re.compile('GIT([0-9]*)-(.*)') |
70aba6b2fe7b
git_handler: export hg extra metadata as git extra metadata (issue121)
Siddharth Agarwal <sid0@fb.com>
parents:
763
diff
changeset
|
45 |
538
a38abdbab77c
Precompile Git URI regular expression
Gregory Szorc <gregory.szorc@gmail.com>
parents:
537
diff
changeset
|
46 # Test for git:// and git+ssh:// URI. |
a38abdbab77c
Precompile Git URI regular expression
Gregory Szorc <gregory.szorc@gmail.com>
parents:
537
diff
changeset
|
47 # Support several URL forms, including separating the |
a38abdbab77c
Precompile Git URI regular expression
Gregory Szorc <gregory.szorc@gmail.com>
parents:
537
diff
changeset
|
48 # host and path with either a / or : (sepr) |
a38abdbab77c
Precompile Git URI regular expression
Gregory Szorc <gregory.szorc@gmail.com>
parents:
537
diff
changeset
|
49 RE_GIT_URI = re.compile( |
a38abdbab77c
Precompile Git URI regular expression
Gregory Szorc <gregory.szorc@gmail.com>
parents:
537
diff
changeset
|
50 r'^(?P<scheme>git([+]ssh)?://)(?P<host>.*?)(:(?P<port>\d+))?' |
a38abdbab77c
Precompile Git URI regular expression
Gregory Szorc <gregory.szorc@gmail.com>
parents:
537
diff
changeset
|
51 r'(?P<sepr>[:/])(?P<path>.*)$') |
a38abdbab77c
Precompile Git URI regular expression
Gregory Szorc <gregory.szorc@gmail.com>
parents:
537
diff
changeset
|
52 |
541
df1598b722e8
Precompile Git progress regular expressions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
540
diff
changeset
|
53 RE_NEWLINES = re.compile('[\r\n]') |
df1598b722e8
Precompile Git progress regular expressions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
540
diff
changeset
|
54 RE_GIT_PROGRESS = re.compile('\((\d+)/(\d+)\)') |
df1598b722e8
Precompile Git progress regular expressions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
540
diff
changeset
|
55 |
542
c9faba7d01f4
Precompile author file regular expression
Gregory Szorc <gregory.szorc@gmail.com>
parents:
541
diff
changeset
|
56 RE_AUTHOR_FILE = re.compile('\s*=\s*') |
c9faba7d01f4
Precompile author file regular expression
Gregory Szorc <gregory.szorc@gmail.com>
parents:
541
diff
changeset
|
57 |
1125
8f55daa87ce4
git-handler: fix deprecated API in next hg version
Paul Morelle <paul.morelle@octobus.net>
parents:
1124
diff
changeset
|
58 # mercurial.utils.dateutil functions were in mercurial.util in Mercurial < 4.6 |
8f55daa87ce4
git-handler: fix deprecated API in next hg version
Paul Morelle <paul.morelle@octobus.net>
parents:
1124
diff
changeset
|
59 try: |
8f55daa87ce4
git-handler: fix deprecated API in next hg version
Paul Morelle <paul.morelle@octobus.net>
parents:
1124
diff
changeset
|
60 from mercurial.utils import dateutil |
8f55daa87ce4
git-handler: fix deprecated API in next hg version
Paul Morelle <paul.morelle@octobus.net>
parents:
1124
diff
changeset
|
61 dateutil.parsedate |
8f55daa87ce4
git-handler: fix deprecated API in next hg version
Paul Morelle <paul.morelle@octobus.net>
parents:
1124
diff
changeset
|
62 except ImportError: |
8f55daa87ce4
git-handler: fix deprecated API in next hg version
Paul Morelle <paul.morelle@octobus.net>
parents:
1124
diff
changeset
|
63 dateutil = hgutil |
8f55daa87ce4
git-handler: fix deprecated API in next hg version
Paul Morelle <paul.morelle@octobus.net>
parents:
1124
diff
changeset
|
64 |
982
296349f421c8
push: better formatting of messages from the server
Sean Farley <sean@farley.io>
parents:
981
diff
changeset
|
65 CALLBACK_BUFFER = '' |
296349f421c8
push: better formatting of messages from the server
Sean Farley <sean@farley.io>
parents:
981
diff
changeset
|
66 |
1115
8ed6c0cae9b8
cleanup: add some blank lines
Sean Farley <sean@farley.io>
parents:
1114
diff
changeset
|
67 |
411
de7317967598
Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents:
408
diff
changeset
|
68 class GitProgress(object): |
de7317967598
Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents:
408
diff
changeset
|
69 """convert git server progress strings into mercurial progress""" |
de7317967598
Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents:
408
diff
changeset
|
70 def __init__(self, ui): |
de7317967598
Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents:
408
diff
changeset
|
71 self.ui = ui |
de7317967598
Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents:
408
diff
changeset
|
72 |
de7317967598
Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents:
408
diff
changeset
|
73 self.lasttopic = None |
de7317967598
Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents:
408
diff
changeset
|
74 self.msgbuf = '' |
de7317967598
Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents:
408
diff
changeset
|
75 |
de7317967598
Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents:
408
diff
changeset
|
76 def progress(self, msg): |
de7317967598
Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents:
408
diff
changeset
|
77 # 'Counting objects: 33640, done.\n' |
de7317967598
Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents:
408
diff
changeset
|
78 # 'Compressing objects: 0% (1/9955) \r |
541
df1598b722e8
Precompile Git progress regular expressions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
540
diff
changeset
|
79 msgs = RE_NEWLINES.split(self.msgbuf + msg) |
411
de7317967598
Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents:
408
diff
changeset
|
80 self.msgbuf = msgs.pop() |
de7317967598
Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents:
408
diff
changeset
|
81 |
de7317967598
Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents:
408
diff
changeset
|
82 for msg in msgs: |
de7317967598
Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents:
408
diff
changeset
|
83 td = msg.split(':', 1) |
de7317967598
Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents:
408
diff
changeset
|
84 data = td.pop() |
de7317967598
Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents:
408
diff
changeset
|
85 if not td: |
de7317967598
Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents:
408
diff
changeset
|
86 self.flush(data) |
de7317967598
Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents:
408
diff
changeset
|
87 continue |
de7317967598
Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents:
408
diff
changeset
|
88 topic = td[0] |
de7317967598
Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents:
408
diff
changeset
|
89 |
541
df1598b722e8
Precompile Git progress regular expressions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
540
diff
changeset
|
90 m = RE_GIT_PROGRESS.search(data) |
411
de7317967598
Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents:
408
diff
changeset
|
91 if m: |
de7317967598
Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents:
408
diff
changeset
|
92 if self.lasttopic and self.lasttopic != topic: |
de7317967598
Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents:
408
diff
changeset
|
93 self.flush() |
de7317967598
Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents:
408
diff
changeset
|
94 self.lasttopic = topic |
de7317967598
Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents:
408
diff
changeset
|
95 |
de7317967598
Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents:
408
diff
changeset
|
96 pos, total = map(int, m.group(1, 2)) |
685
c7129c72baff
git_handler: replace util.progress with ui.progress
Siddharth Agarwal <sid0@fb.com>
parents:
683
diff
changeset
|
97 self.ui.progress(topic, pos, total=total) |
411
de7317967598
Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents:
408
diff
changeset
|
98 else: |
de7317967598
Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents:
408
diff
changeset
|
99 self.flush(msg) |
de7317967598
Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents:
408
diff
changeset
|
100 |
de7317967598
Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents:
408
diff
changeset
|
101 def flush(self, msg=None): |
de7317967598
Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents:
408
diff
changeset
|
102 if self.lasttopic: |
688
1323058cc652
git_handler: fix call to self.ui.progress in flush
Siddharth Agarwal <sid0@fb.com>
parents:
687
diff
changeset
|
103 self.ui.progress(self.lasttopic, None) |
411
de7317967598
Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents:
408
diff
changeset
|
104 self.lasttopic = None |
de7317967598
Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents:
408
diff
changeset
|
105 if msg: |
de7317967598
Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents:
408
diff
changeset
|
106 self.ui.note(msg + '\n') |
de7317967598
Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents:
408
diff
changeset
|
107 |
1115
8ed6c0cae9b8
cleanup: add some blank lines
Sean Farley <sean@farley.io>
parents:
1114
diff
changeset
|
108 |
5
d6c443a91b18
refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
109 class GitHandler(object): |
768
4a9057b16f40
git_handler: rename mapfile to map_file for PEP8 compat
Siddharth Agarwal <sid0@fb.com>
parents:
767
diff
changeset
|
110 map_file = 'git-mapfile' |
770
7835a7559986
git_handler: move git-remote-refs out to a class field for consistency
Siddharth Agarwal <sid0@fb.com>
parents:
769
diff
changeset
|
111 remote_refs_file = 'git-remote-refs' |
769
4b786698329c
git_handler: rename tagsfile to tags_file for PEP8 compat
Siddharth Agarwal <sid0@fb.com>
parents:
768
diff
changeset
|
112 tags_file = 'git-tags' |
19
2be9c0bd88af
Warn, but don't fail when bookmarks is not enabled.
Augie Fackler <durin42@gmail.com>
parents:
17
diff
changeset
|
113 |
5
d6c443a91b18
refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
114 def __init__(self, dest_repo, ui): |
d6c443a91b18
refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
115 self.repo = dest_repo |
d6c443a91b18
refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
116 self.ui = ui |
1085
1003994dd497
share: host the git repository alongside the store
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
1079
diff
changeset
|
117 self.vfs = self.repo.vfs |
133
f2dfb2bed724
Allow storing the git directory intree
Sverre Rabbelier <sverre@rabbelier.nl>
parents:
118
diff
changeset
|
118 |
1085
1003994dd497
share: host the git repository alongside the store
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
1079
diff
changeset
|
119 # Mercurial >= 3.3: repo.shared() |
1003994dd497
share: host the git repository alongside the store
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
1079
diff
changeset
|
120 if dest_repo.sharedpath != dest_repo.path: |
1088
c06d4656b77b
shared: fix compatibility with hg < 4.2
Kevin Bullock <kbullock@ringworld.org>
parents:
1085
diff
changeset
|
121 self.vfs = compat.hgvfs(dest_repo.sharedpath) |
1064
d37336a87b70
config: register git.intree
Kevin Bullock <kbullock@ringworld.org>
parents:
1059
diff
changeset
|
122 if compat.config(ui, 'bool', 'git', 'intree'): |
1018
715cbf3fa24c
vfs: stop using repo.join/wjoin
Durham Goode <durham@fb.com>
parents:
1013
diff
changeset
|
123 self.gitdir = self.repo.wvfs.join('.git') |
133
f2dfb2bed724
Allow storing the git directory intree
Sverre Rabbelier <sverre@rabbelier.nl>
parents:
118
diff
changeset
|
124 else: |
1085
1003994dd497
share: host the git repository alongside the store
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
1079
diff
changeset
|
125 self.gitdir = self.vfs.join('git') |
133
f2dfb2bed724
Allow storing the git directory intree
Sverre Rabbelier <sverre@rabbelier.nl>
parents:
118
diff
changeset
|
126 |
450
163ac98569d3
- add "author file" extension, allows an author translation map
Mike Bayer <mike_mp@zzzcomputing.com>
parents:
448
diff
changeset
|
127 self.init_author_file() |
163ac98569d3
- add "author file" extension, allows an author translation map
Mike Bayer <mike_mp@zzzcomputing.com>
parents:
448
diff
changeset
|
128 |
184
7bf98d3085f4
Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
183
diff
changeset
|
129 self.paths = ui.configitems('paths') |
141
a989866eead8
Make it possible to limit what branches are imported
Sverre Rabbelier <sverre@rabbelier.nl>
parents:
140
diff
changeset
|
130 |
1065
78dc28eb4245
config: register git.branch_bookmark_suffix
Kevin Bullock <kbullock@ringworld.org>
parents:
1064
diff
changeset
|
131 self.branch_bookmark_suffix = compat.config( |
78dc28eb4245
config: register git.branch_bookmark_suffix
Kevin Bullock <kbullock@ringworld.org>
parents:
1064
diff
changeset
|
132 ui, 'string', 'git', 'branch_bookmark_suffix') |
441
35e2813f58a5
- add "branch_bookmark_names" parameter. this allows bookmarks
Mike Bayer <mike_mp@zzzcomputing.com>
parents:
439
diff
changeset
|
133 |
766
da9f47555926
git_handler.load_map: use None as the uninitialized condition
Siddharth Agarwal <sid0@fb.com>
parents:
764
diff
changeset
|
134 self._map_git_real = None |
da9f47555926
git_handler.load_map: use None as the uninitialized condition
Siddharth Agarwal <sid0@fb.com>
parents:
764
diff
changeset
|
135 self._map_hg_real = None |
552
bff92a208c3f
git_handler: lazy-load mapping
Augie Fackler <raf@durin42.com>
parents:
489
diff
changeset
|
136 self.load_tags() |
772
03e1e9929dea
hgrepo: move remote ref loading to git_handler
Siddharth Agarwal <sid0@fb.com>
parents:
771
diff
changeset
|
137 self._remote_refs = None |
552
bff92a208c3f
git_handler: lazy-load mapping
Augie Fackler <raf@durin42.com>
parents:
489
diff
changeset
|
138 |
bff92a208c3f
git_handler: lazy-load mapping
Augie Fackler <raf@durin42.com>
parents:
489
diff
changeset
|
139 @property |
bff92a208c3f
git_handler: lazy-load mapping
Augie Fackler <raf@durin42.com>
parents:
489
diff
changeset
|
140 def _map_git(self): |
884
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
141 if self._map_git_real is None: |
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
142 self.load_map() |
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
143 return self._map_git_real |
552
bff92a208c3f
git_handler: lazy-load mapping
Augie Fackler <raf@durin42.com>
parents:
489
diff
changeset
|
144 |
bff92a208c3f
git_handler: lazy-load mapping
Augie Fackler <raf@durin42.com>
parents:
489
diff
changeset
|
145 @property |
bff92a208c3f
git_handler: lazy-load mapping
Augie Fackler <raf@durin42.com>
parents:
489
diff
changeset
|
146 def _map_hg(self): |
884
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
147 if self._map_hg_real is None: |
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
148 self.load_map() |
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
149 return self._map_hg_real |
19
2be9c0bd88af
Warn, but don't fail when bookmarks is not enabled.
Augie Fackler <durin42@gmail.com>
parents:
17
diff
changeset
|
150 |
772
03e1e9929dea
hgrepo: move remote ref loading to git_handler
Siddharth Agarwal <sid0@fb.com>
parents:
771
diff
changeset
|
151 @property |
03e1e9929dea
hgrepo: move remote ref loading to git_handler
Siddharth Agarwal <sid0@fb.com>
parents:
771
diff
changeset
|
152 def remote_refs(self): |
03e1e9929dea
hgrepo: move remote ref loading to git_handler
Siddharth Agarwal <sid0@fb.com>
parents:
771
diff
changeset
|
153 if self._remote_refs is None: |
03e1e9929dea
hgrepo: move remote ref loading to git_handler
Siddharth Agarwal <sid0@fb.com>
parents:
771
diff
changeset
|
154 self.load_remote_refs() |
03e1e9929dea
hgrepo: move remote ref loading to git_handler
Siddharth Agarwal <sid0@fb.com>
parents:
771
diff
changeset
|
155 return self._remote_refs |
03e1e9929dea
hgrepo: move remote ref loading to git_handler
Siddharth Agarwal <sid0@fb.com>
parents:
771
diff
changeset
|
156 |
691
6ab17ae0c834
git_handler: make self.git a lazily evaluated property
Siddharth Agarwal <sid0@fb.com>
parents:
688
diff
changeset
|
157 @hgutil.propertycache |
6ab17ae0c834
git_handler: make self.git a lazily evaluated property
Siddharth Agarwal <sid0@fb.com>
parents:
688
diff
changeset
|
158 def git(self): |
974
afea0e32db20
git_handler: work around dulwich using unicode for ref names
Augie Fackler <raf@durin42.com>
parents:
965
diff
changeset
|
159 # Dulwich is going to try and join unicode ref names against |
afea0e32db20
git_handler: work around dulwich using unicode for ref names
Augie Fackler <raf@durin42.com>
parents:
965
diff
changeset
|
160 # the repository path to try and read unpacked refs. This |
afea0e32db20
git_handler: work around dulwich using unicode for ref names
Augie Fackler <raf@durin42.com>
parents:
965
diff
changeset
|
161 # doesn't match hg's bytes-only view of filesystems, we just |
afea0e32db20
git_handler: work around dulwich using unicode for ref names
Augie Fackler <raf@durin42.com>
parents:
965
diff
changeset
|
162 # have to cope with that. As a workaround, try decoding our |
afea0e32db20
git_handler: work around dulwich using unicode for ref names
Augie Fackler <raf@durin42.com>
parents:
965
diff
changeset
|
163 # (bytes) path to the repo in hg's active encoding and hope |
afea0e32db20
git_handler: work around dulwich using unicode for ref names
Augie Fackler <raf@durin42.com>
parents:
965
diff
changeset
|
164 # for the best. |
afea0e32db20
git_handler: work around dulwich using unicode for ref names
Augie Fackler <raf@durin42.com>
parents:
965
diff
changeset
|
165 gitpath = self.gitdir.decode(encoding.encoding, encoding.encodingmode) |
691
6ab17ae0c834
git_handler: make self.git a lazily evaluated property
Siddharth Agarwal <sid0@fb.com>
parents:
688
diff
changeset
|
166 # make the git data directory |
258
1590c97d7af0
do not init the cache git repo unless needed (fixes issue 16 bb)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
248
diff
changeset
|
167 if os.path.exists(self.gitdir): |
974
afea0e32db20
git_handler: work around dulwich using unicode for ref names
Augie Fackler <raf@durin42.com>
parents:
965
diff
changeset
|
168 return Repo(gitpath) |
258
1590c97d7af0
do not init the cache git repo unless needed (fixes issue 16 bb)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
248
diff
changeset
|
169 else: |
106
3aa2f6caed16
make the gitdir a constant
Sverre Rabbelier <sverre@rabbelier.nl>
parents:
105
diff
changeset
|
170 os.mkdir(self.gitdir) |
974
afea0e32db20
git_handler: work around dulwich using unicode for ref names
Augie Fackler <raf@durin42.com>
parents:
965
diff
changeset
|
171 return Repo.init_bare(gitpath) |
691
6ab17ae0c834
git_handler: make self.git a lazily evaluated property
Siddharth Agarwal <sid0@fb.com>
parents:
688
diff
changeset
|
172 |
450
163ac98569d3
- add "author file" extension, allows an author translation map
Mike Bayer <mike_mp@zzzcomputing.com>
parents:
448
diff
changeset
|
173 def init_author_file(self): |
163ac98569d3
- add "author file" extension, allows an author translation map
Mike Bayer <mike_mp@zzzcomputing.com>
parents:
448
diff
changeset
|
174 self.author_map = {} |
1066
ddae0045de4e
config: register git.authors
Kevin Bullock <kbullock@ringworld.org>
parents:
1065
diff
changeset
|
175 authors_path = compat.config(self.ui, 'string', 'git', 'authors') |
ddae0045de4e
config: register git.authors
Kevin Bullock <kbullock@ringworld.org>
parents:
1065
diff
changeset
|
176 if authors_path: |
ddae0045de4e
config: register git.authors
Kevin Bullock <kbullock@ringworld.org>
parents:
1065
diff
changeset
|
177 with open(self.repo.wvfs.join(authors_path)) as f: |
450
163ac98569d3
- add "author file" extension, allows an author translation map
Mike Bayer <mike_mp@zzzcomputing.com>
parents:
448
diff
changeset
|
178 for line in f: |
163ac98569d3
- add "author file" extension, allows an author translation map
Mike Bayer <mike_mp@zzzcomputing.com>
parents:
448
diff
changeset
|
179 line = line.strip() |
163ac98569d3
- add "author file" extension, allows an author translation map
Mike Bayer <mike_mp@zzzcomputing.com>
parents:
448
diff
changeset
|
180 if not line or line.startswith('#'): |
163ac98569d3
- add "author file" extension, allows an author translation map
Mike Bayer <mike_mp@zzzcomputing.com>
parents:
448
diff
changeset
|
181 continue |
542
c9faba7d01f4
Precompile author file regular expression
Gregory Szorc <gregory.szorc@gmail.com>
parents:
541
diff
changeset
|
182 from_, to = RE_AUTHOR_FILE.split(line, 2) |
450
163ac98569d3
- add "author file" extension, allows an author translation map
Mike Bayer <mike_mp@zzzcomputing.com>
parents:
448
diff
changeset
|
183 self.author_map[from_] = to |
163ac98569d3
- add "author file" extension, allows an author translation map
Mike Bayer <mike_mp@zzzcomputing.com>
parents:
448
diff
changeset
|
184 |
884
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
185 # FILE LOAD AND SAVE METHODS |
14
36e94e805fa7
added basic config file for remembering remote urls
Scott Chacon <schacon@gmail.com>
parents:
13
diff
changeset
|
186 |
21
13b9a020e382
gpush coming along. will now write blobs it doesn't have yet to git repo.
Scott Chacon <schacon@gmail.com>
parents:
19
diff
changeset
|
187 def map_set(self, gitsha, hgsha): |
13b9a020e382
gpush coming along. will now write blobs it doesn't have yet to git repo.
Scott Chacon <schacon@gmail.com>
parents:
19
diff
changeset
|
188 self._map_git[gitsha] = hgsha |
13b9a020e382
gpush coming along. will now write blobs it doesn't have yet to git repo.
Scott Chacon <schacon@gmail.com>
parents:
19
diff
changeset
|
189 self._map_hg[hgsha] = gitsha |
13b9a020e382
gpush coming along. will now write blobs it doesn't have yet to git repo.
Scott Chacon <schacon@gmail.com>
parents:
19
diff
changeset
|
190 |
13b9a020e382
gpush coming along. will now write blobs it doesn't have yet to git repo.
Scott Chacon <schacon@gmail.com>
parents:
19
diff
changeset
|
191 def map_hg_get(self, gitsha): |
213
61471faeb7fd
small cleanups (tabs, s/TODO :/TODO:/ and dead code)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
212
diff
changeset
|
192 return self._map_git.get(gitsha) |
21
13b9a020e382
gpush coming along. will now write blobs it doesn't have yet to git repo.
Scott Chacon <schacon@gmail.com>
parents:
19
diff
changeset
|
193 |
13b9a020e382
gpush coming along. will now write blobs it doesn't have yet to git repo.
Scott Chacon <schacon@gmail.com>
parents:
19
diff
changeset
|
194 def map_git_get(self, hgsha): |
213
61471faeb7fd
small cleanups (tabs, s/TODO :/TODO:/ and dead code)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
212
diff
changeset
|
195 return self._map_hg.get(hgsha) |
50
d274092e3b24
Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents:
42
diff
changeset
|
196 |
7
89992b6d2eef
mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents:
6
diff
changeset
|
197 def load_map(self): |
875
8c112b6d5e61
git_handler.load_map: avoid property accesses
Siddharth Agarwal <sid0@fb.com>
parents:
869
diff
changeset
|
198 map_git_real = {} |
8c112b6d5e61
git_handler.load_map: avoid property accesses
Siddharth Agarwal <sid0@fb.com>
parents:
869
diff
changeset
|
199 map_hg_real = {} |
1085
1003994dd497
share: host the git repository alongside the store
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
1079
diff
changeset
|
200 if os.path.exists(self.vfs.join(self.map_file)): |
1003994dd497
share: host the git repository alongside the store
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
1079
diff
changeset
|
201 for line in self.vfs(self.map_file): |
876
b250e7b3ad71
git_handler.load_map: avoid split and strip
Siddharth Agarwal <sid0@fb.com>
parents:
875
diff
changeset
|
202 # format is <40 hex digits> <40 hex digits>\n |
b250e7b3ad71
git_handler.load_map: avoid split and strip
Siddharth Agarwal <sid0@fb.com>
parents:
875
diff
changeset
|
203 if len(line) != 82: |
b250e7b3ad71
git_handler.load_map: avoid split and strip
Siddharth Agarwal <sid0@fb.com>
parents:
875
diff
changeset
|
204 raise ValueError( |
b250e7b3ad71
git_handler.load_map: avoid split and strip
Siddharth Agarwal <sid0@fb.com>
parents:
875
diff
changeset
|
205 _('corrupt mapfile: incorrect line length %d') % |
b250e7b3ad71
git_handler.load_map: avoid split and strip
Siddharth Agarwal <sid0@fb.com>
parents:
875
diff
changeset
|
206 len(line)) |
b250e7b3ad71
git_handler.load_map: avoid split and strip
Siddharth Agarwal <sid0@fb.com>
parents:
875
diff
changeset
|
207 gitsha = line[:40] |
b250e7b3ad71
git_handler.load_map: avoid split and strip
Siddharth Agarwal <sid0@fb.com>
parents:
875
diff
changeset
|
208 hgsha = line[41:81] |
875
8c112b6d5e61
git_handler.load_map: avoid property accesses
Siddharth Agarwal <sid0@fb.com>
parents:
869
diff
changeset
|
209 map_git_real[gitsha] = hgsha |
8c112b6d5e61
git_handler.load_map: avoid property accesses
Siddharth Agarwal <sid0@fb.com>
parents:
869
diff
changeset
|
210 map_hg_real[hgsha] = gitsha |
8c112b6d5e61
git_handler.load_map: avoid property accesses
Siddharth Agarwal <sid0@fb.com>
parents:
869
diff
changeset
|
211 self._map_git_real = map_git_real |
8c112b6d5e61
git_handler.load_map: avoid property accesses
Siddharth Agarwal <sid0@fb.com>
parents:
869
diff
changeset
|
212 self._map_hg_real = map_hg_real |
19
2be9c0bd88af
Warn, but don't fail when bookmarks is not enabled.
Augie Fackler <durin42@gmail.com>
parents:
17
diff
changeset
|
213 |
877
be105c4dda7b
git_handler.save_map: pass in the map file explicitly for easier testing
Siddharth Agarwal <sid0@fb.com>
parents:
876
diff
changeset
|
214 def save_map(self, map_file): |
1025
e7a8a5710257
wlock: use non-context-manager form to restore older hg support
Kevin Bullock <kbullock@ringworld.org>
parents:
1024
diff
changeset
|
215 wlock = self.repo.wlock() |
e7a8a5710257
wlock: use non-context-manager form to restore older hg support
Kevin Bullock <kbullock@ringworld.org>
parents:
1024
diff
changeset
|
216 try: |
1085
1003994dd497
share: host the git repository alongside the store
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
1079
diff
changeset
|
217 file = self.vfs(map_file, 'w+', atomictemp=True) |
1023
78959c8e5e60
wlock: take wlock when writing map file
Durham Goode <durham@fb.com>
parents:
1021
diff
changeset
|
218 map_hg = self._map_hg |
78959c8e5e60
wlock: take wlock when writing map file
Durham Goode <durham@fb.com>
parents:
1021
diff
changeset
|
219 buf = cStringIO.StringIO() |
78959c8e5e60
wlock: take wlock when writing map file
Durham Goode <durham@fb.com>
parents:
1021
diff
changeset
|
220 bwrite = buf.write |
78959c8e5e60
wlock: take wlock when writing map file
Durham Goode <durham@fb.com>
parents:
1021
diff
changeset
|
221 for hgsha, gitsha in map_hg.iteritems(): |
78959c8e5e60
wlock: take wlock when writing map file
Durham Goode <durham@fb.com>
parents:
1021
diff
changeset
|
222 bwrite("%s %s\n" % (gitsha, hgsha)) |
78959c8e5e60
wlock: take wlock when writing map file
Durham Goode <durham@fb.com>
parents:
1021
diff
changeset
|
223 file.write(buf.getvalue()) |
78959c8e5e60
wlock: take wlock when writing map file
Durham Goode <durham@fb.com>
parents:
1021
diff
changeset
|
224 buf.close() |
78959c8e5e60
wlock: take wlock when writing map file
Durham Goode <durham@fb.com>
parents:
1021
diff
changeset
|
225 # If this complains, atomictempfile no longer has close |
78959c8e5e60
wlock: take wlock when writing map file
Durham Goode <durham@fb.com>
parents:
1021
diff
changeset
|
226 file.close() |
1025
e7a8a5710257
wlock: use non-context-manager form to restore older hg support
Kevin Bullock <kbullock@ringworld.org>
parents:
1024
diff
changeset
|
227 finally: |
e7a8a5710257
wlock: use non-context-manager form to restore older hg support
Kevin Bullock <kbullock@ringworld.org>
parents:
1024
diff
changeset
|
228 wlock.release() |
19
2be9c0bd88af
Warn, but don't fail when bookmarks is not enabled.
Augie Fackler <durin42@gmail.com>
parents:
17
diff
changeset
|
229 |
187
5f196f80ffb3
Store git tags in .hg/git-tags and let localtags be *local*
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
186
diff
changeset
|
230 def load_tags(self): |
5f196f80ffb3
Store git tags in .hg/git-tags and let localtags be *local*
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
186
diff
changeset
|
231 self.tags = {} |
1085
1003994dd497
share: host the git repository alongside the store
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
1079
diff
changeset
|
232 if os.path.exists(self.vfs.join(self.tags_file)): |
1003994dd497
share: host the git repository alongside the store
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
1079
diff
changeset
|
233 for line in self.vfs(self.tags_file): |
187
5f196f80ffb3
Store git tags in .hg/git-tags and let localtags be *local*
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
186
diff
changeset
|
234 sha, name = line.strip().split(' ', 1) |
5f196f80ffb3
Store git tags in .hg/git-tags and let localtags be *local*
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
186
diff
changeset
|
235 self.tags[name] = sha |
5f196f80ffb3
Store git tags in .hg/git-tags and let localtags be *local*
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
186
diff
changeset
|
236 |
5f196f80ffb3
Store git tags in .hg/git-tags and let localtags be *local*
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
186
diff
changeset
|
237 def save_tags(self): |
1085
1003994dd497
share: host the git repository alongside the store
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
1079
diff
changeset
|
238 file = self.vfs(self.tags_file, 'w+', atomictemp=True) |
187
5f196f80ffb3
Store git tags in .hg/git-tags and let localtags be *local*
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
186
diff
changeset
|
239 for name, sha in sorted(self.tags.iteritems()): |
212
174954c187e0
fix pushing tags to git (see issue 3 bb)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
210
diff
changeset
|
240 if not self.repo.tagtype(name) == 'global': |
174954c187e0
fix pushing tags to git (see issue 3 bb)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
210
diff
changeset
|
241 file.write("%s %s\n" % (sha, name)) |
682
2cfda7bc4c46
git_handler.save_tags: drop support for Mercurial < 1.9
Siddharth Agarwal <sid0@fb.com>
parents:
681
diff
changeset
|
242 # If this complains, atomictempfile no longer has close |
2cfda7bc4c46
git_handler.save_tags: drop support for Mercurial < 1.9
Siddharth Agarwal <sid0@fb.com>
parents:
681
diff
changeset
|
243 file.close() |
187
5f196f80ffb3
Store git tags in .hg/git-tags and let localtags be *local*
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
186
diff
changeset
|
244 |
772
03e1e9929dea
hgrepo: move remote ref loading to git_handler
Siddharth Agarwal <sid0@fb.com>
parents:
771
diff
changeset
|
245 def load_remote_refs(self): |
03e1e9929dea
hgrepo: move remote ref loading to git_handler
Siddharth Agarwal <sid0@fb.com>
parents:
771
diff
changeset
|
246 self._remote_refs = {} |
930
a12e11d9fb11
refs: avoid using dulwich to load refs
Sean Farley <sean@farley.io>
parents:
929
diff
changeset
|
247 refdir = os.path.join(self.git.path, 'refs', 'remotes') |
a12e11d9fb11
refs: avoid using dulwich to load refs
Sean Farley <sean@farley.io>
parents:
929
diff
changeset
|
248 |
a12e11d9fb11
refs: avoid using dulwich to load refs
Sean Farley <sean@farley.io>
parents:
929
diff
changeset
|
249 paths = self.paths |
a12e11d9fb11
refs: avoid using dulwich to load refs
Sean Farley <sean@farley.io>
parents:
929
diff
changeset
|
250 # if paths are set, we should still check 'default' |
a12e11d9fb11
refs: avoid using dulwich to load refs
Sean Farley <sean@farley.io>
parents:
929
diff
changeset
|
251 if not paths: |
1114
6ef251fdbb30
cleanup: use tuple instead of list since path is immutable
Sean Farley <sean@farley.io>
parents:
1113
diff
changeset
|
252 paths = (('default', None),) |
930
a12e11d9fb11
refs: avoid using dulwich to load refs
Sean Farley <sean@farley.io>
parents:
929
diff
changeset
|
253 |
a12e11d9fb11
refs: avoid using dulwich to load refs
Sean Farley <sean@farley.io>
parents:
929
diff
changeset
|
254 # we avoid using dulwich's refs method because it is incredibly slow; |
a12e11d9fb11
refs: avoid using dulwich to load refs
Sean Farley <sean@farley.io>
parents:
929
diff
changeset
|
255 # on a repo with a few hundred branches and a few thousand tags, |
a12e11d9fb11
refs: avoid using dulwich to load refs
Sean Farley <sean@farley.io>
parents:
929
diff
changeset
|
256 # dulwich took about 200ms |
a12e11d9fb11
refs: avoid using dulwich to load refs
Sean Farley <sean@farley.io>
parents:
929
diff
changeset
|
257 for p in paths: |
a12e11d9fb11
refs: avoid using dulwich to load refs
Sean Farley <sean@farley.io>
parents:
929
diff
changeset
|
258 remotedir = os.path.join(refdir, p[0]) |
a12e11d9fb11
refs: avoid using dulwich to load refs
Sean Farley <sean@farley.io>
parents:
929
diff
changeset
|
259 for root, dirs, files in os.walk(remotedir): |
a12e11d9fb11
refs: avoid using dulwich to load refs
Sean Farley <sean@farley.io>
parents:
929
diff
changeset
|
260 for f in files: |
a12e11d9fb11
refs: avoid using dulwich to load refs
Sean Farley <sean@farley.io>
parents:
929
diff
changeset
|
261 try: |
a12e11d9fb11
refs: avoid using dulwich to load refs
Sean Farley <sean@farley.io>
parents:
929
diff
changeset
|
262 ref = root.replace(refdir + os.sep, '') + '/' |
a12e11d9fb11
refs: avoid using dulwich to load refs
Sean Farley <sean@farley.io>
parents:
929
diff
changeset
|
263 node = open(os.path.join(root, f)).read().strip() |
a12e11d9fb11
refs: avoid using dulwich to load refs
Sean Farley <sean@farley.io>
parents:
929
diff
changeset
|
264 self._remote_refs[ref + f] = bin(self._map_git[node]) |
a12e11d9fb11
refs: avoid using dulwich to load refs
Sean Farley <sean@farley.io>
parents:
929
diff
changeset
|
265 except (KeyError, IOError): |
a12e11d9fb11
refs: avoid using dulwich to load refs
Sean Farley <sean@farley.io>
parents:
929
diff
changeset
|
266 pass |
774
9c6bd4102ef5
git_handler: move remote ref writing to a separate function
Siddharth Agarwal <sid0@fb.com>
parents:
773
diff
changeset
|
267 |
884
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
268 # END FILE LOAD AND SAVE METHODS |
7
89992b6d2eef
mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents:
6
diff
changeset
|
269 |
884
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
270 # COMMANDS METHODS |
183
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
271 |
137
5aefcbf1e50c
add a gimport command
Sverre Rabbelier <sverre@rabbelier.nl>
parents:
136
diff
changeset
|
272 def import_commits(self, remote_name): |
796
b21d6d8ea9ba
git_handler.import_commits: pass in refs explicitly
Siddharth Agarwal <sid0@fb.com>
parents:
795
diff
changeset
|
273 refs = self.git.refs.as_dict() |
823
f16eaf601496
gimport: support git.mindate
Siddharth Agarwal <sid0@fb.com>
parents:
822
diff
changeset
|
274 filteredrefs = self.filter_min_date(refs) |
f16eaf601496
gimport: support git.mindate
Siddharth Agarwal <sid0@fb.com>
parents:
822
diff
changeset
|
275 self.import_git_objects(remote_name, filteredrefs) |
796
b21d6d8ea9ba
git_handler.import_commits: pass in refs explicitly
Siddharth Agarwal <sid0@fb.com>
parents:
795
diff
changeset
|
276 self.update_hg_bookmarks(refs) |
877
be105c4dda7b
git_handler.save_map: pass in the map file explicitly for easier testing
Siddharth Agarwal <sid0@fb.com>
parents:
876
diff
changeset
|
277 self.save_map(self.map_file) |
137
5aefcbf1e50c
add a gimport command
Sverre Rabbelier <sverre@rabbelier.nl>
parents:
136
diff
changeset
|
278 |
232
0ba1aee0467c
initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
231
diff
changeset
|
279 def fetch(self, remote, heads): |
1094
5e49230a6cd5
fetch_pack: refactor to use compat.FetchPackResult
Sean Farley <sean@farley.io>
parents:
1088
diff
changeset
|
280 result = self.fetch_pack(remote, heads) |
184
7bf98d3085f4
Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
183
diff
changeset
|
281 remote_name = self.remote_name(remote) |
7bf98d3085f4
Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
183
diff
changeset
|
282 |
1008
4fa1812d1f24
git_handler: use remote HEAD for cloned bookmark (BC)
Sean Farley <sean@farley.io>
parents:
1006
diff
changeset
|
283 # if remote returns a symref for HEAD, then let's store that |
4fa1812d1f24
git_handler: use remote HEAD for cloned bookmark (BC)
Sean Farley <sean@farley.io>
parents:
1006
diff
changeset
|
284 rhead = None |
4fa1812d1f24
git_handler: use remote HEAD for cloned bookmark (BC)
Sean Farley <sean@farley.io>
parents:
1006
diff
changeset
|
285 rnode = None |
703
4cddcb768cf4
git_handler.fetch: actually return number of heads added or removed
Siddharth Agarwal <sid0@fb.com>
parents:
702
diff
changeset
|
286 oldheads = self.repo.changelog.heads() |
4cddcb768cf4
git_handler.fetch: actually return number of heads added or removed
Siddharth Agarwal <sid0@fb.com>
parents:
702
diff
changeset
|
287 imported = 0 |
1094
5e49230a6cd5
fetch_pack: refactor to use compat.FetchPackResult
Sean Farley <sean@farley.io>
parents:
1088
diff
changeset
|
288 if result.refs: |
5e49230a6cd5
fetch_pack: refactor to use compat.FetchPackResult
Sean Farley <sean@farley.io>
parents:
1088
diff
changeset
|
289 filteredrefs = self.filter_min_date(self.filter_refs(result.refs, |
5e49230a6cd5
fetch_pack: refactor to use compat.FetchPackResult
Sean Farley <sean@farley.io>
parents:
1088
diff
changeset
|
290 heads)) |
704
373f854ff58f
git_handler.fetch: only import commits reachable from requested heads
Siddharth Agarwal <sid0@fb.com>
parents:
703
diff
changeset
|
291 imported = self.import_git_objects(remote_name, filteredrefs) |
1094
5e49230a6cd5
fetch_pack: refactor to use compat.FetchPackResult
Sean Farley <sean@farley.io>
parents:
1088
diff
changeset
|
292 self.import_tags(result.refs) |
5e49230a6cd5
fetch_pack: refactor to use compat.FetchPackResult
Sean Farley <sean@farley.io>
parents:
1088
diff
changeset
|
293 self.update_hg_bookmarks(result.refs) |
1008
4fa1812d1f24
git_handler: use remote HEAD for cloned bookmark (BC)
Sean Farley <sean@farley.io>
parents:
1006
diff
changeset
|
294 |
4fa1812d1f24
git_handler: use remote HEAD for cloned bookmark (BC)
Sean Farley <sean@farley.io>
parents:
1006
diff
changeset
|
295 try: |
1094
5e49230a6cd5
fetch_pack: refactor to use compat.FetchPackResult
Sean Farley <sean@farley.io>
parents:
1088
diff
changeset
|
296 symref = result.symrefs['HEAD'] |
1008
4fa1812d1f24
git_handler: use remote HEAD for cloned bookmark (BC)
Sean Farley <sean@farley.io>
parents:
1006
diff
changeset
|
297 if symref.startswith('refs/heads'): |
4fa1812d1f24
git_handler: use remote HEAD for cloned bookmark (BC)
Sean Farley <sean@farley.io>
parents:
1006
diff
changeset
|
298 rhead = symref.replace('refs/heads/', '') |
4fa1812d1f24
git_handler: use remote HEAD for cloned bookmark (BC)
Sean Farley <sean@farley.io>
parents:
1006
diff
changeset
|
299 |
1094
5e49230a6cd5
fetch_pack: refactor to use compat.FetchPackResult
Sean Farley <sean@farley.io>
parents:
1088
diff
changeset
|
300 rnode = result.refs['refs/heads/%s' % rhead] |
1008
4fa1812d1f24
git_handler: use remote HEAD for cloned bookmark (BC)
Sean Farley <sean@farley.io>
parents:
1006
diff
changeset
|
301 rnode = self._map_git[rnode] |
4fa1812d1f24
git_handler: use remote HEAD for cloned bookmark (BC)
Sean Farley <sean@farley.io>
parents:
1006
diff
changeset
|
302 rnode = self.repo[rnode].node() |
4fa1812d1f24
git_handler: use remote HEAD for cloned bookmark (BC)
Sean Farley <sean@farley.io>
parents:
1006
diff
changeset
|
303 except KeyError: |
4fa1812d1f24
git_handler: use remote HEAD for cloned bookmark (BC)
Sean Farley <sean@farley.io>
parents:
1006
diff
changeset
|
304 # if there is any error make sure to clear the variables |
4fa1812d1f24
git_handler: use remote HEAD for cloned bookmark (BC)
Sean Farley <sean@farley.io>
parents:
1006
diff
changeset
|
305 rhead = None |
4fa1812d1f24
git_handler: use remote HEAD for cloned bookmark (BC)
Sean Farley <sean@farley.io>
parents:
1006
diff
changeset
|
306 rnode = None |
4fa1812d1f24
git_handler: use remote HEAD for cloned bookmark (BC)
Sean Farley <sean@farley.io>
parents:
1006
diff
changeset
|
307 |
184
7bf98d3085f4
Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
183
diff
changeset
|
308 if remote_name: |
1094
5e49230a6cd5
fetch_pack: refactor to use compat.FetchPackResult
Sean Farley <sean@farley.io>
parents:
1088
diff
changeset
|
309 self.update_remote_branches(remote_name, result.refs) |
1102
93cb29247d61
exchange: check for remote refs to determine if we're cloning
Kevin Bullock <kbullock@ringworld.org>
parents:
1101
diff
changeset
|
310 elif not self.git.refs.as_dict('refs/remotes/'): |
184
7bf98d3085f4
Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
183
diff
changeset
|
311 # intial cloning |
1094
5e49230a6cd5
fetch_pack: refactor to use compat.FetchPackResult
Sean Farley <sean@farley.io>
parents:
1088
diff
changeset
|
312 self.update_remote_branches('default', result.refs) |
387
ed28dd69df61
git_handler: support versions of hg without bookmarks
Augie Fackler <durin42@gmail.com>
parents:
385
diff
changeset
|
313 |
384
fc37cb795b51
activate a tipmost bookmark (git branch) after clone
Adrian Sampson <adrian@radbox.org>
parents:
382
diff
changeset
|
314 # "Activate" a tipmost bookmark. |
932
07f03124e1b9
git_handler: remove pre-2.8 code for bookmarks
Sean Farley <sean@farley.io>
parents:
931
diff
changeset
|
315 bms = self.repo['tip'].bookmarks() |
07f03124e1b9
git_handler: remove pre-2.8 code for bookmarks
Sean Farley <sean@farley.io>
parents:
931
diff
changeset
|
316 |
1008
4fa1812d1f24
git_handler: use remote HEAD for cloned bookmark (BC)
Sean Farley <sean@farley.io>
parents:
1006
diff
changeset
|
317 # override the 'tipmost' behavior if we know the remote HEAD |
4fa1812d1f24
git_handler: use remote HEAD for cloned bookmark (BC)
Sean Farley <sean@farley.io>
parents:
1006
diff
changeset
|
318 if rnode: |
4fa1812d1f24
git_handler: use remote HEAD for cloned bookmark (BC)
Sean Farley <sean@farley.io>
parents:
1006
diff
changeset
|
319 # make sure the bookmark exists; at the point the remote |
4fa1812d1f24
git_handler: use remote HEAD for cloned bookmark (BC)
Sean Farley <sean@farley.io>
parents:
1006
diff
changeset
|
320 # branches has already been set up |
4fa1812d1f24
git_handler: use remote HEAD for cloned bookmark (BC)
Sean Farley <sean@farley.io>
parents:
1006
diff
changeset
|
321 suffix = self.branch_bookmark_suffix or '' |
1024
078c3912afce
bookmarks: compatibility with new applychanges api
Ryan McElroy <rmcelroy@fb.com>
parents:
1023
diff
changeset
|
322 changes = [(rhead + suffix, rnode)] |
078c3912afce
bookmarks: compatibility with new applychanges api
Ryan McElroy <rmcelroy@fb.com>
parents:
1023
diff
changeset
|
323 util.updatebookmarks(self.repo, changes) |
1008
4fa1812d1f24
git_handler: use remote HEAD for cloned bookmark (BC)
Sean Farley <sean@farley.io>
parents:
1006
diff
changeset
|
324 bms = [rhead + suffix] |
4fa1812d1f24
git_handler: use remote HEAD for cloned bookmark (BC)
Sean Farley <sean@farley.io>
parents:
1006
diff
changeset
|
325 |
384
fc37cb795b51
activate a tipmost bookmark (git branch) after clone
Adrian Sampson <adrian@radbox.org>
parents:
382
diff
changeset
|
326 if bms: |
1135
c4703246f350
compat: mark all compat-checking locations outside hggit.compat with "COMPAT:"
Kevin Bullock <kbullock@ringworld.org>
parents:
1128
diff
changeset
|
327 # COMPAT: hg 3.5 - bookmarks.setcurrent renamed to activate |
905
286555803dae
git_handler: update for bookmark changes in mercurial 3.5
Sean Farley <sean@farley.io>
parents:
885
diff
changeset
|
328 try: |
286555803dae
git_handler: update for bookmark changes in mercurial 3.5
Sean Farley <sean@farley.io>
parents:
885
diff
changeset
|
329 bookmarks.activate(self.repo, bms[0]) |
286555803dae
git_handler: update for bookmark changes in mercurial 3.5
Sean Farley <sean@farley.io>
parents:
885
diff
changeset
|
330 except AttributeError: |
286555803dae
git_handler: update for bookmark changes in mercurial 3.5
Sean Farley <sean@farley.io>
parents:
885
diff
changeset
|
331 bookmarks.setcurrent(self.repo, bms[0]) |
397
60d181f9ecc3
Make pull results more like hg pulls.
Brendan Cully <brendan@kublai.com>
parents:
395
diff
changeset
|
332 |
877
be105c4dda7b
git_handler.save_map: pass in the map file explicitly for easier testing
Siddharth Agarwal <sid0@fb.com>
parents:
876
diff
changeset
|
333 self.save_map(self.map_file) |
7
89992b6d2eef
mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents:
6
diff
changeset
|
334 |
1079
fda826275060
git_handler: add config knob for marking git branches public
Sean Farley <sean@farley.io>
parents:
1078
diff
changeset
|
335 # also mark public any branches the user specified |
fda826275060
git_handler: add config knob for marking git branches public
Sean Farley <sean@farley.io>
parents:
1078
diff
changeset
|
336 blist = [self.repo[branch].node() for branch in |
fda826275060
git_handler: add config knob for marking git branches public
Sean Farley <sean@farley.io>
parents:
1078
diff
changeset
|
337 self.ui.configlist('git', 'public')] |
1078
a70c1f6caead
fetch: mark remote HEAD as public phase
Sean Farley <sean@farley.io>
parents:
1073
diff
changeset
|
338 if rnode and self.ui.configbool('hggit', 'usephases'): |
1079
fda826275060
git_handler: add config knob for marking git branches public
Sean Farley <sean@farley.io>
parents:
1078
diff
changeset
|
339 blist.append(rnode) |
fda826275060
git_handler: add config knob for marking git branches public
Sean Farley <sean@farley.io>
parents:
1078
diff
changeset
|
340 |
fda826275060
git_handler: add config knob for marking git branches public
Sean Farley <sean@farley.io>
parents:
1078
diff
changeset
|
341 if blist: |
1078
a70c1f6caead
fetch: mark remote HEAD as public phase
Sean Farley <sean@farley.io>
parents:
1073
diff
changeset
|
342 lock = self.repo.lock() |
a70c1f6caead
fetch: mark remote HEAD as public phase
Sean Farley <sean@farley.io>
parents:
1073
diff
changeset
|
343 try: |
a70c1f6caead
fetch: mark remote HEAD as public phase
Sean Farley <sean@farley.io>
parents:
1073
diff
changeset
|
344 tr = self.repo.transaction("phase") |
1135
c4703246f350
compat: mark all compat-checking locations outside hggit.compat with "COMPAT:"
Kevin Bullock <kbullock@ringworld.org>
parents:
1128
diff
changeset
|
345 # COMPAT: hg 3.2 - advanceboundary uses transaction |
1078
a70c1f6caead
fetch: mark remote HEAD as public phase
Sean Farley <sean@farley.io>
parents:
1073
diff
changeset
|
346 try: |
a70c1f6caead
fetch: mark remote HEAD as public phase
Sean Farley <sean@farley.io>
parents:
1073
diff
changeset
|
347 phases.advanceboundary(self.repo, tr, phases.public, |
1079
fda826275060
git_handler: add config knob for marking git branches public
Sean Farley <sean@farley.io>
parents:
1078
diff
changeset
|
348 blist) |
1078
a70c1f6caead
fetch: mark remote HEAD as public phase
Sean Farley <sean@farley.io>
parents:
1073
diff
changeset
|
349 except TypeError: |
a70c1f6caead
fetch: mark remote HEAD as public phase
Sean Farley <sean@farley.io>
parents:
1073
diff
changeset
|
350 phases.advanceboundary(self.repo, phases.public, |
1079
fda826275060
git_handler: add config knob for marking git branches public
Sean Farley <sean@farley.io>
parents:
1078
diff
changeset
|
351 blist) |
1078
a70c1f6caead
fetch: mark remote HEAD as public phase
Sean Farley <sean@farley.io>
parents:
1073
diff
changeset
|
352 tr.close() |
a70c1f6caead
fetch: mark remote HEAD as public phase
Sean Farley <sean@farley.io>
parents:
1073
diff
changeset
|
353 finally: |
a70c1f6caead
fetch: mark remote HEAD as public phase
Sean Farley <sean@farley.io>
parents:
1073
diff
changeset
|
354 if tr is not None: |
a70c1f6caead
fetch: mark remote HEAD as public phase
Sean Farley <sean@farley.io>
parents:
1073
diff
changeset
|
355 tr.release() |
a70c1f6caead
fetch: mark remote HEAD as public phase
Sean Farley <sean@farley.io>
parents:
1073
diff
changeset
|
356 lock.release() |
a70c1f6caead
fetch: mark remote HEAD as public phase
Sean Farley <sean@farley.io>
parents:
1073
diff
changeset
|
357 |
703
4cddcb768cf4
git_handler.fetch: actually return number of heads added or removed
Siddharth Agarwal <sid0@fb.com>
parents:
702
diff
changeset
|
358 if imported == 0: |
4cddcb768cf4
git_handler.fetch: actually return number of heads added or removed
Siddharth Agarwal <sid0@fb.com>
parents:
702
diff
changeset
|
359 return 0 |
4cddcb768cf4
git_handler.fetch: actually return number of heads added or removed
Siddharth Agarwal <sid0@fb.com>
parents:
702
diff
changeset
|
360 |
4cddcb768cf4
git_handler.fetch: actually return number of heads added or removed
Siddharth Agarwal <sid0@fb.com>
parents:
702
diff
changeset
|
361 # code taken from localrepo.py:addchangegroup |
4cddcb768cf4
git_handler.fetch: actually return number of heads added or removed
Siddharth Agarwal <sid0@fb.com>
parents:
702
diff
changeset
|
362 dh = 0 |
4cddcb768cf4
git_handler.fetch: actually return number of heads added or removed
Siddharth Agarwal <sid0@fb.com>
parents:
702
diff
changeset
|
363 if oldheads: |
4cddcb768cf4
git_handler.fetch: actually return number of heads added or removed
Siddharth Agarwal <sid0@fb.com>
parents:
702
diff
changeset
|
364 heads = self.repo.changelog.heads() |
4cddcb768cf4
git_handler.fetch: actually return number of heads added or removed
Siddharth Agarwal <sid0@fb.com>
parents:
702
diff
changeset
|
365 dh = len(heads) - len(oldheads) |
4cddcb768cf4
git_handler.fetch: actually return number of heads added or removed
Siddharth Agarwal <sid0@fb.com>
parents:
702
diff
changeset
|
366 for h in heads: |
4cddcb768cf4
git_handler.fetch: actually return number of heads added or removed
Siddharth Agarwal <sid0@fb.com>
parents:
702
diff
changeset
|
367 if h not in oldheads and self.repo[h].closesbranch(): |
4cddcb768cf4
git_handler.fetch: actually return number of heads added or removed
Siddharth Agarwal <sid0@fb.com>
parents:
702
diff
changeset
|
368 dh -= 1 |
4cddcb768cf4
git_handler.fetch: actually return number of heads added or removed
Siddharth Agarwal <sid0@fb.com>
parents:
702
diff
changeset
|
369 |
4cddcb768cf4
git_handler.fetch: actually return number of heads added or removed
Siddharth Agarwal <sid0@fb.com>
parents:
702
diff
changeset
|
370 if dh < 0: |
4cddcb768cf4
git_handler.fetch: actually return number of heads added or removed
Siddharth Agarwal <sid0@fb.com>
parents:
702
diff
changeset
|
371 return dh - 1 |
4cddcb768cf4
git_handler.fetch: actually return number of heads added or removed
Siddharth Agarwal <sid0@fb.com>
parents:
702
diff
changeset
|
372 else: |
4cddcb768cf4
git_handler.fetch: actually return number of heads added or removed
Siddharth Agarwal <sid0@fb.com>
parents:
702
diff
changeset
|
373 return dh + 1 |
397
60d181f9ecc3
Make pull results more like hg pulls.
Brendan Cully <brendan@kublai.com>
parents:
395
diff
changeset
|
374 |
236
42ae65e6c1d1
save the map only once in export
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
235
diff
changeset
|
375 def export_commits(self): |
42ae65e6c1d1
save the map only once in export
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
235
diff
changeset
|
376 try: |
172
ac92cdc45ceb
not trying to write the same tree twice
Scott Chacon <schacon@gmail.com>
parents:
171
diff
changeset
|
377 self.export_git_objects() |
236
42ae65e6c1d1
save the map only once in export
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
235
diff
changeset
|
378 self.export_hg_tags() |
42ae65e6c1d1
save the map only once in export
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
235
diff
changeset
|
379 self.update_references() |
42ae65e6c1d1
save the map only once in export
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
235
diff
changeset
|
380 finally: |
877
be105c4dda7b
git_handler.save_map: pass in the map file explicitly for easier testing
Siddharth Agarwal <sid0@fb.com>
parents:
876
diff
changeset
|
381 self.save_map(self.map_file) |
97 | 382 |
231
bdaec2a079ce
initial support for 'hg outgoing'
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
230
diff
changeset
|
383 def get_refs(self, remote): |
bdaec2a079ce
initial support for 'hg outgoing'
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
230
diff
changeset
|
384 self.export_commits() |
bdaec2a079ce
initial support for 'hg outgoing'
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
230
diff
changeset
|
385 client, path = self.get_transport_and_path(remote) |
bdaec2a079ce
initial support for 'hg outgoing'
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
230
diff
changeset
|
386 old_refs = {} |
bdaec2a079ce
initial support for 'hg outgoing'
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
230
diff
changeset
|
387 new_refs = {} |
884
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
388 |
231
bdaec2a079ce
initial support for 'hg outgoing'
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
230
diff
changeset
|
389 def changed(refs): |
bdaec2a079ce
initial support for 'hg outgoing'
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
230
diff
changeset
|
390 old_refs.update(refs) |
813
345919960ea4
git_handler.get_changed_refs: switch to using get_exportable
Siddharth Agarwal <sid0@fb.com>
parents:
812
diff
changeset
|
391 exportable = self.get_exportable() |
345919960ea4
git_handler.get_changed_refs: switch to using get_exportable
Siddharth Agarwal <sid0@fb.com>
parents:
812
diff
changeset
|
392 new_refs.update(self.get_changed_refs(refs, exportable, True)) |
884
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
393 return refs # always return the same refs to make the send a no-op |
231
bdaec2a079ce
initial support for 'hg outgoing'
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
230
diff
changeset
|
394 |
bdaec2a079ce
initial support for 'hg outgoing'
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
230
diff
changeset
|
395 try: |
442
553dd7078058
Update for newer dulwich and hg versions.
Augie Fackler <durin42@gmail.com>
parents:
441
diff
changeset
|
396 client.send_pack(path, changed, lambda have, want: []) |
243
53b731d2a3e2
outgoing: don't crash when there are unpulled changesets
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
242
diff
changeset
|
397 |
53b731d2a3e2
outgoing: don't crash when there are unpulled changesets
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
242
diff
changeset
|
398 changed_refs = [ref for ref, sha in new_refs.iteritems() |
53b731d2a3e2
outgoing: don't crash when there are unpulled changesets
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
242
diff
changeset
|
399 if sha != old_refs.get(ref)] |
53b731d2a3e2
outgoing: don't crash when there are unpulled changesets
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
242
diff
changeset
|
400 new = [bin(self.map_hg_get(new_refs[ref])) for ref in changed_refs] |
418
10027b50202b
In some situations where a reference is being used but does not exist in _map_git or _map_hg, silently skip the reference rather than throwing an error. This allows hg outgoing to work on repositories which do not contain any revisions at all.
mcc <andrew.mcclure@gmail.com>
parents:
415
diff
changeset
|
401 old = {} |
10027b50202b
In some situations where a reference is being used but does not exist in _map_git or _map_hg, silently skip the reference rather than throwing an error. This allows hg outgoing to work on repositories which do not contain any revisions at all.
mcc <andrew.mcclure@gmail.com>
parents:
415
diff
changeset
|
402 for r in old_refs: |
10027b50202b
In some situations where a reference is being used but does not exist in _map_git or _map_hg, silently skip the reference rather than throwing an error. This allows hg outgoing to work on repositories which do not contain any revisions at all.
mcc <andrew.mcclure@gmail.com>
parents:
415
diff
changeset
|
403 old_ref = self.map_hg_get(old_refs[r]) |
10027b50202b
In some situations where a reference is being used but does not exist in _map_git or _map_hg, silently skip the reference rather than throwing an error. This allows hg outgoing to work on repositories which do not contain any revisions at all.
mcc <andrew.mcclure@gmail.com>
parents:
415
diff
changeset
|
404 if old_ref: |
10027b50202b
In some situations where a reference is being used but does not exist in _map_git or _map_hg, silently skip the reference rather than throwing an error. This allows hg outgoing to work on repositories which do not contain any revisions at all.
mcc <andrew.mcclure@gmail.com>
parents:
415
diff
changeset
|
405 old[bin(old_ref)] = 1 |
231
bdaec2a079ce
initial support for 'hg outgoing'
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
230
diff
changeset
|
406 |
bdaec2a079ce
initial support for 'hg outgoing'
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
230
diff
changeset
|
407 return old, new |
391
9b6597b70839
Improve error reporting in get_refs
Brendan Cully <brendan@kublai.com>
parents:
387
diff
changeset
|
408 except (HangupException, GitProtocolError), e: |
1128
6141895a53c9
compat: switch from hgutil.Abort to error.Abort
Kevin Bullock <kbullock@ringworld.org>
parents:
1127
diff
changeset
|
409 raise error.Abort(_("git remote error: ") + str(e)) |
231
bdaec2a079ce
initial support for 'hg outgoing'
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
230
diff
changeset
|
410 |
230
51e4d6ebbc40
rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
229
diff
changeset
|
411 def push(self, remote, revs, force): |
221
4be68870dc44
do not pull from git when asked to push
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
219
diff
changeset
|
412 self.export_commits() |
487
68e5dddc7a20
push: return 1 if no changes found, 0 if success
David M. Carr <david@carrclan.us>
parents:
475
diff
changeset
|
413 old_refs, new_refs = self.upload_pack(remote, revs, force) |
196
40edc4b814e4
Reorganize push for more symmetry with fetch
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
195
diff
changeset
|
414 remote_name = self.remote_name(remote) |
40edc4b814e4
Reorganize push for more symmetry with fetch
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
195
diff
changeset
|
415 |
487
68e5dddc7a20
push: return 1 if no changes found, 0 if success
David M. Carr <david@carrclan.us>
parents:
475
diff
changeset
|
416 if remote_name and new_refs: |
621
09028a1e9895
git_handler: iterate over new refs in sorted order to stabilize test output
Augie Fackler <raf@durin42.com>
parents:
616
diff
changeset
|
417 for ref, new_sha in sorted(new_refs.iteritems()): |
592
a6b7ad535244
push: provide better output about changed references (issue #64)
David M. Carr <david@carrclan.us>
parents:
591
diff
changeset
|
418 old_sha = old_refs.get(ref) |
a6b7ad535244
push: provide better output about changed references (issue #64)
David M. Carr <david@carrclan.us>
parents:
591
diff
changeset
|
419 if old_sha is None: |
a6b7ad535244
push: provide better output about changed references (issue #64)
David M. Carr <david@carrclan.us>
parents:
591
diff
changeset
|
420 if self.ui.verbose: |
a6b7ad535244
push: provide better output about changed references (issue #64)
David M. Carr <david@carrclan.us>
parents:
591
diff
changeset
|
421 self.ui.note("adding reference %s::%s => GIT:%s\n" % |
884
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
422 (remote_name, ref, new_sha[0:8])) |
592
a6b7ad535244
push: provide better output about changed references (issue #64)
David M. Carr <david@carrclan.us>
parents:
591
diff
changeset
|
423 else: |
a6b7ad535244
push: provide better output about changed references (issue #64)
David M. Carr <david@carrclan.us>
parents:
591
diff
changeset
|
424 self.ui.status("adding reference %s\n" % ref) |
a6b7ad535244
push: provide better output about changed references (issue #64)
David M. Carr <david@carrclan.us>
parents:
591
diff
changeset
|
425 elif new_sha != old_sha: |
a6b7ad535244
push: provide better output about changed references (issue #64)
David M. Carr <david@carrclan.us>
parents:
591
diff
changeset
|
426 if self.ui.verbose: |
a6b7ad535244
push: provide better output about changed references (issue #64)
David M. Carr <david@carrclan.us>
parents:
591
diff
changeset
|
427 self.ui.note("updating reference %s::%s => GIT:%s\n" % |
884
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
428 (remote_name, ref, new_sha[0:8])) |
592
a6b7ad535244
push: provide better output about changed references (issue #64)
David M. Carr <david@carrclan.us>
parents:
591
diff
changeset
|
429 else: |
a6b7ad535244
push: provide better output about changed references (issue #64)
David M. Carr <david@carrclan.us>
parents:
591
diff
changeset
|
430 self.ui.status("updating reference %s\n" % ref) |
559
d4ccec82b816
push: suppress ref output by default
David M. Carr <david@carrclan.us>
parents:
557
diff
changeset
|
431 else: |
592
a6b7ad535244
push: provide better output about changed references (issue #64)
David M. Carr <david@carrclan.us>
parents:
591
diff
changeset
|
432 self.ui.debug("unchanged reference %s::%s => GIT:%s\n" % |
884
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
433 (remote_name, ref, new_sha[0:8])) |
196
40edc4b814e4
Reorganize push for more symmetry with fetch
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
195
diff
changeset
|
434 |
487
68e5dddc7a20
push: return 1 if no changes found, 0 if success
David M. Carr <david@carrclan.us>
parents:
475
diff
changeset
|
435 self.update_remote_branches(remote_name, new_refs) |
68e5dddc7a20
push: return 1 if no changes found, 0 if success
David M. Carr <david@carrclan.us>
parents:
475
diff
changeset
|
436 if old_refs == new_refs: |
489
ccd521a1f585
push: state when no changes are found
David M. Carr <david@carrclan.us>
parents:
488
diff
changeset
|
437 self.ui.status(_("no changes found\n")) |
487
68e5dddc7a20
push: return 1 if no changes found, 0 if success
David M. Carr <david@carrclan.us>
parents:
475
diff
changeset
|
438 ret = None |
68e5dddc7a20
push: return 1 if no changes found, 0 if success
David M. Carr <david@carrclan.us>
parents:
475
diff
changeset
|
439 elif len(new_refs) > len(old_refs): |
68e5dddc7a20
push: return 1 if no changes found, 0 if success
David M. Carr <david@carrclan.us>
parents:
475
diff
changeset
|
440 ret = 1 + (len(new_refs) - len(old_refs)) |
68e5dddc7a20
push: return 1 if no changes found, 0 if success
David M. Carr <david@carrclan.us>
parents:
475
diff
changeset
|
441 elif len(old_refs) > len(new_refs): |
68e5dddc7a20
push: return 1 if no changes found, 0 if success
David M. Carr <david@carrclan.us>
parents:
475
diff
changeset
|
442 ret = -1 - (len(new_refs) - len(old_refs)) |
68e5dddc7a20
push: return 1 if no changes found, 0 if success
David M. Carr <david@carrclan.us>
parents:
475
diff
changeset
|
443 else: |
68e5dddc7a20
push: return 1 if no changes found, 0 if success
David M. Carr <david@carrclan.us>
parents:
475
diff
changeset
|
444 ret = 1 |
68e5dddc7a20
push: return 1 if no changes found, 0 if success
David M. Carr <david@carrclan.us>
parents:
475
diff
changeset
|
445 return ret |
196
40edc4b814e4
Reorganize push for more symmetry with fetch
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
195
diff
changeset
|
446 |
183
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
447 def clear(self): |
1085
1003994dd497
share: host the git repository alongside the store
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
1079
diff
changeset
|
448 mapfile = self.vfs.join(self.map_file) |
183
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
449 if os.path.exists(self.gitdir): |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
450 for root, dirs, files in os.walk(self.gitdir, topdown=False): |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
451 for name in files: |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
452 os.remove(os.path.join(root, name)) |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
453 for name in dirs: |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
454 os.rmdir(os.path.join(root, name)) |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
455 os.rmdir(self.gitdir) |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
456 if os.path.exists(mapfile): |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
457 os.remove(mapfile) |
124
9dafb9ac24ff
hg bookmarks to local git branches
Ian Dees <undees@gmail.com>
parents:
118
diff
changeset
|
458 |
408 | 459 # incoming support |
460 def getremotechanges(self, remote, revs): | |
461 self.export_commits() | |
1094
5e49230a6cd5
fetch_pack: refactor to use compat.FetchPackResult
Sean Farley <sean@farley.io>
parents:
1088
diff
changeset
|
462 result = self.fetch_pack(remote.path, revs) |
408 | 463 |
464 # refs contains all remote refs. Prune to only those requested. | |
465 if revs: | |
466 reqrefs = {} | |
467 for rev in revs: | |
468 for n in ('refs/heads/' + rev, 'refs/tags/' + rev): | |
1094
5e49230a6cd5
fetch_pack: refactor to use compat.FetchPackResult
Sean Farley <sean@farley.io>
parents:
1088
diff
changeset
|
469 if n in result.refs: |
5e49230a6cd5
fetch_pack: refactor to use compat.FetchPackResult
Sean Farley <sean@farley.io>
parents:
1088
diff
changeset
|
470 reqrefs[n] = result.refs[n] |
408 | 471 else: |
1094
5e49230a6cd5
fetch_pack: refactor to use compat.FetchPackResult
Sean Farley <sean@farley.io>
parents:
1088
diff
changeset
|
472 reqrefs = result.refs |
408 | 473 |
789
77416ddca136
git2hg: return a struct from find_incoming
Siddharth Agarwal <sid0@fb.com>
parents:
788
diff
changeset
|
474 commits = [bin(c) for c in self.get_git_incoming(reqrefs).commits] |
408 | 475 |
1094
5e49230a6cd5
fetch_pack: refactor to use compat.FetchPackResult
Sean Farley <sean@farley.io>
parents:
1088
diff
changeset
|
476 b = overlayrepo(self, commits, result.refs) |
408 | 477 |
478 return (b, commits, lambda: None) | |
479 | |
884
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
480 # CHANGESET CONVERSION METHODS |
125 | 481 |
21
13b9a020e382
gpush coming along. will now write blobs it doesn't have yet to git repo.
Scott Chacon <schacon@gmail.com>
parents:
19
diff
changeset
|
482 def export_git_objects(self): |
995
c4a2ef796c19
add progress to commit discovery phase
Ryan McElroy <rmcelroy@fb.com>
parents:
992
diff
changeset
|
483 self.ui.note(_("finding hg commits to export\n")) |
830
5fa9649c4ef6
git_handler: iterate over contexts, not nodes
Siddharth Agarwal <sid0@fb.com>
parents:
826
diff
changeset
|
484 repo = self.repo |
5fa9649c4ef6
git_handler: iterate over contexts, not nodes
Siddharth Agarwal <sid0@fb.com>
parents:
826
diff
changeset
|
485 clnode = repo.changelog.node |
995
c4a2ef796c19
add progress to commit discovery phase
Ryan McElroy <rmcelroy@fb.com>
parents:
992
diff
changeset
|
486 |
832
799c41a24e75
git_handler.export_git_objects: avoid unnecessary list creation
Siddharth Agarwal <sid0@fb.com>
parents:
831
diff
changeset
|
487 nodes = (clnode(n) for n in repo) |
995
c4a2ef796c19
add progress to commit discovery phase
Ryan McElroy <rmcelroy@fb.com>
parents:
992
diff
changeset
|
488 to_export = (repo[node] for node in nodes if not hex(node) in |
1110
94aaea5c65f7
cleanup: fix incorrect indentation
Sean Farley <sean@farley.io>
parents:
1109
diff
changeset
|
489 self._map_hg) |
995
c4a2ef796c19
add progress to commit discovery phase
Ryan McElroy <rmcelroy@fb.com>
parents:
992
diff
changeset
|
490 |
c4a2ef796c19
add progress to commit discovery phase
Ryan McElroy <rmcelroy@fb.com>
parents:
992
diff
changeset
|
491 todo_total = len(repo) - len(self._map_hg) |
c4a2ef796c19
add progress to commit discovery phase
Ryan McElroy <rmcelroy@fb.com>
parents:
992
diff
changeset
|
492 topic = 'find commits to export' |
c4a2ef796c19
add progress to commit discovery phase
Ryan McElroy <rmcelroy@fb.com>
parents:
992
diff
changeset
|
493 pos = 0 |
c4a2ef796c19
add progress to commit discovery phase
Ryan McElroy <rmcelroy@fb.com>
parents:
992
diff
changeset
|
494 unit = 'commits' |
c4a2ef796c19
add progress to commit discovery phase
Ryan McElroy <rmcelroy@fb.com>
parents:
992
diff
changeset
|
495 |
c4a2ef796c19
add progress to commit discovery phase
Ryan McElroy <rmcelroy@fb.com>
parents:
992
diff
changeset
|
496 export = [] |
c4a2ef796c19
add progress to commit discovery phase
Ryan McElroy <rmcelroy@fb.com>
parents:
992
diff
changeset
|
497 for ctx in to_export: |
c4a2ef796c19
add progress to commit discovery phase
Ryan McElroy <rmcelroy@fb.com>
parents:
992
diff
changeset
|
498 item = hex(ctx.node()) |
c4a2ef796c19
add progress to commit discovery phase
Ryan McElroy <rmcelroy@fb.com>
parents:
992
diff
changeset
|
499 pos += 1 |
c4a2ef796c19
add progress to commit discovery phase
Ryan McElroy <rmcelroy@fb.com>
parents:
992
diff
changeset
|
500 repo.ui.progress(topic, pos, item, unit, todo_total) |
c4a2ef796c19
add progress to commit discovery phase
Ryan McElroy <rmcelroy@fb.com>
parents:
992
diff
changeset
|
501 if ctx.extra().get('hg-git', None) != 'octopus': |
c4a2ef796c19
add progress to commit discovery phase
Ryan McElroy <rmcelroy@fb.com>
parents:
992
diff
changeset
|
502 export.append(ctx) |
c4a2ef796c19
add progress to commit discovery phase
Ryan McElroy <rmcelroy@fb.com>
parents:
992
diff
changeset
|
503 |
190
6fbdf1afe032
Better reporting of the number of commits to convert
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
188
diff
changeset
|
504 total = len(export) |
708
4f0a154ae374
git_handler: return early when no commits need to be exported
Siddharth Agarwal <sid0@fb.com>
parents:
704
diff
changeset
|
505 if not total: |
4f0a154ae374
git_handler: return early when no commits need to be exported
Siddharth Agarwal <sid0@fb.com>
parents:
704
diff
changeset
|
506 return |
4f0a154ae374
git_handler: return early when no commits need to be exported
Siddharth Agarwal <sid0@fb.com>
parents:
704
diff
changeset
|
507 |
4f0a154ae374
git_handler: return early when no commits need to be exported
Siddharth Agarwal <sid0@fb.com>
parents:
704
diff
changeset
|
508 self.ui.note(_("exporting hg objects to git\n")) |
596
d6b9c30a3e0f
Export Git objects from incremental Mercurial changes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
593
diff
changeset
|
509 |
d6b9c30a3e0f
Export Git objects from incremental Mercurial changes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
593
diff
changeset
|
510 # By only exporting deltas, the assertion is that all previous objects |
d6b9c30a3e0f
Export Git objects from incremental Mercurial changes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
593
diff
changeset
|
511 # for all other changesets are already present in the Git repository. |
709
5c7943ca051f
hg2git: start incremental conversion from a known commit
Siddharth Agarwal <sid0@fb.com>
parents:
708
diff
changeset
|
512 # This assertion is necessary to prevent redundant work. Here, nodes, |
5c7943ca051f
hg2git: start incremental conversion from a known commit
Siddharth Agarwal <sid0@fb.com>
parents:
708
diff
changeset
|
513 # and therefore export, is in topological order. By definition, |
5c7943ca051f
hg2git: start incremental conversion from a known commit
Siddharth Agarwal <sid0@fb.com>
parents:
708
diff
changeset
|
514 # export[0]'s parents must be present in Git, so we start the |
5c7943ca051f
hg2git: start incremental conversion from a known commit
Siddharth Agarwal <sid0@fb.com>
parents:
708
diff
changeset
|
515 # incremental exporter from there. |
830
5fa9649c4ef6
git_handler: iterate over contexts, not nodes
Siddharth Agarwal <sid0@fb.com>
parents:
826
diff
changeset
|
516 pctx = export[0].p1() |
709
5c7943ca051f
hg2git: start incremental conversion from a known commit
Siddharth Agarwal <sid0@fb.com>
parents:
708
diff
changeset
|
517 pnode = pctx.node() |
5c7943ca051f
hg2git: start incremental conversion from a known commit
Siddharth Agarwal <sid0@fb.com>
parents:
708
diff
changeset
|
518 if pnode == nullid: |
5c7943ca051f
hg2git: start incremental conversion from a known commit
Siddharth Agarwal <sid0@fb.com>
parents:
708
diff
changeset
|
519 gitcommit = None |
5c7943ca051f
hg2git: start incremental conversion from a known commit
Siddharth Agarwal <sid0@fb.com>
parents:
708
diff
changeset
|
520 else: |
5c7943ca051f
hg2git: start incremental conversion from a known commit
Siddharth Agarwal <sid0@fb.com>
parents:
708
diff
changeset
|
521 gitsha = self._map_hg[hex(pnode)] |
5c7943ca051f
hg2git: start incremental conversion from a known commit
Siddharth Agarwal <sid0@fb.com>
parents:
708
diff
changeset
|
522 try: |
5c7943ca051f
hg2git: start incremental conversion from a known commit
Siddharth Agarwal <sid0@fb.com>
parents:
708
diff
changeset
|
523 gitcommit = self.git[gitsha] |
5c7943ca051f
hg2git: start incremental conversion from a known commit
Siddharth Agarwal <sid0@fb.com>
parents:
708
diff
changeset
|
524 except KeyError: |
1128
6141895a53c9
compat: switch from hgutil.Abort to error.Abort
Kevin Bullock <kbullock@ringworld.org>
parents:
1127
diff
changeset
|
525 raise error.Abort(_('Parent SHA-1 not present in Git' |
6141895a53c9
compat: switch from hgutil.Abort to error.Abort
Kevin Bullock <kbullock@ringworld.org>
parents:
1127
diff
changeset
|
526 'repo: %s' % gitsha)) |
709
5c7943ca051f
hg2git: start incremental conversion from a known commit
Siddharth Agarwal <sid0@fb.com>
parents:
708
diff
changeset
|
527 |
5c7943ca051f
hg2git: start incremental conversion from a known commit
Siddharth Agarwal <sid0@fb.com>
parents:
708
diff
changeset
|
528 exporter = hg2git.IncrementalChangesetExporter( |
5c7943ca051f
hg2git: start incremental conversion from a known commit
Siddharth Agarwal <sid0@fb.com>
parents:
708
diff
changeset
|
529 self.repo, pctx, self.git.object_store, gitcommit) |
596
d6b9c30a3e0f
Export Git objects from incremental Mercurial changes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
593
diff
changeset
|
530 |
1067
f4c2b42731ea
config: register hggit.mapsavefrequency
Kevin Bullock <kbullock@ringworld.org>
parents:
1066
diff
changeset
|
531 mapsavefreq = compat.config(self.ui, 'int', 'hggit', |
1110
94aaea5c65f7
cleanup: fix incorrect indentation
Sean Farley <sean@farley.io>
parents:
1109
diff
changeset
|
532 'mapsavefrequency') |
830
5fa9649c4ef6
git_handler: iterate over contexts, not nodes
Siddharth Agarwal <sid0@fb.com>
parents:
826
diff
changeset
|
533 for i, ctx in enumerate(export): |
685
c7129c72baff
git_handler: replace util.progress with ui.progress
Siddharth Agarwal <sid0@fb.com>
parents:
683
diff
changeset
|
534 self.ui.progress('exporting', i, total=total) |
830
5fa9649c4ef6
git_handler: iterate over contexts, not nodes
Siddharth Agarwal <sid0@fb.com>
parents:
826
diff
changeset
|
535 self.export_hg_commit(ctx.node(), exporter) |
1000
d0ce6eaebe7b
githandler: respect mapsavefrequency during export
Ryan McElroy <rmcelroy@fb.com>
parents:
996
diff
changeset
|
536 if mapsavefreq and i % mapsavefreq == 0: |
d0ce6eaebe7b
githandler: respect mapsavefrequency during export
Ryan McElroy <rmcelroy@fb.com>
parents:
996
diff
changeset
|
537 self.ui.debug(_("saving mapfile\n")) |
d0ce6eaebe7b
githandler: respect mapsavefrequency during export
Ryan McElroy <rmcelroy@fb.com>
parents:
996
diff
changeset
|
538 self.save_map(self.map_file) |
685
c7129c72baff
git_handler: replace util.progress with ui.progress
Siddharth Agarwal <sid0@fb.com>
parents:
683
diff
changeset
|
539 self.ui.progress('exporting', None, total=total) |
286
0661d5721ad7
git_handler: use progress API instead of reinventing the wheel
Augie Fackler <durin42@gmail.com>
parents:
285
diff
changeset
|
540 |
996
eb01d99111b6
stop dying if extras is malformed
Ryan McElroy <rmcelroy@fb.com>
parents:
995
diff
changeset
|
541 def set_commiter_from_author(self, commit): |
eb01d99111b6
stop dying if extras is malformed
Ryan McElroy <rmcelroy@fb.com>
parents:
995
diff
changeset
|
542 commit.committer = commit.author |
eb01d99111b6
stop dying if extras is malformed
Ryan McElroy <rmcelroy@fb.com>
parents:
995
diff
changeset
|
543 commit.commit_time = commit.author_time |
eb01d99111b6
stop dying if extras is malformed
Ryan McElroy <rmcelroy@fb.com>
parents:
995
diff
changeset
|
544 commit.commit_timezone = commit.author_timezone |
eb01d99111b6
stop dying if extras is malformed
Ryan McElroy <rmcelroy@fb.com>
parents:
995
diff
changeset
|
545 |
24
41f4e0a85d15
fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents:
23
diff
changeset
|
546 # convert this commit into git objects |
41f4e0a85d15
fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents:
23
diff
changeset
|
547 # go through the manifest, convert all blobs/trees we don't have |
41f4e0a85d15
fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents:
23
diff
changeset
|
548 # write the commit object (with metadata info) |
596
d6b9c30a3e0f
Export Git objects from incremental Mercurial changes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
593
diff
changeset
|
549 def export_hg_commit(self, rev, exporter): |
301
09116995c421
export_hg_commit: fix debug note
Tay Ray Chuan <rctay89@gmail.com>
parents:
288
diff
changeset
|
550 self.ui.note(_("converting revision %s\n") % hex(rev)) |
50
d274092e3b24
Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents:
42
diff
changeset
|
551 |
203
104a4fd6a0af
trying to fix some of the broken tests
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
199
diff
changeset
|
552 oldenc = self.swap_out_encoding() |
104a4fd6a0af
trying to fix some of the broken tests
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
199
diff
changeset
|
553 |
1127
108d9303ef71
git_handler: use repo.__getitem__ instead of (removed) repo.changectx
Paul Morelle <paul.morelle@octobus.net>
parents:
1125
diff
changeset
|
554 ctx = self.repo[rev] |
159
85eae64ca9e2
applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents:
138
diff
changeset
|
555 extra = ctx.extra() |
85eae64ca9e2
applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents:
138
diff
changeset
|
556 |
224
80d67ae190df
port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
222
diff
changeset
|
557 commit = Commit() |
68
d28d3763eda3
Deal with hg authors missing email attributes.
Chris Wanstrath <chris@ozmm.org>
parents:
65
diff
changeset
|
558 |
235
912d6a5837c8
reorganize export_hg_commit
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
234
diff
changeset
|
559 (time, timezone) = ctx.date() |
593
ce6ad4c0cba7
scrub bad timezone values before dulwich sees them
Hal Wine <hwine@mozilla.com>
parents:
592
diff
changeset
|
560 # work around to bad timezone offets - dulwich does not handle |
ce6ad4c0cba7
scrub bad timezone values before dulwich sees them
Hal Wine <hwine@mozilla.com>
parents:
592
diff
changeset
|
561 # sub minute based timezones. In the one known case, it was a |
ce6ad4c0cba7
scrub bad timezone values before dulwich sees them
Hal Wine <hwine@mozilla.com>
parents:
592
diff
changeset
|
562 # manual edit that led to the unusual value. Based on that, |
ce6ad4c0cba7
scrub bad timezone values before dulwich sees them
Hal Wine <hwine@mozilla.com>
parents:
592
diff
changeset
|
563 # there is no reason to round one way or the other, so do the |
ce6ad4c0cba7
scrub bad timezone values before dulwich sees them
Hal Wine <hwine@mozilla.com>
parents:
592
diff
changeset
|
564 # simplest and round down. |
ce6ad4c0cba7
scrub bad timezone values before dulwich sees them
Hal Wine <hwine@mozilla.com>
parents:
592
diff
changeset
|
565 timezone -= (timezone % 60) |
239
c5e5e7849803
split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
238
diff
changeset
|
566 commit.author = self.get_git_author(ctx) |
224
80d67ae190df
port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
222
diff
changeset
|
567 commit.author_time = int(time) |
80d67ae190df
port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
222
diff
changeset
|
568 commit.author_timezone = -timezone |
186
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
569 |
89
e35ed99fa691
committer info now being kept properly
Scott Chacon <schacon@gmail.com>
parents:
88
diff
changeset
|
570 if 'committer' in extra: |
996
eb01d99111b6
stop dying if extras is malformed
Ryan McElroy <rmcelroy@fb.com>
parents:
995
diff
changeset
|
571 try: |
eb01d99111b6
stop dying if extras is malformed
Ryan McElroy <rmcelroy@fb.com>
parents:
995
diff
changeset
|
572 # fixup timezone |
eb01d99111b6
stop dying if extras is malformed
Ryan McElroy <rmcelroy@fb.com>
parents:
995
diff
changeset
|
573 (name, timestamp, timezone) = extra['committer'].rsplit(' ', 2) |
eb01d99111b6
stop dying if extras is malformed
Ryan McElroy <rmcelroy@fb.com>
parents:
995
diff
changeset
|
574 commit.committer = name |
eb01d99111b6
stop dying if extras is malformed
Ryan McElroy <rmcelroy@fb.com>
parents:
995
diff
changeset
|
575 commit.commit_time = timestamp |
237
16f671995881
deal correctly with old timezone format in extra committer
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
236
diff
changeset
|
576 |
996
eb01d99111b6
stop dying if extras is malformed
Ryan McElroy <rmcelroy@fb.com>
parents:
995
diff
changeset
|
577 # work around a timezone format change |
eb01d99111b6
stop dying if extras is malformed
Ryan McElroy <rmcelroy@fb.com>
parents:
995
diff
changeset
|
578 if int(timezone) % 60 != 0: # pragma: no cover |
eb01d99111b6
stop dying if extras is malformed
Ryan McElroy <rmcelroy@fb.com>
parents:
995
diff
changeset
|
579 timezone = parse_timezone(timezone) |
eb01d99111b6
stop dying if extras is malformed
Ryan McElroy <rmcelroy@fb.com>
parents:
995
diff
changeset
|
580 # Newer versions of Dulwich return a tuple here |
eb01d99111b6
stop dying if extras is malformed
Ryan McElroy <rmcelroy@fb.com>
parents:
995
diff
changeset
|
581 if isinstance(timezone, tuple): |
eb01d99111b6
stop dying if extras is malformed
Ryan McElroy <rmcelroy@fb.com>
parents:
995
diff
changeset
|
582 timezone, neg_utc = timezone |
eb01d99111b6
stop dying if extras is malformed
Ryan McElroy <rmcelroy@fb.com>
parents:
995
diff
changeset
|
583 commit._commit_timezone_neg_utc = neg_utc |
eb01d99111b6
stop dying if extras is malformed
Ryan McElroy <rmcelroy@fb.com>
parents:
995
diff
changeset
|
584 else: |
eb01d99111b6
stop dying if extras is malformed
Ryan McElroy <rmcelroy@fb.com>
parents:
995
diff
changeset
|
585 timezone = -int(timezone) |
eb01d99111b6
stop dying if extras is malformed
Ryan McElroy <rmcelroy@fb.com>
parents:
995
diff
changeset
|
586 commit.commit_timezone = timezone |
1112
c66e920d261f
cleanup: put extra space before inline comment
Sean Farley <sean@farley.io>
parents:
1110
diff
changeset
|
587 except: # extra is essentially user-supplied, we must be careful |
996
eb01d99111b6
stop dying if extras is malformed
Ryan McElroy <rmcelroy@fb.com>
parents:
995
diff
changeset
|
588 self.set_commiter_from_author(commit) |
224
80d67ae190df
port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
222
diff
changeset
|
589 else: |
996
eb01d99111b6
stop dying if extras is malformed
Ryan McElroy <rmcelroy@fb.com>
parents:
995
diff
changeset
|
590 self.set_commiter_from_author(commit) |
224
80d67ae190df
port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
222
diff
changeset
|
591 |
239
c5e5e7849803
split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
238
diff
changeset
|
592 commit.parents = [] |
c5e5e7849803
split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
238
diff
changeset
|
593 for parent in self.get_git_parents(ctx): |
c5e5e7849803
split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
238
diff
changeset
|
594 hgsha = hex(parent.node()) |
c5e5e7849803
split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
238
diff
changeset
|
595 git_sha = self.map_git_get(hgsha) |
c5e5e7849803
split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
238
diff
changeset
|
596 if git_sha: |
543
5a688ad69449
Verify tree and parent objects are in Git repo
Gregory Szorc <gregory.szorc@gmail.com>
parents:
542
diff
changeset
|
597 if git_sha not in self.git.object_store: |
1128
6141895a53c9
compat: switch from hgutil.Abort to error.Abort
Kevin Bullock <kbullock@ringworld.org>
parents:
1127
diff
changeset
|
598 raise error.Abort(_('Parent SHA-1 not present in Git' |
6141895a53c9
compat: switch from hgutil.Abort to error.Abort
Kevin Bullock <kbullock@ringworld.org>
parents:
1127
diff
changeset
|
599 'repo: %s' % git_sha)) |
543
5a688ad69449
Verify tree and parent objects are in Git repo
Gregory Szorc <gregory.szorc@gmail.com>
parents:
542
diff
changeset
|
600 |
239
c5e5e7849803
split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
238
diff
changeset
|
601 commit.parents.append(git_sha) |
c5e5e7849803
split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
238
diff
changeset
|
602 |
764
70aba6b2fe7b
git_handler: export hg extra metadata as git extra metadata (issue121)
Siddharth Agarwal <sid0@fb.com>
parents:
763
diff
changeset
|
603 commit.message, extra = self.get_git_message_and_extra(ctx) |
70aba6b2fe7b
git_handler: export hg extra metadata as git extra metadata (issue121)
Siddharth Agarwal <sid0@fb.com>
parents:
763
diff
changeset
|
604 commit.extra.extend(extra) |
239
c5e5e7849803
split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
238
diff
changeset
|
605 |
118
b3be536e3f50
handles git commit encoding fields now
Scott Chacon <schacon@gmail.com>
parents:
113
diff
changeset
|
606 if 'encoding' in extra: |
224
80d67ae190df
port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
222
diff
changeset
|
607 commit.encoding = extra['encoding'] |
1108
aae2d15de6af
git_handler: store gpgsig header to maintain commit coherence
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents:
1104
diff
changeset
|
608 if 'gpgsig' in extra: |
aae2d15de6af
git_handler: store gpgsig header to maintain commit coherence
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents:
1104
diff
changeset
|
609 commit.gpgsig = extra['gpgsig'] |
89
e35ed99fa691
committer info now being kept properly
Scott Chacon <schacon@gmail.com>
parents:
88
diff
changeset
|
610 |
596
d6b9c30a3e0f
Export Git objects from incremental Mercurial changes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
593
diff
changeset
|
611 for obj, nodeid in exporter.update_changeset(ctx): |
696
a7383625c891
git_handler: don't write out objects if already in object store
Siddharth Agarwal <sid0@fb.com>
parents:
692
diff
changeset
|
612 if obj.id not in self.git.object_store: |
a7383625c891
git_handler: don't write out objects if already in object store
Siddharth Agarwal <sid0@fb.com>
parents:
692
diff
changeset
|
613 self.git.object_store.add_object(obj) |
596
d6b9c30a3e0f
Export Git objects from incremental Mercurial changes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
593
diff
changeset
|
614 |
d6b9c30a3e0f
Export Git objects from incremental Mercurial changes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
593
diff
changeset
|
615 tree_sha = exporter.root_tree_sha |
d6b9c30a3e0f
Export Git objects from incremental Mercurial changes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
593
diff
changeset
|
616 |
543
5a688ad69449
Verify tree and parent objects are in Git repo
Gregory Szorc <gregory.szorc@gmail.com>
parents:
542
diff
changeset
|
617 if tree_sha not in self.git.object_store: |
1128
6141895a53c9
compat: switch from hgutil.Abort to error.Abort
Kevin Bullock <kbullock@ringworld.org>
parents:
1127
diff
changeset
|
618 raise error.Abort(_('Tree SHA-1 not present in Git repo: %s' % |
6141895a53c9
compat: switch from hgutil.Abort to error.Abort
Kevin Bullock <kbullock@ringworld.org>
parents:
1127
diff
changeset
|
619 tree_sha)) |
543
5a688ad69449
Verify tree and parent objects are in Git repo
Gregory Szorc <gregory.szorc@gmail.com>
parents:
542
diff
changeset
|
620 |
239
c5e5e7849803
split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
238
diff
changeset
|
621 commit.tree = tree_sha |
c5e5e7849803
split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
238
diff
changeset
|
622 |
696
a7383625c891
git_handler: don't write out objects if already in object store
Siddharth Agarwal <sid0@fb.com>
parents:
692
diff
changeset
|
623 if commit.id not in self.git.object_store: |
a7383625c891
git_handler: don't write out objects if already in object store
Siddharth Agarwal <sid0@fb.com>
parents:
692
diff
changeset
|
624 self.git.object_store.add_object(commit) |
239
c5e5e7849803
split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
238
diff
changeset
|
625 self.map_set(commit.id, ctx.hex()) |
c5e5e7849803
split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
238
diff
changeset
|
626 |
c5e5e7849803
split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
238
diff
changeset
|
627 self.swap_out_encoding(oldenc) |
c5e5e7849803
split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
238
diff
changeset
|
628 return commit.id |
c5e5e7849803
split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
238
diff
changeset
|
629 |
432
ccd38138a3b3
Improve the parsing of author lines from Mercurial to generate committer and author lines that git can correctly understand
Ehsan Akhgari <ehsan.akhgari@gmail.com>
parents:
429
diff
changeset
|
630 def get_valid_git_username_email(self, name): |
448
e58a6d0b80e2
Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents:
447
diff
changeset
|
631 r"""Sanitize usernames and emails to fit git's restrictions. |
e58a6d0b80e2
Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents:
447
diff
changeset
|
632 |
e58a6d0b80e2
Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents:
447
diff
changeset
|
633 The following is taken from the man page of git's fast-import |
e58a6d0b80e2
Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents:
447
diff
changeset
|
634 command: |
e58a6d0b80e2
Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents:
447
diff
changeset
|
635 |
e58a6d0b80e2
Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents:
447
diff
changeset
|
636 [...] Likewise LF means one (and only one) linefeed [...] |
e58a6d0b80e2
Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents:
447
diff
changeset
|
637 |
e58a6d0b80e2
Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents:
447
diff
changeset
|
638 committer |
e58a6d0b80e2
Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents:
447
diff
changeset
|
639 The committer command indicates who made this commit, |
e58a6d0b80e2
Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents:
447
diff
changeset
|
640 and when they made it. |
e58a6d0b80e2
Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents:
447
diff
changeset
|
641 |
e58a6d0b80e2
Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents:
447
diff
changeset
|
642 Here <name> is the person's display name (for example |
e58a6d0b80e2
Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents:
447
diff
changeset
|
643 "Com M Itter") and <email> is the person's email address |
e58a6d0b80e2
Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents:
447
diff
changeset
|
644 ("cm@example.com[1]"). LT and GT are the literal |
e58a6d0b80e2
Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents:
447
diff
changeset
|
645 less-than (\x3c) and greater-than (\x3e) symbols. These |
e58a6d0b80e2
Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents:
447
diff
changeset
|
646 are required to delimit the email address from the other |
e58a6d0b80e2
Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents:
447
diff
changeset
|
647 fields in the line. Note that <name> and <email> are |
e58a6d0b80e2
Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents:
447
diff
changeset
|
648 free-form and may contain any sequence of bytes, except |
e58a6d0b80e2
Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents:
447
diff
changeset
|
649 LT, GT and LF. <name> is typically UTF-8 encoded. |
e58a6d0b80e2
Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents:
447
diff
changeset
|
650 |
e58a6d0b80e2
Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents:
447
diff
changeset
|
651 Accordingly, this function makes sure that there are none of the |
e58a6d0b80e2
Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents:
447
diff
changeset
|
652 characters <, >, or \n in any string which will be used for |
e58a6d0b80e2
Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents:
447
diff
changeset
|
653 a git username or email. Before this, it first removes left |
e58a6d0b80e2
Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents:
447
diff
changeset
|
654 angle brackets and spaces from the beginning, and right angle |
e58a6d0b80e2
Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents:
447
diff
changeset
|
655 brackets and spaces from the end, of this string, to convert |
e58a6d0b80e2
Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents:
447
diff
changeset
|
656 such things as " <john@doe.com> " to "john@doe.com" for |
e58a6d0b80e2
Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents:
447
diff
changeset
|
657 convenience. |
e58a6d0b80e2
Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents:
447
diff
changeset
|
658 |
e58a6d0b80e2
Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents:
447
diff
changeset
|
659 TESTS: |
e58a6d0b80e2
Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents:
447
diff
changeset
|
660 |
1034
fa08148bc5fc
git_handler: use namedtuple as mock repo in doctests
Kevin Bullock <kbullock@ringworld.org>
parents:
1025
diff
changeset
|
661 >>> from collections import namedtuple |
448
e58a6d0b80e2
Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents:
447
diff
changeset
|
662 >>> from mercurial.ui import ui |
1096 | 663 >>> mockrepo = namedtuple('localrepo', ['vfs', 'sharedpath', 'path']) |
1034
fa08148bc5fc
git_handler: use namedtuple as mock repo in doctests
Kevin Bullock <kbullock@ringworld.org>
parents:
1025
diff
changeset
|
664 >>> mockrepo.vfs = '' |
1096 | 665 >>> mockrepo.sharedpath = '' |
666 >>> mockrepo.path = '' | |
1034
fa08148bc5fc
git_handler: use namedtuple as mock repo in doctests
Kevin Bullock <kbullock@ringworld.org>
parents:
1025
diff
changeset
|
667 >>> g = GitHandler(mockrepo, ui()).get_valid_git_username_email |
448
e58a6d0b80e2
Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents:
447
diff
changeset
|
668 >>> g('John Doe') |
e58a6d0b80e2
Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents:
447
diff
changeset
|
669 'John Doe' |
e58a6d0b80e2
Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents:
447
diff
changeset
|
670 >>> g('john@doe.com') |
e58a6d0b80e2
Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents:
447
diff
changeset
|
671 'john@doe.com' |
e58a6d0b80e2
Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents:
447
diff
changeset
|
672 >>> g(' <john@doe.com> ') |
e58a6d0b80e2
Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents:
447
diff
changeset
|
673 'john@doe.com' |
e58a6d0b80e2
Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents:
447
diff
changeset
|
674 >>> g(' <random<\n<garbage\n> > > ') |
e58a6d0b80e2
Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents:
447
diff
changeset
|
675 'random???garbage?' |
e58a6d0b80e2
Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents:
447
diff
changeset
|
676 >>> g('Typo in hgrc >but.hg-git@handles.it.gracefully>') |
e58a6d0b80e2
Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents:
447
diff
changeset
|
677 'Typo in hgrc ?but.hg-git@handles.it.gracefully' |
e58a6d0b80e2
Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents:
447
diff
changeset
|
678 """ |
539
7bf60690386c
Precompile Git username sanitizing regular expression
Gregory Szorc <gregory.szorc@gmail.com>
parents:
538
diff
changeset
|
679 return RE_GIT_SANITIZE_AUTHOR.sub('?', name.lstrip('< ').rstrip('> ')) |
432
ccd38138a3b3
Improve the parsing of author lines from Mercurial to generate committer and author lines that git can correctly understand
Ehsan Akhgari <ehsan.akhgari@gmail.com>
parents:
429
diff
changeset
|
680 |
239
c5e5e7849803
split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
238
diff
changeset
|
681 def get_git_author(self, ctx): |
c5e5e7849803
split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
238
diff
changeset
|
682 # hg authors might not have emails |
c5e5e7849803
split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
238
diff
changeset
|
683 author = ctx.user() |
c5e5e7849803
split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
238
diff
changeset
|
684 |
450
163ac98569d3
- add "author file" extension, allows an author translation map
Mike Bayer <mike_mp@zzzcomputing.com>
parents:
448
diff
changeset
|
685 # see if a translation exists |
537
6e05aa1b536d
Optimize get_git_author
Gregory Szorc <gregory.szorc@gmail.com>
parents:
523
diff
changeset
|
686 author = self.author_map.get(author, author) |
450
163ac98569d3
- add "author file" extension, allows an author translation map
Mike Bayer <mike_mp@zzzcomputing.com>
parents:
448
diff
changeset
|
687 |
239
c5e5e7849803
split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
238
diff
changeset
|
688 # check for git author pattern compliance |
537
6e05aa1b536d
Optimize get_git_author
Gregory Szorc <gregory.szorc@gmail.com>
parents:
523
diff
changeset
|
689 a = RE_GIT_AUTHOR.match(author) |
239
c5e5e7849803
split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
238
diff
changeset
|
690 |
c5e5e7849803
split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
238
diff
changeset
|
691 if a: |
448
e58a6d0b80e2
Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents:
447
diff
changeset
|
692 name = self.get_valid_git_username_email(a.group(1)) |
e58a6d0b80e2
Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents:
447
diff
changeset
|
693 email = self.get_valid_git_username_email(a.group(2)) |
1113
e31243879891
cleanup: use is not None instead of !=
Sean Farley <sean@farley.io>
parents:
1112
diff
changeset
|
694 if a.group(3) is not None and len(a.group(3)) != 0: |
239
c5e5e7849803
split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
238
diff
changeset
|
695 name += ' ext:(' + urllib.quote(a.group(3)) + ')' |
884
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
696 author = '%s <%s>' \ |
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
697 % (self.get_valid_git_username_email(name), |
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
698 self.get_valid_git_username_email(email)) |
401
f17ca8ed620c
Use author as email when it is an email
César Izurieta <cesar@caih.org>
parents:
400
diff
changeset
|
699 elif '@' in author: |
884
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
700 author = '%s <%s>' \ |
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
701 % (self.get_valid_git_username_email(author), |
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
702 self.get_valid_git_username_email(author)) |
239
c5e5e7849803
split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
238
diff
changeset
|
703 else: |
432
ccd38138a3b3
Improve the parsing of author lines from Mercurial to generate committer and author lines that git can correctly understand
Ehsan Akhgari <ehsan.akhgari@gmail.com>
parents:
429
diff
changeset
|
704 author = self.get_valid_git_username_email(author) + ' <none@none>' |
239
c5e5e7849803
split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
238
diff
changeset
|
705 |
c5e5e7849803
split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
238
diff
changeset
|
706 if 'author' in ctx.extra(): |
307
7dfe8be21135
handle apply_delta() return value correctly
Tay Ray Chuan <rctay89@gmail.com>
parents:
302
diff
changeset
|
707 author = "".join(apply_delta(author, ctx.extra()['author'])) |
239
c5e5e7849803
split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
238
diff
changeset
|
708 |
c5e5e7849803
split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
238
diff
changeset
|
709 return author |
c5e5e7849803
split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
238
diff
changeset
|
710 |
c5e5e7849803
split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
238
diff
changeset
|
711 def get_git_parents(self, ctx): |
c5e5e7849803
split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
238
diff
changeset
|
712 def is_octopus_part(ctx): |
884
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
713 olist = ('octopus', 'octopus-done') |
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
714 return ctx.extra().get('hg-git', None) in olist |
239
c5e5e7849803
split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
238
diff
changeset
|
715 |
c5e5e7849803
split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
238
diff
changeset
|
716 parents = [] |
c5e5e7849803
split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
238
diff
changeset
|
717 if ctx.extra().get('hg-git', None) == 'octopus-done': |
c5e5e7849803
split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
238
diff
changeset
|
718 # implode octopus parents |
c5e5e7849803
split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
238
diff
changeset
|
719 part = ctx |
c5e5e7849803
split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
238
diff
changeset
|
720 while is_octopus_part(part): |
c5e5e7849803
split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
238
diff
changeset
|
721 (p1, p2) = part.parents() |
633
a836fc8f6c76
git_handler: don't bail on multiple octopus merges in succession
Siddharth Agarwal <sid0@fb.com>
parents:
629
diff
changeset
|
722 assert ctx.extra().get('hg-git', None) != 'octopus' |
239
c5e5e7849803
split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
238
diff
changeset
|
723 parents.append(p1) |
c5e5e7849803
split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
238
diff
changeset
|
724 part = p2 |
c5e5e7849803
split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
238
diff
changeset
|
725 parents.append(p2) |
c5e5e7849803
split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
238
diff
changeset
|
726 else: |
c5e5e7849803
split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
238
diff
changeset
|
727 parents = ctx.parents() |
c5e5e7849803
split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
238
diff
changeset
|
728 |
c5e5e7849803
split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
238
diff
changeset
|
729 return parents |
c5e5e7849803
split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
238
diff
changeset
|
730 |
764
70aba6b2fe7b
git_handler: export hg extra metadata as git extra metadata (issue121)
Siddharth Agarwal <sid0@fb.com>
parents:
763
diff
changeset
|
731 def get_git_message_and_extra(self, ctx): |
239
c5e5e7849803
split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
238
diff
changeset
|
732 extra = ctx.extra() |
c5e5e7849803
split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
238
diff
changeset
|
733 |
c5e5e7849803
split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
238
diff
changeset
|
734 message = ctx.description() + "\n" |
c5e5e7849803
split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
238
diff
changeset
|
735 if 'message' in extra: |
307
7dfe8be21135
handle apply_delta() return value correctly
Tay Ray Chuan <rctay89@gmail.com>
parents:
302
diff
changeset
|
736 message = "".join(apply_delta(message, extra['message'])) |
239
c5e5e7849803
split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
238
diff
changeset
|
737 |
54
f6e11b9d7562
not adding HG extra info if commits were on the default branch
Scott Chacon <schacon@gmail.com>
parents:
53
diff
changeset
|
738 # HG EXTRA INFORMATION |
764
70aba6b2fe7b
git_handler: export hg extra metadata as git extra metadata (issue121)
Siddharth Agarwal <sid0@fb.com>
parents:
763
diff
changeset
|
739 |
70aba6b2fe7b
git_handler: export hg extra metadata as git extra metadata (issue121)
Siddharth Agarwal <sid0@fb.com>
parents:
763
diff
changeset
|
740 # test only -- do not document this! |
1068
914e5477b17e
config: register git.debugextrainmessage
Kevin Bullock <kbullock@ringworld.org>
parents:
1067
diff
changeset
|
741 extra_in_message = compat.config(self.ui, 'bool', 'git', |
914e5477b17e
config: register git.debugextrainmessage
Kevin Bullock <kbullock@ringworld.org>
parents:
1067
diff
changeset
|
742 'debugextrainmessage') |
67
759ac56497e7
adding hg explicit file renames to the git commit message
Scott Chacon <schacon@gmail.com>
parents:
65
diff
changeset
|
743 extra_message = '' |
764
70aba6b2fe7b
git_handler: export hg extra metadata as git extra metadata (issue121)
Siddharth Agarwal <sid0@fb.com>
parents:
763
diff
changeset
|
744 git_extra = [] |
808
4bca27d22a96
git_handler: write inequality more idiomatically
Siddharth Agarwal <sid0@fb.com>
parents:
807
diff
changeset
|
745 if ctx.branch() != 'default': |
764
70aba6b2fe7b
git_handler: export hg extra metadata as git extra metadata (issue121)
Siddharth Agarwal <sid0@fb.com>
parents:
763
diff
changeset
|
746 # we always store the branch in the extra message |
67
759ac56497e7
adding hg explicit file renames to the git commit message
Scott Chacon <schacon@gmail.com>
parents:
65
diff
changeset
|
747 extra_message += "branch : " + ctx.branch() + "\n" |
65
5ed8316d3cfa
Start using reasonable ui.{status,debug,warn} calls instead of print.
Augie Fackler <durin42@gmail.com>
parents:
56
diff
changeset
|
748 |
764
70aba6b2fe7b
git_handler: export hg extra metadata as git extra metadata (issue121)
Siddharth Agarwal <sid0@fb.com>
parents:
763
diff
changeset
|
749 # Git native extra items always come first, followed by hg renames, |
70aba6b2fe7b
git_handler: export hg extra metadata as git extra metadata (issue121)
Siddharth Agarwal <sid0@fb.com>
parents:
763
diff
changeset
|
750 # followed by hg extra keys |
70aba6b2fe7b
git_handler: export hg extra metadata as git extra metadata (issue121)
Siddharth Agarwal <sid0@fb.com>
parents:
763
diff
changeset
|
751 git_extraitems = [] |
70aba6b2fe7b
git_handler: export hg extra metadata as git extra metadata (issue121)
Siddharth Agarwal <sid0@fb.com>
parents:
763
diff
changeset
|
752 for key, value in extra.items(): |
70aba6b2fe7b
git_handler: export hg extra metadata as git extra metadata (issue121)
Siddharth Agarwal <sid0@fb.com>
parents:
763
diff
changeset
|
753 m = RE_GIT_EXTRA_KEY.match(key) |
70aba6b2fe7b
git_handler: export hg extra metadata as git extra metadata (issue121)
Siddharth Agarwal <sid0@fb.com>
parents:
763
diff
changeset
|
754 if m is not None: |
70aba6b2fe7b
git_handler: export hg extra metadata as git extra metadata (issue121)
Siddharth Agarwal <sid0@fb.com>
parents:
763
diff
changeset
|
755 git_extraitems.append((int(m.group(1)), m.group(2), value)) |
70aba6b2fe7b
git_handler: export hg extra metadata as git extra metadata (issue121)
Siddharth Agarwal <sid0@fb.com>
parents:
763
diff
changeset
|
756 del extra[key] |
70aba6b2fe7b
git_handler: export hg extra metadata as git extra metadata (issue121)
Siddharth Agarwal <sid0@fb.com>
parents:
763
diff
changeset
|
757 |
70aba6b2fe7b
git_handler: export hg extra metadata as git extra metadata (issue121)
Siddharth Agarwal <sid0@fb.com>
parents:
763
diff
changeset
|
758 git_extraitems.sort() |
70aba6b2fe7b
git_handler: export hg extra metadata as git extra metadata (issue121)
Siddharth Agarwal <sid0@fb.com>
parents:
763
diff
changeset
|
759 for i, field, value in git_extraitems: |
70aba6b2fe7b
git_handler: export hg extra metadata as git extra metadata (issue121)
Siddharth Agarwal <sid0@fb.com>
parents:
763
diff
changeset
|
760 git_extra.append((urllib.unquote(field), urllib.unquote(value))) |
70aba6b2fe7b
git_handler: export hg extra metadata as git extra metadata (issue121)
Siddharth Agarwal <sid0@fb.com>
parents:
763
diff
changeset
|
761 |
844
fffe8883960b
git_handler: mark source for rename info as Git or Mercurial
Siddharth Agarwal <sid0@fb.com>
parents:
843
diff
changeset
|
762 if extra.get('hg-git-rename-source', None) != 'git': |
fffe8883960b
git_handler: mark source for rename info as Git or Mercurial
Siddharth Agarwal <sid0@fb.com>
parents:
843
diff
changeset
|
763 renames = [] |
fffe8883960b
git_handler: mark source for rename info as Git or Mercurial
Siddharth Agarwal <sid0@fb.com>
parents:
843
diff
changeset
|
764 for f in ctx.files(): |
fffe8883960b
git_handler: mark source for rename info as Git or Mercurial
Siddharth Agarwal <sid0@fb.com>
parents:
843
diff
changeset
|
765 if f not in ctx.manifest(): |
fffe8883960b
git_handler: mark source for rename info as Git or Mercurial
Siddharth Agarwal <sid0@fb.com>
parents:
843
diff
changeset
|
766 continue |
fffe8883960b
git_handler: mark source for rename info as Git or Mercurial
Siddharth Agarwal <sid0@fb.com>
parents:
843
diff
changeset
|
767 rename = ctx.filectx(f).renamed() |
fffe8883960b
git_handler: mark source for rename info as Git or Mercurial
Siddharth Agarwal <sid0@fb.com>
parents:
843
diff
changeset
|
768 if rename: |
fffe8883960b
git_handler: mark source for rename info as Git or Mercurial
Siddharth Agarwal <sid0@fb.com>
parents:
843
diff
changeset
|
769 renames.append((rename[0], f)) |
239
c5e5e7849803
split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
238
diff
changeset
|
770 |
844
fffe8883960b
git_handler: mark source for rename info as Git or Mercurial
Siddharth Agarwal <sid0@fb.com>
parents:
843
diff
changeset
|
771 if renames: |
fffe8883960b
git_handler: mark source for rename info as Git or Mercurial
Siddharth Agarwal <sid0@fb.com>
parents:
843
diff
changeset
|
772 for oldfile, newfile in renames: |
fffe8883960b
git_handler: mark source for rename info as Git or Mercurial
Siddharth Agarwal <sid0@fb.com>
parents:
843
diff
changeset
|
773 if extra_in_message: |
fffe8883960b
git_handler: mark source for rename info as Git or Mercurial
Siddharth Agarwal <sid0@fb.com>
parents:
843
diff
changeset
|
774 extra_message += ("rename : " + oldfile + " => " + |
fffe8883960b
git_handler: mark source for rename info as Git or Mercurial
Siddharth Agarwal <sid0@fb.com>
parents:
843
diff
changeset
|
775 newfile + "\n") |
fffe8883960b
git_handler: mark source for rename info as Git or Mercurial
Siddharth Agarwal <sid0@fb.com>
parents:
843
diff
changeset
|
776 else: |
fffe8883960b
git_handler: mark source for rename info as Git or Mercurial
Siddharth Agarwal <sid0@fb.com>
parents:
843
diff
changeset
|
777 spec = '%s:%s' % (urllib.quote(oldfile), |
fffe8883960b
git_handler: mark source for rename info as Git or Mercurial
Siddharth Agarwal <sid0@fb.com>
parents:
843
diff
changeset
|
778 urllib.quote(newfile)) |
fffe8883960b
git_handler: mark source for rename info as Git or Mercurial
Siddharth Agarwal <sid0@fb.com>
parents:
843
diff
changeset
|
779 git_extra.append(('HG:rename', spec)) |
164
7e98757deadc
author and extra data fixes
Scott Chacon <schacon@gmail.com>
parents:
162
diff
changeset
|
780 |
764
70aba6b2fe7b
git_handler: export hg extra metadata as git extra metadata (issue121)
Siddharth Agarwal <sid0@fb.com>
parents:
763
diff
changeset
|
781 # hg extra items always go at the end |
759
eb9ebc7ed061
git_handler: store hg extra data in git deterministically by sorting it
Siddharth Agarwal <sid0@fb.com>
parents:
758
diff
changeset
|
782 extraitems = extra.items() |
eb9ebc7ed061
git_handler: store hg extra data in git deterministically by sorting it
Siddharth Agarwal <sid0@fb.com>
parents:
758
diff
changeset
|
783 extraitems.sort() |
eb9ebc7ed061
git_handler: store hg extra data in git deterministically by sorting it
Siddharth Agarwal <sid0@fb.com>
parents:
758
diff
changeset
|
784 for key, value in extraitems: |
844
fffe8883960b
git_handler: mark source for rename info as Git or Mercurial
Siddharth Agarwal <sid0@fb.com>
parents:
843
diff
changeset
|
785 if key in ('author', 'committer', 'encoding', 'message', 'branch', |
fffe8883960b
git_handler: mark source for rename info as Git or Mercurial
Siddharth Agarwal <sid0@fb.com>
parents:
843
diff
changeset
|
786 'hg-git', 'hg-git-rename-source'): |
164
7e98757deadc
author and extra data fixes
Scott Chacon <schacon@gmail.com>
parents:
162
diff
changeset
|
787 continue |
7e98757deadc
author and extra data fixes
Scott Chacon <schacon@gmail.com>
parents:
162
diff
changeset
|
788 else: |
764
70aba6b2fe7b
git_handler: export hg extra metadata as git extra metadata (issue121)
Siddharth Agarwal <sid0@fb.com>
parents:
763
diff
changeset
|
789 if extra_in_message: |
70aba6b2fe7b
git_handler: export hg extra metadata as git extra metadata (issue121)
Siddharth Agarwal <sid0@fb.com>
parents:
763
diff
changeset
|
790 extra_message += ("extra : " + key + " : " + |
70aba6b2fe7b
git_handler: export hg extra metadata as git extra metadata (issue121)
Siddharth Agarwal <sid0@fb.com>
parents:
763
diff
changeset
|
791 urllib.quote(value) + "\n") |
70aba6b2fe7b
git_handler: export hg extra metadata as git extra metadata (issue121)
Siddharth Agarwal <sid0@fb.com>
parents:
763
diff
changeset
|
792 else: |
70aba6b2fe7b
git_handler: export hg extra metadata as git extra metadata (issue121)
Siddharth Agarwal <sid0@fb.com>
parents:
763
diff
changeset
|
793 spec = '%s:%s' % (urllib.quote(key), |
70aba6b2fe7b
git_handler: export hg extra metadata as git extra metadata (issue121)
Siddharth Agarwal <sid0@fb.com>
parents:
763
diff
changeset
|
794 urllib.quote(value)) |
70aba6b2fe7b
git_handler: export hg extra metadata as git extra metadata (issue121)
Siddharth Agarwal <sid0@fb.com>
parents:
763
diff
changeset
|
795 git_extra.append(('HG:extra', spec)) |
164
7e98757deadc
author and extra data fixes
Scott Chacon <schacon@gmail.com>
parents:
162
diff
changeset
|
796 |
758
1d16139b8e50
git_handler: drop unnecessary add_extras boolean from get_git_message
Siddharth Agarwal <sid0@fb.com>
parents:
756
diff
changeset
|
797 if extra_message: |
239
c5e5e7849803
split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
238
diff
changeset
|
798 message += "\n--HG--\n" + extra_message |
50
d274092e3b24
Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents:
42
diff
changeset
|
799 |
884
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
800 if (extra.get('hg-git-rename-source', None) != 'git' and not |
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
801 extra_in_message and not git_extra and extra_message == ''): |
844
fffe8883960b
git_handler: mark source for rename info as Git or Mercurial
Siddharth Agarwal <sid0@fb.com>
parents:
843
diff
changeset
|
802 # We need to store this if no other metadata is stored. This |
fffe8883960b
git_handler: mark source for rename info as Git or Mercurial
Siddharth Agarwal <sid0@fb.com>
parents:
843
diff
changeset
|
803 # indicates that when reimporting the commit into Mercurial we'll |
fffe8883960b
git_handler: mark source for rename info as Git or Mercurial
Siddharth Agarwal <sid0@fb.com>
parents:
843
diff
changeset
|
804 # know not to detect renames. |
fffe8883960b
git_handler: mark source for rename info as Git or Mercurial
Siddharth Agarwal <sid0@fb.com>
parents:
843
diff
changeset
|
805 git_extra.append(('HG:rename-source', 'hg')) |
fffe8883960b
git_handler: mark source for rename info as Git or Mercurial
Siddharth Agarwal <sid0@fb.com>
parents:
843
diff
changeset
|
806 |
764
70aba6b2fe7b
git_handler: export hg extra metadata as git extra metadata (issue121)
Siddharth Agarwal <sid0@fb.com>
parents:
763
diff
changeset
|
807 return message, git_extra |
65
5ed8316d3cfa
Start using reasonable ui.{status,debug,warn} calls instead of print.
Augie Fackler <durin42@gmail.com>
parents:
56
diff
changeset
|
808 |
785
2f6507057987
git_handler: rename getnewgitcommits to get_git_incoming
Siddharth Agarwal <sid0@fb.com>
parents:
784
diff
changeset
|
809 def get_git_incoming(self, refs): |
788
e734d71cc558
git_handler: move get_git_incoming to a separate module
Siddharth Agarwal <sid0@fb.com>
parents:
787
diff
changeset
|
810 return git2hg.find_incoming(self.git.object_store, self._map_git, refs) |
408 | 811 |
797
c7d27c134ed9
git_handler.import_git_objects: require all arguments
Siddharth Agarwal <sid0@fb.com>
parents:
796
diff
changeset
|
812 def import_git_objects(self, remote_name, refs): |
789
77416ddca136
git2hg: return a struct from find_incoming
Siddharth Agarwal <sid0@fb.com>
parents:
788
diff
changeset
|
813 result = self.get_git_incoming(refs) |
77416ddca136
git2hg: return a struct from find_incoming
Siddharth Agarwal <sid0@fb.com>
parents:
788
diff
changeset
|
814 commits = result.commits |
77416ddca136
git2hg: return a struct from find_incoming
Siddharth Agarwal <sid0@fb.com>
parents:
788
diff
changeset
|
815 commit_cache = result.commit_cache |
183
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
816 # import each of the commits, oldest first |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
817 total = len(commits) |
392 | 818 if total: |
819 self.ui.status(_("importing git objects into hg\n")) | |
701
178b15457927
git_handler: base 'no changes found' message on commits, not on heads
Siddharth Agarwal <sid0@fb.com>
parents:
700
diff
changeset
|
820 else: |
178b15457927
git_handler: base 'no changes found' message on commits, not on heads
Siddharth Agarwal <sid0@fb.com>
parents:
700
diff
changeset
|
821 self.ui.status(_("no changes found\n")) |
392 | 822 |
1067
f4c2b42731ea
config: register hggit.mapsavefrequency
Kevin Bullock <kbullock@ringworld.org>
parents:
1066
diff
changeset
|
823 mapsavefreq = compat.config(self.ui, 'int', 'hggit', |
1110
94aaea5c65f7
cleanup: fix incorrect indentation
Sean Farley <sean@farley.io>
parents:
1109
diff
changeset
|
824 'mapsavefrequency') |
183
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
825 for i, csha in enumerate(commits): |
685
c7129c72baff
git_handler: replace util.progress with ui.progress
Siddharth Agarwal <sid0@fb.com>
parents:
683
diff
changeset
|
826 self.ui.progress('importing', i, total=total, unit='commits') |
784
4f425a1be4f3
git_handler: rename convert_list to commit_cache
Siddharth Agarwal <sid0@fb.com>
parents:
783
diff
changeset
|
827 commit = commit_cache[csha] |
190
6fbdf1afe032
Better reporting of the number of commits to convert
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
188
diff
changeset
|
828 self.import_git_commit(commit) |
916
6aa31a3b0506
gitimport: add save frequency config
Durham Goode <durham@fb.com>
parents:
915
diff
changeset
|
829 if mapsavefreq and i % mapsavefreq == 0: |
6aa31a3b0506
gitimport: add save frequency config
Durham Goode <durham@fb.com>
parents:
915
diff
changeset
|
830 self.ui.debug(_("saving mapfile\n")) |
6aa31a3b0506
gitimport: add save frequency config
Durham Goode <durham@fb.com>
parents:
915
diff
changeset
|
831 self.save_map(self.map_file) |
685
c7129c72baff
git_handler: replace util.progress with ui.progress
Siddharth Agarwal <sid0@fb.com>
parents:
683
diff
changeset
|
832 self.ui.progress('importing', None, total=total, unit='commits') |
183
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
833 |
683
13d64d9dd26c
git_handler: remove old and bogus code for deleting entries from tags cache
Siddharth Agarwal <sid0@fb.com>
parents:
682
diff
changeset
|
834 # TODO if the tags cache is used, remove any dangling tag references |
702
439e57b724b6
import_git_objects: return number of commits imported
Siddharth Agarwal <sid0@fb.com>
parents:
701
diff
changeset
|
835 return total |
400
6d4f3b6d2e08
respect references to tags that differ between git and .hgtags
Adrian Sampson <adrian@radbox.org>
parents:
398
diff
changeset
|
836 |
183
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
837 def import_git_commit(self, commit): |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
838 self.ui.debug(_("importing: %s\n") % commit.id) |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
839 |
837
6866ae460ee7
git_handler.import_git_commit: figure out when to detect renames
Siddharth Agarwal <sid0@fb.com>
parents:
836
diff
changeset
|
840 detect_renames = False |
293
8aaae306d46f
git_handler: 80 columns cleanup
Augie Fackler <durin42@gmail.com>
parents:
292
diff
changeset
|
841 (strip_message, hg_renames, |
795
c19835c3c60d
git_handler: move extract_hg_metadata into git2hg
Siddharth Agarwal <sid0@fb.com>
parents:
789
diff
changeset
|
842 hg_branch, extra) = git2hg.extract_hg_metadata( |
763
13a3513f8e67
git_handler: support extracting metadata from Git extra fields
Siddharth Agarwal <sid0@fb.com>
parents:
759
diff
changeset
|
843 commit.message, commit.extra) |
835
6c9c40d9e9c1
git2hg: while extracting metadata, detect which VCS commits were made in
Siddharth Agarwal <sid0@fb.com>
parents:
832
diff
changeset
|
844 if hg_renames is None: |
837
6866ae460ee7
git_handler.import_git_commit: figure out when to detect renames
Siddharth Agarwal <sid0@fb.com>
parents:
836
diff
changeset
|
845 detect_renames = True |
844
fffe8883960b
git_handler: mark source for rename info as Git or Mercurial
Siddharth Agarwal <sid0@fb.com>
parents:
843
diff
changeset
|
846 # We have to store this unconditionally, even if there are no |
fffe8883960b
git_handler: mark source for rename info as Git or Mercurial
Siddharth Agarwal <sid0@fb.com>
parents:
843
diff
changeset
|
847 # renames detected from Git. This is because we export an extra |
fffe8883960b
git_handler: mark source for rename info as Git or Mercurial
Siddharth Agarwal <sid0@fb.com>
parents:
843
diff
changeset
|
848 # 'HG:rename-source' Git parameter when this isn't set, which will |
fffe8883960b
git_handler: mark source for rename info as Git or Mercurial
Siddharth Agarwal <sid0@fb.com>
parents:
843
diff
changeset
|
849 # break bidirectionality. |
fffe8883960b
git_handler: mark source for rename info as Git or Mercurial
Siddharth Agarwal <sid0@fb.com>
parents:
843
diff
changeset
|
850 extra['hg-git-rename-source'] = 'git' |
836
c24d2ea1361b
git_handler.import_git_commit: rename 'hg_renames' to 'renames'
Siddharth Agarwal <sid0@fb.com>
parents:
835
diff
changeset
|
851 else: |
c24d2ea1361b
git_handler.import_git_commit: rename 'hg_renames' to 'renames'
Siddharth Agarwal <sid0@fb.com>
parents:
835
diff
changeset
|
852 renames = hg_renames |
183
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
853 |
640
cacd98c7382e
git_handler: move gparents initialization up to start of import_git_commit
Siddharth Agarwal <sid0@fb.com>
parents:
639
diff
changeset
|
854 gparents = map(self.map_hg_get, commit.parents) |
cacd98c7382e
git_handler: move gparents initialization up to start of import_git_commit
Siddharth Agarwal <sid0@fb.com>
parents:
639
diff
changeset
|
855 |
641
5a17de2247bf
git_handler: move check for gparents in repo to start of import_git_commit
Siddharth Agarwal <sid0@fb.com>
parents:
640
diff
changeset
|
856 for parent in gparents: |
5a17de2247bf
git_handler: move check for gparents in repo to start of import_git_commit
Siddharth Agarwal <sid0@fb.com>
parents:
640
diff
changeset
|
857 if parent not in self.repo: |
1128
6141895a53c9
compat: switch from hgutil.Abort to error.Abort
Kevin Bullock <kbullock@ringworld.org>
parents:
1127
diff
changeset
|
858 raise error.Abort(_('you appear to have run strip - ' |
6141895a53c9
compat: switch from hgutil.Abort to error.Abort
Kevin Bullock <kbullock@ringworld.org>
parents:
1127
diff
changeset
|
859 'please run hg git-cleanup')) |
641
5a17de2247bf
git_handler: move check for gparents in repo to start of import_git_commit
Siddharth Agarwal <sid0@fb.com>
parents:
640
diff
changeset
|
860 |
639
42ca3ace9a0f
git_handler: return gitlinks in get_files_changed
Siddharth Agarwal <sid0@fb.com>
parents:
635
diff
changeset
|
861 # get a list of the changed, added, removed files and gitlinks |
840
edcdb7620f4d
git_handler.get_files_changed: return detected renames
Siddharth Agarwal <sid0@fb.com>
parents:
839
diff
changeset
|
862 files, gitlinks, git_renames = self.get_files_changed(commit, |
edcdb7620f4d
git_handler.get_files_changed: return detected renames
Siddharth Agarwal <sid0@fb.com>
parents:
839
diff
changeset
|
863 detect_renames) |
edcdb7620f4d
git_handler.get_files_changed: return detected renames
Siddharth Agarwal <sid0@fb.com>
parents:
839
diff
changeset
|
864 if detect_renames: |
edcdb7620f4d
git_handler.get_files_changed: return detected renames
Siddharth Agarwal <sid0@fb.com>
parents:
839
diff
changeset
|
865 renames = git_renames |
183
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
866 |
476
b9ede5f91701
Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
475
diff
changeset
|
867 git_commit_tree = self.git[commit.tree] |
b9ede5f91701
Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
475
diff
changeset
|
868 |
642
f492e4759e52
git_handler: fix hgsubstate generation
Siddharth Agarwal <sid0@fb.com>
parents:
641
diff
changeset
|
869 # Analyze hgsubstate and build an updated version using SHAs from |
f492e4759e52
git_handler: fix hgsubstate generation
Siddharth Agarwal <sid0@fb.com>
parents:
641
diff
changeset
|
870 # gitlinks. Order of application: |
f492e4759e52
git_handler: fix hgsubstate generation
Siddharth Agarwal <sid0@fb.com>
parents:
641
diff
changeset
|
871 # - preexisting .hgsubstate in git tree |
f492e4759e52
git_handler: fix hgsubstate generation
Siddharth Agarwal <sid0@fb.com>
parents:
641
diff
changeset
|
872 # - .hgsubstate from hg parent |
f492e4759e52
git_handler: fix hgsubstate generation
Siddharth Agarwal <sid0@fb.com>
parents:
641
diff
changeset
|
873 # - changes in gitlinks |
f492e4759e52
git_handler: fix hgsubstate generation
Siddharth Agarwal <sid0@fb.com>
parents:
641
diff
changeset
|
874 hgsubstate = util.parse_hgsubstate( |
f492e4759e52
git_handler: fix hgsubstate generation
Siddharth Agarwal <sid0@fb.com>
parents:
641
diff
changeset
|
875 self.git_file_readlines(git_commit_tree, '.hgsubstate')) |
f492e4759e52
git_handler: fix hgsubstate generation
Siddharth Agarwal <sid0@fb.com>
parents:
641
diff
changeset
|
876 parentsubdata = '' |
f492e4759e52
git_handler: fix hgsubstate generation
Siddharth Agarwal <sid0@fb.com>
parents:
641
diff
changeset
|
877 if gparents: |
1127
108d9303ef71
git_handler: use repo.__getitem__ instead of (removed) repo.changectx
Paul Morelle <paul.morelle@octobus.net>
parents:
1125
diff
changeset
|
878 p1ctx = self.repo[gparents[0]] |
642
f492e4759e52
git_handler: fix hgsubstate generation
Siddharth Agarwal <sid0@fb.com>
parents:
641
diff
changeset
|
879 if '.hgsubstate' in p1ctx: |
884
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
880 parentsubdata = p1ctx.filectx('.hgsubstate').data() |
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
881 parentsubdata = parentsubdata.splitlines() |
642
f492e4759e52
git_handler: fix hgsubstate generation
Siddharth Agarwal <sid0@fb.com>
parents:
641
diff
changeset
|
882 parentsubstate = util.parse_hgsubstate(parentsubdata) |
f492e4759e52
git_handler: fix hgsubstate generation
Siddharth Agarwal <sid0@fb.com>
parents:
641
diff
changeset
|
883 for path, sha in parentsubstate.iteritems(): |
f492e4759e52
git_handler: fix hgsubstate generation
Siddharth Agarwal <sid0@fb.com>
parents:
641
diff
changeset
|
884 hgsubstate[path] = sha |
f492e4759e52
git_handler: fix hgsubstate generation
Siddharth Agarwal <sid0@fb.com>
parents:
641
diff
changeset
|
885 for path, sha in gitlinks.iteritems(): |
f492e4759e52
git_handler: fix hgsubstate generation
Siddharth Agarwal <sid0@fb.com>
parents:
641
diff
changeset
|
886 if sha is None: |
f492e4759e52
git_handler: fix hgsubstate generation
Siddharth Agarwal <sid0@fb.com>
parents:
641
diff
changeset
|
887 hgsubstate.pop(path, None) |
f492e4759e52
git_handler: fix hgsubstate generation
Siddharth Agarwal <sid0@fb.com>
parents:
641
diff
changeset
|
888 else: |
476
b9ede5f91701
Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
475
diff
changeset
|
889 hgsubstate[path] = sha |
642
f492e4759e52
git_handler: fix hgsubstate generation
Siddharth Agarwal <sid0@fb.com>
parents:
641
diff
changeset
|
890 # in case .hgsubstate wasn't among changed files |
917
3246f2fab625
import_git_commit: skip hgsubstate logic if file was deleted
Sean Farley <sean@farley.io>
parents:
916
diff
changeset
|
891 # force its inclusion if it wasn't already deleted |
3246f2fab625
import_git_commit: skip hgsubstate logic if file was deleted
Sean Farley <sean@farley.io>
parents:
916
diff
changeset
|
892 hgsubdeleted = files.get('.hgsubstate') |
3246f2fab625
import_git_commit: skip hgsubstate logic if file was deleted
Sean Farley <sean@farley.io>
parents:
916
diff
changeset
|
893 if hgsubdeleted: |
3246f2fab625
import_git_commit: skip hgsubstate logic if file was deleted
Sean Farley <sean@farley.io>
parents:
916
diff
changeset
|
894 hgsubdeleted = hgsubdeleted[0] |
3246f2fab625
import_git_commit: skip hgsubstate logic if file was deleted
Sean Farley <sean@farley.io>
parents:
916
diff
changeset
|
895 if hgsubdeleted or (not hgsubstate and parentsubdata): |
642
f492e4759e52
git_handler: fix hgsubstate generation
Siddharth Agarwal <sid0@fb.com>
parents:
641
diff
changeset
|
896 files['.hgsubstate'] = True, None, None |
f492e4759e52
git_handler: fix hgsubstate generation
Siddharth Agarwal <sid0@fb.com>
parents:
641
diff
changeset
|
897 elif util.serialize_hgsubstate(hgsubstate) != parentsubdata: |
f492e4759e52
git_handler: fix hgsubstate generation
Siddharth Agarwal <sid0@fb.com>
parents:
641
diff
changeset
|
898 files['.hgsubstate'] = False, 0100644, None |
476
b9ede5f91701
Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
475
diff
changeset
|
899 |
b9ede5f91701
Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
475
diff
changeset
|
900 # Analyze .hgsub and merge with .gitmodules |
b9ede5f91701
Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
475
diff
changeset
|
901 hgsub = None |
b9ede5f91701
Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
475
diff
changeset
|
902 gitmodules = self.parse_gitmodules(git_commit_tree) |
642
f492e4759e52
git_handler: fix hgsubstate generation
Siddharth Agarwal <sid0@fb.com>
parents:
641
diff
changeset
|
903 if gitmodules: |
884
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
904 hgsub = util.parse_hgsub(self.git_file_readlines(git_commit_tree, |
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
905 '.hgsub')) |
476
b9ede5f91701
Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
475
diff
changeset
|
906 for (sm_path, sm_url, sm_name) in gitmodules: |
b9ede5f91701
Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
475
diff
changeset
|
907 hgsub[sm_path] = '[git]' + sm_url |
b9ede5f91701
Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
475
diff
changeset
|
908 files['.hgsub'] = (False, 0100644, None) |
884
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
909 elif (commit.parents and '.gitmodules' in |
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
910 self.git[self.git[commit.parents[0]].tree]): |
476
b9ede5f91701
Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
475
diff
changeset
|
911 # no .gitmodules in this commit, however present in the parent |
b9ede5f91701
Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
475
diff
changeset
|
912 # mark its hg counterpart as deleted (assuming .hgsub is there |
b9ede5f91701
Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
475
diff
changeset
|
913 # due to the same import_git_commit process |
b9ede5f91701
Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
475
diff
changeset
|
914 files['.hgsub'] = (True, 0100644, None) |
b9ede5f91701
Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
475
diff
changeset
|
915 |
183
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
916 date = (commit.author_time, -commit.author_timezone) |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
917 text = strip_message |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
918 |
226
3b8804c59b63
drop untested commit_import_ctx (use commitctx instead).
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
225
diff
changeset
|
919 origtext = text |
186
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
920 try: |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
921 text.decode('utf-8') |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
922 except UnicodeDecodeError: |
224
80d67ae190df
port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
222
diff
changeset
|
923 text = self.decode_guess(text, commit.encoding) |
226
3b8804c59b63
drop untested commit_import_ctx (use commitctx instead).
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
225
diff
changeset
|
924 |
3b8804c59b63
drop untested commit_import_ctx (use commitctx instead).
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
225
diff
changeset
|
925 text = '\n'.join([l.rstrip() for l in text.splitlines()]).strip('\n') |
3b8804c59b63
drop untested commit_import_ctx (use commitctx instead).
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
225
diff
changeset
|
926 if text + '\n' != origtext: |
884
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
927 extra['message'] = create_delta(text + '\n', origtext) |
186
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
928 |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
929 author = commit.author |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
930 |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
931 # convert extra data back to the end |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
932 if ' ext:' in commit.author: |
540
3fb942852b1c
Precompile Git author extra data regular expression
Gregory Szorc <gregory.szorc@gmail.com>
parents:
539
diff
changeset
|
933 m = RE_GIT_AUTHOR_EXTRA.match(commit.author) |
186
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
934 if m: |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
935 name = m.group(1) |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
936 ex = urllib.unquote(m.group(2)) |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
937 email = m.group(3) |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
938 author = name + ' <' + email + '>' + ex |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
939 |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
940 if ' <none@none>' in commit.author: |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
941 author = commit.author[:-12] |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
942 |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
943 try: |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
944 author.decode('utf-8') |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
945 except UnicodeDecodeError: |
225
cde57730faa7
store non utf-8 encoded author/commit message as deltas
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
224
diff
changeset
|
946 origauthor = author |
224
80d67ae190df
port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
222
diff
changeset
|
947 author = self.decode_guess(author, commit.encoding) |
225
cde57730faa7
store non utf-8 encoded author/commit message as deltas
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
224
diff
changeset
|
948 extra['author'] = create_delta(author, origauthor) |
186
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
949 |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
950 oldenc = self.swap_out_encoding() |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
951 |
406
50698ff64c41
Fix round-trip fidelity for merges of converged files.
Christian Walther <cwalther@gmx.ch>
parents:
401
diff
changeset
|
952 def findconvergedfiles(p1, p2): |
50698ff64c41
Fix round-trip fidelity for merges of converged files.
Christian Walther <cwalther@gmx.ch>
parents:
401
diff
changeset
|
953 # If any files have the same contents in both parents of a merge |
50698ff64c41
Fix round-trip fidelity for merges of converged files.
Christian Walther <cwalther@gmx.ch>
parents:
401
diff
changeset
|
954 # (and are therefore not reported as changed by Git) but are at |
50698ff64c41
Fix round-trip fidelity for merges of converged files.
Christian Walther <cwalther@gmx.ch>
parents:
401
diff
changeset
|
955 # different file revisions in Mercurial (because they arrived at |
50698ff64c41
Fix round-trip fidelity for merges of converged files.
Christian Walther <cwalther@gmx.ch>
parents:
401
diff
changeset
|
956 # those contents in different ways), we need to include them in |
50698ff64c41
Fix round-trip fidelity for merges of converged files.
Christian Walther <cwalther@gmx.ch>
parents:
401
diff
changeset
|
957 # the list of changed files so that Mercurial can join up their |
50698ff64c41
Fix round-trip fidelity for merges of converged files.
Christian Walther <cwalther@gmx.ch>
parents:
401
diff
changeset
|
958 # filelog histories (same as if the merge was done in Mercurial to |
50698ff64c41
Fix round-trip fidelity for merges of converged files.
Christian Walther <cwalther@gmx.ch>
parents:
401
diff
changeset
|
959 # begin with). |
50698ff64c41
Fix round-trip fidelity for merges of converged files.
Christian Walther <cwalther@gmx.ch>
parents:
401
diff
changeset
|
960 if p2 == nullid: |
50698ff64c41
Fix round-trip fidelity for merges of converged files.
Christian Walther <cwalther@gmx.ch>
parents:
401
diff
changeset
|
961 return [] |
1127
108d9303ef71
git_handler: use repo.__getitem__ instead of (removed) repo.changectx
Paul Morelle <paul.morelle@octobus.net>
parents:
1125
diff
changeset
|
962 manifest1 = self.repo[p1].manifest() |
108d9303ef71
git_handler: use repo.__getitem__ instead of (removed) repo.changectx
Paul Morelle <paul.morelle@octobus.net>
parents:
1125
diff
changeset
|
963 manifest2 = self.repo[p2].manifest() |
884
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
964 return [path for path, node1 in manifest1.iteritems() if path not |
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
965 in files and manifest2.get(path, node1) != node1] |
406
50698ff64c41
Fix round-trip fidelity for merges of converged files.
Christian Walther <cwalther@gmx.ch>
parents:
401
diff
changeset
|
966 |
183
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
967 def getfilectx(repo, memctx, f): |
406
50698ff64c41
Fix round-trip fidelity for merges of converged files.
Christian Walther <cwalther@gmx.ch>
parents:
401
diff
changeset
|
968 info = files.get(f) |
884
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
969 if info is not None: |
406
50698ff64c41
Fix round-trip fidelity for merges of converged files.
Christian Walther <cwalther@gmx.ch>
parents:
401
diff
changeset
|
970 # it's a file reported as modified from Git |
50698ff64c41
Fix round-trip fidelity for merges of converged files.
Christian Walther <cwalther@gmx.ch>
parents:
401
diff
changeset
|
971 delete, mode, sha = info |
50698ff64c41
Fix round-trip fidelity for merges of converged files.
Christian Walther <cwalther@gmx.ch>
parents:
401
diff
changeset
|
972 if delete: |
1135
c4703246f350
compat: mark all compat-checking locations outside hggit.compat with "COMPAT:"
Kevin Bullock <kbullock@ringworld.org>
parents:
1128
diff
changeset
|
973 # COMPAT: hg 3.2 - expects this function to return |
c4703246f350
compat: mark all compat-checking locations outside hggit.compat with "COMPAT:"
Kevin Bullock <kbullock@ringworld.org>
parents:
1128
diff
changeset
|
974 # None for missing files |
756
0a673c9330ba
git_handler: fix filectxfn compatibility with hg's default branch
Siddharth Agarwal <sid0@fb.com>
parents:
752
diff
changeset
|
975 if getattr(memctx, '_returnnoneformissingfiles', False): |
0a673c9330ba
git_handler: fix filectxfn compatibility with hg's default branch
Siddharth Agarwal <sid0@fb.com>
parents:
752
diff
changeset
|
976 return None |
0a673c9330ba
git_handler: fix filectxfn compatibility with hg's default branch
Siddharth Agarwal <sid0@fb.com>
parents:
752
diff
changeset
|
977 else: # Mercurial < 3.2 |
0a673c9330ba
git_handler: fix filectxfn compatibility with hg's default branch
Siddharth Agarwal <sid0@fb.com>
parents:
752
diff
changeset
|
978 raise IOError |
275
c2d6b1093e7e
fix a bug when a directory is replaced with a file
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
261
diff
changeset
|
979 |
884
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
980 if not sha: # indicates there's no git counterpart |
476
b9ede5f91701
Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
475
diff
changeset
|
981 e = '' |
b9ede5f91701
Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
475
diff
changeset
|
982 copied_path = None |
b9ede5f91701
Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
475
diff
changeset
|
983 if '.hgsubstate' == f: |
b9ede5f91701
Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
475
diff
changeset
|
984 data = util.serialize_hgsubstate(hgsubstate) |
b9ede5f91701
Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
475
diff
changeset
|
985 elif '.hgsub' == f: |
b9ede5f91701
Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
475
diff
changeset
|
986 data = util.serialize_hgsub(hgsub) |
b9ede5f91701
Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
475
diff
changeset
|
987 else: |
b9ede5f91701
Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
475
diff
changeset
|
988 data = self.git[sha].data |
836
c24d2ea1361b
git_handler.import_git_commit: rename 'hg_renames' to 'renames'
Siddharth Agarwal <sid0@fb.com>
parents:
835
diff
changeset
|
989 copied_path = renames.get(f) |
476
b9ede5f91701
Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
475
diff
changeset
|
990 e = self.convert_git_int_mode(mode) |
406
50698ff64c41
Fix round-trip fidelity for merges of converged files.
Christian Walther <cwalther@gmx.ch>
parents:
401
diff
changeset
|
991 else: |
50698ff64c41
Fix round-trip fidelity for merges of converged files.
Christian Walther <cwalther@gmx.ch>
parents:
401
diff
changeset
|
992 # it's a converged file |
50698ff64c41
Fix round-trip fidelity for merges of converged files.
Christian Walther <cwalther@gmx.ch>
parents:
401
diff
changeset
|
993 fc = context.filectx(self.repo, f, changeid=memctx.p1().rev()) |
50698ff64c41
Fix round-trip fidelity for merges of converged files.
Christian Walther <cwalther@gmx.ch>
parents:
401
diff
changeset
|
994 data = fc.data() |
50698ff64c41
Fix round-trip fidelity for merges of converged files.
Christian Walther <cwalther@gmx.ch>
parents:
401
diff
changeset
|
995 e = fc.flags() |
906
d153586c28f8
git_handler: properly handle paths when files converge
Gregory Szorc <gps@mozilla.com>
parents:
905
diff
changeset
|
996 copied_path = None |
d153586c28f8
git_handler: properly handle paths when files converge
Gregory Szorc <gps@mozilla.com>
parents:
905
diff
changeset
|
997 copied = fc.renamed() |
d153586c28f8
git_handler: properly handle paths when files converge
Gregory Szorc <gps@mozilla.com>
parents:
905
diff
changeset
|
998 if copied: |
d153586c28f8
git_handler: properly handle paths when files converge
Gregory Szorc <gps@mozilla.com>
parents:
905
diff
changeset
|
999 copied_path = copied[0] |
275
c2d6b1093e7e
fix a bug when a directory is replaced with a file
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
261
diff
changeset
|
1000 |
1104
e326b349eba6
compat: extract function for memfilectx signature variants
Kevin Bullock <kbullock@ringworld.org>
parents:
1102
diff
changeset
|
1001 return compat.memfilectx(self.repo, memctx, f, data, |
e326b349eba6
compat: extract function for memfilectx signature variants
Kevin Bullock <kbullock@ringworld.org>
parents:
1102
diff
changeset
|
1002 islink='l' in e, |
e326b349eba6
compat: extract function for memfilectx signature variants
Kevin Bullock <kbullock@ringworld.org>
parents:
1102
diff
changeset
|
1003 isexec='x' in e, |
e326b349eba6
compat: extract function for memfilectx signature variants
Kevin Bullock <kbullock@ringworld.org>
parents:
1102
diff
changeset
|
1004 copied=copied_path) |
183
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
1005 |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
1006 p1, p2 = (nullid, nullid) |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
1007 octopus = False |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
1008 |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
1009 if len(gparents) > 1: |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
1010 # merge, possibly octopus |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
1011 def commit_octopus(p1, p2): |
884
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1012 ctx = context.memctx(self.repo, (p1, p2), text, list(files) + |
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1013 findconvergedfiles(p1, p2), getfilectx, |
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1014 author, date, {'hg-git': 'octopus'}) |
739
a46cd7139699
git_handler: set substate to None to cope with Mercurial changes
Siddharth Agarwal <sid0@fb.com>
parents:
738
diff
changeset
|
1015 # See comment below about setting substate to None. |
a46cd7139699
git_handler: set substate to None to cope with Mercurial changes
Siddharth Agarwal <sid0@fb.com>
parents:
738
diff
changeset
|
1016 ctx.substate = None |
183
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
1017 return hex(self.repo.commitctx(ctx)) |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
1018 |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
1019 octopus = len(gparents) > 2 |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
1020 p2 = gparents.pop() |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
1021 p1 = gparents.pop() |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
1022 while len(gparents) > 0: |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
1023 p2 = commit_octopus(p1, p2) |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
1024 p1 = gparents.pop() |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
1025 else: |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
1026 if gparents: |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
1027 p1 = gparents.pop() |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
1028 |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
1029 # if named branch, add to extra |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
1030 if hg_branch: |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
1031 extra['branch'] = hg_branch |
1021
17f64b9bfa62
git_handler: explicitly set default branch
Stanislau Hlebik <stash@fb.com>
parents:
1018
diff
changeset
|
1032 else: |
17f64b9bfa62
git_handler: explicitly set default branch
Stanislau Hlebik <stash@fb.com>
parents:
1018
diff
changeset
|
1033 extra['branch'] = 'default' |
183
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
1034 |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
1035 # if committer is different than author, add it to extra |
224
80d67ae190df
port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
222
diff
changeset
|
1036 if commit.author != commit.committer \ |
884
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1037 or commit.author_time != commit.commit_time \ |
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1038 or commit.author_timezone != commit.commit_timezone: |
293
8aaae306d46f
git_handler: 80 columns cleanup
Augie Fackler <durin42@gmail.com>
parents:
292
diff
changeset
|
1039 extra['committer'] = "%s %d %d" % ( |
8aaae306d46f
git_handler: 80 columns cleanup
Augie Fackler <durin42@gmail.com>
parents:
292
diff
changeset
|
1040 commit.committer, commit.commit_time, -commit.commit_timezone) |
183
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
1041 |
224
80d67ae190df
port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
222
diff
changeset
|
1042 if commit.encoding: |
80d67ae190df
port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
222
diff
changeset
|
1043 extra['encoding'] = commit.encoding |
1108
aae2d15de6af
git_handler: store gpgsig header to maintain commit coherence
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents:
1104
diff
changeset
|
1044 if commit.gpgsig: |
aae2d15de6af
git_handler: store gpgsig header to maintain commit coherence
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents:
1104
diff
changeset
|
1045 extra['gpgsig'] = commit.gpgsig |
183
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
1046 |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
1047 if octopus: |
884
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1048 extra['hg-git'] = 'octopus-done' |
183
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
1049 |
406
50698ff64c41
Fix round-trip fidelity for merges of converged files.
Christian Walther <cwalther@gmx.ch>
parents:
401
diff
changeset
|
1050 ctx = context.memctx(self.repo, (p1, p2), text, |
50698ff64c41
Fix round-trip fidelity for merges of converged files.
Christian Walther <cwalther@gmx.ch>
parents:
401
diff
changeset
|
1051 list(files) + findconvergedfiles(p1, p2), |
50698ff64c41
Fix round-trip fidelity for merges of converged files.
Christian Walther <cwalther@gmx.ch>
parents:
401
diff
changeset
|
1052 getfilectx, author, date, extra) |
739
a46cd7139699
git_handler: set substate to None to cope with Mercurial changes
Siddharth Agarwal <sid0@fb.com>
parents:
738
diff
changeset
|
1053 # Starting Mercurial commit d2743be1bb06, memctx imports from |
a46cd7139699
git_handler: set substate to None to cope with Mercurial changes
Siddharth Agarwal <sid0@fb.com>
parents:
738
diff
changeset
|
1054 # committablectx. This means that it has a 'substate' property that |
a46cd7139699
git_handler: set substate to None to cope with Mercurial changes
Siddharth Agarwal <sid0@fb.com>
parents:
738
diff
changeset
|
1055 # contains the subrepo state. Ordinarily, Mercurial expects the subrepo |
a46cd7139699
git_handler: set substate to None to cope with Mercurial changes
Siddharth Agarwal <sid0@fb.com>
parents:
738
diff
changeset
|
1056 # to be present while making a new commit -- since hg-git is importing |
884
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1057 # purely in-memory commits without backing stores for the subrepos, |
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1058 # that won't work. Forcibly set the substate to None so that there's no |
739
a46cd7139699
git_handler: set substate to None to cope with Mercurial changes
Siddharth Agarwal <sid0@fb.com>
parents:
738
diff
changeset
|
1059 # attempt to read subrepos. |
a46cd7139699
git_handler: set substate to None to cope with Mercurial changes
Siddharth Agarwal <sid0@fb.com>
parents:
738
diff
changeset
|
1060 ctx.substate = None |
226
3b8804c59b63
drop untested commit_import_ctx (use commitctx instead).
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
225
diff
changeset
|
1061 node = self.repo.commitctx(ctx) |
183
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
1062 |
186
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
1063 self.swap_out_encoding(oldenc) |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
1064 |
183
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
1065 # save changeset to mapping file |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
1066 cs = hex(node) |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
1067 self.map_set(commit.id, cs) |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
1068 |
884
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1069 # PACK UPLOADING AND FETCHING |
19
2be9c0bd88af
Warn, but don't fail when bookmarks is not enabled.
Augie Fackler <durin42@gmail.com>
parents:
17
diff
changeset
|
1070 |
230
51e4d6ebbc40
rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
229
diff
changeset
|
1071 def upload_pack(self, remote, revs, force): |
184
7bf98d3085f4
Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
183
diff
changeset
|
1072 client, path = self.get_transport_and_path(remote) |
487
68e5dddc7a20
push: return 1 if no changes found, 0 if success
David M. Carr <david@carrclan.us>
parents:
475
diff
changeset
|
1073 old_refs = {} |
591
163c452531cf
push: add more output about what was added (issue #64)
David M. Carr <david@carrclan.us>
parents:
590
diff
changeset
|
1074 change_totals = {} |
163c452531cf
push: add more output about what was added (issue #64)
David M. Carr <david@carrclan.us>
parents:
590
diff
changeset
|
1075 |
230
51e4d6ebbc40
rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
229
diff
changeset
|
1076 def changed(refs): |
591
163c452531cf
push: add more output about what was added (issue #64)
David M. Carr <david@carrclan.us>
parents:
590
diff
changeset
|
1077 self.ui.status(_("searching for changes\n")) |
487
68e5dddc7a20
push: return 1 if no changes found, 0 if success
David M. Carr <david@carrclan.us>
parents:
475
diff
changeset
|
1078 old_refs.update(refs) |
813
345919960ea4
git_handler.get_changed_refs: switch to using get_exportable
Siddharth Agarwal <sid0@fb.com>
parents:
812
diff
changeset
|
1079 all_exportable = self.get_exportable() |
345919960ea4
git_handler.get_changed_refs: switch to using get_exportable
Siddharth Agarwal <sid0@fb.com>
parents:
812
diff
changeset
|
1080 if revs is None: |
345919960ea4
git_handler.get_changed_refs: switch to using get_exportable
Siddharth Agarwal <sid0@fb.com>
parents:
812
diff
changeset
|
1081 exportable = all_exportable |
345919960ea4
git_handler.get_changed_refs: switch to using get_exportable
Siddharth Agarwal <sid0@fb.com>
parents:
812
diff
changeset
|
1082 else: |
345919960ea4
git_handler.get_changed_refs: switch to using get_exportable
Siddharth Agarwal <sid0@fb.com>
parents:
812
diff
changeset
|
1083 exportable = {} |
345919960ea4
git_handler.get_changed_refs: switch to using get_exportable
Siddharth Agarwal <sid0@fb.com>
parents:
812
diff
changeset
|
1084 for rev in (hex(r) for r in revs): |
345919960ea4
git_handler.get_changed_refs: switch to using get_exportable
Siddharth Agarwal <sid0@fb.com>
parents:
812
diff
changeset
|
1085 if rev not in all_exportable: |
1128
6141895a53c9
compat: switch from hgutil.Abort to error.Abort
Kevin Bullock <kbullock@ringworld.org>
parents:
1127
diff
changeset
|
1086 raise error.Abort("revision %s cannot be pushed since" |
6141895a53c9
compat: switch from hgutil.Abort to error.Abort
Kevin Bullock <kbullock@ringworld.org>
parents:
1127
diff
changeset
|
1087 " it doesn't have a bookmark" % |
6141895a53c9
compat: switch from hgutil.Abort to error.Abort
Kevin Bullock <kbullock@ringworld.org>
parents:
1127
diff
changeset
|
1088 self.repo[rev]) |
813
345919960ea4
git_handler.get_changed_refs: switch to using get_exportable
Siddharth Agarwal <sid0@fb.com>
parents:
812
diff
changeset
|
1089 exportable[rev] = all_exportable[rev] |
345919960ea4
git_handler.get_changed_refs: switch to using get_exportable
Siddharth Agarwal <sid0@fb.com>
parents:
812
diff
changeset
|
1090 return self.get_changed_refs(refs, exportable, force) |
230
51e4d6ebbc40
rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
229
diff
changeset
|
1091 |
1124
666ab5997802
client: update to dulwich 0.19+
Kevin Bullock <kbullock@ringworld.org>
parents:
1116
diff
changeset
|
1092 def genpack(have, want, progress=None, ofs_delta=True): |
591
163c452531cf
push: add more output about what was added (issue #64)
David M. Carr <david@carrclan.us>
parents:
590
diff
changeset
|
1093 commits = [] |
163c452531cf
push: add more output about what was added (issue #64)
David M. Carr <david@carrclan.us>
parents:
590
diff
changeset
|
1094 for mo in self.git.object_store.find_missing_objects(have, want): |
163c452531cf
push: add more output about what was added (issue #64)
David M. Carr <david@carrclan.us>
parents:
590
diff
changeset
|
1095 (sha, name) = mo |
163c452531cf
push: add more output about what was added (issue #64)
David M. Carr <david@carrclan.us>
parents:
590
diff
changeset
|
1096 o = self.git.object_store[sha] |
163c452531cf
push: add more output about what was added (issue #64)
David M. Carr <david@carrclan.us>
parents:
590
diff
changeset
|
1097 t = type(o) |
163c452531cf
push: add more output about what was added (issue #64)
David M. Carr <david@carrclan.us>
parents:
590
diff
changeset
|
1098 change_totals[t] = change_totals.get(t, 0) + 1 |
163c452531cf
push: add more output about what was added (issue #64)
David M. Carr <david@carrclan.us>
parents:
590
diff
changeset
|
1099 if isinstance(o, Commit): |
163c452531cf
push: add more output about what was added (issue #64)
David M. Carr <david@carrclan.us>
parents:
590
diff
changeset
|
1100 commits.append(sha) |
163c452531cf
push: add more output about what was added (issue #64)
David M. Carr <david@carrclan.us>
parents:
590
diff
changeset
|
1101 commit_count = len(commits) |
163c452531cf
push: add more output about what was added (issue #64)
David M. Carr <david@carrclan.us>
parents:
590
diff
changeset
|
1102 self.ui.note(_("%d commits found\n") % commit_count) |
163c452531cf
push: add more output about what was added (issue #64)
David M. Carr <david@carrclan.us>
parents:
590
diff
changeset
|
1103 if commit_count > 0: |
163c452531cf
push: add more output about what was added (issue #64)
David M. Carr <david@carrclan.us>
parents:
590
diff
changeset
|
1104 self.ui.debug(_("list of commits:\n")) |
163c452531cf
push: add more output about what was added (issue #64)
David M. Carr <david@carrclan.us>
parents:
590
diff
changeset
|
1105 for commit in commits: |
163c452531cf
push: add more output about what was added (issue #64)
David M. Carr <david@carrclan.us>
parents:
590
diff
changeset
|
1106 self.ui.debug("%s\n" % commit) |
163c452531cf
push: add more output about what was added (issue #64)
David M. Carr <david@carrclan.us>
parents:
590
diff
changeset
|
1107 self.ui.status(_("adding objects\n")) |
1124
666ab5997802
client: update to dulwich 0.19+
Kevin Bullock <kbullock@ringworld.org>
parents:
1116
diff
changeset
|
1108 return self.git.object_store.generate_pack_data( |
666ab5997802
client: update to dulwich 0.19+
Kevin Bullock <kbullock@ringworld.org>
parents:
1116
diff
changeset
|
1109 have, want, progress=progress, ofs_delta=ofs_delta) |
591
163c452531cf
push: add more output about what was added (issue #64)
David M. Carr <david@carrclan.us>
parents:
590
diff
changeset
|
1110 |
954
528015bde034
push: print messages from the server
Sean Farley <sean@farley.io>
parents:
952
diff
changeset
|
1111 def callback(remote_info): |
982
296349f421c8
push: better formatting of messages from the server
Sean Farley <sean@farley.io>
parents:
981
diff
changeset
|
1112 # dulwich (perhaps git?) wraps remote output at a fixed width but |
296349f421c8
push: better formatting of messages from the server
Sean Farley <sean@farley.io>
parents:
981
diff
changeset
|
1113 # signifies the end of transmission with a double new line |
296349f421c8
push: better formatting of messages from the server
Sean Farley <sean@farley.io>
parents:
981
diff
changeset
|
1114 global CALLBACK_BUFFER |
296349f421c8
push: better formatting of messages from the server
Sean Farley <sean@farley.io>
parents:
981
diff
changeset
|
1115 if remote_info and not remote_info.endswith('\n\n'): |
296349f421c8
push: better formatting of messages from the server
Sean Farley <sean@farley.io>
parents:
981
diff
changeset
|
1116 CALLBACK_BUFFER += remote_info |
296349f421c8
push: better formatting of messages from the server
Sean Farley <sean@farley.io>
parents:
981
diff
changeset
|
1117 return |
296349f421c8
push: better formatting of messages from the server
Sean Farley <sean@farley.io>
parents:
981
diff
changeset
|
1118 |
296349f421c8
push: better formatting of messages from the server
Sean Farley <sean@farley.io>
parents:
981
diff
changeset
|
1119 remote_info = CALLBACK_BUFFER + remote_info |
296349f421c8
push: better formatting of messages from the server
Sean Farley <sean@farley.io>
parents:
981
diff
changeset
|
1120 CALLBACK_BUFFER = '' |
954
528015bde034
push: print messages from the server
Sean Farley <sean@farley.io>
parents:
952
diff
changeset
|
1121 if not remote_info: |
982
296349f421c8
push: better formatting of messages from the server
Sean Farley <sean@farley.io>
parents:
981
diff
changeset
|
1122 remote_info = '\n' |
296349f421c8
push: better formatting of messages from the server
Sean Farley <sean@farley.io>
parents:
981
diff
changeset
|
1123 |
296349f421c8
push: better formatting of messages from the server
Sean Farley <sean@farley.io>
parents:
981
diff
changeset
|
1124 for line in remote_info[:-1].split('\n'): |
954
528015bde034
push: print messages from the server
Sean Farley <sean@farley.io>
parents:
952
diff
changeset
|
1125 self.ui.status(_("remote: %s\n") % line) |
528015bde034
push: print messages from the server
Sean Farley <sean@farley.io>
parents:
952
diff
changeset
|
1126 |
26
a1a5391bc3c3
edit ssh command to quote the path, also convert tags properly on fetch
Scott Chacon <schacon@gmail.com>
parents:
25
diff
changeset
|
1127 try: |
954
528015bde034
push: print messages from the server
Sean Farley <sean@farley.io>
parents:
952
diff
changeset
|
1128 new_refs = client.send_pack(path, changed, genpack, |
528015bde034
push: print messages from the server
Sean Farley <sean@farley.io>
parents:
952
diff
changeset
|
1129 progress=callback) |
591
163c452531cf
push: add more output about what was added (issue #64)
David M. Carr <david@carrclan.us>
parents:
590
diff
changeset
|
1130 if len(change_totals) > 0: |
163c452531cf
push: add more output about what was added (issue #64)
David M. Carr <david@carrclan.us>
parents:
590
diff
changeset
|
1131 self.ui.status(_("added %d commits with %d trees" |
163c452531cf
push: add more output about what was added (issue #64)
David M. Carr <david@carrclan.us>
parents:
590
diff
changeset
|
1132 " and %d blobs\n") % |
163c452531cf
push: add more output about what was added (issue #64)
David M. Carr <david@carrclan.us>
parents:
590
diff
changeset
|
1133 (change_totals.get(Commit, 0), |
163c452531cf
push: add more output about what was added (issue #64)
David M. Carr <david@carrclan.us>
parents:
590
diff
changeset
|
1134 change_totals.get(Tree, 0), |
163c452531cf
push: add more output about what was added (issue #64)
David M. Carr <david@carrclan.us>
parents:
590
diff
changeset
|
1135 change_totals.get(Blob, 0))) |
487
68e5dddc7a20
push: return 1 if no changes found, 0 if success
David M. Carr <david@carrclan.us>
parents:
475
diff
changeset
|
1136 return old_refs, new_refs |
394
721165a45385
Catch GitProtocolError wherever HangupException can occur.
Brendan Cully <brendan@kublai.com>
parents:
392
diff
changeset
|
1137 except (HangupException, GitProtocolError), e: |
1128
6141895a53c9
compat: switch from hgutil.Abort to error.Abort
Kevin Bullock <kbullock@ringworld.org>
parents:
1127
diff
changeset
|
1138 raise error.Abort(_("git remote error: ") + str(e)) |
50
d274092e3b24
Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents:
42
diff
changeset
|
1139 |
813
345919960ea4
git_handler.get_changed_refs: switch to using get_exportable
Siddharth Agarwal <sid0@fb.com>
parents:
812
diff
changeset
|
1140 def get_changed_refs(self, refs, exportable, force): |
230
51e4d6ebbc40
rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
229
diff
changeset
|
1141 new_refs = refs.copy() |
242
0ac974306e08
push the tip to master if remote repository is empty (closes issue 11 bb)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
239
diff
changeset
|
1142 |
884
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1143 # The remote repo is empty and the local one doesn't have |
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1144 # bookmarks/tags |
863
9e0954d9abb3
git_handler: slight style cleanup for previous patch
Augie Fackler <raf@durin42.com>
parents:
862
diff
changeset
|
1145 # |
9e0954d9abb3
git_handler: slight style cleanup for previous patch
Augie Fackler <raf@durin42.com>
parents:
862
diff
changeset
|
1146 # (older dulwich versions return the proto-level |
9e0954d9abb3
git_handler: slight style cleanup for previous patch
Augie Fackler <raf@durin42.com>
parents:
862
diff
changeset
|
1147 # capabilities^{} key when the dict should have been |
9e0954d9abb3
git_handler: slight style cleanup for previous patch
Augie Fackler <raf@durin42.com>
parents:
862
diff
changeset
|
1148 # empty. That check can probably be removed at some point in |
9e0954d9abb3
git_handler: slight style cleanup for previous patch
Augie Fackler <raf@durin42.com>
parents:
862
diff
changeset
|
1149 # the future.) |
9e0954d9abb3
git_handler: slight style cleanup for previous patch
Augie Fackler <raf@durin42.com>
parents:
862
diff
changeset
|
1150 if not refs or refs.keys()[0] == 'capabilities^{}': |
814
6cdeafb8ca46
git_handler.get_chanaged_refs: use exportable for no-ref check
Siddharth Agarwal <sid0@fb.com>
parents:
813
diff
changeset
|
1151 if not exportable: |
555
06a29fdd52a7
push: fix traceback when pushing empty hg repo to empty git repo (issue #58)
David M. Carr <david@carrclan.us>
parents:
553
diff
changeset
|
1152 tip = self.repo.lookup('tip') |
06a29fdd52a7
push: fix traceback when pushing empty hg repo to empty git repo (issue #58)
David M. Carr <david@carrclan.us>
parents:
553
diff
changeset
|
1153 if tip != nullid: |
862
9036716a1271
Allow for dulwich to not return the magic "capabilities^{}" ref.
Jelmer Vernooij <jelmer@samba.org>
parents:
861
diff
changeset
|
1154 if 'capabilities^{}' in new_refs: |
9036716a1271
Allow for dulwich to not return the magic "capabilities^{}" ref.
Jelmer Vernooij <jelmer@samba.org>
parents:
861
diff
changeset
|
1155 del new_refs['capabilities^{}'] |
555
06a29fdd52a7
push: fix traceback when pushing empty hg repo to empty git repo (issue #58)
David M. Carr <david@carrclan.us>
parents:
553
diff
changeset
|
1156 tip = hex(tip) |
1135
c4703246f350
compat: mark all compat-checking locations outside hggit.compat with "COMPAT:"
Kevin Bullock <kbullock@ringworld.org>
parents:
1128
diff
changeset
|
1157 # COMPAT: hg 1.8 - bookmarks extension moved to core |
555
06a29fdd52a7
push: fix traceback when pushing empty hg repo to empty git repo (issue #58)
David M. Carr <david@carrclan.us>
parents:
553
diff
changeset
|
1158 try: |
884
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1159 commands.bookmark(self.ui, self.repo, 'master', |
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1160 rev=tip, force=True) |
555
06a29fdd52a7
push: fix traceback when pushing empty hg repo to empty git repo (issue #58)
David M. Carr <david@carrclan.us>
parents:
553
diff
changeset
|
1161 except NameError: |
884
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1162 bookmarks.bookmark(self.ui, self.repo, 'master', |
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1163 rev=tip, force=True) |
1135
c4703246f350
compat: mark all compat-checking locations outside hggit.compat with "COMPAT:"
Kevin Bullock <kbullock@ringworld.org>
parents:
1128
diff
changeset
|
1164 # COMPAT: hg 3.5 - bookmarks.setcurrent renamed to activate |
905
286555803dae
git_handler: update for bookmark changes in mercurial 3.5
Sean Farley <sean@farley.io>
parents:
885
diff
changeset
|
1165 try: |
286555803dae
git_handler: update for bookmark changes in mercurial 3.5
Sean Farley <sean@farley.io>
parents:
885
diff
changeset
|
1166 bookmarks.activate(self.repo, 'master') |
286555803dae
git_handler: update for bookmark changes in mercurial 3.5
Sean Farley <sean@farley.io>
parents:
885
diff
changeset
|
1167 except AttributeError: |
286555803dae
git_handler: update for bookmark changes in mercurial 3.5
Sean Farley <sean@farley.io>
parents:
885
diff
changeset
|
1168 bookmarks.setcurrent(self.repo, 'master') |
555
06a29fdd52a7
push: fix traceback when pushing empty hg repo to empty git repo (issue #58)
David M. Carr <david@carrclan.us>
parents:
553
diff
changeset
|
1169 new_refs['refs/heads/master'] = self.map_git_get(tip) |
242
0ac974306e08
push the tip to master if remote repository is empty (closes issue 11 bb)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
239
diff
changeset
|
1170 |
931
f33faedc1add
push: use unfiltered repo for looking previously mapped nodes
Sean Farley <sean@farley.io>
parents:
930
diff
changeset
|
1171 # mapped nodes might be hidden |
f33faedc1add
push: use unfiltered repo for looking previously mapped nodes
Sean Farley <sean@farley.io>
parents:
930
diff
changeset
|
1172 unfiltered = self.repo.unfiltered() |
813
345919960ea4
git_handler.get_changed_refs: switch to using get_exportable
Siddharth Agarwal <sid0@fb.com>
parents:
812
diff
changeset
|
1173 for rev, rev_refs in exportable.iteritems(): |
230
51e4d6ebbc40
rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
229
diff
changeset
|
1174 ctx = self.repo[rev] |
813
345919960ea4
git_handler.get_changed_refs: switch to using get_exportable
Siddharth Agarwal <sid0@fb.com>
parents:
812
diff
changeset
|
1175 if not rev_refs: |
1128
6141895a53c9
compat: switch from hgutil.Abort to error.Abort
Kevin Bullock <kbullock@ringworld.org>
parents:
1127
diff
changeset
|
1176 raise error.Abort("revision %s cannot be pushed since" |
6141895a53c9
compat: switch from hgutil.Abort to error.Abort
Kevin Bullock <kbullock@ringworld.org>
parents:
1127
diff
changeset
|
1177 " it doesn't have a bookmark" % ctx) |
149 | 1178 |
310
53b0d608dcd5
when pushing, check if server is advertising annotated tags
Tay Ray Chuan <rctay89@gmail.com>
parents:
302
diff
changeset
|
1179 # Check if the tags the server is advertising are annotated tags, |
884
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1180 # by attempting to retrieve it from the our git repo, and building |
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1181 # a list of these tags. |
310
53b0d608dcd5
when pushing, check if server is advertising annotated tags
Tay Ray Chuan <rctay89@gmail.com>
parents:
302
diff
changeset
|
1182 # |
53b0d608dcd5
when pushing, check if server is advertising annotated tags
Tay Ray Chuan <rctay89@gmail.com>
parents:
302
diff
changeset
|
1183 # This is possible, even though (currently) annotated tags are |
53b0d608dcd5
when pushing, check if server is advertising annotated tags
Tay Ray Chuan <rctay89@gmail.com>
parents:
302
diff
changeset
|
1184 # dereferenced and stored as lightweight ones, as the annotated tag |
53b0d608dcd5
when pushing, check if server is advertising annotated tags
Tay Ray Chuan <rctay89@gmail.com>
parents:
302
diff
changeset
|
1185 # is still stored in the git repo. |
53b0d608dcd5
when pushing, check if server is advertising annotated tags
Tay Ray Chuan <rctay89@gmail.com>
parents:
302
diff
changeset
|
1186 uptodate_annotated_tags = [] |
813
345919960ea4
git_handler.get_changed_refs: switch to using get_exportable
Siddharth Agarwal <sid0@fb.com>
parents:
812
diff
changeset
|
1187 for ref in rev_refs.tags: |
310
53b0d608dcd5
when pushing, check if server is advertising annotated tags
Tay Ray Chuan <rctay89@gmail.com>
parents:
302
diff
changeset
|
1188 # Check tag. |
884
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1189 if ref not in refs: |
310
53b0d608dcd5
when pushing, check if server is advertising annotated tags
Tay Ray Chuan <rctay89@gmail.com>
parents:
302
diff
changeset
|
1190 continue |
53b0d608dcd5
when pushing, check if server is advertising annotated tags
Tay Ray Chuan <rctay89@gmail.com>
parents:
302
diff
changeset
|
1191 try: |
53b0d608dcd5
when pushing, check if server is advertising annotated tags
Tay Ray Chuan <rctay89@gmail.com>
parents:
302
diff
changeset
|
1192 # We're not using Repo.tag(), as it's deprecated. |
53b0d608dcd5
when pushing, check if server is advertising annotated tags
Tay Ray Chuan <rctay89@gmail.com>
parents:
302
diff
changeset
|
1193 tag = self.git.get_object(refs[ref]) |
53b0d608dcd5
when pushing, check if server is advertising annotated tags
Tay Ray Chuan <rctay89@gmail.com>
parents:
302
diff
changeset
|
1194 if not isinstance(tag, Tag): |
53b0d608dcd5
when pushing, check if server is advertising annotated tags
Tay Ray Chuan <rctay89@gmail.com>
parents:
302
diff
changeset
|
1195 continue |
53b0d608dcd5
when pushing, check if server is advertising annotated tags
Tay Ray Chuan <rctay89@gmail.com>
parents:
302
diff
changeset
|
1196 except KeyError: |
53b0d608dcd5
when pushing, check if server is advertising annotated tags
Tay Ray Chuan <rctay89@gmail.com>
parents:
302
diff
changeset
|
1197 continue |
53b0d608dcd5
when pushing, check if server is advertising annotated tags
Tay Ray Chuan <rctay89@gmail.com>
parents:
302
diff
changeset
|
1198 |
53b0d608dcd5
when pushing, check if server is advertising annotated tags
Tay Ray Chuan <rctay89@gmail.com>
parents:
302
diff
changeset
|
1199 # If we've reached here, the tag's good. |
53b0d608dcd5
when pushing, check if server is advertising annotated tags
Tay Ray Chuan <rctay89@gmail.com>
parents:
302
diff
changeset
|
1200 uptodate_annotated_tags.append(ref) |
53b0d608dcd5
when pushing, check if server is advertising annotated tags
Tay Ray Chuan <rctay89@gmail.com>
parents:
302
diff
changeset
|
1201 |
813
345919960ea4
git_handler.get_changed_refs: switch to using get_exportable
Siddharth Agarwal <sid0@fb.com>
parents:
812
diff
changeset
|
1202 for ref in rev_refs: |
230
51e4d6ebbc40
rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
229
diff
changeset
|
1203 if ref not in refs: |
51e4d6ebbc40
rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
229
diff
changeset
|
1204 new_refs[ref] = self.map_git_get(ctx.hex()) |
51e4d6ebbc40
rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
229
diff
changeset
|
1205 elif new_refs[ref] in self._map_git: |
931
f33faedc1add
push: use unfiltered repo for looking previously mapped nodes
Sean Farley <sean@farley.io>
parents:
930
diff
changeset
|
1206 rctx = unfiltered[self.map_hg_get(new_refs[ref])] |
230
51e4d6ebbc40
rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
229
diff
changeset
|
1207 if rctx.ancestor(ctx) == rctx or force: |
51e4d6ebbc40
rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
229
diff
changeset
|
1208 new_refs[ref] = self.map_git_get(ctx.hex()) |
51e4d6ebbc40
rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
229
diff
changeset
|
1209 else: |
1128
6141895a53c9
compat: switch from hgutil.Abort to error.Abort
Kevin Bullock <kbullock@ringworld.org>
parents:
1127
diff
changeset
|
1210 raise error.Abort("pushing %s overwrites %s" |
6141895a53c9
compat: switch from hgutil.Abort to error.Abort
Kevin Bullock <kbullock@ringworld.org>
parents:
1127
diff
changeset
|
1211 % (ref, ctx)) |
310
53b0d608dcd5
when pushing, check if server is advertising annotated tags
Tay Ray Chuan <rctay89@gmail.com>
parents:
302
diff
changeset
|
1212 elif ref in uptodate_annotated_tags: |
53b0d608dcd5
when pushing, check if server is advertising annotated tags
Tay Ray Chuan <rctay89@gmail.com>
parents:
302
diff
changeset
|
1213 # we already have the annotated tag. |
53b0d608dcd5
when pushing, check if server is advertising annotated tags
Tay Ray Chuan <rctay89@gmail.com>
parents:
302
diff
changeset
|
1214 pass |
230
51e4d6ebbc40
rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
229
diff
changeset
|
1215 else: |
1128
6141895a53c9
compat: switch from hgutil.Abort to error.Abort
Kevin Bullock <kbullock@ringworld.org>
parents:
1127
diff
changeset
|
1216 raise error.Abort( |
629
3ff09f0fac7a
git_handler.py: less cryptic error message when push fails
anatoly techtonik <techtonik@gmail.com>
parents:
621
diff
changeset
|
1217 "branch '%s' changed on the server, " |
3ff09f0fac7a
git_handler.py: less cryptic error message when push fails
anatoly techtonik <techtonik@gmail.com>
parents:
621
diff
changeset
|
1218 "please pull and merge before pushing" % ref) |
126 | 1219 |
230
51e4d6ebbc40
rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
229
diff
changeset
|
1220 return new_refs |
51e4d6ebbc40
rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
229
diff
changeset
|
1221 |
557
4f4ab2d89375
gitrepo: initial support for listkeys
David M. Carr <david@carrclan.us>
parents:
555
diff
changeset
|
1222 def fetch_pack(self, remote_name, heads=None): |
933
7b89630a2a48
git_handler: rename local variable to not shadow import name
Sean Farley <sean@farley.io>
parents:
932
diff
changeset
|
1223 localclient, path = self.get_transport_and_path(remote_name) |
915
efcefc3522bd
pull: consider remotes during discovery
Durham Goode <durham@fb.com>
parents:
906
diff
changeset
|
1224 |
efcefc3522bd
pull: consider remotes during discovery
Durham Goode <durham@fb.com>
parents:
906
diff
changeset
|
1225 # The dulwich default walk only checks refs/heads/. We also want to |
1116 | 1226 # consider remotes when doing discovery, so we build our own list. We |
915
efcefc3522bd
pull: consider remotes during discovery
Durham Goode <durham@fb.com>
parents:
906
diff
changeset
|
1227 # can't just do 'refs/' here because the tag class doesn't have a |
1116 | 1228 # parents function for walking, and older versions of dulwich don't |
1229 # like that. | |
915
efcefc3522bd
pull: consider remotes during discovery
Durham Goode <durham@fb.com>
parents:
906
diff
changeset
|
1230 haveheads = self.git.refs.as_dict('refs/remotes/').values() |
efcefc3522bd
pull: consider remotes during discovery
Durham Goode <durham@fb.com>
parents:
906
diff
changeset
|
1231 haveheads.extend(self.git.refs.as_dict('refs/heads/').values()) |
efcefc3522bd
pull: consider remotes during discovery
Durham Goode <durham@fb.com>
parents:
906
diff
changeset
|
1232 graphwalker = self.git.get_graph_walker(heads=haveheads) |
697
a58ae693ab72
determine_wants: factor ref filtering code out into a separate function
Siddharth Agarwal <sid0@fb.com>
parents:
696
diff
changeset
|
1233 |
232
0ba1aee0467c
initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
231
diff
changeset
|
1234 def determine_wants(refs): |
948
988d84cc5565
determine_wants: deal with refs being None
Siddharth Agarwal <sid0@fb.com>
parents:
934
diff
changeset
|
1235 if refs is None: |
988d84cc5565
determine_wants: deal with refs being None
Siddharth Agarwal <sid0@fb.com>
parents:
934
diff
changeset
|
1236 return None |
697
a58ae693ab72
determine_wants: factor ref filtering code out into a separate function
Siddharth Agarwal <sid0@fb.com>
parents:
696
diff
changeset
|
1237 filteredrefs = self.filter_refs(refs, heads) |
a58ae693ab72
determine_wants: factor ref filtering code out into a separate function
Siddharth Agarwal <sid0@fb.com>
parents:
696
diff
changeset
|
1238 return [x for x in filteredrefs.itervalues() if x not in self.git] |
609
ec6d4146d5ca
git_handler: clean up trailing whitespace
Augie Fackler <raf@durin42.com>
parents:
608
diff
changeset
|
1239 |
5
d6c443a91b18
refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
1240 try: |
608
47df57f2bb2b
fix/work around https://bugs.launchpad.net/dulwich/+bug/1025886
domruf <dominikruf@gmail.com>
parents:
590
diff
changeset
|
1241 progress = GitProgress(self.ui) |
610
30d502905da9
git_handler: fix bugs introduced by 47df57f2bb2b which could never have passed tests
Augie Fackler <raf@durin42.com>
parents:
609
diff
changeset
|
1242 f = StringIO.StringIO() |
1006
9b7088850ca8
git_handler: use our read_pkt_refs for fetch_pack
Sean Farley <sean@farley.io>
parents:
1000
diff
changeset
|
1243 |
1094
5e49230a6cd5
fetch_pack: refactor to use compat.FetchPackResult
Sean Farley <sean@farley.io>
parents:
1088
diff
changeset
|
1244 # only newer versions (0.18) of dulwich have symref support |
1006
9b7088850ca8
git_handler: use our read_pkt_refs for fetch_pack
Sean Farley <sean@farley.io>
parents:
1000
diff
changeset
|
1245 client.read_pkt_refs = compat.read_pkt_refs |
933
7b89630a2a48
git_handler: rename local variable to not shadow import name
Sean Farley <sean@farley.io>
parents:
932
diff
changeset
|
1246 ret = localclient.fetch_pack(path, determine_wants, graphwalker, |
7b89630a2a48
git_handler: rename local variable to not shadow import name
Sean Farley <sean@farley.io>
parents:
932
diff
changeset
|
1247 f.write, progress.progress) |
608
47df57f2bb2b
fix/work around https://bugs.launchpad.net/dulwich/+bug/1025886
domruf <dominikruf@gmail.com>
parents:
590
diff
changeset
|
1248 if(f.pos != 0): |
47df57f2bb2b
fix/work around https://bugs.launchpad.net/dulwich/+bug/1025886
domruf <dominikruf@gmail.com>
parents:
590
diff
changeset
|
1249 f.seek(0) |
885
77252ce6e9af
git_handler: remove unused variables
Sean Farley <sean@farley.io>
parents:
884
diff
changeset
|
1250 self.git.object_store.add_thin_pack(f.read, None) |
608
47df57f2bb2b
fix/work around https://bugs.launchpad.net/dulwich/+bug/1025886
domruf <dominikruf@gmail.com>
parents:
590
diff
changeset
|
1251 progress.flush() |
616
1d326a57e2dd
git-handler: turn refs from None to {} so that empty git repos can convert
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
611
diff
changeset
|
1252 |
1d326a57e2dd
git-handler: turn refs from None to {} so that empty git repos can convert
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
611
diff
changeset
|
1253 # For empty repos dulwich gives us None, but since later |
1d326a57e2dd
git-handler: turn refs from None to {} so that empty git repos can convert
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
611
diff
changeset
|
1254 # we want to iterate over this, we really want an empty |
1d326a57e2dd
git-handler: turn refs from None to {} so that empty git repos can convert
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
611
diff
changeset
|
1255 # iterable |
1094
5e49230a6cd5
fetch_pack: refactor to use compat.FetchPackResult
Sean Farley <sean@farley.io>
parents:
1088
diff
changeset
|
1256 if ret is None: |
5e49230a6cd5
fetch_pack: refactor to use compat.FetchPackResult
Sean Farley <sean@farley.io>
parents:
1088
diff
changeset
|
1257 ret = {} |
5e49230a6cd5
fetch_pack: refactor to use compat.FetchPackResult
Sean Farley <sean@farley.io>
parents:
1088
diff
changeset
|
1258 |
5e49230a6cd5
fetch_pack: refactor to use compat.FetchPackResult
Sean Farley <sean@farley.io>
parents:
1088
diff
changeset
|
1259 # for older dulwich, the return type was a dict, meaning we're |
5e49230a6cd5
fetch_pack: refactor to use compat.FetchPackResult
Sean Farley <sean@farley.io>
parents:
1088
diff
changeset
|
1260 # running our monkey patch read_pkt_refs |
5e49230a6cd5
fetch_pack: refactor to use compat.FetchPackResult
Sean Farley <sean@farley.io>
parents:
1088
diff
changeset
|
1261 if isinstance(ret, dict): |
5e49230a6cd5
fetch_pack: refactor to use compat.FetchPackResult
Sean Farley <sean@farley.io>
parents:
1088
diff
changeset
|
1262 head = ret.get("HEAD") |
5e49230a6cd5
fetch_pack: refactor to use compat.FetchPackResult
Sean Farley <sean@farley.io>
parents:
1088
diff
changeset
|
1263 symrefs = {} |
5e49230a6cd5
fetch_pack: refactor to use compat.FetchPackResult
Sean Farley <sean@farley.io>
parents:
1088
diff
changeset
|
1264 # we want to raise a KeyError if HEAD is not a key |
5e49230a6cd5
fetch_pack: refactor to use compat.FetchPackResult
Sean Farley <sean@farley.io>
parents:
1088
diff
changeset
|
1265 if head: |
5e49230a6cd5
fetch_pack: refactor to use compat.FetchPackResult
Sean Farley <sean@farley.io>
parents:
1088
diff
changeset
|
1266 symrefs["HEAD"] = head |
5e49230a6cd5
fetch_pack: refactor to use compat.FetchPackResult
Sean Farley <sean@farley.io>
parents:
1088
diff
changeset
|
1267 # use FetchPackResult as upstream now does |
1116 | 1268 agent = client.default_user_agent_string() |
1269 ret = compat.FetchPackResult(ret, symrefs, agent) | |
1094
5e49230a6cd5
fetch_pack: refactor to use compat.FetchPackResult
Sean Farley <sean@farley.io>
parents:
1088
diff
changeset
|
1270 return ret |
608
47df57f2bb2b
fix/work around https://bugs.launchpad.net/dulwich/+bug/1025886
domruf <dominikruf@gmail.com>
parents:
590
diff
changeset
|
1271 except (HangupException, GitProtocolError), e: |
1128
6141895a53c9
compat: switch from hgutil.Abort to error.Abort
Kevin Bullock <kbullock@ringworld.org>
parents:
1127
diff
changeset
|
1272 raise error.Abort(_("git remote error: ") + str(e)) |
5
d6c443a91b18
refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
1273 |
884
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1274 # REFERENCES HANDLING |
183
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
1275 |
697
a58ae693ab72
determine_wants: factor ref filtering code out into a separate function
Siddharth Agarwal <sid0@fb.com>
parents:
696
diff
changeset
|
1276 def filter_refs(self, refs, heads): |
715
268b9f6ed1c8
filter_refs: only return all refs when heads is None
Siddharth Agarwal <sid0@fb.com>
parents:
709
diff
changeset
|
1277 '''For a dictionary of refs: shas, if heads is None then return refs |
697
a58ae693ab72
determine_wants: factor ref filtering code out into a separate function
Siddharth Agarwal <sid0@fb.com>
parents:
696
diff
changeset
|
1278 that match the heads. Otherwise, return refs that are heads or tags. |
a58ae693ab72
determine_wants: factor ref filtering code out into a separate function
Siddharth Agarwal <sid0@fb.com>
parents:
696
diff
changeset
|
1279 |
a58ae693ab72
determine_wants: factor ref filtering code out into a separate function
Siddharth Agarwal <sid0@fb.com>
parents:
696
diff
changeset
|
1280 ''' |
818
2c5e41d670b5
git_handler: return filtered refs as an OrderedDict
Siddharth Agarwal <sid0@fb.com>
parents:
817
diff
changeset
|
1281 filteredrefs = [] |
715
268b9f6ed1c8
filter_refs: only return all refs when heads is None
Siddharth Agarwal <sid0@fb.com>
parents:
709
diff
changeset
|
1282 if heads is not None: |
697
a58ae693ab72
determine_wants: factor ref filtering code out into a separate function
Siddharth Agarwal <sid0@fb.com>
parents:
696
diff
changeset
|
1283 # contains pairs of ('refs/(heads|tags|...)/foo', 'foo') |
a58ae693ab72
determine_wants: factor ref filtering code out into a separate function
Siddharth Agarwal <sid0@fb.com>
parents:
696
diff
changeset
|
1284 # if ref is just '<foo>', then we get ('foo', 'foo') |
884
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1285 stripped_refs = [(r, r[r.find('/', r.find('/') + 1) + 1:]) for r in |
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1286 refs] |
697
a58ae693ab72
determine_wants: factor ref filtering code out into a separate function
Siddharth Agarwal <sid0@fb.com>
parents:
696
diff
changeset
|
1287 for h in heads: |
820
0d6d2fcc62b6
git_handler: support wildcards for Git branch name matching
Siddharth Agarwal <sid0@fb.com>
parents:
819
diff
changeset
|
1288 if h.endswith('/*'): |
0d6d2fcc62b6
git_handler: support wildcards for Git branch name matching
Siddharth Agarwal <sid0@fb.com>
parents:
819
diff
changeset
|
1289 prefix = h[:-1] # include the / but not the * |
0d6d2fcc62b6
git_handler: support wildcards for Git branch name matching
Siddharth Agarwal <sid0@fb.com>
parents:
819
diff
changeset
|
1290 r = [pair[0] for pair in stripped_refs |
0d6d2fcc62b6
git_handler: support wildcards for Git branch name matching
Siddharth Agarwal <sid0@fb.com>
parents:
819
diff
changeset
|
1291 if pair[1].startswith(prefix)] |
0d6d2fcc62b6
git_handler: support wildcards for Git branch name matching
Siddharth Agarwal <sid0@fb.com>
parents:
819
diff
changeset
|
1292 r.sort() |
0d6d2fcc62b6
git_handler: support wildcards for Git branch name matching
Siddharth Agarwal <sid0@fb.com>
parents:
819
diff
changeset
|
1293 filteredrefs.extend(r) |
697
a58ae693ab72
determine_wants: factor ref filtering code out into a separate function
Siddharth Agarwal <sid0@fb.com>
parents:
696
diff
changeset
|
1294 else: |
820
0d6d2fcc62b6
git_handler: support wildcards for Git branch name matching
Siddharth Agarwal <sid0@fb.com>
parents:
819
diff
changeset
|
1295 r = [pair[0] for pair in stripped_refs if pair[1] == h] |
0d6d2fcc62b6
git_handler: support wildcards for Git branch name matching
Siddharth Agarwal <sid0@fb.com>
parents:
819
diff
changeset
|
1296 if not r: |
1128
6141895a53c9
compat: switch from hgutil.Abort to error.Abort
Kevin Bullock <kbullock@ringworld.org>
parents:
1127
diff
changeset
|
1297 raise error.Abort("ref %s not found on remote server" |
6141895a53c9
compat: switch from hgutil.Abort to error.Abort
Kevin Bullock <kbullock@ringworld.org>
parents:
1127
diff
changeset
|
1298 % h) |
820
0d6d2fcc62b6
git_handler: support wildcards for Git branch name matching
Siddharth Agarwal <sid0@fb.com>
parents:
819
diff
changeset
|
1299 elif len(r) == 1: |
0d6d2fcc62b6
git_handler: support wildcards for Git branch name matching
Siddharth Agarwal <sid0@fb.com>
parents:
819
diff
changeset
|
1300 filteredrefs.append(r[0]) |
0d6d2fcc62b6
git_handler: support wildcards for Git branch name matching
Siddharth Agarwal <sid0@fb.com>
parents:
819
diff
changeset
|
1301 else: |
1128
6141895a53c9
compat: switch from hgutil.Abort to error.Abort
Kevin Bullock <kbullock@ringworld.org>
parents:
1127
diff
changeset
|
1302 raise error.Abort("ambiguous reference %s: %r" |
6141895a53c9
compat: switch from hgutil.Abort to error.Abort
Kevin Bullock <kbullock@ringworld.org>
parents:
1127
diff
changeset
|
1303 % (h, r)) |
697
a58ae693ab72
determine_wants: factor ref filtering code out into a separate function
Siddharth Agarwal <sid0@fb.com>
parents:
696
diff
changeset
|
1304 else: |
a58ae693ab72
determine_wants: factor ref filtering code out into a separate function
Siddharth Agarwal <sid0@fb.com>
parents:
696
diff
changeset
|
1305 for ref, sha in refs.iteritems(): |
884
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1306 if (not ref.endswith('^{}') and |
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1307 (ref.startswith('refs/heads/') or |
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1308 ref.startswith('refs/tags/'))): |
818
2c5e41d670b5
git_handler: return filtered refs as an OrderedDict
Siddharth Agarwal <sid0@fb.com>
parents:
817
diff
changeset
|
1309 filteredrefs.append(ref) |
819
826296785e8b
git_handler.filter_refs: sort returned refs if none are provided
Siddharth Agarwal <sid0@fb.com>
parents:
818
diff
changeset
|
1310 filteredrefs.sort() |
818
2c5e41d670b5
git_handler: return filtered refs as an OrderedDict
Siddharth Agarwal <sid0@fb.com>
parents:
817
diff
changeset
|
1311 |
884
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1312 # the choice of OrderedDict vs plain dict has no impact on stock |
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1313 # hg-git, but allows extensions to customize the order in which refs |
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1314 # are returned |
818
2c5e41d670b5
git_handler: return filtered refs as an OrderedDict
Siddharth Agarwal <sid0@fb.com>
parents:
817
diff
changeset
|
1315 return util.OrderedDict((r, refs[r]) for r in filteredrefs) |
697
a58ae693ab72
determine_wants: factor ref filtering code out into a separate function
Siddharth Agarwal <sid0@fb.com>
parents:
696
diff
changeset
|
1316 |
821
53e7e8f34dcd
git_handler: introduce a function and config to filter by minimum date
Siddharth Agarwal <sid0@fb.com>
parents:
820
diff
changeset
|
1317 def filter_min_date(self, refs): |
53e7e8f34dcd
git_handler: introduce a function and config to filter by minimum date
Siddharth Agarwal <sid0@fb.com>
parents:
820
diff
changeset
|
1318 '''filter refs by minimum date |
53e7e8f34dcd
git_handler: introduce a function and config to filter by minimum date
Siddharth Agarwal <sid0@fb.com>
parents:
820
diff
changeset
|
1319 |
53e7e8f34dcd
git_handler: introduce a function and config to filter by minimum date
Siddharth Agarwal <sid0@fb.com>
parents:
820
diff
changeset
|
1320 This only works for refs that are available locally.''' |
1069
88db6948a5a8
config: register git.mindate
Kevin Bullock <kbullock@ringworld.org>
parents:
1068
diff
changeset
|
1321 min_date = compat.config(self.ui, 'string', 'git', 'mindate') |
821
53e7e8f34dcd
git_handler: introduce a function and config to filter by minimum date
Siddharth Agarwal <sid0@fb.com>
parents:
820
diff
changeset
|
1322 if min_date is None: |
53e7e8f34dcd
git_handler: introduce a function and config to filter by minimum date
Siddharth Agarwal <sid0@fb.com>
parents:
820
diff
changeset
|
1323 return refs |
53e7e8f34dcd
git_handler: introduce a function and config to filter by minimum date
Siddharth Agarwal <sid0@fb.com>
parents:
820
diff
changeset
|
1324 |
53e7e8f34dcd
git_handler: introduce a function and config to filter by minimum date
Siddharth Agarwal <sid0@fb.com>
parents:
820
diff
changeset
|
1325 # filter refs older than min_timestamp |
1125
8f55daa87ce4
git-handler: fix deprecated API in next hg version
Paul Morelle <paul.morelle@octobus.net>
parents:
1124
diff
changeset
|
1326 min_timestamp, min_offset = dateutil.parsedate(min_date) |
884
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1327 |
826
7c1452551db1
git_handler.filter_min_date: support tag times for annotated tags
Siddharth Agarwal <sid0@fb.com>
parents:
823
diff
changeset
|
1328 def check_min_time(obj): |
7c1452551db1
git_handler.filter_min_date: support tag times for annotated tags
Siddharth Agarwal <sid0@fb.com>
parents:
823
diff
changeset
|
1329 if isinstance(obj, Tag): |
7c1452551db1
git_handler.filter_min_date: support tag times for annotated tags
Siddharth Agarwal <sid0@fb.com>
parents:
823
diff
changeset
|
1330 return obj.tag_time >= min_timestamp |
7c1452551db1
git_handler.filter_min_date: support tag times for annotated tags
Siddharth Agarwal <sid0@fb.com>
parents:
823
diff
changeset
|
1331 else: |
7c1452551db1
git_handler.filter_min_date: support tag times for annotated tags
Siddharth Agarwal <sid0@fb.com>
parents:
823
diff
changeset
|
1332 return obj.commit_time >= min_timestamp |
821
53e7e8f34dcd
git_handler: introduce a function and config to filter by minimum date
Siddharth Agarwal <sid0@fb.com>
parents:
820
diff
changeset
|
1333 return util.OrderedDict((ref, sha) for ref, sha in refs.iteritems() |
826
7c1452551db1
git_handler.filter_min_date: support tag times for annotated tags
Siddharth Agarwal <sid0@fb.com>
parents:
823
diff
changeset
|
1334 if check_min_time(self.git[sha])) |
821
53e7e8f34dcd
git_handler: introduce a function and config to filter by minimum date
Siddharth Agarwal <sid0@fb.com>
parents:
820
diff
changeset
|
1335 |
183
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
1336 def update_references(self): |
812
2e77e332f3b3
git_handler.update_references: switch to using get_exportable
Siddharth Agarwal <sid0@fb.com>
parents:
811
diff
changeset
|
1337 exportable = self.get_exportable() |
183
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
1338 |
195
e09d71dc4cb4
Drop importbranch/exportbranch options (exportbranch was really broken)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
194
diff
changeset
|
1339 # Create a local Git branch name for each |
e09d71dc4cb4
Drop importbranch/exportbranch options (exportbranch was really broken)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
194
diff
changeset
|
1340 # Mercurial bookmark. |
812
2e77e332f3b3
git_handler.update_references: switch to using get_exportable
Siddharth Agarwal <sid0@fb.com>
parents:
811
diff
changeset
|
1341 for hg_sha, refs in exportable.iteritems(): |
2e77e332f3b3
git_handler.update_references: switch to using get_exportable
Siddharth Agarwal <sid0@fb.com>
parents:
811
diff
changeset
|
1342 for git_ref in refs.heads: |
2e77e332f3b3
git_handler.update_references: switch to using get_exportable
Siddharth Agarwal <sid0@fb.com>
parents:
811
diff
changeset
|
1343 git_sha = self.map_git_get(hg_sha) |
2e77e332f3b3
git_handler.update_references: switch to using get_exportable
Siddharth Agarwal <sid0@fb.com>
parents:
811
diff
changeset
|
1344 if git_sha: |
2e77e332f3b3
git_handler.update_references: switch to using get_exportable
Siddharth Agarwal <sid0@fb.com>
parents:
811
diff
changeset
|
1345 self.git.refs[git_ref] = git_sha |
183
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
1346 |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
1347 def export_hg_tags(self): |
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
1348 for tag, sha in self.repo.tags().iteritems(): |
210
9a27c618d0ed
remove broken tagging code (see issue 3 bb)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
207
diff
changeset
|
1349 if self.repo.tagtype(tag) in ('global', 'git'): |
381
80544310834a
fix handling of spaces in hg tag names
Dmitry Gladkov <dmitry.gladkov@gmail.com>
parents:
376
diff
changeset
|
1350 tag = tag.replace(' ', '_') |
587
1ab57b19cb3a
git_handler: defend against unexported revisions in tag exporting
Augie Fackler <raf@durin42.com>
parents:
552
diff
changeset
|
1351 target = self.map_git_get(hex(sha)) |
1ab57b19cb3a
git_handler: defend against unexported revisions in tag exporting
Augie Fackler <raf@durin42.com>
parents:
552
diff
changeset
|
1352 if target is not None: |
601
65d8a43bc5ee
git_handler: skip exporting hg tags whose names are not valid as git tag name
nsuke <nsukeg@gmail.com>
parents:
596
diff
changeset
|
1353 tag_refname = 'refs/tags/' + tag |
65d8a43bc5ee
git_handler: skip exporting hg tags whose names are not valid as git tag name
nsuke <nsukeg@gmail.com>
parents:
596
diff
changeset
|
1354 if(check_ref_format(tag_refname)): |
884
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1355 self.git.refs[tag_refname] = target |
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1356 self.tags[tag] = hex(sha) |
601
65d8a43bc5ee
git_handler: skip exporting hg tags whose names are not valid as git tag name
nsuke <nsukeg@gmail.com>
parents:
596
diff
changeset
|
1357 else: |
884
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1358 self.repo.ui.warn('Skipping export of tag %s because ' |
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1359 'it has invalid name as a git ' |
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1360 'refname.\n' % tag) |
587
1ab57b19cb3a
git_handler: defend against unexported revisions in tag exporting
Augie Fackler <raf@durin42.com>
parents:
552
diff
changeset
|
1361 else: |
1ab57b19cb3a
git_handler: defend against unexported revisions in tag exporting
Augie Fackler <raf@durin42.com>
parents:
552
diff
changeset
|
1362 self.repo.ui.warn( |
1ab57b19cb3a
git_handler: defend against unexported revisions in tag exporting
Augie Fackler <raf@durin42.com>
parents:
552
diff
changeset
|
1363 'Skipping export of tag %s because it ' |
601
65d8a43bc5ee
git_handler: skip exporting hg tags whose names are not valid as git tag name
nsuke <nsukeg@gmail.com>
parents:
596
diff
changeset
|
1364 'has no matching git revision.\n' % tag) |
183
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
1365 |
441
35e2813f58a5
- add "branch_bookmark_names" parameter. this allows bookmarks
Mike Bayer <mike_mp@zzzcomputing.com>
parents:
439
diff
changeset
|
1366 def _filter_for_bookmarks(self, bms): |
35e2813f58a5
- add "branch_bookmark_names" parameter. this allows bookmarks
Mike Bayer <mike_mp@zzzcomputing.com>
parents:
439
diff
changeset
|
1367 if not self.branch_bookmark_suffix: |
35e2813f58a5
- add "branch_bookmark_names" parameter. this allows bookmarks
Mike Bayer <mike_mp@zzzcomputing.com>
parents:
439
diff
changeset
|
1368 return [(bm, bm) for bm in bms] |
35e2813f58a5
- add "branch_bookmark_names" parameter. this allows bookmarks
Mike Bayer <mike_mp@zzzcomputing.com>
parents:
439
diff
changeset
|
1369 else: |
35e2813f58a5
- add "branch_bookmark_names" parameter. this allows bookmarks
Mike Bayer <mike_mp@zzzcomputing.com>
parents:
439
diff
changeset
|
1370 def _filter_bm(bm): |
35e2813f58a5
- add "branch_bookmark_names" parameter. this allows bookmarks
Mike Bayer <mike_mp@zzzcomputing.com>
parents:
439
diff
changeset
|
1371 if bm.endswith(self.branch_bookmark_suffix): |
35e2813f58a5
- add "branch_bookmark_names" parameter. this allows bookmarks
Mike Bayer <mike_mp@zzzcomputing.com>
parents:
439
diff
changeset
|
1372 return bm[0:-(len(self.branch_bookmark_suffix))] |
35e2813f58a5
- add "branch_bookmark_names" parameter. this allows bookmarks
Mike Bayer <mike_mp@zzzcomputing.com>
parents:
439
diff
changeset
|
1373 else: |
35e2813f58a5
- add "branch_bookmark_names" parameter. this allows bookmarks
Mike Bayer <mike_mp@zzzcomputing.com>
parents:
439
diff
changeset
|
1374 return bm |
35e2813f58a5
- add "branch_bookmark_names" parameter. this allows bookmarks
Mike Bayer <mike_mp@zzzcomputing.com>
parents:
439
diff
changeset
|
1375 return [(_filter_bm(bm), bm) for bm in bms] |
35e2813f58a5
- add "branch_bookmark_names" parameter. this allows bookmarks
Mike Bayer <mike_mp@zzzcomputing.com>
parents:
439
diff
changeset
|
1376 |
811
256a232e689d
git_handler: add a way to get all heads that can be exported to Git
Siddharth Agarwal <sid0@fb.com>
parents:
810
diff
changeset
|
1377 def get_exportable(self): |
256a232e689d
git_handler: add a way to get all heads that can be exported to Git
Siddharth Agarwal <sid0@fb.com>
parents:
810
diff
changeset
|
1378 class heads_tags(object): |
256a232e689d
git_handler: add a way to get all heads that can be exported to Git
Siddharth Agarwal <sid0@fb.com>
parents:
810
diff
changeset
|
1379 def __init__(self): |
256a232e689d
git_handler: add a way to get all heads that can be exported to Git
Siddharth Agarwal <sid0@fb.com>
parents:
810
diff
changeset
|
1380 self.heads = set() |
256a232e689d
git_handler: add a way to get all heads that can be exported to Git
Siddharth Agarwal <sid0@fb.com>
parents:
810
diff
changeset
|
1381 self.tags = set() |
884
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1382 |
811
256a232e689d
git_handler: add a way to get all heads that can be exported to Git
Siddharth Agarwal <sid0@fb.com>
parents:
810
diff
changeset
|
1383 def __iter__(self): |
256a232e689d
git_handler: add a way to get all heads that can be exported to Git
Siddharth Agarwal <sid0@fb.com>
parents:
810
diff
changeset
|
1384 return itertools.chain(self.heads, self.tags) |
884
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1385 |
811
256a232e689d
git_handler: add a way to get all heads that can be exported to Git
Siddharth Agarwal <sid0@fb.com>
parents:
810
diff
changeset
|
1386 def __nonzero__(self): |
256a232e689d
git_handler: add a way to get all heads that can be exported to Git
Siddharth Agarwal <sid0@fb.com>
parents:
810
diff
changeset
|
1387 return bool(self.heads) or bool(self.tags) |
256a232e689d
git_handler: add a way to get all heads that can be exported to Git
Siddharth Agarwal <sid0@fb.com>
parents:
810
diff
changeset
|
1388 |
256a232e689d
git_handler: add a way to get all heads that can be exported to Git
Siddharth Agarwal <sid0@fb.com>
parents:
810
diff
changeset
|
1389 res = collections.defaultdict(heads_tags) |
256a232e689d
git_handler: add a way to get all heads that can be exported to Git
Siddharth Agarwal <sid0@fb.com>
parents:
810
diff
changeset
|
1390 |
256a232e689d
git_handler: add a way to get all heads that can be exported to Git
Siddharth Agarwal <sid0@fb.com>
parents:
810
diff
changeset
|
1391 bms = self.repo._bookmarks |
256a232e689d
git_handler: add a way to get all heads that can be exported to Git
Siddharth Agarwal <sid0@fb.com>
parents:
810
diff
changeset
|
1392 for filtered_bm, bm in self._filter_for_bookmarks(bms): |
256a232e689d
git_handler: add a way to get all heads that can be exported to Git
Siddharth Agarwal <sid0@fb.com>
parents:
810
diff
changeset
|
1393 res[hex(bms[bm])].heads.add('refs/heads/' + filtered_bm) |
256a232e689d
git_handler: add a way to get all heads that can be exported to Git
Siddharth Agarwal <sid0@fb.com>
parents:
810
diff
changeset
|
1394 for tag, sha in self.tags.iteritems(): |
256a232e689d
git_handler: add a way to get all heads that can be exported to Git
Siddharth Agarwal <sid0@fb.com>
parents:
810
diff
changeset
|
1395 res[sha].tags.add('refs/tags/' + tag) |
256a232e689d
git_handler: add a way to get all heads that can be exported to Git
Siddharth Agarwal <sid0@fb.com>
parents:
810
diff
changeset
|
1396 return res |
256a232e689d
git_handler: add a way to get all heads that can be exported to Git
Siddharth Agarwal <sid0@fb.com>
parents:
810
diff
changeset
|
1397 |
187
5f196f80ffb3
Store git tags in .hg/git-tags and let localtags be *local*
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
186
diff
changeset
|
1398 def import_tags(self, refs): |
149 | 1399 keys = refs.keys() |
1400 if not keys: | |
187
5f196f80ffb3
Store git tags in .hg/git-tags and let localtags be *local*
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
186
diff
changeset
|
1401 return |
687
7ca655e44d9a
git_handler: don't compute tags for each tag imported
Siddharth Agarwal <sid0@fb.com>
parents:
685
diff
changeset
|
1402 repotags = self.repo.tags() |
187
5f196f80ffb3
Store git tags in .hg/git-tags and let localtags be *local*
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
186
diff
changeset
|
1403 for k in keys[:]: |
149 | 1404 ref_name = k |
1405 parts = k.split('/') | |
194
a5c53e94d92b
Do not depend on the cache git repository for reference pushing
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
190
diff
changeset
|
1406 if parts[0] == 'refs' and parts[1] == 'tags': |
149 | 1407 ref_name = "/".join([v for v in parts[2:]]) |
232
0ba1aee0467c
initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
231
diff
changeset
|
1408 # refs contains all the refs in the server, not just |
0ba1aee0467c
initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
231
diff
changeset
|
1409 # the ones we are pulling |
0ba1aee0467c
initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
231
diff
changeset
|
1410 if refs[k] not in self.git.object_store: |
0ba1aee0467c
initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
231
diff
changeset
|
1411 continue |
149 | 1412 if ref_name[-3:] == '^{}': |
1413 ref_name = ref_name[:-3] | |
884
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1414 if ref_name not in repotags: |
149 | 1415 obj = self.git.get_object(refs[k]) |
1416 sha = None | |
884
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1417 if isinstance(obj, Commit): # lightweight |
149 | 1418 sha = self.map_hg_get(refs[k]) |
698
6dc550f2fa78
import_tags: don't import tags that don't have an hg commit equivalent
Siddharth Agarwal <sid0@fb.com>
parents:
697
diff
changeset
|
1419 if sha is not None: |
6dc550f2fa78
import_tags: don't import tags that don't have an hg commit equivalent
Siddharth Agarwal <sid0@fb.com>
parents:
697
diff
changeset
|
1420 self.tags[ref_name] = sha |
884
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1421 elif isinstance(obj, Tag): # annotated |
337
6cea997ee302
enforce stricter matching for pull -r
Tay Ray Chuan <rctay89@gmail.com>
parents:
258
diff
changeset
|
1422 (obj_type, obj_sha) = obj.object |
149 | 1423 obj = self.git.get_object(obj_sha) |
884
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1424 if isinstance(obj, Commit): |
149 | 1425 sha = self.map_hg_get(obj_sha) |
187
5f196f80ffb3
Store git tags in .hg/git-tags and let localtags be *local*
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
186
diff
changeset
|
1426 # TODO: better handling for annotated tags |
698
6dc550f2fa78
import_tags: don't import tags that don't have an hg commit equivalent
Siddharth Agarwal <sid0@fb.com>
parents:
697
diff
changeset
|
1427 if sha is not None: |
6dc550f2fa78
import_tags: don't import tags that don't have an hg commit equivalent
Siddharth Agarwal <sid0@fb.com>
parents:
697
diff
changeset
|
1428 self.tags[ref_name] = sha |
187
5f196f80ffb3
Store git tags in .hg/git-tags and let localtags be *local*
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
186
diff
changeset
|
1429 self.save_tags() |
181
8690377c3ce9
Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
179
diff
changeset
|
1430 |
184
7bf98d3085f4
Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
183
diff
changeset
|
1431 def update_hg_bookmarks(self, refs): |
29
2a5c0bf0fef5
Another way of fixing no-bookmark issue, along with updated test.
Augie Fackler <durin42@gmail.com>
parents:
28
diff
changeset
|
1432 try: |
932
07f03124e1b9
git_handler: remove pre-2.8 code for bookmarks
Sean Farley <sean@farley.io>
parents:
931
diff
changeset
|
1433 bms = self.repo._bookmarks |
441
35e2813f58a5
- add "branch_bookmark_names" parameter. this allows bookmarks
Mike Bayer <mike_mp@zzzcomputing.com>
parents:
439
diff
changeset
|
1434 |
884
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1435 heads = dict([(ref[11:], refs[ref]) for ref in refs |
184
7bf98d3085f4
Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
183
diff
changeset
|
1436 if ref.startswith('refs/heads/')]) |
156
a507384308b2
Allow bookmarking a specific branch
Sverre Rabbelier <sverre@rabbelier.nl>
parents:
155
diff
changeset
|
1437 |
599
e0089655caa6
Fixes #54 | option branch_bookmark_suffix doesn't move bookmarks along
André Felipe Dias <andref.dias@pronus.eng.br>
parents:
596
diff
changeset
|
1438 suffix = self.branch_bookmark_suffix or '' |
1024
078c3912afce
bookmarks: compatibility with new applychanges api
Ryan McElroy <rmcelroy@fb.com>
parents:
1023
diff
changeset
|
1439 changes = [] |
156
a507384308b2
Allow bookmarking a specific branch
Sverre Rabbelier <sverre@rabbelier.nl>
parents:
155
diff
changeset
|
1440 for head, sha in heads.iteritems(): |
232
0ba1aee0467c
initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
231
diff
changeset
|
1441 # refs contains all the refs in the server, not just |
0ba1aee0467c
initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
231
diff
changeset
|
1442 # the ones we are pulling |
700
e29e280776ff
update_hg_bookmarks: don't update bookmarks that don't have an hg commit
Siddharth Agarwal <sid0@fb.com>
parents:
699
diff
changeset
|
1443 hgsha = self.map_hg_get(sha) |
e29e280776ff
update_hg_bookmarks: don't update bookmarks that don't have an hg commit
Siddharth Agarwal <sid0@fb.com>
parents:
699
diff
changeset
|
1444 if hgsha is None: |
232
0ba1aee0467c
initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
231
diff
changeset
|
1445 continue |
700
e29e280776ff
update_hg_bookmarks: don't update bookmarks that don't have an hg commit
Siddharth Agarwal <sid0@fb.com>
parents:
699
diff
changeset
|
1446 hgsha = bin(hgsha) |
884
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1447 if head not in bms: |
184
7bf98d3085f4
Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
183
diff
changeset
|
1448 # new branch |
1024
078c3912afce
bookmarks: compatibility with new applychanges api
Ryan McElroy <rmcelroy@fb.com>
parents:
1023
diff
changeset
|
1449 changes.append((head + suffix, hgsha)) |
184
7bf98d3085f4
Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
183
diff
changeset
|
1450 else: |
7bf98d3085f4
Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
183
diff
changeset
|
1451 bm = self.repo[bms[head]] |
7bf98d3085f4
Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
183
diff
changeset
|
1452 if bm.ancestor(self.repo[hgsha]) == bm: |
7bf98d3085f4
Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
183
diff
changeset
|
1453 # fast forward |
1024
078c3912afce
bookmarks: compatibility with new applychanges api
Ryan McElroy <rmcelroy@fb.com>
parents:
1023
diff
changeset
|
1454 changes.append((head + suffix, hgsha)) |
441
35e2813f58a5
- add "branch_bookmark_names" parameter. this allows bookmarks
Mike Bayer <mike_mp@zzzcomputing.com>
parents:
439
diff
changeset
|
1455 |
156
a507384308b2
Allow bookmarking a specific branch
Sverre Rabbelier <sverre@rabbelier.nl>
parents:
155
diff
changeset
|
1456 if heads: |
1024
078c3912afce
bookmarks: compatibility with new applychanges api
Ryan McElroy <rmcelroy@fb.com>
parents:
1023
diff
changeset
|
1457 util.updatebookmarks(self.repo, changes) |
161
134915637cf7
Merge branch 'octo' with octo merge code
Scott Chacon <schacon@gmail.com>
diff
changeset
|
1458 |
29
2a5c0bf0fef5
Another way of fixing no-bookmark issue, along with updated test.
Augie Fackler <durin42@gmail.com>
parents:
28
diff
changeset
|
1459 except AttributeError: |
95
7de67fcb18b0
be better about internationalizing strings
Sverre Rabbelier <sverre@rabbelier.nl>
parents:
94
diff
changeset
|
1460 self.ui.warn(_('creating bookmarks failed, do you have' |
7de67fcb18b0
be better about internationalizing strings
Sverre Rabbelier <sverre@rabbelier.nl>
parents:
94
diff
changeset
|
1461 ' bookmarks enabled?\n')) |
65
5ed8316d3cfa
Start using reasonable ui.{status,debug,warn} calls instead of print.
Augie Fackler <durin42@gmail.com>
parents:
56
diff
changeset
|
1462 |
184
7bf98d3085f4
Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
183
diff
changeset
|
1463 def update_remote_branches(self, remote_name, refs): |
773
55887ce9fb98
git_handler.update_remote_branches: rename 'tags' to 'remote_refs'
Siddharth Agarwal <sid0@fb.com>
parents:
772
diff
changeset
|
1464 remote_refs = self.remote_refs |
367
699088d9dd9f
hgrepo: completely rework handing of remote refs marking
Augie Fackler <durin42@gmail.com>
parents:
361
diff
changeset
|
1465 # since we re-write all refs for this remote each time, prune |
773
55887ce9fb98
git_handler.update_remote_branches: rename 'tags' to 'remote_refs'
Siddharth Agarwal <sid0@fb.com>
parents:
772
diff
changeset
|
1466 # all entries matching this remote from our refs list now so |
367
699088d9dd9f
hgrepo: completely rework handing of remote refs marking
Augie Fackler <durin42@gmail.com>
parents:
361
diff
changeset
|
1467 # that we avoid any stale refs hanging around forever |
773
55887ce9fb98
git_handler.update_remote_branches: rename 'tags' to 'remote_refs'
Siddharth Agarwal <sid0@fb.com>
parents:
772
diff
changeset
|
1468 for t in list(remote_refs): |
367
699088d9dd9f
hgrepo: completely rework handing of remote refs marking
Augie Fackler <durin42@gmail.com>
parents:
361
diff
changeset
|
1469 if t.startswith(remote_name + '/'): |
773
55887ce9fb98
git_handler.update_remote_branches: rename 'tags' to 'remote_refs'
Siddharth Agarwal <sid0@fb.com>
parents:
772
diff
changeset
|
1470 del remote_refs[t] |
305
ad2ea8d6ef94
update_remote_branches: refactor head usage
Tay Ray Chuan <rctay89@gmail.com>
parents:
304
diff
changeset
|
1471 for ref_name, sha in refs.iteritems(): |
224
80d67ae190df
port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
222
diff
changeset
|
1472 if ref_name.startswith('refs/heads'): |
699
a72816ade410
update_remote_branches: don't store refs that don't have an hg equivalent
Siddharth Agarwal <sid0@fb.com>
parents:
698
diff
changeset
|
1473 hgsha = self.map_hg_get(sha) |
a72816ade410
update_remote_branches: don't store refs that don't have an hg equivalent
Siddharth Agarwal <sid0@fb.com>
parents:
698
diff
changeset
|
1474 if hgsha is None or hgsha not in self.repo: |
367
699088d9dd9f
hgrepo: completely rework handing of remote refs marking
Augie Fackler <durin42@gmail.com>
parents:
361
diff
changeset
|
1475 continue |
305
ad2ea8d6ef94
update_remote_branches: refactor head usage
Tay Ray Chuan <rctay89@gmail.com>
parents:
304
diff
changeset
|
1476 head = ref_name[11:] |
773
55887ce9fb98
git_handler.update_remote_branches: rename 'tags' to 'remote_refs'
Siddharth Agarwal <sid0@fb.com>
parents:
772
diff
changeset
|
1477 remote_refs['/'.join((remote_name, head))] = bin(hgsha) |
367
699088d9dd9f
hgrepo: completely rework handing of remote refs marking
Augie Fackler <durin42@gmail.com>
parents:
361
diff
changeset
|
1478 # TODO(durin42): what is this doing? |
305
ad2ea8d6ef94
update_remote_branches: refactor head usage
Tay Ray Chuan <rctay89@gmail.com>
parents:
304
diff
changeset
|
1479 new_ref = 'refs/remotes/%s/%s' % (remote_name, head) |
ad2ea8d6ef94
update_remote_branches: refactor head usage
Tay Ray Chuan <rctay89@gmail.com>
parents:
304
diff
changeset
|
1480 self.git.refs[new_ref] = sha |
884
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1481 elif (ref_name.startswith('refs/tags') and not |
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1482 ref_name.endswith('^{}')): |
305
ad2ea8d6ef94
update_remote_branches: refactor head usage
Tay Ray Chuan <rctay89@gmail.com>
parents:
304
diff
changeset
|
1483 self.git.refs[ref_name] = sha |
196
40edc4b814e4
Reorganize push for more symmetry with fetch
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
195
diff
changeset
|
1484 |
884
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1485 # UTILITY FUNCTIONS |
183
469e80d3142a
Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
1486 |
53
5deb5cbd86aa
respecting file modes on git import
Scott Chacon <schacon@gmail.com>
parents:
52
diff
changeset
|
1487 def convert_git_int_mode(self, mode): |
213
61471faeb7fd
small cleanups (tabs, s/TODO :/TODO:/ and dead code)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
212
diff
changeset
|
1488 # TODO: make these into constants |
53
5deb5cbd86aa
respecting file modes on git import
Scott Chacon <schacon@gmail.com>
parents:
52
diff
changeset
|
1489 convert = { |
884
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1490 0100644: '', |
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1491 0100755: 'x', |
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1492 0120000: 'l' |
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1493 } |
53
5deb5cbd86aa
respecting file modes on git import
Scott Chacon <schacon@gmail.com>
parents:
52
diff
changeset
|
1494 if mode in convert: |
5deb5cbd86aa
respecting file modes on git import
Scott Chacon <schacon@gmail.com>
parents:
52
diff
changeset
|
1495 return convert[mode] |
5deb5cbd86aa
respecting file modes on git import
Scott Chacon <schacon@gmail.com>
parents:
52
diff
changeset
|
1496 return '' |
65
5ed8316d3cfa
Start using reasonable ui.{status,debug,warn} calls instead of print.
Augie Fackler <durin42@gmail.com>
parents:
56
diff
changeset
|
1497 |
224
80d67ae190df
port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
222
diff
changeset
|
1498 def get_file(self, commit, f): |
80d67ae190df
port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
222
diff
changeset
|
1499 otree = self.git.tree(commit.tree) |
80d67ae190df
port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
222
diff
changeset
|
1500 parts = f.split('/') |
80d67ae190df
port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
222
diff
changeset
|
1501 for part in parts: |
80d67ae190df
port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
222
diff
changeset
|
1502 (mode, sha) = otree[part] |
80d67ae190df
port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
222
diff
changeset
|
1503 obj = self.git.get_object(sha) |
884
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1504 if isinstance(obj, Blob): |
224
80d67ae190df
port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
222
diff
changeset
|
1505 return (mode, sha, obj._text) |
80d67ae190df
port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
222
diff
changeset
|
1506 elif isinstance(obj, Tree): |
80d67ae190df
port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
222
diff
changeset
|
1507 otree = obj |
80d67ae190df
port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
222
diff
changeset
|
1508 |
837
6866ae460ee7
git_handler.import_git_commit: figure out when to detect renames
Siddharth Agarwal <sid0@fb.com>
parents:
836
diff
changeset
|
1509 def get_files_changed(self, commit, detect_renames): |
275
c2d6b1093e7e
fix a bug when a directory is replaced with a file
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
261
diff
changeset
|
1510 tree = commit.tree |
c2d6b1093e7e
fix a bug when a directory is replaced with a file
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
261
diff
changeset
|
1511 btree = None |
c2d6b1093e7e
fix a bug when a directory is replaced with a file
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
261
diff
changeset
|
1512 |
c2d6b1093e7e
fix a bug when a directory is replaced with a file
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
261
diff
changeset
|
1513 if commit.parents: |
c2d6b1093e7e
fix a bug when a directory is replaced with a file
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
261
diff
changeset
|
1514 btree = self.git[commit.parents[0]].tree |
224
80d67ae190df
port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
222
diff
changeset
|
1515 |
275
c2d6b1093e7e
fix a bug when a directory is replaced with a file
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
261
diff
changeset
|
1516 files = {} |
639
42ca3ace9a0f
git_handler: return gitlinks in get_files_changed
Siddharth Agarwal <sid0@fb.com>
parents:
635
diff
changeset
|
1517 gitlinks = {} |
840
edcdb7620f4d
git_handler.get_files_changed: return detected renames
Siddharth Agarwal <sid0@fb.com>
parents:
839
diff
changeset
|
1518 renames = None |
843
da804eac2b00
git_handler.get_files_changed: detect renames when asked to do so
Siddharth Agarwal <sid0@fb.com>
parents:
840
diff
changeset
|
1519 rename_detector = None |
840
edcdb7620f4d
git_handler.get_files_changed: return detected renames
Siddharth Agarwal <sid0@fb.com>
parents:
839
diff
changeset
|
1520 if detect_renames: |
edcdb7620f4d
git_handler.get_files_changed: return detected renames
Siddharth Agarwal <sid0@fb.com>
parents:
839
diff
changeset
|
1521 renames = {} |
843
da804eac2b00
git_handler.get_files_changed: detect renames when asked to do so
Siddharth Agarwal <sid0@fb.com>
parents:
840
diff
changeset
|
1522 rename_detector = self._rename_detector |
da804eac2b00
git_handler.get_files_changed: detect renames when asked to do so
Siddharth Agarwal <sid0@fb.com>
parents:
840
diff
changeset
|
1523 |
884
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1524 # this set is unused if rename detection isn't enabled -- that makes |
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1525 # the code below simpler |
864
4d246150d850
git_handler: handle case where file is renamed and replaced by a symlink
Siddharth Agarwal <sid0@fb.com>
parents:
863
diff
changeset
|
1526 renamed_out = set() |
4d246150d850
git_handler: handle case where file is renamed and replaced by a symlink
Siddharth Agarwal <sid0@fb.com>
parents:
863
diff
changeset
|
1527 |
843
da804eac2b00
git_handler.get_files_changed: detect renames when asked to do so
Siddharth Agarwal <sid0@fb.com>
parents:
840
diff
changeset
|
1528 changes = diff_tree.tree_changes(self.git.object_store, btree, tree, |
da804eac2b00
git_handler.get_files_changed: detect renames when asked to do so
Siddharth Agarwal <sid0@fb.com>
parents:
840
diff
changeset
|
1529 rename_detector=rename_detector) |
840
edcdb7620f4d
git_handler.get_files_changed: return detected renames
Siddharth Agarwal <sid0@fb.com>
parents:
839
diff
changeset
|
1530 |
838
f6f84d51a154
git_handler.get_files_changed: switch to diff_tree's tree_changes
Siddharth Agarwal <sid0@fb.com>
parents:
837
diff
changeset
|
1531 for change in changes: |
f6f84d51a154
git_handler.get_files_changed: switch to diff_tree's tree_changes
Siddharth Agarwal <sid0@fb.com>
parents:
837
diff
changeset
|
1532 oldfile, oldmode, oldsha = change.old |
f6f84d51a154
git_handler.get_files_changed: switch to diff_tree's tree_changes
Siddharth Agarwal <sid0@fb.com>
parents:
837
diff
changeset
|
1533 newfile, newmode, newsha = change.new |
884
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1534 # actions are described by the following table ('no' means 'does |
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1535 # not exist'): |
639
42ca3ace9a0f
git_handler: return gitlinks in get_files_changed
Siddharth Agarwal <sid0@fb.com>
parents:
635
diff
changeset
|
1536 # old new | action |
42ca3ace9a0f
git_handler: return gitlinks in get_files_changed
Siddharth Agarwal <sid0@fb.com>
parents:
635
diff
changeset
|
1537 # no file | record file |
42ca3ace9a0f
git_handler: return gitlinks in get_files_changed
Siddharth Agarwal <sid0@fb.com>
parents:
635
diff
changeset
|
1538 # no gitlink | record gitlink |
42ca3ace9a0f
git_handler: return gitlinks in get_files_changed
Siddharth Agarwal <sid0@fb.com>
parents:
635
diff
changeset
|
1539 # file no | delete file |
42ca3ace9a0f
git_handler: return gitlinks in get_files_changed
Siddharth Agarwal <sid0@fb.com>
parents:
635
diff
changeset
|
1540 # file file | record file |
42ca3ace9a0f
git_handler: return gitlinks in get_files_changed
Siddharth Agarwal <sid0@fb.com>
parents:
635
diff
changeset
|
1541 # file gitlink | delete file and record gitlink |
42ca3ace9a0f
git_handler: return gitlinks in get_files_changed
Siddharth Agarwal <sid0@fb.com>
parents:
635
diff
changeset
|
1542 # gitlink no | delete gitlink |
42ca3ace9a0f
git_handler: return gitlinks in get_files_changed
Siddharth Agarwal <sid0@fb.com>
parents:
635
diff
changeset
|
1543 # gitlink file | delete gitlink and record file |
42ca3ace9a0f
git_handler: return gitlinks in get_files_changed
Siddharth Agarwal <sid0@fb.com>
parents:
635
diff
changeset
|
1544 # gitlink gitlink | record gitlink |
853
89bfb9994732
git_handler: handle symlink <-> regular file transitions properly
Siddharth Agarwal <sid0@fb.com>
parents:
844
diff
changeset
|
1545 # |
89bfb9994732
git_handler: handle symlink <-> regular file transitions properly
Siddharth Agarwal <sid0@fb.com>
parents:
844
diff
changeset
|
1546 # There's an edge case here -- symlink <-> regular file transitions |
89bfb9994732
git_handler: handle symlink <-> regular file transitions properly
Siddharth Agarwal <sid0@fb.com>
parents:
844
diff
changeset
|
1547 # are returned by dulwich as separate deletes and adds, not |
884
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1548 # modifications. The order of those results is unspecified and |
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1549 # could be either way round. Handle both cases: delete first, then |
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1550 # add -- delete stored in 'old = file' case, then overwritten by |
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1551 # 'new = file' case. add first, then delete -- record stored in |
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1552 # 'new = file' case, then membership check fails in 'old = file' |
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1553 # case so is not overwritten there. This is not an issue for |
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1554 # gitlink <-> {symlink, regular file} transitions because they |
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1555 # write to separate dictionaries. |
864
4d246150d850
git_handler: handle case where file is renamed and replaced by a symlink
Siddharth Agarwal <sid0@fb.com>
parents:
863
diff
changeset
|
1556 # |
884
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1557 # There's a similar edge case when rename detection is enabled: if |
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1558 # a file is renamed and then replaced by a symlink (typically to |
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1559 # the new location), it is returned by dulwich as an add and a |
864
4d246150d850
git_handler: handle case where file is renamed and replaced by a symlink
Siddharth Agarwal <sid0@fb.com>
parents:
863
diff
changeset
|
1560 # rename. The order of those results is unspecified. Handle both |
884
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1561 # cases: rename first, then add -- delete stored in 'new = file' |
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1562 # case with renamed_out, then renamed_out check passes in 'old = |
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1563 # file' case so is overwritten. add first, then rename -- add |
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1564 # stored in 'old = file' case, then membership check fails in 'new |
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1565 # = file' case so is overwritten. |
287
e08a22250fa9
Don't import git submodule files (we don't support them .. yet).
jeremy avnet <brainsik@saucelabs.com>
parents:
286
diff
changeset
|
1566 if newmode == 0160000: |
639
42ca3ace9a0f
git_handler: return gitlinks in get_files_changed
Siddharth Agarwal <sid0@fb.com>
parents:
635
diff
changeset
|
1567 # new = gitlink |
42ca3ace9a0f
git_handler: return gitlinks in get_files_changed
Siddharth Agarwal <sid0@fb.com>
parents:
635
diff
changeset
|
1568 gitlinks[newfile] = newsha |
843
da804eac2b00
git_handler.get_files_changed: detect renames when asked to do so
Siddharth Agarwal <sid0@fb.com>
parents:
840
diff
changeset
|
1569 if change.type == diff_tree.CHANGE_RENAME: |
da804eac2b00
git_handler.get_files_changed: detect renames when asked to do so
Siddharth Agarwal <sid0@fb.com>
parents:
840
diff
changeset
|
1570 # don't record the rename because only file -> file renames |
da804eac2b00
git_handler.get_files_changed: detect renames when asked to do so
Siddharth Agarwal <sid0@fb.com>
parents:
840
diff
changeset
|
1571 # make sense in Mercurial |
da804eac2b00
git_handler.get_files_changed: detect renames when asked to do so
Siddharth Agarwal <sid0@fb.com>
parents:
840
diff
changeset
|
1572 gitlinks[oldfile] = None |
639
42ca3ace9a0f
git_handler: return gitlinks in get_files_changed
Siddharth Agarwal <sid0@fb.com>
parents:
635
diff
changeset
|
1573 if oldmode is not None and oldmode != 0160000: |
42ca3ace9a0f
git_handler: return gitlinks in get_files_changed
Siddharth Agarwal <sid0@fb.com>
parents:
635
diff
changeset
|
1574 # file -> gitlink |
42ca3ace9a0f
git_handler: return gitlinks in get_files_changed
Siddharth Agarwal <sid0@fb.com>
parents:
635
diff
changeset
|
1575 files[oldfile] = True, None, None |
42ca3ace9a0f
git_handler: return gitlinks in get_files_changed
Siddharth Agarwal <sid0@fb.com>
parents:
635
diff
changeset
|
1576 continue |
42ca3ace9a0f
git_handler: return gitlinks in get_files_changed
Siddharth Agarwal <sid0@fb.com>
parents:
635
diff
changeset
|
1577 if oldmode == 0160000 and newmode != 0160000: |
42ca3ace9a0f
git_handler: return gitlinks in get_files_changed
Siddharth Agarwal <sid0@fb.com>
parents:
635
diff
changeset
|
1578 # gitlink -> no/file (gitlink -> gitlink is covered above) |
42ca3ace9a0f
git_handler: return gitlinks in get_files_changed
Siddharth Agarwal <sid0@fb.com>
parents:
635
diff
changeset
|
1579 gitlinks[oldfile] = None |
42ca3ace9a0f
git_handler: return gitlinks in get_files_changed
Siddharth Agarwal <sid0@fb.com>
parents:
635
diff
changeset
|
1580 continue |
42ca3ace9a0f
git_handler: return gitlinks in get_files_changed
Siddharth Agarwal <sid0@fb.com>
parents:
635
diff
changeset
|
1581 if newfile is not None: |
987
be0d1413a06f
git_handler: detect and reject nested Mercurial repositories
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
982
diff
changeset
|
1582 self.audit_hg_path(newfile) |
639
42ca3ace9a0f
git_handler: return gitlinks in get_files_changed
Siddharth Agarwal <sid0@fb.com>
parents:
635
diff
changeset
|
1583 # new = file |
42ca3ace9a0f
git_handler: return gitlinks in get_files_changed
Siddharth Agarwal <sid0@fb.com>
parents:
635
diff
changeset
|
1584 files[newfile] = False, newmode, newsha |
843
da804eac2b00
git_handler.get_files_changed: detect renames when asked to do so
Siddharth Agarwal <sid0@fb.com>
parents:
840
diff
changeset
|
1585 if renames is not None and newfile != oldfile: |
da804eac2b00
git_handler.get_files_changed: detect renames when asked to do so
Siddharth Agarwal <sid0@fb.com>
parents:
840
diff
changeset
|
1586 renames[newfile] = oldfile |
864
4d246150d850
git_handler: handle case where file is renamed and replaced by a symlink
Siddharth Agarwal <sid0@fb.com>
parents:
863
diff
changeset
|
1587 renamed_out.add(oldfile) |
4d246150d850
git_handler: handle case where file is renamed and replaced by a symlink
Siddharth Agarwal <sid0@fb.com>
parents:
863
diff
changeset
|
1588 # the membership check is explained in a comment above |
4d246150d850
git_handler: handle case where file is renamed and replaced by a symlink
Siddharth Agarwal <sid0@fb.com>
parents:
863
diff
changeset
|
1589 if (change.type == diff_tree.CHANGE_RENAME and |
4d246150d850
git_handler: handle case where file is renamed and replaced by a symlink
Siddharth Agarwal <sid0@fb.com>
parents:
863
diff
changeset
|
1590 oldfile not in files): |
843
da804eac2b00
git_handler.get_files_changed: detect renames when asked to do so
Siddharth Agarwal <sid0@fb.com>
parents:
840
diff
changeset
|
1591 files[oldfile] = True, None, None |
639
42ca3ace9a0f
git_handler: return gitlinks in get_files_changed
Siddharth Agarwal <sid0@fb.com>
parents:
635
diff
changeset
|
1592 else: |
42ca3ace9a0f
git_handler: return gitlinks in get_files_changed
Siddharth Agarwal <sid0@fb.com>
parents:
635
diff
changeset
|
1593 # old = file |
864
4d246150d850
git_handler: handle case where file is renamed and replaced by a symlink
Siddharth Agarwal <sid0@fb.com>
parents:
863
diff
changeset
|
1594 # files renamed_out | action |
4d246150d850
git_handler: handle case where file is renamed and replaced by a symlink
Siddharth Agarwal <sid0@fb.com>
parents:
863
diff
changeset
|
1595 # no * | write |
4d246150d850
git_handler: handle case where file is renamed and replaced by a symlink
Siddharth Agarwal <sid0@fb.com>
parents:
863
diff
changeset
|
1596 # yes no | ignore |
4d246150d850
git_handler: handle case where file is renamed and replaced by a symlink
Siddharth Agarwal <sid0@fb.com>
parents:
863
diff
changeset
|
1597 # yes yes | write |
4d246150d850
git_handler: handle case where file is renamed and replaced by a symlink
Siddharth Agarwal <sid0@fb.com>
parents:
863
diff
changeset
|
1598 if oldfile not in files or oldfile in renamed_out: |
853
89bfb9994732
git_handler: handle symlink <-> regular file transitions properly
Siddharth Agarwal <sid0@fb.com>
parents:
844
diff
changeset
|
1599 files[oldfile] = True, None, None |
287
e08a22250fa9
Don't import git submodule files (we don't support them .. yet).
jeremy avnet <brainsik@saucelabs.com>
parents:
286
diff
changeset
|
1600 |
840
edcdb7620f4d
git_handler.get_files_changed: return detected renames
Siddharth Agarwal <sid0@fb.com>
parents:
839
diff
changeset
|
1601 return files, gitlinks, renames |
224
80d67ae190df
port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
222
diff
changeset
|
1602 |
839
83a0e6c0e82c
git_handler: add a way to get a rename detector
Siddharth Agarwal <sid0@fb.com>
parents:
838
diff
changeset
|
1603 @hgutil.propertycache |
83a0e6c0e82c
git_handler: add a way to get a rename detector
Siddharth Agarwal <sid0@fb.com>
parents:
838
diff
changeset
|
1604 def _rename_detector(self): |
83a0e6c0e82c
git_handler: add a way to get a rename detector
Siddharth Agarwal <sid0@fb.com>
parents:
838
diff
changeset
|
1605 # disabled by default to avoid surprises |
1070
0b4144897f73
config: register git.similarity
Kevin Bullock <kbullock@ringworld.org>
parents:
1069
diff
changeset
|
1606 similarity = compat.config(self.ui, 'int', 'git', 'similarity') |
839
83a0e6c0e82c
git_handler: add a way to get a rename detector
Siddharth Agarwal <sid0@fb.com>
parents:
838
diff
changeset
|
1607 if similarity < 0 or similarity > 100: |
1128
6141895a53c9
compat: switch from hgutil.Abort to error.Abort
Kevin Bullock <kbullock@ringworld.org>
parents:
1127
diff
changeset
|
1608 raise error.Abort(_('git.similarity must be between 0 and 100')) |
839
83a0e6c0e82c
git_handler: add a way to get a rename detector
Siddharth Agarwal <sid0@fb.com>
parents:
838
diff
changeset
|
1609 if similarity == 0: |
83a0e6c0e82c
git_handler: add a way to get a rename detector
Siddharth Agarwal <sid0@fb.com>
parents:
838
diff
changeset
|
1610 return None |
83a0e6c0e82c
git_handler: add a way to get a rename detector
Siddharth Agarwal <sid0@fb.com>
parents:
838
diff
changeset
|
1611 |
83a0e6c0e82c
git_handler: add a way to get a rename detector
Siddharth Agarwal <sid0@fb.com>
parents:
838
diff
changeset
|
1612 # default is borrowed from Git |
1071
00baa6a2abc8
config: register git.renamelimit
Kevin Bullock <kbullock@ringworld.org>
parents:
1070
diff
changeset
|
1613 max_files = compat.config(self.ui, 'int', 'git', 'renamelimit') |
1059
0a4b119fb2b4
renames: fix range check for renamelimit
Kevin Bullock <kbullock@ringworld.org>
parents:
1057
diff
changeset
|
1614 if max_files < 0: |
1128
6141895a53c9
compat: switch from hgutil.Abort to error.Abort
Kevin Bullock <kbullock@ringworld.org>
parents:
1127
diff
changeset
|
1615 raise error.Abort(_('git.renamelimit must be non-negative')) |
839
83a0e6c0e82c
git_handler: add a way to get a rename detector
Siddharth Agarwal <sid0@fb.com>
parents:
838
diff
changeset
|
1616 if max_files == 0: |
83a0e6c0e82c
git_handler: add a way to get a rename detector
Siddharth Agarwal <sid0@fb.com>
parents:
838
diff
changeset
|
1617 max_files = None |
83a0e6c0e82c
git_handler: add a way to get a rename detector
Siddharth Agarwal <sid0@fb.com>
parents:
838
diff
changeset
|
1618 |
1072
f7433379c04a
config: register git.findcopiesharder
Kevin Bullock <kbullock@ringworld.org>
parents:
1071
diff
changeset
|
1619 find_copies_harder = compat.config(self.ui, 'bool', 'git', |
f7433379c04a
config: register git.findcopiesharder
Kevin Bullock <kbullock@ringworld.org>
parents:
1071
diff
changeset
|
1620 'findcopiesharder') |
843
da804eac2b00
git_handler.get_files_changed: detect renames when asked to do so
Siddharth Agarwal <sid0@fb.com>
parents:
840
diff
changeset
|
1621 return diff_tree.RenameDetector(self.git.object_store, |
884
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1622 rename_threshold=similarity, |
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1623 max_files=max_files, |
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1624 find_copies_harder=find_copies_harder) |
839
83a0e6c0e82c
git_handler: add a way to get a rename detector
Siddharth Agarwal <sid0@fb.com>
parents:
838
diff
changeset
|
1625 |
476
b9ede5f91701
Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
475
diff
changeset
|
1626 def parse_gitmodules(self, tree_obj): |
b9ede5f91701
Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
475
diff
changeset
|
1627 """Parse .gitmodules from a git tree specified by tree_obj |
b9ede5f91701
Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
475
diff
changeset
|
1628 |
b9ede5f91701
Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
475
diff
changeset
|
1629 :return: list of tuples (submodule path, url, name), |
b9ede5f91701
Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
475
diff
changeset
|
1630 where name is quoted part of the section's name, or |
b9ede5f91701
Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
475
diff
changeset
|
1631 empty list if nothing found |
b9ede5f91701
Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
475
diff
changeset
|
1632 """ |
b9ede5f91701
Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
475
diff
changeset
|
1633 rv = [] |
b9ede5f91701
Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
475
diff
changeset
|
1634 try: |
884
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1635 unused_mode, gitmodules_sha = tree_obj['.gitmodules'] |
476
b9ede5f91701
Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
475
diff
changeset
|
1636 except KeyError: |
b9ede5f91701
Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
475
diff
changeset
|
1637 return rv |
b9ede5f91701
Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
475
diff
changeset
|
1638 gitmodules_content = self.git[gitmodules_sha].data |
b9ede5f91701
Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
475
diff
changeset
|
1639 fo = StringIO.StringIO(gitmodules_content) |
b9ede5f91701
Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
475
diff
changeset
|
1640 tt = dul_config.ConfigFile.from_file(fo) |
b9ede5f91701
Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
475
diff
changeset
|
1641 for section in tt.keys(): |
b9ede5f91701
Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
475
diff
changeset
|
1642 section_kind, section_name = section |
b9ede5f91701
Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
475
diff
changeset
|
1643 if section_kind == 'submodule': |
b9ede5f91701
Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
475
diff
changeset
|
1644 sm_path = tt.get(section, 'path') |
884
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1645 sm_url = tt.get(section, 'url') |
476
b9ede5f91701
Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
475
diff
changeset
|
1646 rv.append((sm_path, sm_url, section_name)) |
b9ede5f91701
Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
475
diff
changeset
|
1647 return rv |
b9ede5f91701
Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
475
diff
changeset
|
1648 |
b9ede5f91701
Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
475
diff
changeset
|
1649 def git_file_readlines(self, tree_obj, fname): |
b9ede5f91701
Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
475
diff
changeset
|
1650 """Read content of a named entry from the git commit tree |
b9ede5f91701
Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
475
diff
changeset
|
1651 |
b9ede5f91701
Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
475
diff
changeset
|
1652 :return: list of lines |
b9ede5f91701
Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
475
diff
changeset
|
1653 """ |
b9ede5f91701
Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
475
diff
changeset
|
1654 if fname in tree_obj: |
b9ede5f91701
Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
475
diff
changeset
|
1655 unused_mode, sha = tree_obj[fname] |
b9ede5f91701
Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
475
diff
changeset
|
1656 content = self.git[sha].data |
b9ede5f91701
Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
475
diff
changeset
|
1657 return content.splitlines() |
b9ede5f91701
Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
475
diff
changeset
|
1658 return [] |
b9ede5f91701
Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
475
diff
changeset
|
1659 |
184
7bf98d3085f4
Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
183
diff
changeset
|
1660 def remote_name(self, remote): |
7bf98d3085f4
Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
183
diff
changeset
|
1661 names = [name for name, path in self.paths if path == remote] |
7bf98d3085f4
Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
183
diff
changeset
|
1662 if names: |
7bf98d3085f4
Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
183
diff
changeset
|
1663 return names[0] |
7bf98d3085f4
Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
183
diff
changeset
|
1664 |
987
be0d1413a06f
git_handler: detect and reject nested Mercurial repositories
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
982
diff
changeset
|
1665 def audit_hg_path(self, path): |
be0d1413a06f
git_handler: detect and reject nested Mercurial repositories
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
982
diff
changeset
|
1666 if '.hg' in path.split(os.path.sep): |
1073
03e7c9d1fbb6
config: register git.blockdothg
Kevin Bullock <kbullock@ringworld.org>
parents:
1072
diff
changeset
|
1667 if compat.config(self.ui, 'bool', 'git', 'blockdothg'): |
1128
6141895a53c9
compat: switch from hgutil.Abort to error.Abort
Kevin Bullock <kbullock@ringworld.org>
parents:
1127
diff
changeset
|
1668 raise error.Abort( |
987
be0d1413a06f
git_handler: detect and reject nested Mercurial repositories
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
982
diff
changeset
|
1669 ('Refusing to import problematic path %r' % path), |
be0d1413a06f
git_handler: detect and reject nested Mercurial repositories
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
982
diff
changeset
|
1670 hint=("Mercurial cannot check out paths inside nested " + |
be0d1413a06f
git_handler: detect and reject nested Mercurial repositories
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
982
diff
changeset
|
1671 "repositories; if you need to continue, then set " + |
be0d1413a06f
git_handler: detect and reject nested Mercurial repositories
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
982
diff
changeset
|
1672 "'[git] blockdothg = false' in your hgrc.")) |
be0d1413a06f
git_handler: detect and reject nested Mercurial repositories
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
982
diff
changeset
|
1673 self.ui.warn(('warning: path %r is within a nested repository, ' + |
be0d1413a06f
git_handler: detect and reject nested Mercurial repositories
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
982
diff
changeset
|
1674 'which Mercurial cannot check out.\n') |
be0d1413a06f
git_handler: detect and reject nested Mercurial repositories
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
982
diff
changeset
|
1675 % path) |
be0d1413a06f
git_handler: detect and reject nested Mercurial repositories
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
982
diff
changeset
|
1676 |
186
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
1677 # Stolen from hgsubversion |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
1678 def swap_out_encoding(self, new_encoding='UTF-8'): |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
1679 try: |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
1680 from mercurial import encoding |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
1681 old = encoding.encoding |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
1682 encoding.encoding = new_encoding |
956
06385a2b30f3
init: handle AttributeError in addition to ImportError
timeless@gmail.com
parents:
954
diff
changeset
|
1683 except (AttributeError, ImportError): |
186
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
1684 old = hgutil._encoding |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
1685 hgutil._encoding = new_encoding |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
1686 return old |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
1687 |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
1688 def decode_guess(self, string, encoding): |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
1689 # text is not valid utf-8, try to make sense of it |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
1690 if encoding: |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
1691 try: |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
1692 return string.decode(encoding).encode('utf-8') |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
1693 except UnicodeDecodeError: |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
1694 pass |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
1695 |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
1696 try: |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
1697 return string.decode('latin-1').encode('utf-8') |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
1698 except UnicodeDecodeError: |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
1699 return string.decode('ascii', 'replace').encode('utf-8') |
f4caf22b87cd
Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
184
diff
changeset
|
1700 |
5
d6c443a91b18
refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
1701 def get_transport_and_path(self, uri): |
921
5f93caf337a9
git_handler: test for a raw git ssh uri
Sean Farley <sean@farley.io>
parents:
917
diff
changeset
|
1702 """Method that sets up the transport (either ssh or http(s)) |
5f93caf337a9
git_handler: test for a raw git ssh uri
Sean Farley <sean@farley.io>
parents:
917
diff
changeset
|
1703 |
5f93caf337a9
git_handler: test for a raw git ssh uri
Sean Farley <sean@farley.io>
parents:
917
diff
changeset
|
1704 Tests: |
5f93caf337a9
git_handler: test for a raw git ssh uri
Sean Farley <sean@farley.io>
parents:
917
diff
changeset
|
1705 |
1034
fa08148bc5fc
git_handler: use namedtuple as mock repo in doctests
Kevin Bullock <kbullock@ringworld.org>
parents:
1025
diff
changeset
|
1706 >>> from collections import namedtuple |
921
5f93caf337a9
git_handler: test for a raw git ssh uri
Sean Farley <sean@farley.io>
parents:
917
diff
changeset
|
1707 >>> from dulwich.client import HttpGitClient, SSHGitClient |
5f93caf337a9
git_handler: test for a raw git ssh uri
Sean Farley <sean@farley.io>
parents:
917
diff
changeset
|
1708 >>> from mercurial.ui import ui |
1096 | 1709 >>> mockrepo = namedtuple('localrepo', ['vfs', 'sharedpath', 'path']) |
1034
fa08148bc5fc
git_handler: use namedtuple as mock repo in doctests
Kevin Bullock <kbullock@ringworld.org>
parents:
1025
diff
changeset
|
1710 >>> mockrepo.vfs = '' |
1096 | 1711 >>> mockrepo.sharedpath = '' |
1712 >>> mockrepo.path = '' | |
1034
fa08148bc5fc
git_handler: use namedtuple as mock repo in doctests
Kevin Bullock <kbullock@ringworld.org>
parents:
1025
diff
changeset
|
1713 >>> g = GitHandler(mockrepo, ui()) |
1116 | 1714 >>> tp = g.get_transport_and_path |
1715 >>> client, url = tp('http://fqdn.com/test.git') | |
921
5f93caf337a9
git_handler: test for a raw git ssh uri
Sean Farley <sean@farley.io>
parents:
917
diff
changeset
|
1716 >>> print isinstance(client, HttpGitClient) |
5f93caf337a9
git_handler: test for a raw git ssh uri
Sean Farley <sean@farley.io>
parents:
917
diff
changeset
|
1717 True |
5f93caf337a9
git_handler: test for a raw git ssh uri
Sean Farley <sean@farley.io>
parents:
917
diff
changeset
|
1718 >>> print url |
5f93caf337a9
git_handler: test for a raw git ssh uri
Sean Farley <sean@farley.io>
parents:
917
diff
changeset
|
1719 http://fqdn.com/test.git |
1116 | 1720 >>> client, url = tp('git@fqdn.com:user/repo.git') |
921
5f93caf337a9
git_handler: test for a raw git ssh uri
Sean Farley <sean@farley.io>
parents:
917
diff
changeset
|
1721 >>> print isinstance(client, SSHGitClient) |
5f93caf337a9
git_handler: test for a raw git ssh uri
Sean Farley <sean@farley.io>
parents:
917
diff
changeset
|
1722 True |
5f93caf337a9
git_handler: test for a raw git ssh uri
Sean Farley <sean@farley.io>
parents:
917
diff
changeset
|
1723 >>> print url |
5f93caf337a9
git_handler: test for a raw git ssh uri
Sean Farley <sean@farley.io>
parents:
917
diff
changeset
|
1724 user/repo.git |
5f93caf337a9
git_handler: test for a raw git ssh uri
Sean Farley <sean@farley.io>
parents:
917
diff
changeset
|
1725 >>> print client.host |
5f93caf337a9
git_handler: test for a raw git ssh uri
Sean Farley <sean@farley.io>
parents:
917
diff
changeset
|
1726 git@fqdn.com |
5f93caf337a9
git_handler: test for a raw git ssh uri
Sean Farley <sean@farley.io>
parents:
917
diff
changeset
|
1727 """ |
369
e5c743cd0da1
pass hg's ui.ssh config to dulwich
Tay Ray Chuan <rctay89@gmail.com>
parents:
368
diff
changeset
|
1728 # pass hg's ui.ssh config to dulwich |
e5c743cd0da1
pass hg's ui.ssh config to dulwich
Tay Ray Chuan <rctay89@gmail.com>
parents:
368
diff
changeset
|
1729 if not issubclass(client.get_ssh_vendor, _ssh.SSHVendor): |
e5c743cd0da1
pass hg's ui.ssh config to dulwich
Tay Ray Chuan <rctay89@gmail.com>
parents:
368
diff
changeset
|
1730 client.get_ssh_vendor = _ssh.generate_ssh_vendor(self.ui) |
e5c743cd0da1
pass hg's ui.ssh config to dulwich
Tay Ray Chuan <rctay89@gmail.com>
parents:
368
diff
changeset
|
1731 |
921
5f93caf337a9
git_handler: test for a raw git ssh uri
Sean Farley <sean@farley.io>
parents:
917
diff
changeset
|
1732 # test for raw git ssh uri here so that we can reuse the logic below |
5f93caf337a9
git_handler: test for a raw git ssh uri
Sean Farley <sean@farley.io>
parents:
917
diff
changeset
|
1733 if util.isgitsshuri(uri): |
5f93caf337a9
git_handler: test for a raw git ssh uri
Sean Farley <sean@farley.io>
parents:
917
diff
changeset
|
1734 uri = "git+ssh://" + uri |
5f93caf337a9
git_handler: test for a raw git ssh uri
Sean Farley <sean@farley.io>
parents:
917
diff
changeset
|
1735 |
538
a38abdbab77c
Precompile Git URI regular expression
Gregory Szorc <gregory.szorc@gmail.com>
parents:
537
diff
changeset
|
1736 git_match = RE_GIT_URI.match(uri) |
446
7e6fc0efc500
Removed support for URLs beginning with git@. These URLs are not possible from within mercurial.
Jason R. Coombs <jaraco@jaraco.com>
parents:
445
diff
changeset
|
1737 if git_match: |
7e6fc0efc500
Removed support for URLs beginning with git@. These URLs are not possible from within mercurial.
Jason R. Coombs <jaraco@jaraco.com>
parents:
445
diff
changeset
|
1738 res = git_match.groupdict() |
1042
b4d2180739bb
ssh: avoid SSH command-line injection [SEC]
Sean Farley <sean@farley.io>
parents:
1035
diff
changeset
|
1739 host, port, sepr = res['host'], res['port'], res['sepr'] |
884
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1740 transport = client.TCPGitClient |
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1741 if 'ssh' in res['scheme']: |
1042
b4d2180739bb
ssh: avoid SSH command-line injection [SEC]
Sean Farley <sean@farley.io>
parents:
1035
diff
changeset
|
1742 util.checksafessh(host) |
884
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1743 transport = client.SSHGitClient |
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1744 path = res['path'] |
600
ca86479dd2d9
Make the path part of URL contain a leading slash only if it's not followed by tilde. (issue #71)
Risto Kankkunen <risto.kankkunen@iki.fi>
parents:
599
diff
changeset
|
1745 if sepr == '/' and not path.startswith('~'): |
446
7e6fc0efc500
Removed support for URLs beginning with git@. These URLs are not possible from within mercurial.
Jason R. Coombs <jaraco@jaraco.com>
parents:
445
diff
changeset
|
1746 path = '/' + path |
447
1189e52ba27c
Strip trailing slash for heroku-style URLs. Fixes #31. Includes a regression test for the fix.
Jason R. Coombs <jaraco@jaraco.com>
parents:
446
diff
changeset
|
1747 # strip trailing slash for heroku-style URLs |
1189e52ba27c
Strip trailing slash for heroku-style URLs. Fixes #31. Includes a regression test for the fix.
Jason R. Coombs <jaraco@jaraco.com>
parents:
446
diff
changeset
|
1748 # ssh+git://git@heroku.com:project.git/ |
1189e52ba27c
Strip trailing slash for heroku-style URLs. Fixes #31. Includes a regression test for the fix.
Jason R. Coombs <jaraco@jaraco.com>
parents:
446
diff
changeset
|
1749 if sepr == ':' and path.endswith('.git/'): |
1189e52ba27c
Strip trailing slash for heroku-style URLs. Fixes #31. Includes a regression test for the fix.
Jason R. Coombs <jaraco@jaraco.com>
parents:
446
diff
changeset
|
1750 path = path.rstrip('/') |
446
7e6fc0efc500
Removed support for URLs beginning with git@. These URLs are not possible from within mercurial.
Jason R. Coombs <jaraco@jaraco.com>
parents:
445
diff
changeset
|
1751 if port: |
7e6fc0efc500
Removed support for URLs beginning with git@. These URLs are not possible from within mercurial.
Jason R. Coombs <jaraco@jaraco.com>
parents:
445
diff
changeset
|
1752 client.port = port |
261
29e5072ddaab
Handle normal relative SSH paths (i.e for heroku and gitosis) as well as github style paths.
Lincoln Stoll <lstoll@lstoll.net>
parents:
260
diff
changeset
|
1753 |
741
ab8562b11c4f
git_handler: enable thin pack optimization (issue102)
Takumi IINO <trot.thunder@gmail.com>
parents:
740
diff
changeset
|
1754 return transport(host, port=port), path |
439
3f45c88100e8
add support for the HTTP smart protocol when using Dulwich tip
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
432
diff
changeset
|
1755 |
3f45c88100e8
add support for the HTTP smart protocol when using Dulwich tip
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
432
diff
changeset
|
1756 if uri.startswith('git+http://') or uri.startswith('git+https://'): |
3f45c88100e8
add support for the HTTP smart protocol when using Dulwich tip
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
432
diff
changeset
|
1757 uri = uri[4:] |
3f45c88100e8
add support for the HTTP smart protocol when using Dulwich tip
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
432
diff
changeset
|
1758 |
3f45c88100e8
add support for the HTTP smart protocol when using Dulwich tip
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
432
diff
changeset
|
1759 if uri.startswith('http://') or uri.startswith('https://'): |
1035
cfcd3032355c
compat: remove unused argument
Kevin Bullock <kbullock@ringworld.org>
parents:
1034
diff
changeset
|
1760 pmgr = compat.passwordmgr(self.ui) |
992
05c8aa7d3edc
git_handler: use compat.passwordmgr for hg < 3.9 support
Sean Farley <sean@farley.io>
parents:
987
diff
changeset
|
1761 auth = urllib2.HTTPBasicAuthHandler(pmgr) |
05c8aa7d3edc
git_handler: use compat.passwordmgr for hg < 3.9 support
Sean Farley <sean@farley.io>
parents:
987
diff
changeset
|
1762 |
884
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1763 opener = urllib2.build_opener(auth) |
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1764 ua = 'git/20x6 (hg-git ; uses dulwich and hg ; like git-core)' |
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1765 opener.addheaders = [('User-Agent', ua)] |
869
6547d63aee4e
git_handler: reintroduce compatibility with dulwich 0.9.4 (issue124)
Siddharth Agarwal <sid0@fb.com>
parents:
868
diff
changeset
|
1766 try: |
6547d63aee4e
git_handler: reintroduce compatibility with dulwich 0.9.4 (issue124)
Siddharth Agarwal <sid0@fb.com>
parents:
868
diff
changeset
|
1767 return client.HttpGitClient(uri, opener=opener), uri |
6547d63aee4e
git_handler: reintroduce compatibility with dulwich 0.9.4 (issue124)
Siddharth Agarwal <sid0@fb.com>
parents:
868
diff
changeset
|
1768 except TypeError as e: |
6547d63aee4e
git_handler: reintroduce compatibility with dulwich 0.9.4 (issue124)
Siddharth Agarwal <sid0@fb.com>
parents:
868
diff
changeset
|
1769 if e.message.find("unexpected keyword argument 'opener'") >= 0: |
884
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1770 # Dulwich 0.9.4, which is the latest version that ships |
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1771 # with Ubuntu 14.04, doesn't support the 'opener' keyword. |
4288d2de3cbf
git_handler: whitespace and formating changes
Sean Farley <sean@farley.io>
parents:
883
diff
changeset
|
1772 # Try without authentication. |
869
6547d63aee4e
git_handler: reintroduce compatibility with dulwich 0.9.4 (issue124)
Siddharth Agarwal <sid0@fb.com>
parents:
868
diff
changeset
|
1773 return client.HttpGitClient(uri), uri |
6547d63aee4e
git_handler: reintroduce compatibility with dulwich 0.9.4 (issue124)
Siddharth Agarwal <sid0@fb.com>
parents:
868
diff
changeset
|
1774 else: |
6547d63aee4e
git_handler: reintroduce compatibility with dulwich 0.9.4 (issue124)
Siddharth Agarwal <sid0@fb.com>
parents:
868
diff
changeset
|
1775 raise |
439
3f45c88100e8
add support for the HTTP smart protocol when using Dulwich tip
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
432
diff
changeset
|
1776 |
5
d6c443a91b18
refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
1777 # if its not git or git+ssh, try a local url.. |
741
ab8562b11c4f
git_handler: enable thin pack optimization (issue102)
Takumi IINO <trot.thunder@gmail.com>
parents:
740
diff
changeset
|
1778 return client.SubprocessGitClient(), uri |