annotate hggit/git_handler.py @ 596:d6b9c30a3e0f

Export Git objects from incremental Mercurial changes This replaces the brute force Mercurial to Git export with one that is incremental. It results in a decent performance win and paves the road for parallel export via using multiple incremental exporters.
author Gregory Szorc <gregory.szorc@gmail.com>
date Tue, 19 Mar 2013 22:44:01 -0700
parents ce6ad4c0cba7
children e0089655caa6 65d8a43bc5ee
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
267
7814c26758a2 remove unused imports
Antonin Amand <antonin.amand@gmail.com>
parents: 266
diff changeset
1 import os, math, urllib, re
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
2 import stat, posixpath, StringIO
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
3
523
8c1f2b07c04b outgoing: re-introduce support for outgoing
David M. Carr <david@carrclan.us>
parents: 490
diff changeset
4 from dulwich.errors import HangupException, GitProtocolError, UpdateRefsError
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
5 from dulwich.objects import Blob, Commit, Tag, Tree, parse_timezone, S_IFGITLINK
225
cde57730faa7 store non utf-8 encoded author/commit message as deltas
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 224
diff changeset
6 from dulwich.pack import create_delta, apply_delta
5
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
7 from dulwich.repo import Repo
285
5e5aee9b32d4 git_handler: slight style cleanup
Augie Fackler <durin42@gmail.com>
parents: 284
diff changeset
8 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
9 from dulwich import config as dul_config
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
10
375
454fc525ac75 support upcoming Mercurial 1.8
Kevin Bullock <kbullock@ringworld.org>
parents: 374
diff changeset
11 try:
454fc525ac75 support upcoming Mercurial 1.8
Kevin Bullock <kbullock@ringworld.org>
parents: 374
diff changeset
12 from mercurial import bookmarks
454fc525ac75 support upcoming Mercurial 1.8
Kevin Bullock <kbullock@ringworld.org>
parents: 374
diff changeset
13 bookmarks.update
379
ed8034b1cb0d Made hggit.git_handler.get_changed_refs try to use commands.bookmark before trying with bookmarks.bookmark, for compatibility with Mercurial 1.8+.
DontCare4Free <webmaster@dontcare4free.tk>
parents: 376
diff changeset
14 from mercurial import commands
375
454fc525ac75 support upcoming Mercurial 1.8
Kevin Bullock <kbullock@ringworld.org>
parents: 374
diff changeset
15 except ImportError:
454fc525ac75 support upcoming Mercurial 1.8
Kevin Bullock <kbullock@ringworld.org>
parents: 374
diff changeset
16 from hgext import bookmarks
439
3f45c88100e8 add support for the HTTP smart protocol when using Dulwich tip
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 432
diff changeset
17 try:
3f45c88100e8 add support for the HTTP smart protocol when using Dulwich tip
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 432
diff changeset
18 from mercurial.error import RepoError
3f45c88100e8 add support for the HTTP smart protocol when using Dulwich tip
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 432
diff changeset
19 except ImportError:
3f45c88100e8 add support for the HTTP smart protocol when using Dulwich tip
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 432
diff changeset
20 from mercurial.repo import RepoError
3f45c88100e8 add support for the HTTP smart protocol when using Dulwich tip
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 432
diff changeset
21
5
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
22 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
23 from mercurial.node import hex, bin, nullid
222
e414c72d3ec9 fix compatibility with mercurial 1.1
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 221
diff changeset
24 from mercurial import context, util as hgutil
300
eec31dee258e Various hg 1.4 compat fixes.
Augie Fackler <durin42@gmail.com>
parents: 298
diff changeset
25 from mercurial import error
222
e414c72d3ec9 fix compatibility with mercurial 1.1
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 221
diff changeset
26
369
e5c743cd0da1 pass hg's ui.ssh config to dulwich
Tay Ray Chuan <rctay89@gmail.com>
parents: 368
diff changeset
27 import _ssh
596
d6b9c30a3e0f Export Git objects from incremental Mercurial changes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 593
diff changeset
28 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
29 import util
408
2dcfd4bbfc1a Support for hg incoming
Brendan Cully <brendan@kublai.com>
parents: 406
diff changeset
30 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
31
596
d6b9c30a3e0f Export Git objects from incremental Mercurial changes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 593
diff changeset
32
537
6e05aa1b536d Optimize get_git_author
Gregory Szorc <gregory.szorc@gmail.com>
parents: 523
diff changeset
33 RE_GIT_AUTHOR = re.compile('^(.*?) ?\<(.*?)(?:\>(.*))?$')
6e05aa1b536d Optimize get_git_author
Gregory Szorc <gregory.szorc@gmail.com>
parents: 523
diff changeset
34
539
7bf60690386c Precompile Git username sanitizing regular expression
Gregory Szorc <gregory.szorc@gmail.com>
parents: 538
diff changeset
35 RE_GIT_SANITIZE_AUTHOR = re.compile('[<>\n]')
7bf60690386c Precompile Git username sanitizing regular expression
Gregory Szorc <gregory.szorc@gmail.com>
parents: 538
diff changeset
36
540
3fb942852b1c Precompile Git author extra data regular expression
Gregory Szorc <gregory.szorc@gmail.com>
parents: 539
diff changeset
37 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
38
538
a38abdbab77c Precompile Git URI regular expression
Gregory Szorc <gregory.szorc@gmail.com>
parents: 537
diff changeset
39 # Test for git:// and git+ssh:// URI.
a38abdbab77c Precompile Git URI regular expression
Gregory Szorc <gregory.szorc@gmail.com>
parents: 537
diff changeset
40 # Support several URL forms, including separating the
a38abdbab77c Precompile Git URI regular expression
Gregory Szorc <gregory.szorc@gmail.com>
parents: 537
diff changeset
41 # host and path with either a / or : (sepr)
a38abdbab77c Precompile Git URI regular expression
Gregory Szorc <gregory.szorc@gmail.com>
parents: 537
diff changeset
42 RE_GIT_URI = re.compile(
a38abdbab77c Precompile Git URI regular expression
Gregory Szorc <gregory.szorc@gmail.com>
parents: 537
diff changeset
43 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
44 r'(?P<sepr>[:/])(?P<path>.*)$')
a38abdbab77c Precompile Git URI regular expression
Gregory Szorc <gregory.szorc@gmail.com>
parents: 537
diff changeset
45
541
df1598b722e8 Precompile Git progress regular expressions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 540
diff changeset
46 RE_NEWLINES = re.compile('[\r\n]')
df1598b722e8 Precompile Git progress regular expressions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 540
diff changeset
47 RE_GIT_PROGRESS = re.compile('\((\d+)/(\d+)\)')
df1598b722e8 Precompile Git progress regular expressions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 540
diff changeset
48
542
c9faba7d01f4 Precompile author file regular expression
Gregory Szorc <gregory.szorc@gmail.com>
parents: 541
diff changeset
49 RE_AUTHOR_FILE = re.compile('\s*=\s*')
c9faba7d01f4 Precompile author file regular expression
Gregory Szorc <gregory.szorc@gmail.com>
parents: 541
diff changeset
50
411
de7317967598 Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents: 408
diff changeset
51 class GitProgress(object):
de7317967598 Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents: 408
diff changeset
52 """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
53 def __init__(self, ui):
de7317967598 Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents: 408
diff changeset
54 self.ui = ui
de7317967598 Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents: 408
diff changeset
55
de7317967598 Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents: 408
diff changeset
56 self.lasttopic = None
de7317967598 Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents: 408
diff changeset
57 self.msgbuf = ''
de7317967598 Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents: 408
diff changeset
58
de7317967598 Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents: 408
diff changeset
59 def progress(self, msg):
de7317967598 Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents: 408
diff changeset
60 # 'Counting objects: 33640, done.\n'
de7317967598 Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents: 408
diff changeset
61 # 'Compressing objects: 0% (1/9955) \r
541
df1598b722e8 Precompile Git progress regular expressions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 540
diff changeset
62 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
63 self.msgbuf = msgs.pop()
de7317967598 Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents: 408
diff changeset
64
de7317967598 Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents: 408
diff changeset
65 for msg in msgs:
de7317967598 Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents: 408
diff changeset
66 td = msg.split(':', 1)
de7317967598 Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents: 408
diff changeset
67 data = td.pop()
de7317967598 Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents: 408
diff changeset
68 if not td:
de7317967598 Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents: 408
diff changeset
69 self.flush(data)
de7317967598 Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents: 408
diff changeset
70 continue
de7317967598 Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents: 408
diff changeset
71 topic = td[0]
de7317967598 Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents: 408
diff changeset
72
541
df1598b722e8 Precompile Git progress regular expressions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 540
diff changeset
73 m = RE_GIT_PROGRESS.search(data)
411
de7317967598 Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents: 408
diff changeset
74 if m:
de7317967598 Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents: 408
diff changeset
75 if self.lasttopic and self.lasttopic != topic:
de7317967598 Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents: 408
diff changeset
76 self.flush()
de7317967598 Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents: 408
diff changeset
77 self.lasttopic = topic
de7317967598 Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents: 408
diff changeset
78
de7317967598 Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents: 408
diff changeset
79 pos, total = map(int, m.group(1, 2))
413
b8eeabb61c7b test fixes for progress cleanup
Augie Fackler <durin42@gmail.com>
parents: 411
diff changeset
80 util.progress(self.ui, topic, pos, total=total)
411
de7317967598 Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents: 408
diff changeset
81 else:
de7317967598 Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents: 408
diff changeset
82 self.flush(msg)
de7317967598 Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents: 408
diff changeset
83
de7317967598 Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents: 408
diff changeset
84 def flush(self, msg=None):
de7317967598 Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents: 408
diff changeset
85 if self.lasttopic:
413
b8eeabb61c7b test fixes for progress cleanup
Augie Fackler <durin42@gmail.com>
parents: 411
diff changeset
86 util.progress(self.ui, self.lasttopic, None)
411
de7317967598 Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents: 408
diff changeset
87 self.lasttopic = None
de7317967598 Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents: 408
diff changeset
88 if msg:
de7317967598 Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents: 408
diff changeset
89 self.ui.note(msg + '\n')
de7317967598 Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents: 408
diff changeset
90
5
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
91 class GitHandler(object):
298
6ad6945b6629 pull: make it possible to un-wedge the repo after stripping git revs
Augie Fackler <durin42@gmail.com>
parents: 293
diff changeset
92 mapfile = 'git-mapfile'
6ad6945b6629 pull: make it possible to un-wedge the repo after stripping git revs
Augie Fackler <durin42@gmail.com>
parents: 293
diff changeset
93 tagsfile = 'git-tags'
19
2be9c0bd88af Warn, but don't fail when bookmarks is not enabled.
Augie Fackler <durin42@gmail.com>
parents: 17
diff changeset
94
5
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
95 def __init__(self, dest_repo, ui):
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
96 self.repo = dest_repo
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
97 self.ui = ui
133
f2dfb2bed724 Allow storing the git directory intree
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 118
diff changeset
98
324
f0c1c35d95ba explicitly expect boolean values for git.intree
Tay Ray Chuan <rctay89@gmail.com>
parents: 320
diff changeset
99 if ui.configbool('git', 'intree'):
133
f2dfb2bed724 Allow storing the git directory intree
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 118
diff changeset
100 self.gitdir = self.repo.wjoin('.git')
f2dfb2bed724 Allow storing the git directory intree
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 118
diff changeset
101 else:
f2dfb2bed724 Allow storing the git directory intree
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 118
diff changeset
102 self.gitdir = self.repo.join('git')
f2dfb2bed724 Allow storing the git directory intree
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 118
diff changeset
103
450
163ac98569d3 - add "author file" extension, allows an author translation map
Mike Bayer <mike_mp@zzzcomputing.com>
parents: 448
diff changeset
104 self.init_author_file()
163ac98569d3 - add "author file" extension, allows an author translation map
Mike Bayer <mike_mp@zzzcomputing.com>
parents: 448
diff changeset
105
184
7bf98d3085f4 Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 183
diff changeset
106 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
107
441
35e2813f58a5 - add "branch_bookmark_names" parameter. this allows bookmarks
Mike Bayer <mike_mp@zzzcomputing.com>
parents: 439
diff changeset
108 self.branch_bookmark_suffix = ui.config('git', 'branch_bookmark_suffix')
35e2813f58a5 - add "branch_bookmark_names" parameter. this allows bookmarks
Mike Bayer <mike_mp@zzzcomputing.com>
parents: 439
diff changeset
109
552
bff92a208c3f git_handler: lazy-load mapping
Augie Fackler <raf@durin42.com>
parents: 489
diff changeset
110 self._map_git_real = {}
bff92a208c3f git_handler: lazy-load mapping
Augie Fackler <raf@durin42.com>
parents: 489
diff changeset
111 self._map_hg_real = {}
bff92a208c3f git_handler: lazy-load mapping
Augie Fackler <raf@durin42.com>
parents: 489
diff changeset
112 self.load_tags()
bff92a208c3f git_handler: lazy-load mapping
Augie Fackler <raf@durin42.com>
parents: 489
diff changeset
113
bff92a208c3f git_handler: lazy-load mapping
Augie Fackler <raf@durin42.com>
parents: 489
diff changeset
114 @property
bff92a208c3f git_handler: lazy-load mapping
Augie Fackler <raf@durin42.com>
parents: 489
diff changeset
115 def _map_git(self):
bff92a208c3f git_handler: lazy-load mapping
Augie Fackler <raf@durin42.com>
parents: 489
diff changeset
116 if not self._map_git_real:
7
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
117 self.load_map()
552
bff92a208c3f git_handler: lazy-load mapping
Augie Fackler <raf@durin42.com>
parents: 489
diff changeset
118 return self._map_git_real
bff92a208c3f git_handler: lazy-load mapping
Augie Fackler <raf@durin42.com>
parents: 489
diff changeset
119
bff92a208c3f git_handler: lazy-load mapping
Augie Fackler <raf@durin42.com>
parents: 489
diff changeset
120 @property
bff92a208c3f git_handler: lazy-load mapping
Augie Fackler <raf@durin42.com>
parents: 489
diff changeset
121 def _map_hg(self):
bff92a208c3f git_handler: lazy-load mapping
Augie Fackler <raf@durin42.com>
parents: 489
diff changeset
122 if not self._map_hg_real:
bff92a208c3f git_handler: lazy-load mapping
Augie Fackler <raf@durin42.com>
parents: 489
diff changeset
123 self.load_map()
bff92a208c3f git_handler: lazy-load mapping
Augie Fackler <raf@durin42.com>
parents: 489
diff changeset
124 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
125
2be9c0bd88af Warn, but don't fail when bookmarks is not enabled.
Augie Fackler <durin42@gmail.com>
parents: 17
diff changeset
126 # make the git data directory
16
58cd05129119 moved init into git_handler
Scott Chacon <schacon@gmail.com>
parents: 14
diff changeset
127 def init_if_missing(self):
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
128 if os.path.exists(self.gitdir):
1590c97d7af0 do not init the cache git repo unless needed (fixes issue 16 bb)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 248
diff changeset
129 self.git = Repo(self.gitdir)
1590c97d7af0 do not init the cache git repo unless needed (fixes issue 16 bb)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 248
diff changeset
130 else:
106
3aa2f6caed16 make the gitdir a constant
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 105
diff changeset
131 os.mkdir(self.gitdir)
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
132 self.git = Repo.init_bare(self.gitdir)
7
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
133
450
163ac98569d3 - add "author file" extension, allows an author translation map
Mike Bayer <mike_mp@zzzcomputing.com>
parents: 448
diff changeset
134 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
135 self.author_map = {}
163ac98569d3 - add "author file" extension, allows an author translation map
Mike Bayer <mike_mp@zzzcomputing.com>
parents: 448
diff changeset
136 if self.ui.config('git', 'authors'):
554
cac070a4b521 git_handler: replace with-statement with try-finally
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 553
diff changeset
137 f = open(self.repo.wjoin(
cac070a4b521 git_handler: replace with-statement with try-finally
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 553
diff changeset
138 self.ui.config('git', 'authors')))
cac070a4b521 git_handler: replace with-statement with try-finally
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 553
diff changeset
139 try:
450
163ac98569d3 - add "author file" extension, allows an author translation map
Mike Bayer <mike_mp@zzzcomputing.com>
parents: 448
diff changeset
140 for line in f:
163ac98569d3 - add "author file" extension, allows an author translation map
Mike Bayer <mike_mp@zzzcomputing.com>
parents: 448
diff changeset
141 line = line.strip()
163ac98569d3 - add "author file" extension, allows an author translation map
Mike Bayer <mike_mp@zzzcomputing.com>
parents: 448
diff changeset
142 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
143 continue
542
c9faba7d01f4 Precompile author file regular expression
Gregory Szorc <gregory.szorc@gmail.com>
parents: 541
diff changeset
144 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
145 self.author_map[from_] = to
554
cac070a4b521 git_handler: replace with-statement with try-finally
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 553
diff changeset
146 finally:
cac070a4b521 git_handler: replace with-statement with try-finally
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 553
diff changeset
147 f.close()
450
163ac98569d3 - add "author file" extension, allows an author translation map
Mike Bayer <mike_mp@zzzcomputing.com>
parents: 448
diff changeset
148
14
36e94e805fa7 added basic config file for remembering remote urls
Scott Chacon <schacon@gmail.com>
parents: 13
diff changeset
149 ## FILE LOAD AND SAVE METHODS
36e94e805fa7 added basic config file for remembering remote urls
Scott Chacon <schacon@gmail.com>
parents: 13
diff changeset
150
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
151 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
152 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
153 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
154
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
155 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
156 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
157
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
158 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
159 return self._map_hg.get(hgsha)
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
160
7
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
161 def load_map(self):
105
41e76444105c make git-mapfile and git-configfile constants
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 104
diff changeset
162 if os.path.exists(self.repo.join(self.mapfile)):
41e76444105c make git-mapfile and git-configfile constants
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 104
diff changeset
163 for line in self.repo.opener(self.mapfile):
7
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
164 gitsha, hgsha = line.strip().split(' ', 1)
552
bff92a208c3f git_handler: lazy-load mapping
Augie Fackler <raf@durin42.com>
parents: 489
diff changeset
165 self._map_git_real[gitsha] = hgsha
bff92a208c3f git_handler: lazy-load mapping
Augie Fackler <raf@durin42.com>
parents: 489
diff changeset
166 self._map_hg_real[hgsha] = gitsha
19
2be9c0bd88af Warn, but don't fail when bookmarks is not enabled.
Augie Fackler <durin42@gmail.com>
parents: 17
diff changeset
167
7
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
168 def save_map(self):
105
41e76444105c make git-mapfile and git-configfile constants
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 104
diff changeset
169 file = self.repo.opener(self.mapfile, 'w+', atomictemp=True)
238
028de6256c2b switch object mapping to hg->git since the many to one is that direction
Sverre Rabbelier <srabbelier@google.com>
parents: 237
diff changeset
170 for hgsha, gitsha in sorted(self._map_hg.iteritems()):
7
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
171 file.write("%s %s\n" % (gitsha, hgsha))
429
6674c0d42d68 Adapt to atomictempfile API changes from Mercurial.
Augie Fackler <durin42@gmail.com>
parents: 422
diff changeset
172 # If this complains that NoneType is not callable, then
6674c0d42d68 Adapt to atomictempfile API changes from Mercurial.
Augie Fackler <durin42@gmail.com>
parents: 422
diff changeset
173 # atomictempfile no longer has either of rename (pre-1.9) or
6674c0d42d68 Adapt to atomictempfile API changes from Mercurial.
Augie Fackler <durin42@gmail.com>
parents: 422
diff changeset
174 # close (post-1.9)
6674c0d42d68 Adapt to atomictempfile API changes from Mercurial.
Augie Fackler <durin42@gmail.com>
parents: 422
diff changeset
175 getattr(file, 'rename', getattr(file, 'close', None))()
19
2be9c0bd88af Warn, but don't fail when bookmarks is not enabled.
Augie Fackler <durin42@gmail.com>
parents: 17
diff changeset
176
187
5f196f80ffb3 Store git tags in .hg/git-tags and let localtags be *local*
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 186
diff changeset
177 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
178 self.tags = {}
5f196f80ffb3 Store git tags in .hg/git-tags and let localtags be *local*
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 186
diff changeset
179 if os.path.exists(self.repo.join(self.tagsfile)):
5f196f80ffb3 Store git tags in .hg/git-tags and let localtags be *local*
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 186
diff changeset
180 for line in self.repo.opener(self.tagsfile):
5f196f80ffb3 Store git tags in .hg/git-tags and let localtags be *local*
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 186
diff changeset
181 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
182 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
183
5f196f80ffb3 Store git tags in .hg/git-tags and let localtags be *local*
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 186
diff changeset
184 def save_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
185 file = self.repo.opener(self.tagsfile, 'w+', atomictemp=True)
5f196f80ffb3 Store git tags in .hg/git-tags and let localtags be *local*
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 186
diff changeset
186 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
187 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
188 file.write("%s %s\n" % (sha, name))
429
6674c0d42d68 Adapt to atomictempfile API changes from Mercurial.
Augie Fackler <durin42@gmail.com>
parents: 422
diff changeset
189 # If this complains that NoneType is not callable, then
6674c0d42d68 Adapt to atomictempfile API changes from Mercurial.
Augie Fackler <durin42@gmail.com>
parents: 422
diff changeset
190 # atomictempfile no longer has either of rename (pre-1.9) or
6674c0d42d68 Adapt to atomictempfile API changes from Mercurial.
Augie Fackler <durin42@gmail.com>
parents: 422
diff changeset
191 # close (post-1.9)
6674c0d42d68 Adapt to atomictempfile API changes from Mercurial.
Augie Fackler <durin42@gmail.com>
parents: 422
diff changeset
192 getattr(file, 'rename', getattr(file, 'close', None))()
187
5f196f80ffb3 Store git tags in .hg/git-tags and let localtags be *local*
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 186
diff changeset
193
14
36e94e805fa7 added basic config file for remembering remote urls
Scott Chacon <schacon@gmail.com>
parents: 13
diff changeset
194 ## END FILE LOAD AND SAVE METHODS
7
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
195
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
196 ## COMMANDS METHODS
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
197
137
5aefcbf1e50c add a gimport command
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 136
diff changeset
198 def import_commits(self, remote_name):
5aefcbf1e50c add a gimport command
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 136
diff changeset
199 self.import_git_objects(remote_name)
422
09cedf16ecc0 Fix all-version-tests.
Augie Fackler <durin42@gmail.com>
parents: 419
diff changeset
200 self.update_hg_bookmarks(self.git.get_refs())
137
5aefcbf1e50c add a gimport command
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 136
diff changeset
201 self.save_map()
5aefcbf1e50c add a gimport command
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 136
diff changeset
202
232
0ba1aee0467c initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 231
diff changeset
203 def fetch(self, remote, heads):
236
42ae65e6c1d1 save the map only once in export
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 235
diff changeset
204 self.export_commits()
232
0ba1aee0467c initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 231
diff changeset
205 refs = 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
206 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
207
397
60d181f9ecc3 Make pull results more like hg pulls.
Brendan Cully <brendan@kublai.com>
parents: 395
diff changeset
208 oldrefs = self.git.get_refs()
56
5185af4e649a hg gfetch now works
Scott Chacon <schacon@gmail.com>
parents: 54
diff changeset
209 if refs:
149
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
210 self.import_git_objects(remote_name, refs)
187
5f196f80ffb3 Store git tags in .hg/git-tags and let localtags be *local*
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 186
diff changeset
211 self.import_tags(refs)
184
7bf98d3085f4 Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 183
diff changeset
212 self.update_hg_bookmarks(refs)
7bf98d3085f4 Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 183
diff changeset
213 if remote_name:
7bf98d3085f4 Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 183
diff changeset
214 self.update_remote_branches(remote_name, refs)
7bf98d3085f4 Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 183
diff changeset
215 elif not self.paths:
7bf98d3085f4 Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 183
diff changeset
216 # intial cloning
7bf98d3085f4 Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 183
diff changeset
217 self.update_remote_branches('default', refs)
387
ed28dd69df61 git_handler: support versions of hg without bookmarks
Augie Fackler <durin42@gmail.com>
parents: 385
diff changeset
218
384
fc37cb795b51 activate a tipmost bookmark (git branch) after clone
Adrian Sampson <adrian@radbox.org>
parents: 382
diff changeset
219 # "Activate" a tipmost bookmark.
387
ed28dd69df61 git_handler: support versions of hg without bookmarks
Augie Fackler <durin42@gmail.com>
parents: 385
diff changeset
220 bms = getattr(self.repo['tip'], 'bookmarks',
ed28dd69df61 git_handler: support versions of hg without bookmarks
Augie Fackler <durin42@gmail.com>
parents: 385
diff changeset
221 lambda : None)()
384
fc37cb795b51 activate a tipmost bookmark (git branch) after clone
Adrian Sampson <adrian@radbox.org>
parents: 382
diff changeset
222 if bms:
fc37cb795b51 activate a tipmost bookmark (git branch) after clone
Adrian Sampson <adrian@radbox.org>
parents: 382
diff changeset
223 bookmarks.setcurrent(self.repo, bms[0])
397
60d181f9ecc3 Make pull results more like hg pulls.
Brendan Cully <brendan@kublai.com>
parents: 395
diff changeset
224
60d181f9ecc3 Make pull results more like hg pulls.
Brendan Cully <brendan@kublai.com>
parents: 395
diff changeset
225 def remoteref(ref):
60d181f9ecc3 Make pull results more like hg pulls.
Brendan Cully <brendan@kublai.com>
parents: 395
diff changeset
226 rn = remote_name or 'default'
60d181f9ecc3 Make pull results more like hg pulls.
Brendan Cully <brendan@kublai.com>
parents: 395
diff changeset
227 return 'refs/remotes/' + rn + ref[10:]
60d181f9ecc3 Make pull results more like hg pulls.
Brendan Cully <brendan@kublai.com>
parents: 395
diff changeset
228
408
2dcfd4bbfc1a Support for hg incoming
Brendan Cully <brendan@kublai.com>
parents: 406
diff changeset
229 modheads = [refs[k] for k in refs if k.startswith('refs/heads/')
2dcfd4bbfc1a Support for hg incoming
Brendan Cully <brendan@kublai.com>
parents: 406
diff changeset
230 and not k.endswith('^{}')
2dcfd4bbfc1a Support for hg incoming
Brendan Cully <brendan@kublai.com>
parents: 406
diff changeset
231 and refs[k] != oldrefs.get(remoteref(k))]
397
60d181f9ecc3 Make pull results more like hg pulls.
Brendan Cully <brendan@kublai.com>
parents: 395
diff changeset
232
60d181f9ecc3 Make pull results more like hg pulls.
Brendan Cully <brendan@kublai.com>
parents: 395
diff changeset
233 if not modheads:
60d181f9ecc3 Make pull results more like hg pulls.
Brendan Cully <brendan@kublai.com>
parents: 395
diff changeset
234 self.ui.status(_("no changes found\n"))
184
7bf98d3085f4 Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 183
diff changeset
235
7
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
236 self.save_map()
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
237
397
60d181f9ecc3 Make pull results more like hg pulls.
Brendan Cully <brendan@kublai.com>
parents: 395
diff changeset
238 return len(modheads)
60d181f9ecc3 Make pull results more like hg pulls.
Brendan Cully <brendan@kublai.com>
parents: 395
diff changeset
239
236
42ae65e6c1d1 save the map only once in export
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 235
diff changeset
240 def export_commits(self):
42ae65e6c1d1 save the map only once in export
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 235
diff changeset
241 try:
172
ac92cdc45ceb not trying to write the same tree twice
Scott Chacon <schacon@gmail.com>
parents: 171
diff changeset
242 self.export_git_objects()
236
42ae65e6c1d1 save the map only once in export
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 235
diff changeset
243 self.export_hg_tags()
42ae65e6c1d1 save the map only once in export
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 235
diff changeset
244 self.update_references()
42ae65e6c1d1 save the map only once in export
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 235
diff changeset
245 finally:
42ae65e6c1d1 save the map only once in export
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 235
diff changeset
246 self.save_map()
97
f0628f5270b6 add gexport command
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 96
diff changeset
247
231
bdaec2a079ce initial support for 'hg outgoing'
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 230
diff changeset
248 def get_refs(self, remote):
bdaec2a079ce initial support for 'hg outgoing'
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 230
diff changeset
249 self.export_commits()
bdaec2a079ce initial support for 'hg outgoing'
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 230
diff changeset
250 client, path = self.get_transport_and_path(remote)
bdaec2a079ce initial support for 'hg outgoing'
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 230
diff changeset
251 old_refs = {}
bdaec2a079ce initial support for 'hg outgoing'
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 230
diff changeset
252 new_refs = {}
bdaec2a079ce initial support for 'hg outgoing'
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 230
diff changeset
253 def changed(refs):
bdaec2a079ce initial support for 'hg outgoing'
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 230
diff changeset
254 old_refs.update(refs)
bdaec2a079ce initial support for 'hg outgoing'
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 230
diff changeset
255 to_push = set(self.local_heads().values() + self.tags.values())
bdaec2a079ce initial support for 'hg outgoing'
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 230
diff changeset
256 new_refs.update(self.get_changed_refs(refs, to_push, True))
544
ebf4ea20ade5 outgoing: don't delete remote refs
David M. Carr <david@carrclan.us>
parents: 543
diff changeset
257 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
258
bdaec2a079ce initial support for 'hg outgoing'
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 230
diff changeset
259 try:
442
553dd7078058 Update for newer dulwich and hg versions.
Augie Fackler <durin42@gmail.com>
parents: 441
diff changeset
260 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
261
53b731d2a3e2 outgoing: don't crash when there are unpulled changesets
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 242
diff changeset
262 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
263 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
264 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
265 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
266 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
267 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
268 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
269 old[bin(old_ref)] = 1
231
bdaec2a079ce initial support for 'hg outgoing'
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 230
diff changeset
270
bdaec2a079ce initial support for 'hg outgoing'
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 230
diff changeset
271 return old, new
391
9b6597b70839 Improve error reporting in get_refs
Brendan Cully <brendan@kublai.com>
parents: 387
diff changeset
272 except (HangupException, GitProtocolError), e:
9b6597b70839 Improve error reporting in get_refs
Brendan Cully <brendan@kublai.com>
parents: 387
diff changeset
273 raise hgutil.Abort(_("git remote error: ") + str(e))
231
bdaec2a079ce initial support for 'hg outgoing'
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 230
diff changeset
274
230
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
275 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
276 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
277 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
278 remote_name = self.remote_name(remote)
40edc4b814e4 Reorganize push for more symmetry with fetch
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 195
diff changeset
279
487
68e5dddc7a20 push: return 1 if no changes found, 0 if success
David M. Carr <david@carrclan.us>
parents: 475
diff changeset
280 if remote_name and new_refs:
488
4793c3725abe push: only output updated refs
David M. Carr <david@carrclan.us>
parents: 487
diff changeset
281 for ref, new_sha in new_refs.iteritems():
592
a6b7ad535244 push: provide better output about changed references (issue #64)
David M. Carr <david@carrclan.us>
parents: 591
diff changeset
282 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
283 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
284 if self.ui.verbose:
a6b7ad535244 push: provide better output about changed references (issue #64)
David M. Carr <david@carrclan.us>
parents: 591
diff changeset
285 self.ui.note("adding reference %s::%s => GIT:%s\n" %
559
d4ccec82b816 push: suppress ref output by default
David M. Carr <david@carrclan.us>
parents: 557
diff changeset
286 (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
287 else:
a6b7ad535244 push: provide better output about changed references (issue #64)
David M. Carr <david@carrclan.us>
parents: 591
diff changeset
288 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
289 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
290 if self.ui.verbose:
a6b7ad535244 push: provide better output about changed references (issue #64)
David M. Carr <david@carrclan.us>
parents: 591
diff changeset
291 self.ui.note("updating reference %s::%s => GIT:%s\n" %
a6b7ad535244 push: provide better output about changed references (issue #64)
David M. Carr <david@carrclan.us>
parents: 591
diff changeset
292 (remote_name, ref, new_sha[0:8]))
a6b7ad535244 push: provide better output about changed references (issue #64)
David M. Carr <david@carrclan.us>
parents: 591
diff changeset
293 else:
a6b7ad535244 push: provide better output about changed references (issue #64)
David M. Carr <david@carrclan.us>
parents: 591
diff changeset
294 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
295 else:
592
a6b7ad535244 push: provide better output about changed references (issue #64)
David M. Carr <david@carrclan.us>
parents: 591
diff changeset
296 self.ui.debug("unchanged reference %s::%s => GIT:%s\n" %
488
4793c3725abe push: only output updated refs
David M. Carr <david@carrclan.us>
parents: 487
diff changeset
297 (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
298
487
68e5dddc7a20 push: return 1 if no changes found, 0 if success
David M. Carr <david@carrclan.us>
parents: 475
diff changeset
299 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
300 if old_refs == new_refs:
489
ccd521a1f585 push: state when no changes are found
David M. Carr <david@carrclan.us>
parents: 488
diff changeset
301 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
302 ret = None
68e5dddc7a20 push: return 1 if no changes found, 0 if success
David M. Carr <david@carrclan.us>
parents: 475
diff changeset
303 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
304 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
305 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
306 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
307 else:
68e5dddc7a20 push: return 1 if no changes found, 0 if success
David M. Carr <david@carrclan.us>
parents: 475
diff changeset
308 ret = 1
68e5dddc7a20 push: return 1 if no changes found, 0 if success
David M. Carr <david@carrclan.us>
parents: 475
diff changeset
309 return ret
196
40edc4b814e4 Reorganize push for more symmetry with fetch
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 195
diff changeset
310
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
311 def clear(self):
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
312 mapfile = self.repo.join(self.mapfile)
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
313 if os.path.exists(self.gitdir):
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
314 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
315 for name in files:
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
316 os.remove(os.path.join(root, name))
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
317 for name in dirs:
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
318 os.rmdir(os.path.join(root, name))
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
319 os.rmdir(self.gitdir)
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
320 if os.path.exists(mapfile):
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
321 os.remove(mapfile)
124
9dafb9ac24ff hg bookmarks to local git branches
Ian Dees <undees@gmail.com>
parents: 118
diff changeset
322
408
2dcfd4bbfc1a Support for hg incoming
Brendan Cully <brendan@kublai.com>
parents: 406
diff changeset
323 # incoming support
2dcfd4bbfc1a Support for hg incoming
Brendan Cully <brendan@kublai.com>
parents: 406
diff changeset
324 def getremotechanges(self, remote, revs):
2dcfd4bbfc1a Support for hg incoming
Brendan Cully <brendan@kublai.com>
parents: 406
diff changeset
325 self.export_commits()
2dcfd4bbfc1a Support for hg incoming
Brendan Cully <brendan@kublai.com>
parents: 406
diff changeset
326 refs = self.fetch_pack(remote.path, revs)
2dcfd4bbfc1a Support for hg incoming
Brendan Cully <brendan@kublai.com>
parents: 406
diff changeset
327
2dcfd4bbfc1a Support for hg incoming
Brendan Cully <brendan@kublai.com>
parents: 406
diff changeset
328 # refs contains all remote refs. Prune to only those requested.
2dcfd4bbfc1a Support for hg incoming
Brendan Cully <brendan@kublai.com>
parents: 406
diff changeset
329 if revs:
2dcfd4bbfc1a Support for hg incoming
Brendan Cully <brendan@kublai.com>
parents: 406
diff changeset
330 reqrefs = {}
2dcfd4bbfc1a Support for hg incoming
Brendan Cully <brendan@kublai.com>
parents: 406
diff changeset
331 for rev in revs:
2dcfd4bbfc1a Support for hg incoming
Brendan Cully <brendan@kublai.com>
parents: 406
diff changeset
332 for n in ('refs/heads/' + rev, 'refs/tags/' + rev):
2dcfd4bbfc1a Support for hg incoming
Brendan Cully <brendan@kublai.com>
parents: 406
diff changeset
333 if n in refs:
2dcfd4bbfc1a Support for hg incoming
Brendan Cully <brendan@kublai.com>
parents: 406
diff changeset
334 reqrefs[n] = refs[n]
2dcfd4bbfc1a Support for hg incoming
Brendan Cully <brendan@kublai.com>
parents: 406
diff changeset
335 else:
2dcfd4bbfc1a Support for hg incoming
Brendan Cully <brendan@kublai.com>
parents: 406
diff changeset
336 reqrefs = refs
2dcfd4bbfc1a Support for hg incoming
Brendan Cully <brendan@kublai.com>
parents: 406
diff changeset
337
2dcfd4bbfc1a Support for hg incoming
Brendan Cully <brendan@kublai.com>
parents: 406
diff changeset
338 commits = [bin(c) for c in self.getnewgitcommits(reqrefs)[1]]
2dcfd4bbfc1a Support for hg incoming
Brendan Cully <brendan@kublai.com>
parents: 406
diff changeset
339
2dcfd4bbfc1a Support for hg incoming
Brendan Cully <brendan@kublai.com>
parents: 406
diff changeset
340 b = overlayrepo(self, commits, refs)
2dcfd4bbfc1a Support for hg incoming
Brendan Cully <brendan@kublai.com>
parents: 406
diff changeset
341
2dcfd4bbfc1a Support for hg incoming
Brendan Cully <brendan@kublai.com>
parents: 406
diff changeset
342 return (b, commits, lambda: None)
2dcfd4bbfc1a Support for hg incoming
Brendan Cully <brendan@kublai.com>
parents: 406
diff changeset
343
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
344 ## CHANGESET CONVERSION METHODS
125
5b702bbf078f local git branches to remotes
Ian Dees <undees@gmail.com>
parents: 124
diff changeset
345
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
346 def export_git_objects(self):
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
347 self.init_if_missing()
1590c97d7af0 do not init the cache git repo unless needed (fixes issue 16 bb)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 248
diff changeset
348
190
6fbdf1afe032 Better reporting of the number of commits to convert
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 188
diff changeset
349 nodes = [self.repo.lookup(n) for n in self.repo]
6fbdf1afe032 Better reporting of the number of commits to convert
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 188
diff changeset
350 export = [node for node in nodes if not hex(node) in self._map_hg]
6fbdf1afe032 Better reporting of the number of commits to convert
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 188
diff changeset
351 total = len(export)
392
8bb058d6a9ee Message cleanups
Brendan Cully <brendan@kublai.com>
parents: 391
diff changeset
352 if total:
560
9c71a6f00863 push: suppress "exporting hg objects to git" message
David M. Carr <david@carrclan.us>
parents: 559
diff changeset
353 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
354
d6b9c30a3e0f Export Git objects from incremental Mercurial changes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 593
diff changeset
355 # 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
356 # for all other changesets are already present in the Git repository.
d6b9c30a3e0f Export Git objects from incremental Mercurial changes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 593
diff changeset
357 # This assertion is necessary to prevent redundant work.
d6b9c30a3e0f Export Git objects from incremental Mercurial changes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 593
diff changeset
358 exporter = hg2git.IncrementalChangesetExporter(self.repo)
d6b9c30a3e0f Export Git objects from incremental Mercurial changes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 593
diff changeset
359
190
6fbdf1afe032 Better reporting of the number of commits to convert
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 188
diff changeset
360 for i, rev in enumerate(export):
392
8bb058d6a9ee Message cleanups
Brendan Cully <brendan@kublai.com>
parents: 391
diff changeset
361 util.progress(self.ui, 'exporting', i, total=total)
159
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
362 ctx = self.repo.changectx(rev)
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
363 state = ctx.extra().get('hg-git', None)
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
364 if state == 'octopus':
293
8aaae306d46f git_handler: 80 columns cleanup
Augie Fackler <durin42@gmail.com>
parents: 292
diff changeset
365 self.ui.debug("revision %d is a part "
8aaae306d46f git_handler: 80 columns cleanup
Augie Fackler <durin42@gmail.com>
parents: 292
diff changeset
366 "of octopus explosion\n" % ctx.rev())
159
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
367 continue
596
d6b9c30a3e0f Export Git objects from incremental Mercurial changes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 593
diff changeset
368 self.export_hg_commit(rev, exporter)
374
f008197045d3 progress: use gerund form for import
timeless <timeless@gmail.com>
parents: 369
diff changeset
369 util.progress(self.ui, 'importing', None, total=total)
286
0661d5721ad7 git_handler: use progress API instead of reinventing the wheel
Augie Fackler <durin42@gmail.com>
parents: 285
diff changeset
370
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
371
24
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
372 # 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
373 # 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
374 # 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
375 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
376 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
377
203
104a4fd6a0af trying to fix some of the broken tests
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 199
diff changeset
378 oldenc = self.swap_out_encoding()
104a4fd6a0af trying to fix some of the broken tests
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 199
diff changeset
379
159
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
380 ctx = self.repo.changectx(rev)
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
381 extra = ctx.extra()
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
382
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
383 commit = Commit()
68
d28d3763eda3 Deal with hg authors missing email attributes.
Chris Wanstrath <chris@ozmm.org>
parents: 65
diff changeset
384
235
912d6a5837c8 reorganize export_hg_commit
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 234
diff changeset
385 (time, timezone) = ctx.date()
593
ce6ad4c0cba7 scrub bad timezone values before dulwich sees them
Hal Wine <hwine@mozilla.com>
parents: 592
diff changeset
386 # 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
387 # 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
388 # 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
389 # 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
390 # simplest and round down.
ce6ad4c0cba7 scrub bad timezone values before dulwich sees them
Hal Wine <hwine@mozilla.com>
parents: 592
diff changeset
391 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
392 commit.author = self.get_git_author(ctx)
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
393 commit.author_time = int(time)
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
394 commit.author_timezone = -timezone
186
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
395
89
e35ed99fa691 committer info now being kept properly
Scott Chacon <schacon@gmail.com>
parents: 88
diff changeset
396 if 'committer' in extra:
131
dd6c77ec206c store commitdate in mercurial's internal format.
Dmitriy Taychenachev <dimichxp@gmail.com>
parents: 129
diff changeset
397 # fixup timezone
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
398 (name, timestamp, timezone) = extra['committer'].rsplit(' ', 2)
237
16f671995881 deal correctly with old timezone format in extra committer
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 236
diff changeset
399 commit.committer = name
16f671995881 deal correctly with old timezone format in extra committer
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 236
diff changeset
400 commit.commit_time = timestamp
16f671995881 deal correctly with old timezone format in extra committer
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 236
diff changeset
401
16f671995881 deal correctly with old timezone format in extra committer
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 236
diff changeset
402 # work around a timezone format change
16f671995881 deal correctly with old timezone format in extra committer
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 236
diff changeset
403 if int(timezone) % 60 != 0: #pragma: no cover
16f671995881 deal correctly with old timezone format in extra committer
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 236
diff changeset
404 timezone = parse_timezone(timezone)
360
c1fa188046d7 Looks like the latest version of Dulwich returns a tuple here. Let's handle that
Mike Blume <mike@loggly.com>
parents: 338
diff changeset
405 # Newer versions of Dulwich return a tuple here
c1fa188046d7 Looks like the latest version of Dulwich returns a tuple here. Let's handle that
Mike Blume <mike@loggly.com>
parents: 338
diff changeset
406 if isinstance(timezone, tuple):
c1fa188046d7 Looks like the latest version of Dulwich returns a tuple here. Let's handle that
Mike Blume <mike@loggly.com>
parents: 338
diff changeset
407 timezone, neg_utc = timezone
361
4e1ac77815c3 fix typo -- my bad >.<
Mike Blume <mike@loggly.com>
parents: 360
diff changeset
408 commit._commit_timezone_neg_utc = neg_utc
237
16f671995881 deal correctly with old timezone format in extra committer
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 236
diff changeset
409 else:
16f671995881 deal correctly with old timezone format in extra committer
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 236
diff changeset
410 timezone = -int(timezone)
16f671995881 deal correctly with old timezone format in extra committer
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 236
diff changeset
411 commit.commit_timezone = timezone
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
412 else:
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
413 commit.committer = commit.author
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
414 commit.commit_time = commit.author_time
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
415 commit.commit_timezone = commit.author_timezone
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
416
239
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
417 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
418 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
419 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
420 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
421 if git_sha:
543
5a688ad69449 Verify tree and parent objects are in Git repo
Gregory Szorc <gregory.szorc@gmail.com>
parents: 542
diff changeset
422 if git_sha not in self.git.object_store:
5a688ad69449 Verify tree and parent objects are in Git repo
Gregory Szorc <gregory.szorc@gmail.com>
parents: 542
diff changeset
423 raise hgutil.Abort(_('Parent SHA-1 not present in Git'
5a688ad69449 Verify tree and parent objects are in Git repo
Gregory Szorc <gregory.szorc@gmail.com>
parents: 542
diff changeset
424 'repo: %s' % git_sha))
5a688ad69449 Verify tree and parent objects are in Git repo
Gregory Szorc <gregory.szorc@gmail.com>
parents: 542
diff changeset
425
239
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
426 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
427
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
428 commit.message = self.get_git_message(ctx)
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
429
118
b3be536e3f50 handles git commit encoding fields now
Scott Chacon <schacon@gmail.com>
parents: 113
diff changeset
430 if 'encoding' in extra:
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
431 commit.encoding = extra['encoding']
89
e35ed99fa691 committer info now being kept properly
Scott Chacon <schacon@gmail.com>
parents: 88
diff changeset
432
596
d6b9c30a3e0f Export Git objects from incremental Mercurial changes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 593
diff changeset
433 for obj, nodeid in exporter.update_changeset(ctx):
d6b9c30a3e0f Export Git objects from incremental Mercurial changes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 593
diff changeset
434 self.git.object_store.add_object(obj)
d6b9c30a3e0f Export Git objects from incremental Mercurial changes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 593
diff changeset
435
d6b9c30a3e0f Export Git objects from incremental Mercurial changes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 593
diff changeset
436 tree_sha = exporter.root_tree_sha
d6b9c30a3e0f Export Git objects from incremental Mercurial changes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 593
diff changeset
437
543
5a688ad69449 Verify tree and parent objects are in Git repo
Gregory Szorc <gregory.szorc@gmail.com>
parents: 542
diff changeset
438 if tree_sha not in self.git.object_store:
5a688ad69449 Verify tree and parent objects are in Git repo
Gregory Szorc <gregory.szorc@gmail.com>
parents: 542
diff changeset
439 raise hgutil.Abort(_('Tree SHA-1 not present in Git repo: %s' %
5a688ad69449 Verify tree and parent objects are in Git repo
Gregory Szorc <gregory.szorc@gmail.com>
parents: 542
diff changeset
440 tree_sha))
5a688ad69449 Verify tree and parent objects are in Git repo
Gregory Szorc <gregory.szorc@gmail.com>
parents: 542
diff changeset
441
239
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
442 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
443
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
444 self.git.object_store.add_object(commit)
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
445 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
446
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
447 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
448 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
449
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
450 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
451 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
452
e58a6d0b80e2 Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents: 447
diff changeset
453 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
454 command:
e58a6d0b80e2 Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents: 447
diff changeset
455
e58a6d0b80e2 Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents: 447
diff changeset
456 [...] 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
457
e58a6d0b80e2 Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents: 447
diff changeset
458 committer
e58a6d0b80e2 Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents: 447
diff changeset
459 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
460 and when they made it.
e58a6d0b80e2 Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents: 447
diff changeset
461
e58a6d0b80e2 Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents: 447
diff changeset
462 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
463 "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
464 ("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
465 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
466 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
467 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
468 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
469 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
470
e58a6d0b80e2 Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents: 447
diff changeset
471 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
472 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
473 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
474 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
475 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
476 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
477 convenience.
e58a6d0b80e2 Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents: 447
diff changeset
478
e58a6d0b80e2 Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents: 447
diff changeset
479 TESTS:
e58a6d0b80e2 Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents: 447
diff changeset
480
e58a6d0b80e2 Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents: 447
diff changeset
481 >>> from mercurial.ui import ui
e58a6d0b80e2 Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents: 447
diff changeset
482 >>> g = GitHandler('', ui()).get_valid_git_username_email
e58a6d0b80e2 Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents: 447
diff changeset
483 >>> g('John Doe')
e58a6d0b80e2 Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents: 447
diff changeset
484 'John Doe'
e58a6d0b80e2 Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents: 447
diff changeset
485 >>> g('john@doe.com')
e58a6d0b80e2 Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents: 447
diff changeset
486 'john@doe.com'
e58a6d0b80e2 Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents: 447
diff changeset
487 >>> g(' <john@doe.com> ')
e58a6d0b80e2 Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents: 447
diff changeset
488 'john@doe.com'
e58a6d0b80e2 Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents: 447
diff changeset
489 >>> g(' <random<\n<garbage\n> > > ')
e58a6d0b80e2 Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents: 447
diff changeset
490 'random???garbage?'
e58a6d0b80e2 Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents: 447
diff changeset
491 >>> 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
492 '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
493 """
539
7bf60690386c Precompile Git username sanitizing regular expression
Gregory Szorc <gregory.szorc@gmail.com>
parents: 538
diff changeset
494 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
495
239
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
496 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
497 # 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
498 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
499
450
163ac98569d3 - add "author file" extension, allows an author translation map
Mike Bayer <mike_mp@zzzcomputing.com>
parents: 448
diff changeset
500 # see if a translation exists
537
6e05aa1b536d Optimize get_git_author
Gregory Szorc <gregory.szorc@gmail.com>
parents: 523
diff changeset
501 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
502
239
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
503 # check for git author pattern compliance
537
6e05aa1b536d Optimize get_git_author
Gregory Szorc <gregory.szorc@gmail.com>
parents: 523
diff changeset
504 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
505
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
506 if a:
448
e58a6d0b80e2 Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents: 447
diff changeset
507 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
508 email = self.get_valid_git_username_email(a.group(2))
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
509 if a.group(3) != 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
510 name += ' ext:(' + urllib.quote(a.group(3)) + ')'
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
511 author = self.get_valid_git_username_email(name) + ' <' + 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
512 elif '@' in author:
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
513 author = self.get_valid_git_username_email(author) + ' <' + 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
514 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
515 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
516
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
517 if 'author' in ctx.extra():
307
7dfe8be21135 handle apply_delta() return value correctly
Tay Ray Chuan <rctay89@gmail.com>
parents: 302
diff changeset
518 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
519
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
520 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
521
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
522 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
523 def is_octopus_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
524 return ctx.extra().get('hg-git', None) in ('octopus', '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
525
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
526 parents = []
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
527 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
528 # 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
529 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
530 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
531 (p1, p2) = part.parents()
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
532 assert not is_octopus_part(p1)
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
533 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
534 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
535 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
536 else:
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
537 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
538
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
539 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
540
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
541 def get_git_message(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
542 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
543
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
544 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
545 if 'message' in extra:
307
7dfe8be21135 handle apply_delta() return value correctly
Tay Ray Chuan <rctay89@gmail.com>
parents: 302
diff changeset
546 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
547
54
f6e11b9d7562 not adding HG extra info if commits were on the default branch
Scott Chacon <schacon@gmail.com>
parents: 53
diff changeset
548 # HG EXTRA INFORMATION
f6e11b9d7562 not adding HG extra info if commits were on the default branch
Scott Chacon <schacon@gmail.com>
parents: 53
diff changeset
549 add_extras = False
67
759ac56497e7 adding hg explicit file renames to the git commit message
Scott Chacon <schacon@gmail.com>
parents: 65
diff changeset
550 extra_message = ''
54
f6e11b9d7562 not adding HG extra info if commits were on the default branch
Scott Chacon <schacon@gmail.com>
parents: 53
diff changeset
551 if not ctx.branch() == 'default':
f6e11b9d7562 not adding HG extra info if commits were on the default branch
Scott Chacon <schacon@gmail.com>
parents: 53
diff changeset
552 add_extras = True
67
759ac56497e7 adding hg explicit file renames to the git commit message
Scott Chacon <schacon@gmail.com>
parents: 65
diff changeset
553 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
554
239
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
555 renames = []
247
3c01e07b0252 look for renamed files only in files modified by the commit
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 245
diff changeset
556 for f in ctx.files():
3c01e07b0252 look for renamed files only in files modified by the commit
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 245
diff changeset
557 if f not in ctx.manifest():
3c01e07b0252 look for renamed files only in files modified by the commit
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 245
diff changeset
558 continue
239
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
559 rename = ctx.filectx(f).renamed()
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
560 if rename:
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
561 renames.append((rename[0], f))
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
562
67
759ac56497e7 adding hg explicit file renames to the git commit message
Scott Chacon <schacon@gmail.com>
parents: 65
diff changeset
563 if renames:
759ac56497e7 adding hg explicit file renames to the git commit message
Scott Chacon <schacon@gmail.com>
parents: 65
diff changeset
564 add_extras = True
759ac56497e7 adding hg explicit file renames to the git commit message
Scott Chacon <schacon@gmail.com>
parents: 65
diff changeset
565 for oldfile, newfile in renames:
759ac56497e7 adding hg explicit file renames to the git commit message
Scott Chacon <schacon@gmail.com>
parents: 65
diff changeset
566 extra_message += "rename : " + oldfile + " => " + newfile + "\n"
164
7e98757deadc author and extra data fixes
Scott Chacon <schacon@gmail.com>
parents: 162
diff changeset
567
7e98757deadc author and extra data fixes
Scott Chacon <schacon@gmail.com>
parents: 162
diff changeset
568 for key, value in extra.iteritems():
203
104a4fd6a0af trying to fix some of the broken tests
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 199
diff changeset
569 if key in ('author', 'committer', 'encoding', 'message', 'branch', 'hg-git'):
164
7e98757deadc author and extra data fixes
Scott Chacon <schacon@gmail.com>
parents: 162
diff changeset
570 continue
7e98757deadc author and extra data fixes
Scott Chacon <schacon@gmail.com>
parents: 162
diff changeset
571 else:
181
8690377c3ce9 Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 179
diff changeset
572 add_extras = True
164
7e98757deadc author and extra data fixes
Scott Chacon <schacon@gmail.com>
parents: 162
diff changeset
573 extra_message += "extra : " + key + " : " + urllib.quote(value) + "\n"
7e98757deadc author and extra data fixes
Scott Chacon <schacon@gmail.com>
parents: 162
diff changeset
574
54
f6e11b9d7562 not adding HG extra info if commits were on the default branch
Scott Chacon <schacon@gmail.com>
parents: 53
diff changeset
575 if add_extras:
239
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
576 message += "\n--HG--\n" + extra_message
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
577
239
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
578 return message
65
5ed8316d3cfa Start using reasonable ui.{status,debug,warn} calls instead of print.
Augie Fackler <durin42@gmail.com>
parents: 56
diff changeset
579
408
2dcfd4bbfc1a Support for hg incoming
Brendan Cully <brendan@kublai.com>
parents: 406
diff changeset
580 def getnewgitcommits(self, refs=None):
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
581 self.init_if_missing()
1590c97d7af0 do not init the cache git repo unless needed (fixes issue 16 bb)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 248
diff changeset
582
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
583 # import heads and fetched tags as remote references
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
584 todo = []
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
585 done = set()
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
586 convert_list = {}
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
587
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
588 # get a list of all the head shas
282
8655c071a15d make sure no tag object are included in the DAG we build
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 276
diff changeset
589 seenheads = set()
8655c071a15d make sure no tag object are included in the DAG we build
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 276
diff changeset
590 if refs is None:
288
efe9e6a9235f fix gimport and add test for using to work on hg repos from git (issue 73)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 287
diff changeset
591 refs = self.git.refs.as_dict()
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
592 if refs:
282
8655c071a15d make sure no tag object are included in the DAG we build
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 276
diff changeset
593 for sha in refs.itervalues():
8655c071a15d make sure no tag object are included in the DAG we build
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 276
diff changeset
594 # refs contains all the refs in the server, not just the ones
8655c071a15d make sure no tag object are included in the DAG we build
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 276
diff changeset
595 # we are pulling
8655c071a15d make sure no tag object are included in the DAG we build
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 276
diff changeset
596 if sha in self.git.object_store:
8655c071a15d make sure no tag object are included in the DAG we build
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 276
diff changeset
597 obj = self.git.get_object(sha)
8655c071a15d make sure no tag object are included in the DAG we build
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 276
diff changeset
598 while isinstance(obj, Tag):
337
6cea997ee302 enforce stricter matching for pull -r
Tay Ray Chuan <rctay89@gmail.com>
parents: 258
diff changeset
599 obj_type, sha = obj.object
282
8655c071a15d make sure no tag object are included in the DAG we build
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 276
diff changeset
600 obj = self.git.get_object(sha)
8655c071a15d make sure no tag object are included in the DAG we build
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 276
diff changeset
601 if isinstance (obj, Commit) and sha not in seenheads:
8655c071a15d make sure no tag object are included in the DAG we build
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 276
diff changeset
602 seenheads.add(sha)
8655c071a15d make sure no tag object are included in the DAG we build
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 276
diff changeset
603 todo.append(sha)
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
604
284
12cfa77a2ab0 sort heads by commit date in topological sort
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 283
diff changeset
605 # sort by commit date
12cfa77a2ab0 sort heads by commit date in topological sort
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 283
diff changeset
606 def commitdate(sha):
12cfa77a2ab0 sort heads by commit date in topological sort
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 283
diff changeset
607 obj = self.git.get_object(sha)
12cfa77a2ab0 sort heads by commit date in topological sort
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 283
diff changeset
608 return obj.commit_time-obj.commit_timezone
12cfa77a2ab0 sort heads by commit date in topological sort
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 283
diff changeset
609
12cfa77a2ab0 sort heads by commit date in topological sort
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 283
diff changeset
610 todo.sort(key=commitdate, reverse=True)
12cfa77a2ab0 sort heads by commit date in topological sort
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 283
diff changeset
611
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
612 # traverse the heads getting a list of all the unique commits
283
90458271e374 use a simple toposort algorithm for DAG (post order from a DFS from the heads)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 282
diff changeset
613 commits = []
90458271e374 use a simple toposort algorithm for DAG (post order from a DFS from the heads)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 282
diff changeset
614 seen = set(todo)
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
615 while todo:
283
90458271e374 use a simple toposort algorithm for DAG (post order from a DFS from the heads)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 282
diff changeset
616 sha = todo[-1]
90458271e374 use a simple toposort algorithm for DAG (post order from a DFS from the heads)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 282
diff changeset
617 if sha in done:
90458271e374 use a simple toposort algorithm for DAG (post order from a DFS from the heads)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 282
diff changeset
618 todo.pop()
90458271e374 use a simple toposort algorithm for DAG (post order from a DFS from the heads)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 282
diff changeset
619 continue
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
620 assert isinstance(sha, str)
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
621 obj = self.git.get_object(sha)
282
8655c071a15d make sure no tag object are included in the DAG we build
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 276
diff changeset
622 assert isinstance(obj, Commit)
283
90458271e374 use a simple toposort algorithm for DAG (post order from a DFS from the heads)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 282
diff changeset
623 for p in obj.parents:
90458271e374 use a simple toposort algorithm for DAG (post order from a DFS from the heads)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 282
diff changeset
624 if p not in done:
90458271e374 use a simple toposort algorithm for DAG (post order from a DFS from the heads)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 282
diff changeset
625 todo.append(p)
90458271e374 use a simple toposort algorithm for DAG (post order from a DFS from the heads)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 282
diff changeset
626 break
90458271e374 use a simple toposort algorithm for DAG (post order from a DFS from the heads)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 282
diff changeset
627 else:
90458271e374 use a simple toposort algorithm for DAG (post order from a DFS from the heads)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 282
diff changeset
628 commits.append(sha)
90458271e374 use a simple toposort algorithm for DAG (post order from a DFS from the heads)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 282
diff changeset
629 convert_list[sha] = obj
90458271e374 use a simple toposort algorithm for DAG (post order from a DFS from the heads)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 282
diff changeset
630 done.add(sha)
90458271e374 use a simple toposort algorithm for DAG (post order from a DFS from the heads)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 282
diff changeset
631 todo.pop()
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
632
408
2dcfd4bbfc1a Support for hg incoming
Brendan Cully <brendan@kublai.com>
parents: 406
diff changeset
633 return convert_list, [commit for commit in commits if not commit in self._map_git]
2dcfd4bbfc1a Support for hg incoming
Brendan Cully <brendan@kublai.com>
parents: 406
diff changeset
634
2dcfd4bbfc1a Support for hg incoming
Brendan Cully <brendan@kublai.com>
parents: 406
diff changeset
635 def import_git_objects(self, remote_name=None, refs=None):
2dcfd4bbfc1a Support for hg incoming
Brendan Cully <brendan@kublai.com>
parents: 406
diff changeset
636 convert_list, commits = self.getnewgitcommits(refs)
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
637 # import each of the commits, oldest first
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
638 total = len(commits)
392
8bb058d6a9ee Message cleanups
Brendan Cully <brendan@kublai.com>
parents: 391
diff changeset
639 if total:
8bb058d6a9ee Message cleanups
Brendan Cully <brendan@kublai.com>
parents: 391
diff changeset
640 self.ui.status(_("importing git objects into hg\n"))
8bb058d6a9ee Message cleanups
Brendan Cully <brendan@kublai.com>
parents: 391
diff changeset
641
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
642 for i, csha in enumerate(commits):
374
f008197045d3 progress: use gerund form for import
timeless <timeless@gmail.com>
parents: 369
diff changeset
643 util.progress(self.ui, 'importing', i, total=total, unit='commits')
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
644 commit = convert_list[csha]
190
6fbdf1afe032 Better reporting of the number of commits to convert
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 188
diff changeset
645 self.import_git_commit(commit)
374
f008197045d3 progress: use gerund form for import
timeless <timeless@gmail.com>
parents: 369
diff changeset
646 util.progress(self.ui, 'importing', None, total=total, unit='commits')
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
647
400
6d4f3b6d2e08 respect references to tags that differ between git and .hgtags
Adrian Sampson <adrian@radbox.org>
parents: 398
diff changeset
648 # Remove any dangling tag references.
6d4f3b6d2e08 respect references to tags that differ between git and .hgtags
Adrian Sampson <adrian@radbox.org>
parents: 398
diff changeset
649 for name, rev in self.repo.tags().items():
6d4f3b6d2e08 respect references to tags that differ between git and .hgtags
Adrian Sampson <adrian@radbox.org>
parents: 398
diff changeset
650 if not rev in self.repo:
6d4f3b6d2e08 respect references to tags that differ between git and .hgtags
Adrian Sampson <adrian@radbox.org>
parents: 398
diff changeset
651 if hasattr(self, 'tagscache') and self.tagscache and \
6d4f3b6d2e08 respect references to tags that differ between git and .hgtags
Adrian Sampson <adrian@radbox.org>
parents: 398
diff changeset
652 'name' in self.tagscache:
6d4f3b6d2e08 respect references to tags that differ between git and .hgtags
Adrian Sampson <adrian@radbox.org>
parents: 398
diff changeset
653 # Mercurial 1.4 and earlier.
6d4f3b6d2e08 respect references to tags that differ between git and .hgtags
Adrian Sampson <adrian@radbox.org>
parents: 398
diff changeset
654 del self.repo.tagscache[name]
6d4f3b6d2e08 respect references to tags that differ between git and .hgtags
Adrian Sampson <adrian@radbox.org>
parents: 398
diff changeset
655 elif hasattr(self, '_tags') and self._tags and \
6d4f3b6d2e08 respect references to tags that differ between git and .hgtags
Adrian Sampson <adrian@radbox.org>
parents: 398
diff changeset
656 'name' in self._tags:
6d4f3b6d2e08 respect references to tags that differ between git and .hgtags
Adrian Sampson <adrian@radbox.org>
parents: 398
diff changeset
657 # Mercurial 1.5 and later.
6d4f3b6d2e08 respect references to tags that differ between git and .hgtags
Adrian Sampson <adrian@radbox.org>
parents: 398
diff changeset
658 del self.repo._tags[name]
475
03d8e33bf776 git_handler: fix safehasattr - hg util is hgutil
Mads Kiilerich <mads@kiilerich.com>
parents: 460
diff changeset
659 if (hgutil.safehasattr(self.repo, '_tagtypes') and
460
5861777f2f5e git_handler: fix import_git_objects for Mercurial 2.0+ (issue 36)
Kevin Bullock <kbullock@ringworld.org>
parents: 456
diff changeset
660 self.repo._tagtypes and
5861777f2f5e git_handler: fix import_git_objects for Mercurial 2.0+ (issue 36)
Kevin Bullock <kbullock@ringworld.org>
parents: 456
diff changeset
661 name in self.repo._tagtypes):
5861777f2f5e git_handler: fix import_git_objects for Mercurial 2.0+ (issue 36)
Kevin Bullock <kbullock@ringworld.org>
parents: 456
diff changeset
662 # Mercurial 1.9 and earlier.
400
6d4f3b6d2e08 respect references to tags that differ between git and .hgtags
Adrian Sampson <adrian@radbox.org>
parents: 398
diff changeset
663 del self.repo._tagtypes[name]
475
03d8e33bf776 git_handler: fix safehasattr - hg util is hgutil
Mads Kiilerich <mads@kiilerich.com>
parents: 460
diff changeset
664 elif (hgutil.safehasattr(self.repo, 'tagscache') and
460
5861777f2f5e git_handler: fix import_git_objects for Mercurial 2.0+ (issue 36)
Kevin Bullock <kbullock@ringworld.org>
parents: 456
diff changeset
665 self.repo.tagscache and
475
03d8e33bf776 git_handler: fix safehasattr - hg util is hgutil
Mads Kiilerich <mads@kiilerich.com>
parents: 460
diff changeset
666 hgutil.safehasattr(self.repo.tagscache, '_tagtypes') and
460
5861777f2f5e git_handler: fix import_git_objects for Mercurial 2.0+ (issue 36)
Kevin Bullock <kbullock@ringworld.org>
parents: 456
diff changeset
667 self.repo.tagscache._tagtypes and
5861777f2f5e git_handler: fix import_git_objects for Mercurial 2.0+ (issue 36)
Kevin Bullock <kbullock@ringworld.org>
parents: 456
diff changeset
668 name in self.repo.tagscache._tagtypes):
5861777f2f5e git_handler: fix import_git_objects for Mercurial 2.0+ (issue 36)
Kevin Bullock <kbullock@ringworld.org>
parents: 456
diff changeset
669 # Mercurial 2.0 and later.
5861777f2f5e git_handler: fix import_git_objects for Mercurial 2.0+ (issue 36)
Kevin Bullock <kbullock@ringworld.org>
parents: 456
diff changeset
670 del self.repo.tagscache._tagtypes[name]
400
6d4f3b6d2e08 respect references to tags that differ between git and .hgtags
Adrian Sampson <adrian@radbox.org>
parents: 398
diff changeset
671
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
672 def import_git_commit(self, commit):
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
673 self.ui.debug(_("importing: %s\n") % commit.id)
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
674
293
8aaae306d46f git_handler: 80 columns cleanup
Augie Fackler <durin42@gmail.com>
parents: 292
diff changeset
675 (strip_message, hg_renames,
8aaae306d46f git_handler: 80 columns cleanup
Augie Fackler <durin42@gmail.com>
parents: 292
diff changeset
676 hg_branch, extra) = self.extract_hg_metadata(commit.message)
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
677
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
678 # get a list of the changed, added, removed files
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
679 files = self.get_files_changed(commit)
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
680
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
681 # Handle gitlinks: collect
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
682 gitlinks = self.collect_gitlinks(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
683 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
684
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
685 # Analyze hgsubstate and build an updated version
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
686 # using SHAs from gitlinks
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
687 hgsubstate = 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
688 if gitlinks:
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
689 hgsubstate = util.parse_hgsubstate(self.git_file_readlines(git_commit_tree, '.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
690 for path, sha in gitlinks:
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
691 hgsubstate[path] = sha
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
692 # in case .hgsubstate wasn't among changed files
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
693 # force its inclusion
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
694 files['.hgsubstate'] = (False, 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
695
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
696 # 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
697 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
698 gitmodules = self.parse_gitmodules(git_commit_tree)
478
64eb2789e5bf git_handler: remove tab character that snuck in
Augie Fackler <raf@durin42.com>
parents: 476
diff changeset
699 if gitmodules or gitlinks:
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
700 hgsub = util.parse_hgsub(self.git_file_readlines(git_commit_tree, '.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
701 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
702 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
703 files['.hgsub'] = (False, 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
704 elif commit.parents and '.gitmodules' in self.git[self.git[commit.parents[0]].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
705 # 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
706 # 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
707 # 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
708 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
709
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
710 date = (commit.author_time, -commit.author_timezone)
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
711 text = strip_message
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
712
226
3b8804c59b63 drop untested commit_import_ctx (use commitctx instead).
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 225
diff changeset
713 origtext = text
186
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
714 try:
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
715 text.decode('utf-8')
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
716 except UnicodeDecodeError:
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
717 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
718
3b8804c59b63 drop untested commit_import_ctx (use commitctx instead).
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 225
diff changeset
719 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
720 if text + '\n' != origtext:
3b8804c59b63 drop untested commit_import_ctx (use commitctx instead).
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 225
diff changeset
721 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
722
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
723 author = commit.author
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
724
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
725 # convert extra data back to the end
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
726 if ' ext:' in commit.author:
540
3fb942852b1c Precompile Git author extra data regular expression
Gregory Szorc <gregory.szorc@gmail.com>
parents: 539
diff changeset
727 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
728 if m:
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
729 name = m.group(1)
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
730 ex = urllib.unquote(m.group(2))
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
731 email = m.group(3)
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
732 author = name + ' <' + email + '>' + ex
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
733
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
734 if ' <none@none>' in commit.author:
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
735 author = commit.author[:-12]
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
736
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
737 try:
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
738 author.decode('utf-8')
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
739 except UnicodeDecodeError:
225
cde57730faa7 store non utf-8 encoded author/commit message as deltas
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 224
diff changeset
740 origauthor = author
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
741 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
742 extra['author'] = create_delta(author, origauthor)
186
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
743
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
744 oldenc = self.swap_out_encoding()
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
745
406
50698ff64c41 Fix round-trip fidelity for merges of converged files.
Christian Walther <cwalther@gmx.ch>
parents: 401
diff changeset
746 def findconvergedfiles(p1, p2):
50698ff64c41 Fix round-trip fidelity for merges of converged files.
Christian Walther <cwalther@gmx.ch>
parents: 401
diff changeset
747 # 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
748 # (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
749 # 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
750 # 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
751 # 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
752 # 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
753 # begin with).
50698ff64c41 Fix round-trip fidelity for merges of converged files.
Christian Walther <cwalther@gmx.ch>
parents: 401
diff changeset
754 if p2 == nullid:
50698ff64c41 Fix round-trip fidelity for merges of converged files.
Christian Walther <cwalther@gmx.ch>
parents: 401
diff changeset
755 return []
50698ff64c41 Fix round-trip fidelity for merges of converged files.
Christian Walther <cwalther@gmx.ch>
parents: 401
diff changeset
756 manifest1 = self.repo.changectx(p1).manifest()
50698ff64c41 Fix round-trip fidelity for merges of converged files.
Christian Walther <cwalther@gmx.ch>
parents: 401
diff changeset
757 manifest2 = self.repo.changectx(p2).manifest()
50698ff64c41 Fix round-trip fidelity for merges of converged files.
Christian Walther <cwalther@gmx.ch>
parents: 401
diff changeset
758 return [path for path, node1 in manifest1.iteritems()
50698ff64c41 Fix round-trip fidelity for merges of converged files.
Christian Walther <cwalther@gmx.ch>
parents: 401
diff changeset
759 if path not in files and manifest2.get(path, node1) != node1]
50698ff64c41 Fix round-trip fidelity for merges of converged files.
Christian Walther <cwalther@gmx.ch>
parents: 401
diff changeset
760
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
761 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
762 info = files.get(f)
50698ff64c41 Fix round-trip fidelity for merges of converged files.
Christian Walther <cwalther@gmx.ch>
parents: 401
diff changeset
763 if info != None:
50698ff64c41 Fix round-trip fidelity for merges of converged files.
Christian Walther <cwalther@gmx.ch>
parents: 401
diff changeset
764 # 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
765 delete, mode, sha = info
50698ff64c41 Fix round-trip fidelity for merges of converged files.
Christian Walther <cwalther@gmx.ch>
parents: 401
diff changeset
766 if delete:
50698ff64c41 Fix round-trip fidelity for merges of converged files.
Christian Walther <cwalther@gmx.ch>
parents: 401
diff changeset
767 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
768
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
769 if not sha: # indicates there's no git counterpart
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
770 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
771 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
772 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
773 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
774 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
775 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
776 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
777 data = 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
778 copied_path = hg_renames.get(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
779 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
780 else:
50698ff64c41 Fix round-trip fidelity for merges of converged files.
Christian Walther <cwalther@gmx.ch>
parents: 401
diff changeset
781 # it's a converged file
50698ff64c41 Fix round-trip fidelity for merges of converged files.
Christian Walther <cwalther@gmx.ch>
parents: 401
diff changeset
782 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
783 data = fc.data()
50698ff64c41 Fix round-trip fidelity for merges of converged files.
Christian Walther <cwalther@gmx.ch>
parents: 401
diff changeset
784 e = fc.flags()
50698ff64c41 Fix round-trip fidelity for merges of converged files.
Christian Walther <cwalther@gmx.ch>
parents: 401
diff changeset
785 copied_path = fc.renamed()
275
c2d6b1093e7e fix a bug when a directory is replaced with a file
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 261
diff changeset
786
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
787 return context.memfilectx(f, data, 'l' in e, 'x' in e, copied_path)
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
788
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
789 gparents = map(self.map_hg_get, commit.parents)
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
790 p1, p2 = (nullid, nullid)
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
791 octopus = False
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
792
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
793 if len(gparents) > 1:
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
794 # merge, possibly octopus
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
795 def commit_octopus(p1, p2):
406
50698ff64c41 Fix round-trip fidelity for merges of converged files.
Christian Walther <cwalther@gmx.ch>
parents: 401
diff changeset
796 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
797 list(files) + findconvergedfiles(p1, p2),
50698ff64c41 Fix round-trip fidelity for merges of converged files.
Christian Walther <cwalther@gmx.ch>
parents: 401
diff changeset
798 getfilectx, author, date, {'hg-git': 'octopus'})
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
799 return hex(self.repo.commitctx(ctx))
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
800
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
801 octopus = len(gparents) > 2
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
802 p2 = gparents.pop()
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
803 p1 = gparents.pop()
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
804 while len(gparents) > 0:
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
805 p2 = commit_octopus(p1, p2)
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
806 p1 = gparents.pop()
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
807 else:
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
808 if gparents:
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
809 p1 = gparents.pop()
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
810
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
811 pa = None
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
812 if not (p2 == nullid):
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
813 node1 = self.repo.changectx(p1)
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
814 node2 = self.repo.changectx(p2)
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
815 pa = node1.ancestor(node2)
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
816
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
817 # if named branch, add to extra
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
818 if hg_branch:
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
819 extra['branch'] = hg_branch
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
820
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
821 # 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
822 if commit.author != commit.committer \
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
823 or commit.author_time != commit.commit_time \
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
824 or commit.author_timezone != commit.commit_timezone:
293
8aaae306d46f git_handler: 80 columns cleanup
Augie Fackler <durin42@gmail.com>
parents: 292
diff changeset
825 extra['committer'] = "%s %d %d" % (
8aaae306d46f git_handler: 80 columns cleanup
Augie Fackler <durin42@gmail.com>
parents: 292
diff changeset
826 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
827
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
828 if commit.encoding:
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
829 extra['encoding'] = commit.encoding
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
830
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
831 if hg_branch:
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
832 extra['branch'] = hg_branch
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
833
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
834 if octopus:
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
835 extra['hg-git'] ='octopus-done'
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
836
300
eec31dee258e Various hg 1.4 compat fixes.
Augie Fackler <durin42@gmail.com>
parents: 298
diff changeset
837 # TODO use 'n in self.repo' when we require hg 1.5
eec31dee258e Various hg 1.4 compat fixes.
Augie Fackler <durin42@gmail.com>
parents: 298
diff changeset
838 def repo_contains(n):
eec31dee258e Various hg 1.4 compat fixes.
Augie Fackler <durin42@gmail.com>
parents: 298
diff changeset
839 try:
eec31dee258e Various hg 1.4 compat fixes.
Augie Fackler <durin42@gmail.com>
parents: 298
diff changeset
840 return bool(self.repo.lookup(n))
eec31dee258e Various hg 1.4 compat fixes.
Augie Fackler <durin42@gmail.com>
parents: 298
diff changeset
841 except error.RepoLookupError:
eec31dee258e Various hg 1.4 compat fixes.
Augie Fackler <durin42@gmail.com>
parents: 298
diff changeset
842 return False
eec31dee258e Various hg 1.4 compat fixes.
Augie Fackler <durin42@gmail.com>
parents: 298
diff changeset
843
eec31dee258e Various hg 1.4 compat fixes.
Augie Fackler <durin42@gmail.com>
parents: 298
diff changeset
844 if not (repo_contains(p1) and repo_contains(p2)):
eec31dee258e Various hg 1.4 compat fixes.
Augie Fackler <durin42@gmail.com>
parents: 298
diff changeset
845 raise hgutil.Abort(_('you appear to have run strip - '
eec31dee258e Various hg 1.4 compat fixes.
Augie Fackler <durin42@gmail.com>
parents: 298
diff changeset
846 'please run hg git-cleanup'))
406
50698ff64c41 Fix round-trip fidelity for merges of converged files.
Christian Walther <cwalther@gmx.ch>
parents: 401
diff changeset
847 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
848 list(files) + findconvergedfiles(p1, p2),
50698ff64c41 Fix round-trip fidelity for merges of converged files.
Christian Walther <cwalther@gmx.ch>
parents: 401
diff changeset
849 getfilectx, author, date, extra)
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
850
226
3b8804c59b63 drop untested commit_import_ctx (use commitctx instead).
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 225
diff changeset
851 node = self.repo.commitctx(ctx)
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
852
186
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
853 self.swap_out_encoding(oldenc)
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
854
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
855 # save changeset to mapping file
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
856 cs = hex(node)
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
857 self.map_set(commit.id, cs)
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
858
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
859 ## 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
860
230
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
861 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
862 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
863 old_refs = {}
591
163c452531cf push: add more output about what was added (issue #64)
David M. Carr <david@carrclan.us>
parents: 590
diff changeset
864 change_totals = {}
163c452531cf push: add more output about what was added (issue #64)
David M. Carr <david@carrclan.us>
parents: 590
diff changeset
865
230
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
866 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
867 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
868 old_refs.update(refs)
230
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
869 to_push = revs or set(self.local_heads().values() + self.tags.values())
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
870 return self.get_changed_refs(refs, to_push, force)
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
871
591
163c452531cf push: add more output about what was added (issue #64)
David M. Carr <david@carrclan.us>
parents: 590
diff changeset
872 def genpack(have, want):
163c452531cf push: add more output about what was added (issue #64)
David M. Carr <david@carrclan.us>
parents: 590
diff changeset
873 commits = []
163c452531cf push: add more output about what was added (issue #64)
David M. Carr <david@carrclan.us>
parents: 590
diff changeset
874 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
875 (sha, name) = mo
163c452531cf push: add more output about what was added (issue #64)
David M. Carr <david@carrclan.us>
parents: 590
diff changeset
876 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
877 t = type(o)
163c452531cf push: add more output about what was added (issue #64)
David M. Carr <david@carrclan.us>
parents: 590
diff changeset
878 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
879 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
880 commits.append(sha)
163c452531cf push: add more output about what was added (issue #64)
David M. Carr <david@carrclan.us>
parents: 590
diff changeset
881 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
882 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
883 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
884 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
885 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
886 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
887 self.ui.status(_("adding objects\n"))
163c452531cf push: add more output about what was added (issue #64)
David M. Carr <david@carrclan.us>
parents: 590
diff changeset
888 return self.git.object_store.generate_pack_contents(have, want)
163c452531cf push: add more output about what was added (issue #64)
David M. Carr <david@carrclan.us>
parents: 590
diff changeset
889
26
a1a5391bc3c3 edit ssh command to quote the path, also convert tags properly on fetch
Scott Chacon <schacon@gmail.com>
parents: 25
diff changeset
890 try:
487
68e5dddc7a20 push: return 1 if no changes found, 0 if success
David M. Carr <david@carrclan.us>
parents: 475
diff changeset
891 new_refs = client.send_pack(path, changed, genpack)
591
163c452531cf push: add more output about what was added (issue #64)
David M. Carr <david@carrclan.us>
parents: 590
diff changeset
892 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
893 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
894 " 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
895 (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
896 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
897 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
898 return old_refs, new_refs
394
721165a45385 Catch GitProtocolError wherever HangupException can occur.
Brendan Cully <brendan@kublai.com>
parents: 392
diff changeset
899 except (HangupException, GitProtocolError), e:
721165a45385 Catch GitProtocolError wherever HangupException can occur.
Brendan Cully <brendan@kublai.com>
parents: 392
diff changeset
900 raise hgutil.Abort(_("git remote error: ") + str(e))
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
901
230
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
902 def get_changed_refs(self, refs, revs, force):
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
903 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
904
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
905 #The remote repo is empty and the local one doesn't have bookmarks/tags
248
bfe6fd2fdb9b push tip to master in an empty repository even if there are tags
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 247
diff changeset
906 if refs.keys()[0] == 'capabilities^{}':
bfe6fd2fdb9b push tip to master in an empty repository even if there are tags
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 247
diff changeset
907 if not self.local_heads():
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
908 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
909 if tip != nullid:
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
910 del new_refs['capabilities^{}']
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
911 tip = hex(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
912 try:
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
913 commands.bookmark(self.ui, self.repo, 'master', tip, force=True)
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
914 except NameError:
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
915 bookmarks.bookmark(self.ui, self.repo, 'master', tip, force=True)
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
916 bookmarks.setcurrent(self.repo, 'master')
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
917 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
918
230
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
919 for rev in revs:
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
920 ctx = self.repo[rev]
376
b4f5f2729acb git_handler: update ctx label handling for bookmarks in core
Augie Fackler <durin42@gmail.com>
parents: 375
diff changeset
921 if getattr(ctx, 'bookmarks', None):
441
35e2813f58a5 - add "branch_bookmark_names" parameter. this allows bookmarks
Mike Bayer <mike_mp@zzzcomputing.com>
parents: 439
diff changeset
922 labels = lambda c: ctx.tags() + [
448
e58a6d0b80e2 Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents: 447
diff changeset
923 fltr for fltr, bm
441
35e2813f58a5 - add "branch_bookmark_names" parameter. this allows bookmarks
Mike Bayer <mike_mp@zzzcomputing.com>
parents: 439
diff changeset
924 in self._filter_for_bookmarks(ctx.bookmarks())
35e2813f58a5 - add "branch_bookmark_names" parameter. this allows bookmarks
Mike Bayer <mike_mp@zzzcomputing.com>
parents: 439
diff changeset
925 ]
376
b4f5f2729acb git_handler: update ctx label handling for bookmarks in core
Augie Fackler <durin42@gmail.com>
parents: 375
diff changeset
926 else:
b4f5f2729acb git_handler: update ctx label handling for bookmarks in core
Augie Fackler <durin42@gmail.com>
parents: 375
diff changeset
927 labels = lambda c: ctx.tags()
381
80544310834a fix handling of spaces in hg tag names
Dmitry Gladkov <dmitry.gladkov@gmail.com>
parents: 376
diff changeset
928 prep = lambda itr: [i.replace(' ', '_') for i in itr]
80544310834a fix handling of spaces in hg tag names
Dmitry Gladkov <dmitry.gladkov@gmail.com>
parents: 376
diff changeset
929
80544310834a fix handling of spaces in hg tag names
Dmitry Gladkov <dmitry.gladkov@gmail.com>
parents: 376
diff changeset
930 heads = [t for t in prep(labels(ctx)) if t in self.local_heads()]
80544310834a fix handling of spaces in hg tag names
Dmitry Gladkov <dmitry.gladkov@gmail.com>
parents: 376
diff changeset
931 tags = [t for t in prep(labels(ctx)) if t in self.tags]
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
932
230
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
933 if not (heads or tags):
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
934 raise hgutil.Abort("revision %s cannot be pushed since"
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
935 " it doesn't have a ref" % ctx)
149
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
936
310
53b0d608dcd5 when pushing, check if server is advertising annotated tags
Tay Ray Chuan <rctay89@gmail.com>
parents: 302
diff changeset
937 # Check if the tags the server is advertising are annotated tags,
53b0d608dcd5 when pushing, check if server is advertising annotated tags
Tay Ray Chuan <rctay89@gmail.com>
parents: 302
diff changeset
938 # by attempting to retrieve it from the our git repo, and building a
53b0d608dcd5 when pushing, check if server is advertising annotated tags
Tay Ray Chuan <rctay89@gmail.com>
parents: 302
diff changeset
939 # list of these tags.
53b0d608dcd5 when pushing, check if server is advertising annotated tags
Tay Ray Chuan <rctay89@gmail.com>
parents: 302
diff changeset
940 #
53b0d608dcd5 when pushing, check if server is advertising annotated tags
Tay Ray Chuan <rctay89@gmail.com>
parents: 302
diff changeset
941 # 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
942 # 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
943 # 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
944 uptodate_annotated_tags = []
53b0d608dcd5 when pushing, check if server is advertising annotated tags
Tay Ray Chuan <rctay89@gmail.com>
parents: 302
diff changeset
945 for r in tags:
53b0d608dcd5 when pushing, check if server is advertising annotated tags
Tay Ray Chuan <rctay89@gmail.com>
parents: 302
diff changeset
946 ref = 'refs/tags/'+r
53b0d608dcd5 when pushing, check if server is advertising annotated tags
Tay Ray Chuan <rctay89@gmail.com>
parents: 302
diff changeset
947 # Check tag.
53b0d608dcd5 when pushing, check if server is advertising annotated tags
Tay Ray Chuan <rctay89@gmail.com>
parents: 302
diff changeset
948 if not ref in refs:
53b0d608dcd5 when pushing, check if server is advertising annotated tags
Tay Ray Chuan <rctay89@gmail.com>
parents: 302
diff changeset
949 continue
53b0d608dcd5 when pushing, check if server is advertising annotated tags
Tay Ray Chuan <rctay89@gmail.com>
parents: 302
diff changeset
950 try:
53b0d608dcd5 when pushing, check if server is advertising annotated tags
Tay Ray Chuan <rctay89@gmail.com>
parents: 302
diff changeset
951 # 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
952 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
953 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
954 continue
53b0d608dcd5 when pushing, check if server is advertising annotated tags
Tay Ray Chuan <rctay89@gmail.com>
parents: 302
diff changeset
955 except KeyError:
53b0d608dcd5 when pushing, check if server is advertising annotated tags
Tay Ray Chuan <rctay89@gmail.com>
parents: 302
diff changeset
956 continue
53b0d608dcd5 when pushing, check if server is advertising annotated tags
Tay Ray Chuan <rctay89@gmail.com>
parents: 302
diff changeset
957
53b0d608dcd5 when pushing, check if server is advertising annotated tags
Tay Ray Chuan <rctay89@gmail.com>
parents: 302
diff changeset
958 # 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
959 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
960
230
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
961 for r in heads + tags:
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
962 if r in heads:
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
963 ref = 'refs/heads/'+r
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
964 else:
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
965 ref = 'refs/tags/'+r
181
8690377c3ce9 Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 179
diff changeset
966
230
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
967 if ref not in refs:
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
968 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
969 elif new_refs[ref] in self._map_git:
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
970 rctx = self.repo[self.map_hg_get(new_refs[ref])]
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
971 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
972 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
973 else:
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
974 raise hgutil.Abort("pushing %s overwrites %s"
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
975 % (ref, ctx))
310
53b0d608dcd5 when pushing, check if server is advertising annotated tags
Tay Ray Chuan <rctay89@gmail.com>
parents: 302
diff changeset
976 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
977 # 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
978 pass
230
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
979 else:
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
980 raise hgutil.Abort("%s changed on the server, please pull "
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
981 "and merge before pushing" % ref)
126
705b88c9f3d1 remote branches to server
Ian Dees <undees@gmail.com>
parents: 125
diff changeset
982
230
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
983 return new_refs
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
984
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
985
557
4f4ab2d89375 gitrepo: initial support for listkeys
David M. Carr <david@carrclan.us>
parents: 555
diff changeset
986 def fetch_pack(self, remote_name, heads=None):
182
9bdd8e76bbab Remove remotes support (use the paths section in hgrc instead)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 181
diff changeset
987 client, path = self.get_transport_and_path(remote_name)
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
988 graphwalker = self.git.get_graph_walker()
232
0ba1aee0467c initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 231
diff changeset
989 def determine_wants(refs):
0ba1aee0467c initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 231
diff changeset
990 if heads:
0ba1aee0467c initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 231
diff changeset
991 want = []
337
6cea997ee302 enforce stricter matching for pull -r
Tay Ray Chuan <rctay89@gmail.com>
parents: 258
diff changeset
992 # contains pairs of ('refs/(heads|tags|...)/foo', 'foo')
6cea997ee302 enforce stricter matching for pull -r
Tay Ray Chuan <rctay89@gmail.com>
parents: 258
diff changeset
993 # if ref is just '<foo>', then we get ('foo', 'foo')
6cea997ee302 enforce stricter matching for pull -r
Tay Ray Chuan <rctay89@gmail.com>
parents: 258
diff changeset
994 stripped_refs = [
6cea997ee302 enforce stricter matching for pull -r
Tay Ray Chuan <rctay89@gmail.com>
parents: 258
diff changeset
995 (r, r[r.find('/', r.find('/')+1)+1:])
6cea997ee302 enforce stricter matching for pull -r
Tay Ray Chuan <rctay89@gmail.com>
parents: 258
diff changeset
996 for r in refs]
232
0ba1aee0467c initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 231
diff changeset
997 for h in heads:
337
6cea997ee302 enforce stricter matching for pull -r
Tay Ray Chuan <rctay89@gmail.com>
parents: 258
diff changeset
998 r = [pair[0] for pair in stripped_refs if pair[1] == h]
232
0ba1aee0467c initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 231
diff changeset
999 if not r:
292
19f201d64a16 git_handler: fix % formatting in ref errors.
Augie Fackler <durin42@gmail.com>
parents: 288
diff changeset
1000 raise hgutil.Abort("ref %s not found on remote server" % h)
232
0ba1aee0467c initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 231
diff changeset
1001 elif len(r) == 1:
0ba1aee0467c initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 231
diff changeset
1002 want.append(refs[r[0]])
0ba1aee0467c initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 231
diff changeset
1003 else:
292
19f201d64a16 git_handler: fix % formatting in ref errors.
Augie Fackler <durin42@gmail.com>
parents: 288
diff changeset
1004 raise hgutil.Abort("ambiguous reference %s: %r" % (h, r))
232
0ba1aee0467c initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 231
diff changeset
1005 else:
0ba1aee0467c initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 231
diff changeset
1006 want = [sha for ref, sha in refs.iteritems()
417
65b414ab988c only want heads and tags
Scott Chacon <schacon@gmail.com>
parents: 415
diff changeset
1007 if not ref.endswith('^{}')
65b414ab988c only want heads and tags
Scott Chacon <schacon@gmail.com>
parents: 415
diff changeset
1008 and ( ref.startswith('refs/heads/') or ref.startswith('refs/tags/') ) ]
395
01c9eeedde04 Only fetch objects that are not already present.
Brendan Cully <brendan@kublai.com>
parents: 394
diff changeset
1009 want = [x for x in want if x not in self.git]
232
0ba1aee0467c initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 231
diff changeset
1010 return want
5
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
1011 f, commit = self.git.object_store.add_pack()
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
1012 try:
266
5347d8c94021 python 2.4 syntax fix
Antonin Amand <antonin.amand@gmail.com>
parents: 261
diff changeset
1013 try:
411
de7317967598 Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents: 408
diff changeset
1014 progress = GitProgress(self.ui)
de7317967598 Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents: 408
diff changeset
1015 ret = client.fetch_pack(path, determine_wants, graphwalker,
de7317967598 Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents: 408
diff changeset
1016 f.write, progress.progress)
de7317967598 Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents: 408
diff changeset
1017 progress.flush()
de7317967598 Convert dulwich progress into mercurial ui.progress
Brendan Cully <brendan@kublai.com>
parents: 408
diff changeset
1018 return ret
394
721165a45385 Catch GitProtocolError wherever HangupException can occur.
Brendan Cully <brendan@kublai.com>
parents: 392
diff changeset
1019 except (HangupException, GitProtocolError), e:
721165a45385 Catch GitProtocolError wherever HangupException can occur.
Brendan Cully <brendan@kublai.com>
parents: 392
diff changeset
1020 raise hgutil.Abort(_("git remote error: ") + str(e))
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
1021 finally:
5
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
1022 commit()
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
1023
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
1024 ## REFERENCES HANDLING
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
1025
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
1026 def update_references(self):
195
e09d71dc4cb4 Drop importbranch/exportbranch options (exportbranch was really broken)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 194
diff changeset
1027 heads = self.local_heads()
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
1028
195
e09d71dc4cb4 Drop importbranch/exportbranch options (exportbranch was really broken)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 194
diff changeset
1029 # 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
1030 # Mercurial bookmark.
e09d71dc4cb4 Drop importbranch/exportbranch options (exportbranch was really broken)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 194
diff changeset
1031 for key in heads:
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
1032 git_ref = self.map_git_get(heads[key])
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
1033 if git_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
1034 self.git.refs['refs/heads/' + key] = self.map_git_get(heads[key])
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
1035
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
1036 def export_hg_tags(self):
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
1037 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
1038 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
1039 tag = tag.replace(' ', '_')
587
1ab57b19cb3a git_handler: defend against unexported revisions in tag exporting
Augie Fackler <raf@durin42.com>
parents: 552
diff changeset
1040 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
1041 if target is not None:
1ab57b19cb3a git_handler: defend against unexported revisions in tag exporting
Augie Fackler <raf@durin42.com>
parents: 552
diff changeset
1042 self.git.refs['refs/tags/' + tag] = target
1ab57b19cb3a git_handler: defend against unexported revisions in tag exporting
Augie Fackler <raf@durin42.com>
parents: 552
diff changeset
1043 self.tags[tag] = hex(sha)
1ab57b19cb3a git_handler: defend against unexported revisions in tag exporting
Augie Fackler <raf@durin42.com>
parents: 552
diff changeset
1044 else:
1ab57b19cb3a git_handler: defend against unexported revisions in tag exporting
Augie Fackler <raf@durin42.com>
parents: 552
diff changeset
1045 self.repo.ui.warn(
1ab57b19cb3a git_handler: defend against unexported revisions in tag exporting
Augie Fackler <raf@durin42.com>
parents: 552
diff changeset
1046 'Skipping export of tag %s because it '
1ab57b19cb3a git_handler: defend against unexported revisions in tag exporting
Augie Fackler <raf@durin42.com>
parents: 552
diff changeset
1047 'has no matching git revision.' % tag)
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
1048
441
35e2813f58a5 - add "branch_bookmark_names" parameter. this allows bookmarks
Mike Bayer <mike_mp@zzzcomputing.com>
parents: 439
diff changeset
1049 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
1050 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
1051 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
1052 else:
35e2813f58a5 - add "branch_bookmark_names" parameter. this allows bookmarks
Mike Bayer <mike_mp@zzzcomputing.com>
parents: 439
diff changeset
1053 def _filter_bm(bm):
35e2813f58a5 - add "branch_bookmark_names" parameter. this allows bookmarks
Mike Bayer <mike_mp@zzzcomputing.com>
parents: 439
diff changeset
1054 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
1055 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
1056 else:
35e2813f58a5 - add "branch_bookmark_names" parameter. this allows bookmarks
Mike Bayer <mike_mp@zzzcomputing.com>
parents: 439
diff changeset
1057 return bm
35e2813f58a5 - add "branch_bookmark_names" parameter. this allows bookmarks
Mike Bayer <mike_mp@zzzcomputing.com>
parents: 439
diff changeset
1058 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
1059
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
1060 def local_heads(self):
194
a5c53e94d92b Do not depend on the cache git repository for reference pushing
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 190
diff changeset
1061 try:
268
6fded8e42858 git_handler: update for slight API change in bookmarks
Augie Fackler <durin42@gmail.com>
parents: 267
diff changeset
1062 if getattr(bookmarks, 'parse', None):
6fded8e42858 git_handler: update for slight API change in bookmarks
Augie Fackler <durin42@gmail.com>
parents: 267
diff changeset
1063 bms = bookmarks.parse(self.repo)
6fded8e42858 git_handler: update for slight API change in bookmarks
Augie Fackler <durin42@gmail.com>
parents: 267
diff changeset
1064 else:
6fded8e42858 git_handler: update for slight API change in bookmarks
Augie Fackler <durin42@gmail.com>
parents: 267
diff changeset
1065 bms = self.repo._bookmarks
448
e58a6d0b80e2 Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents: 447
diff changeset
1066 return dict([(filtered_bm, hex(bms[bm])) for
441
35e2813f58a5 - add "branch_bookmark_names" parameter. this allows bookmarks
Mike Bayer <mike_mp@zzzcomputing.com>
parents: 439
diff changeset
1067 filtered_bm, bm in self._filter_for_bookmarks(bms)])
215
b5d4d1552765 add some annotations for test coverage
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 213
diff changeset
1068 except AttributeError: #pragma: no cover
194
a5c53e94d92b Do not depend on the cache git repository for reference pushing
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 190
diff changeset
1069 return {}
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
1070
187
5f196f80ffb3 Store git tags in .hg/git-tags and let localtags be *local*
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 186
diff changeset
1071 def import_tags(self, refs):
149
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
1072 keys = refs.keys()
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
1073 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
1074 return
5f196f80ffb3 Store git tags in .hg/git-tags and let localtags be *local*
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 186
diff changeset
1075 for k in keys[:]:
149
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
1076 ref_name = k
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
1077 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
1078 if parts[0] == 'refs' and parts[1] == 'tags':
149
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
1079 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
1080 # 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
1081 # the ones we are pulling
0ba1aee0467c initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 231
diff changeset
1082 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
1083 continue
149
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
1084 if ref_name[-3:] == '^{}':
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
1085 ref_name = ref_name[:-3]
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
1086 if not ref_name in self.repo.tags():
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
1087 obj = self.git.get_object(refs[k])
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
1088 sha = None
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
1089 if isinstance (obj, Commit): # lightweight
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
1090 sha = self.map_hg_get(refs[k])
187
5f196f80ffb3 Store git tags in .hg/git-tags and let localtags be *local*
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 186
diff changeset
1091 self.tags[ref_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
1092 elif isinstance (obj, Tag): # annotated
337
6cea997ee302 enforce stricter matching for pull -r
Tay Ray Chuan <rctay89@gmail.com>
parents: 258
diff changeset
1093 (obj_type, obj_sha) = obj.object
149
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
1094 obj = self.git.get_object(obj_sha)
181
8690377c3ce9 Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 179
diff changeset
1095 if isinstance (obj, Commit):
149
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
1096 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
1097 # TODO: better handling for annotated tags
5f196f80ffb3 Store git tags in .hg/git-tags and let localtags be *local*
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 186
diff changeset
1098 self.tags[ref_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
1099 self.save_tags()
181
8690377c3ce9 Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 179
diff changeset
1100
184
7bf98d3085f4 Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 183
diff changeset
1101 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
1102 try:
268
6fded8e42858 git_handler: update for slight API change in bookmarks
Augie Fackler <durin42@gmail.com>
parents: 267
diff changeset
1103 oldbm = getattr(bookmarks, 'parse', None)
6fded8e42858 git_handler: update for slight API change in bookmarks
Augie Fackler <durin42@gmail.com>
parents: 267
diff changeset
1104 if oldbm:
6fded8e42858 git_handler: update for slight API change in bookmarks
Augie Fackler <durin42@gmail.com>
parents: 267
diff changeset
1105 bms = bookmarks.parse(self.repo)
6fded8e42858 git_handler: update for slight API change in bookmarks
Augie Fackler <durin42@gmail.com>
parents: 267
diff changeset
1106 else:
6fded8e42858 git_handler: update for slight API change in bookmarks
Augie Fackler <durin42@gmail.com>
parents: 267
diff changeset
1107 bms = self.repo._bookmarks
441
35e2813f58a5 - add "branch_bookmark_names" parameter. this allows bookmarks
Mike Bayer <mike_mp@zzzcomputing.com>
parents: 439
diff changeset
1108
184
7bf98d3085f4 Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 183
diff changeset
1109 heads = dict([(ref[11:],refs[ref]) for ref in refs
7bf98d3085f4 Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 183
diff changeset
1110 if ref.startswith('refs/heads/')])
156
a507384308b2 Allow bookmarking a specific branch
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 155
diff changeset
1111
a507384308b2 Allow bookmarking a specific branch
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 155
diff changeset
1112 for head, sha in heads.iteritems():
232
0ba1aee0467c initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 231
diff changeset
1113 # 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
1114 # the ones we are pulling
0ba1aee0467c initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 231
diff changeset
1115 if sha not in self.git.object_store:
0ba1aee0467c initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 231
diff changeset
1116 continue
188
5d48a2310e16 Use mercurial.node.bin instead of dulwich.objects.hex_to_sha
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 187
diff changeset
1117 hgsha = bin(self.map_hg_get(sha))
184
7bf98d3085f4 Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 183
diff changeset
1118 if not head in bms:
7bf98d3085f4 Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 183
diff changeset
1119 # new branch
7bf98d3085f4 Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 183
diff changeset
1120 bms[head] = hgsha
7bf98d3085f4 Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 183
diff changeset
1121 else:
7bf98d3085f4 Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 183
diff changeset
1122 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
1123 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
1124 # fast forward
7bf98d3085f4 Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 183
diff changeset
1125 bms[head] = hgsha
441
35e2813f58a5 - add "branch_bookmark_names" parameter. this allows bookmarks
Mike Bayer <mike_mp@zzzcomputing.com>
parents: 439
diff changeset
1126
35e2813f58a5 - add "branch_bookmark_names" parameter. this allows bookmarks
Mike Bayer <mike_mp@zzzcomputing.com>
parents: 439
diff changeset
1127 # if there's a branch bookmark suffix,
35e2813f58a5 - add "branch_bookmark_names" parameter. this allows bookmarks
Mike Bayer <mike_mp@zzzcomputing.com>
parents: 439
diff changeset
1128 # then add it on to all bookmark names
35e2813f58a5 - add "branch_bookmark_names" parameter. this allows bookmarks
Mike Bayer <mike_mp@zzzcomputing.com>
parents: 439
diff changeset
1129 # that would otherwise conflict with a branch
35e2813f58a5 - add "branch_bookmark_names" parameter. this allows bookmarks
Mike Bayer <mike_mp@zzzcomputing.com>
parents: 439
diff changeset
1130 # name
35e2813f58a5 - add "branch_bookmark_names" parameter. this allows bookmarks
Mike Bayer <mike_mp@zzzcomputing.com>
parents: 439
diff changeset
1131 if self.branch_bookmark_suffix:
35e2813f58a5 - add "branch_bookmark_names" parameter. this allows bookmarks
Mike Bayer <mike_mp@zzzcomputing.com>
parents: 439
diff changeset
1132 real_branch_names = self.repo.branchmap()
35e2813f58a5 - add "branch_bookmark_names" parameter. this allows bookmarks
Mike Bayer <mike_mp@zzzcomputing.com>
parents: 439
diff changeset
1133 bms = dict(
35e2813f58a5 - add "branch_bookmark_names" parameter. this allows bookmarks
Mike Bayer <mike_mp@zzzcomputing.com>
parents: 439
diff changeset
1134 (
448
e58a6d0b80e2 Remove illegal characters from username/email
Keshav Kini <keshav.kini@gmail.com>
parents: 447
diff changeset
1135 bm_name + self.branch_bookmark_suffix
441
35e2813f58a5 - add "branch_bookmark_names" parameter. this allows bookmarks
Mike Bayer <mike_mp@zzzcomputing.com>
parents: 439
diff changeset
1136 if bm_name in real_branch_names
35e2813f58a5 - add "branch_bookmark_names" parameter. this allows bookmarks
Mike Bayer <mike_mp@zzzcomputing.com>
parents: 439
diff changeset
1137 else bm_name,
35e2813f58a5 - add "branch_bookmark_names" parameter. this allows bookmarks
Mike Bayer <mike_mp@zzzcomputing.com>
parents: 439
diff changeset
1138 bms[bm_name]
35e2813f58a5 - add "branch_bookmark_names" parameter. this allows bookmarks
Mike Bayer <mike_mp@zzzcomputing.com>
parents: 439
diff changeset
1139 )
35e2813f58a5 - add "branch_bookmark_names" parameter. this allows bookmarks
Mike Bayer <mike_mp@zzzcomputing.com>
parents: 439
diff changeset
1140 for bm_name in bms
35e2813f58a5 - add "branch_bookmark_names" parameter. this allows bookmarks
Mike Bayer <mike_mp@zzzcomputing.com>
parents: 439
diff changeset
1141 )
156
a507384308b2 Allow bookmarking a specific branch
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 155
diff changeset
1142 if heads:
268
6fded8e42858 git_handler: update for slight API change in bookmarks
Augie Fackler <durin42@gmail.com>
parents: 267
diff changeset
1143 if oldbm:
6fded8e42858 git_handler: update for slight API change in bookmarks
Augie Fackler <durin42@gmail.com>
parents: 267
diff changeset
1144 bookmarks.write(self.repo, bms)
6fded8e42858 git_handler: update for slight API change in bookmarks
Augie Fackler <durin42@gmail.com>
parents: 267
diff changeset
1145 else:
6fded8e42858 git_handler: update for slight API change in bookmarks
Augie Fackler <durin42@gmail.com>
parents: 267
diff changeset
1146 self.repo._bookmarks = bms
589
96e75caaf900 git_handler: add bookmark compatibility with new bmstore (issue #60)
David M. Carr <david@carrclan.us>
parents: 587
diff changeset
1147 if getattr(bms, 'write', None): # hg >= 2.5
96e75caaf900 git_handler: add bookmark compatibility with new bmstore (issue #60)
David M. Carr <david@carrclan.us>
parents: 587
diff changeset
1148 bms.write()
96e75caaf900 git_handler: add bookmark compatibility with new bmstore (issue #60)
David M. Carr <david@carrclan.us>
parents: 587
diff changeset
1149 else: # hg < 2.5
96e75caaf900 git_handler: add bookmark compatibility with new bmstore (issue #60)
David M. Carr <david@carrclan.us>
parents: 587
diff changeset
1150 bookmarks.write(self.repo)
161
134915637cf7 Merge branch 'octo' with octo merge code
Scott Chacon <schacon@gmail.com>
parents: 157 160
diff changeset
1151
29
2a5c0bf0fef5 Another way of fixing no-bookmark issue, along with updated test.
Augie Fackler <durin42@gmail.com>
parents: 28
diff changeset
1152 except AttributeError:
95
7de67fcb18b0 be better about internationalizing strings
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 94
diff changeset
1153 self.ui.warn(_('creating bookmarks failed, do you have'
7de67fcb18b0 be better about internationalizing strings
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 94
diff changeset
1154 ' 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
1155
184
7bf98d3085f4 Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 183
diff changeset
1156 def update_remote_branches(self, remote_name, refs):
367
699088d9dd9f hgrepo: completely rework handing of remote refs marking
Augie Fackler <durin42@gmail.com>
parents: 361
diff changeset
1157 tagfile = self.repo.join(os.path.join('git-remote-refs'))
699088d9dd9f hgrepo: completely rework handing of remote refs marking
Augie Fackler <durin42@gmail.com>
parents: 361
diff changeset
1158 tags = self.repo.gitrefs()
699088d9dd9f hgrepo: completely rework handing of remote refs marking
Augie Fackler <durin42@gmail.com>
parents: 361
diff changeset
1159 # since we re-write all refs for this remote each time, prune
699088d9dd9f hgrepo: completely rework handing of remote refs marking
Augie Fackler <durin42@gmail.com>
parents: 361
diff changeset
1160 # all entries matching this remote from our tags list now so
699088d9dd9f hgrepo: completely rework handing of remote refs marking
Augie Fackler <durin42@gmail.com>
parents: 361
diff changeset
1161 # that we avoid any stale refs hanging around forever
699088d9dd9f hgrepo: completely rework handing of remote refs marking
Augie Fackler <durin42@gmail.com>
parents: 361
diff changeset
1162 for t in list(tags):
699088d9dd9f hgrepo: completely rework handing of remote refs marking
Augie Fackler <durin42@gmail.com>
parents: 361
diff changeset
1163 if t.startswith(remote_name + '/'):
699088d9dd9f hgrepo: completely rework handing of remote refs marking
Augie Fackler <durin42@gmail.com>
parents: 361
diff changeset
1164 del tags[t]
368
ae78f94f64fd Fix bug where remote ref map wrote out binary nodes.
Augie Fackler <durin42@gmail.com>
parents: 367
diff changeset
1165 tags = dict((k, hex(v)) for k, v in tags.iteritems())
367
699088d9dd9f hgrepo: completely rework handing of remote refs marking
Augie Fackler <durin42@gmail.com>
parents: 361
diff changeset
1166 store = self.git.object_store
305
ad2ea8d6ef94 update_remote_branches: refactor head usage
Tay Ray Chuan <rctay89@gmail.com>
parents: 304
diff changeset
1167 for ref_name, sha in refs.iteritems():
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
1168 if ref_name.startswith('refs/heads'):
367
699088d9dd9f hgrepo: completely rework handing of remote refs marking
Augie Fackler <durin42@gmail.com>
parents: 361
diff changeset
1169 if sha not in store:
699088d9dd9f hgrepo: completely rework handing of remote refs marking
Augie Fackler <durin42@gmail.com>
parents: 361
diff changeset
1170 continue
699088d9dd9f hgrepo: completely rework handing of remote refs marking
Augie Fackler <durin42@gmail.com>
parents: 361
diff changeset
1171 hgsha = self.map_hg_get(sha)
305
ad2ea8d6ef94 update_remote_branches: refactor head usage
Tay Ray Chuan <rctay89@gmail.com>
parents: 304
diff changeset
1172 head = ref_name[11:]
367
699088d9dd9f hgrepo: completely rework handing of remote refs marking
Augie Fackler <durin42@gmail.com>
parents: 361
diff changeset
1173 tags['/'.join((remote_name, head))] = hgsha
699088d9dd9f hgrepo: completely rework handing of remote refs marking
Augie Fackler <durin42@gmail.com>
parents: 361
diff changeset
1174 # TODO(durin42): what is this doing?
305
ad2ea8d6ef94 update_remote_branches: refactor head usage
Tay Ray Chuan <rctay89@gmail.com>
parents: 304
diff changeset
1175 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
1176 self.git.refs[new_ref] = sha
316
7e5ed21ceec1 git_handler: prefer () continuation to \ continuation.
Augie Fackler <durin42@gmail.com>
parents: 306
diff changeset
1177 elif (ref_name.startswith('refs/tags')
7e5ed21ceec1 git_handler: prefer () continuation to \ continuation.
Augie Fackler <durin42@gmail.com>
parents: 306
diff changeset
1178 and not ref_name.endswith('^{}')):
305
ad2ea8d6ef94 update_remote_branches: refactor head usage
Tay Ray Chuan <rctay89@gmail.com>
parents: 304
diff changeset
1179 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
1180
367
699088d9dd9f hgrepo: completely rework handing of remote refs marking
Augie Fackler <durin42@gmail.com>
parents: 361
diff changeset
1181 tf = open(tagfile, 'wb')
699088d9dd9f hgrepo: completely rework handing of remote refs marking
Augie Fackler <durin42@gmail.com>
parents: 361
diff changeset
1182 for tag, node in tags.iteritems():
699088d9dd9f hgrepo: completely rework handing of remote refs marking
Augie Fackler <durin42@gmail.com>
parents: 361
diff changeset
1183 tf.write('%s %s\n' % (node, tag))
699088d9dd9f hgrepo: completely rework handing of remote refs marking
Augie Fackler <durin42@gmail.com>
parents: 361
diff changeset
1184 tf.close()
699088d9dd9f hgrepo: completely rework handing of remote refs marking
Augie Fackler <durin42@gmail.com>
parents: 361
diff changeset
1185
196
40edc4b814e4 Reorganize push for more symmetry with fetch
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 195
diff changeset
1186
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
1187 ## UTILITY FUNCTIONS
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
1188
53
5deb5cbd86aa respecting file modes on git import
Scott Chacon <schacon@gmail.com>
parents: 52
diff changeset
1189 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
1190 # TODO: make these into constants
53
5deb5cbd86aa respecting file modes on git import
Scott Chacon <schacon@gmail.com>
parents: 52
diff changeset
1191 convert = {
121
0c94e860a0ed use octal numbers for modes.
Dmitriy Taychenachev <dimichxp@gmail.com>
parents: 120
diff changeset
1192 0100644: '',
0c94e860a0ed use octal numbers for modes.
Dmitriy Taychenachev <dimichxp@gmail.com>
parents: 120
diff changeset
1193 0100755: 'x',
0c94e860a0ed use octal numbers for modes.
Dmitriy Taychenachev <dimichxp@gmail.com>
parents: 120
diff changeset
1194 0120000: 'l'}
53
5deb5cbd86aa respecting file modes on git import
Scott Chacon <schacon@gmail.com>
parents: 52
diff changeset
1195 if mode in convert:
5deb5cbd86aa respecting file modes on git import
Scott Chacon <schacon@gmail.com>
parents: 52
diff changeset
1196 return convert[mode]
5deb5cbd86aa respecting file modes on git import
Scott Chacon <schacon@gmail.com>
parents: 52
diff changeset
1197 return ''
65
5ed8316d3cfa Start using reasonable ui.{status,debug,warn} calls instead of print.
Augie Fackler <durin42@gmail.com>
parents: 56
diff changeset
1198
71
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
1199 def extract_hg_metadata(self, message):
227
c4f6e6f24bf1 fix bug introduced by previous commit
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 226
diff changeset
1200 split = message.split("\n--HG--\n", 1)
71
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
1201 renames = {}
164
7e98757deadc author and extra data fixes
Scott Chacon <schacon@gmail.com>
parents: 162
diff changeset
1202 extra = {}
79
7b4cf18c896b readded yet another piece of code that disappeared at some point, recovering branches properly
Scott Chacon <schacon@gmail.com>
parents: 78
diff changeset
1203 branch = False
71
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
1204 if len(split) == 2:
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
1205 message, meta = split
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
1206 lines = meta.split("\n")
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
1207 for line in lines:
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
1208 if line == '':
181
8690377c3ce9 Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 179
diff changeset
1209 continue
8690377c3ce9 Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 179
diff changeset
1210
456
4ed0d8dac6e7 git_handler: add missing not from hg metadata extraction
Augie Fackler <raf@durin42.com>
parents: 452
diff changeset
1211 if ' : ' not in line:
452
797a3584c78f git_handler: fix line.split error when bad data from a rebase is in the log
Sean Farley <sean@mcs.anl.gov>
parents: 450
diff changeset
1212 break
71
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
1213 command, data = line.split(" : ", 1)
181
8690377c3ce9 Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 179
diff changeset
1214
71
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
1215 if command == 'rename':
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
1216 before, after = data.split(" => ", 1)
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
1217 renames[after] = before
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
1218 if command == 'branch':
79
7b4cf18c896b readded yet another piece of code that disappeared at some point, recovering branches properly
Scott Chacon <schacon@gmail.com>
parents: 78
diff changeset
1219 branch = data
164
7e98757deadc author and extra data fixes
Scott Chacon <schacon@gmail.com>
parents: 162
diff changeset
1220 if command == 'extra':
7e98757deadc author and extra data fixes
Scott Chacon <schacon@gmail.com>
parents: 162
diff changeset
1221 before, after = data.split(" : ", 1)
7e98757deadc author and extra data fixes
Scott Chacon <schacon@gmail.com>
parents: 162
diff changeset
1222 extra[before] = urllib.unquote(after)
204
4734153365ac revert the changes made in 405a915bf352 and 8bfa8aa6b68f
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 203
diff changeset
1223 return (message, renames, branch, extra)
181
8690377c3ce9 Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 179
diff changeset
1224
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
1225 def get_file(self, commit, f):
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
1226 otree = self.git.tree(commit.tree)
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
1227 parts = f.split('/')
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
1228 for part in parts:
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
1229 (mode, sha) = otree[part]
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
1230 obj = self.git.get_object(sha)
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
1231 if isinstance (obj, Blob):
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
1232 return (mode, sha, obj._text)
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
1233 elif isinstance(obj, Tree):
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
1234 otree = obj
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
1235
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
1236 def get_files_changed(self, commit):
275
c2d6b1093e7e fix a bug when a directory is replaced with a file
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 261
diff changeset
1237 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
1238 btree = None
c2d6b1093e7e fix a bug when a directory is replaced with a file
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 261
diff changeset
1239
c2d6b1093e7e fix a bug when a directory is replaced with a file
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 261
diff changeset
1240 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
1241 btree = self.git[commit.parents[0]].tree
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
1242
275
c2d6b1093e7e fix a bug when a directory is replaced with a file
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 261
diff changeset
1243 changes = self.git.object_store.tree_changes(btree, tree)
c2d6b1093e7e fix a bug when a directory is replaced with a file
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 261
diff changeset
1244 files = {}
c2d6b1093e7e fix a bug when a directory is replaced with a file
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 261
diff changeset
1245 for (oldfile, newfile), (oldmode, newmode), (oldsha, newsha) in changes:
287
e08a22250fa9 Don't import git submodule files (we don't support them .. yet).
jeremy avnet <brainsik@saucelabs.com>
parents: 286
diff changeset
1246 # don't create new submodules
e08a22250fa9 Don't import git submodule files (we don't support them .. yet).
jeremy avnet <brainsik@saucelabs.com>
parents: 286
diff changeset
1247 if newmode == 0160000:
e08a22250fa9 Don't import git submodule files (we don't support them .. yet).
jeremy avnet <brainsik@saucelabs.com>
parents: 286
diff changeset
1248 if oldfile:
e08a22250fa9 Don't import git submodule files (we don't support them .. yet).
jeremy avnet <brainsik@saucelabs.com>
parents: 286
diff changeset
1249 # become a regular delete
e08a22250fa9 Don't import git submodule files (we don't support them .. yet).
jeremy avnet <brainsik@saucelabs.com>
parents: 286
diff changeset
1250 newfile, newmode = None, None
e08a22250fa9 Don't import git submodule files (we don't support them .. yet).
jeremy avnet <brainsik@saucelabs.com>
parents: 286
diff changeset
1251 else:
e08a22250fa9 Don't import git submodule files (we don't support them .. yet).
jeremy avnet <brainsik@saucelabs.com>
parents: 286
diff changeset
1252 continue
e08a22250fa9 Don't import git submodule files (we don't support them .. yet).
jeremy avnet <brainsik@saucelabs.com>
parents: 286
diff changeset
1253 # so old submodules shoudn't exist
e08a22250fa9 Don't import git submodule files (we don't support them .. yet).
jeremy avnet <brainsik@saucelabs.com>
parents: 286
diff changeset
1254 if oldmode == 0160000:
e08a22250fa9 Don't import git submodule files (we don't support them .. yet).
jeremy avnet <brainsik@saucelabs.com>
parents: 286
diff changeset
1255 if newfile:
e08a22250fa9 Don't import git submodule files (we don't support them .. yet).
jeremy avnet <brainsik@saucelabs.com>
parents: 286
diff changeset
1256 # become a regular add
e08a22250fa9 Don't import git submodule files (we don't support them .. yet).
jeremy avnet <brainsik@saucelabs.com>
parents: 286
diff changeset
1257 oldfile, oldmode = None, None
e08a22250fa9 Don't import git submodule files (we don't support them .. yet).
jeremy avnet <brainsik@saucelabs.com>
parents: 286
diff changeset
1258 else:
e08a22250fa9 Don't import git submodule files (we don't support them .. yet).
jeremy avnet <brainsik@saucelabs.com>
parents: 286
diff changeset
1259 continue
e08a22250fa9 Don't import git submodule files (we don't support them .. yet).
jeremy avnet <brainsik@saucelabs.com>
parents: 286
diff changeset
1260
275
c2d6b1093e7e fix a bug when a directory is replaced with a file
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 261
diff changeset
1261 if newfile is None:
c2d6b1093e7e fix a bug when a directory is replaced with a file
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 261
diff changeset
1262 file = oldfile
c2d6b1093e7e fix a bug when a directory is replaced with a file
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 261
diff changeset
1263 delete = True
c2d6b1093e7e fix a bug when a directory is replaced with a file
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 261
diff changeset
1264 else:
c2d6b1093e7e fix a bug when a directory is replaced with a file
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 261
diff changeset
1265 file = newfile
c2d6b1093e7e fix a bug when a directory is replaced with a file
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 261
diff changeset
1266 delete = False
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
1267
275
c2d6b1093e7e fix a bug when a directory is replaced with a file
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 261
diff changeset
1268 files[file] = (delete, newmode, newsha)
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
1269
275
c2d6b1093e7e fix a bug when a directory is replaced with a file
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 261
diff changeset
1270 return files
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
1271
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
1272 def collect_gitlinks(self, tree_id):
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
1273 """Walk the tree and collect all gitlink entries
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
1274 :param tree_id: sha of the 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
1275 :return: list of tuples (commit sha, full entry path)
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
1276 """
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
1277 queue = [(tree_id, '')]
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
1278 gitlinks = []
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
1279 while queue:
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
1280 e, path = queue.pop(0)
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
1281 o = self.git.object_store[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
1282 for (name, mode, sha) in o.iteritems():
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
1283 if mode == S_IFGITLINK:
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
1284 gitlinks.append((posixpath.join(path, name), sha))
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
1285 elif stat.S_ISDIR(mode):
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
1286 queue.append((sha, posixpath.join(path, 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
1287 return gitlinks
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
1288
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
1289 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
1290 """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
1291
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
1292 :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
1293 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
1294 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
1295 """
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
1296 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
1297 try:
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
1298 unused_mode,gitmodules_sha = tree_obj['.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
1299 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
1300 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
1301 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
1302 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
1303 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
1304 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
1305 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
1306 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
1307 sm_path = tt.get(section, 'path')
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
1308 sm_url = tt.get(section, '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
1309 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
1310 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
1311
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
1312 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
1313 """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
1314
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
1315 :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
1316 """
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
1317 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
1318 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
1319 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
1320 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
1321 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
1322
184
7bf98d3085f4 Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 183
diff changeset
1323 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
1324 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
1325 if names:
7bf98d3085f4 Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 183
diff changeset
1326 return names[0]
7bf98d3085f4 Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 183
diff changeset
1327
186
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
1328 # Stolen from hgsubversion
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
1329 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
1330 try:
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
1331 from mercurial import encoding
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
1332 old = encoding.encoding
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
1333 encoding.encoding = new_encoding
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
1334 except ImportError:
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
1335 old = hgutil._encoding
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
1336 hgutil._encoding = new_encoding
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
1337 return old
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
1338
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
1339 def decode_guess(self, string, encoding):
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
1340 # 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
1341 if encoding:
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
1342 try:
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
1343 return string.decode(encoding).encode('utf-8')
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
1344 except UnicodeDecodeError:
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
1345 pass
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
1346
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
1347 try:
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
1348 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
1349 except UnicodeDecodeError:
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
1350 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
1351
5
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
1352 def get_transport_and_path(self, uri):
369
e5c743cd0da1 pass hg's ui.ssh config to dulwich
Tay Ray Chuan <rctay89@gmail.com>
parents: 368
diff changeset
1353 # 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
1354 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
1355 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
1356
538
a38abdbab77c Precompile Git URI regular expression
Gregory Szorc <gregory.szorc@gmail.com>
parents: 537
diff changeset
1357 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
1358 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
1359 res = git_match.groupdict()
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
1360 transport = client.SSHGitClient if 'ssh' in res['scheme'] else client.TCPGitClient
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
1361 host, port, sepr, path = res['host'], res['port'], res['sepr'], res['path']
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
1362 if sepr == '/':
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
1363 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
1364 # 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
1365 # 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
1366 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
1367 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
1368 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
1369 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
1370
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
1371 return transport(host, thin_packs=False, 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
1372
3f45c88100e8 add support for the HTTP smart protocol when using Dulwich tip
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 432
diff changeset
1373 httpclient = getattr(client, 'HttpGitClient', None)
3f45c88100e8 add support for the HTTP smart protocol when using Dulwich tip
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 432
diff changeset
1374
3f45c88100e8 add support for the HTTP smart protocol when using Dulwich tip
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 432
diff changeset
1375 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
1376 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
1377
3f45c88100e8 add support for the HTTP smart protocol when using Dulwich tip
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 432
diff changeset
1378 if uri.startswith('http://') or uri.startswith('https://'):
3f45c88100e8 add support for the HTTP smart protocol when using Dulwich tip
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 432
diff changeset
1379 if not httpclient:
3f45c88100e8 add support for the HTTP smart protocol when using Dulwich tip
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 432
diff changeset
1380 raise RepoError('git via HTTP requires dulwich 0.8.1 or later')
3f45c88100e8 add support for the HTTP smart protocol when using Dulwich tip
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 432
diff changeset
1381 else:
3f45c88100e8 add support for the HTTP smart protocol when using Dulwich tip
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 432
diff changeset
1382 return client.HttpGitClient(uri, thin_packs=False), uri
3f45c88100e8 add support for the HTTP smart protocol when using Dulwich tip
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 432
diff changeset
1383
5
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
1384 # if its not git or git+ssh, try a local url..
286
0661d5721ad7 git_handler: use progress API instead of reinventing the wheel
Augie Fackler <durin42@gmail.com>
parents: 285
diff changeset
1385 return client.SubprocessGitClient(thin_packs=False), uri