annotate hggit/git_handler.py @ 381:80544310834a

fix handling of spaces in hg tag names
author Dmitry Gladkov <dmitry.gladkov@gmail.com>
date Wed, 23 Mar 2011 01:03:29 +0200
parents b4f5f2729acb
children f55869b556f0
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
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
2
230
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
3 from dulwich.errors import HangupException
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
4 from dulwich.index import commit_tree
237
16f671995881 deal correctly with old timezone format in extra committer
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 236
diff changeset
5 from dulwich.objects import Blob, Commit, Tag, Tree, parse_timezone
225
cde57730faa7 store non utf-8 encoded author/commit message as deltas
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 224
diff changeset
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
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
9
375
454fc525ac75 support upcoming Mercurial 1.8
Kevin Bullock <kbullock@ringworld.org>
parents: 374
diff changeset
10 try:
454fc525ac75 support upcoming Mercurial 1.8
Kevin Bullock <kbullock@ringworld.org>
parents: 374
diff changeset
11 from mercurial import bookmarks
454fc525ac75 support upcoming Mercurial 1.8
Kevin Bullock <kbullock@ringworld.org>
parents: 374
diff changeset
12 bookmarks.update
454fc525ac75 support upcoming Mercurial 1.8
Kevin Bullock <kbullock@ringworld.org>
parents: 374
diff changeset
13 except ImportError:
454fc525ac75 support upcoming Mercurial 1.8
Kevin Bullock <kbullock@ringworld.org>
parents: 374
diff changeset
14 from hgext import bookmarks
5
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
15 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
16 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
17 from mercurial import context, util as hgutil
300
eec31dee258e Various hg 1.4 compat fixes.
Augie Fackler <durin42@gmail.com>
parents: 298
diff changeset
18 from mercurial import error
222
e414c72d3ec9 fix compatibility with mercurial 1.1
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 221
diff changeset
19
369
e5c743cd0da1 pass hg's ui.ssh config to dulwich
Tay Ray Chuan <rctay89@gmail.com>
parents: 368
diff changeset
20 import _ssh
320
6eded2e4c616 Un-break hg 1.3 by adding a compat layer for progress.
Augie Fackler <durin42@gmail.com>
parents: 317
diff changeset
21 import util
24
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
22
5
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
23 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
24 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
25 tagsfile = 'git-tags'
19
2be9c0bd88af Warn, but don't fail when bookmarks is not enabled.
Augie Fackler <durin42@gmail.com>
parents: 17
diff changeset
26
5
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
27 def __init__(self, dest_repo, ui):
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
28 self.repo = dest_repo
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
29 self.ui = ui
133
f2dfb2bed724 Allow storing the git directory intree
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 118
diff changeset
30
324
f0c1c35d95ba explicitly expect boolean values for git.intree
Tay Ray Chuan <rctay89@gmail.com>
parents: 320
diff changeset
31 if ui.configbool('git', 'intree'):
133
f2dfb2bed724 Allow storing the git directory intree
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 118
diff changeset
32 self.gitdir = self.repo.wjoin('.git')
f2dfb2bed724 Allow storing the git directory intree
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 118
diff changeset
33 else:
f2dfb2bed724 Allow storing the git directory intree
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 118
diff changeset
34 self.gitdir = self.repo.join('git')
f2dfb2bed724 Allow storing the git directory intree
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 118
diff changeset
35
184
7bf98d3085f4 Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 183
diff changeset
36 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
37
7
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
38 self.load_map()
187
5f196f80ffb3 Store git tags in .hg/git-tags and let localtags be *local*
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 186
diff changeset
39 self.load_tags()
19
2be9c0bd88af Warn, but don't fail when bookmarks is not enabled.
Augie Fackler <durin42@gmail.com>
parents: 17
diff changeset
40
2be9c0bd88af Warn, but don't fail when bookmarks is not enabled.
Augie Fackler <durin42@gmail.com>
parents: 17
diff changeset
41 # make the git data directory
16
58cd05129119 moved init into git_handler
Scott Chacon <schacon@gmail.com>
parents: 14
diff changeset
42 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
43 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
44 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
45 else:
106
3aa2f6caed16 make the gitdir a constant
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 105
diff changeset
46 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
47 self.git = Repo.init_bare(self.gitdir)
7
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
48
14
36e94e805fa7 added basic config file for remembering remote urls
Scott Chacon <schacon@gmail.com>
parents: 13
diff changeset
49 ## FILE LOAD AND SAVE METHODS
36e94e805fa7 added basic config file for remembering remote urls
Scott Chacon <schacon@gmail.com>
parents: 13
diff changeset
50
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
51 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
52 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
53 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
54
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
55 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
56 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
57
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
58 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
59 return self._map_hg.get(hgsha)
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
60
7
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
61 def load_map(self):
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
62 self._map_git = {}
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
63 self._map_hg = {}
105
41e76444105c make git-mapfile and git-configfile constants
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 104
diff changeset
64 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
65 for line in self.repo.opener(self.mapfile):
7
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
66 gitsha, hgsha = line.strip().split(' ', 1)
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
67 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
68 self._map_hg[hgsha] = gitsha
19
2be9c0bd88af Warn, but don't fail when bookmarks is not enabled.
Augie Fackler <durin42@gmail.com>
parents: 17
diff changeset
69
7
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
70 def save_map(self):
105
41e76444105c make git-mapfile and git-configfile constants
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 104
diff changeset
71 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
72 for hgsha, gitsha in sorted(self._map_hg.iteritems()):
7
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
73 file.write("%s %s\n" % (gitsha, hgsha))
101
7c57f15d397c use atomictemp to prevent corruption on ctrl-c
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 100
diff changeset
74 file.rename()
19
2be9c0bd88af Warn, but don't fail when bookmarks is not enabled.
Augie Fackler <durin42@gmail.com>
parents: 17
diff changeset
75
187
5f196f80ffb3 Store git tags in .hg/git-tags and let localtags be *local*
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 186
diff changeset
76 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
77 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
78 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
79 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
80 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
81 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
82
5f196f80ffb3 Store git tags in .hg/git-tags and let localtags be *local*
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 186
diff changeset
83 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
84 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
85 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
86 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
87 file.write("%s %s\n" % (sha, name))
187
5f196f80ffb3 Store git tags in .hg/git-tags and let localtags be *local*
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 186
diff changeset
88 file.rename()
5f196f80ffb3 Store git tags in .hg/git-tags and let localtags be *local*
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 186
diff changeset
89
14
36e94e805fa7 added basic config file for remembering remote urls
Scott Chacon <schacon@gmail.com>
parents: 13
diff changeset
90 ## END FILE LOAD AND SAVE METHODS
7
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
91
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
92 ## COMMANDS METHODS
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
93
137
5aefcbf1e50c add a gimport command
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 136
diff changeset
94 def import_commits(self, remote_name):
5aefcbf1e50c add a gimport command
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 136
diff changeset
95 self.import_git_objects(remote_name)
5aefcbf1e50c add a gimport command
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 136
diff changeset
96 self.save_map()
5aefcbf1e50c add a gimport command
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 136
diff changeset
97
232
0ba1aee0467c initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 231
diff changeset
98 def fetch(self, remote, heads):
236
42ae65e6c1d1 save the map only once in export
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 235
diff changeset
99 self.export_commits()
232
0ba1aee0467c initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 231
diff changeset
100 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
101 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
102
56
5185af4e649a hg gfetch now works
Scott Chacon <schacon@gmail.com>
parents: 54
diff changeset
103 if refs:
149
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
104 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
105 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
106 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
107 if remote_name:
7bf98d3085f4 Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 183
diff changeset
108 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
109 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
110 # intial cloning
7bf98d3085f4 Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 183
diff changeset
111 self.update_remote_branches('default', refs)
196
40edc4b814e4 Reorganize push for more symmetry with fetch
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 195
diff changeset
112 else:
40edc4b814e4 Reorganize push for more symmetry with fetch
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 195
diff changeset
113 self.ui.status(_("nothing new on the server\n"))
184
7bf98d3085f4 Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 183
diff changeset
114
7
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
115 self.save_map()
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
116
236
42ae65e6c1d1 save the map only once in export
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 235
diff changeset
117 def export_commits(self):
42ae65e6c1d1 save the map only once in export
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 235
diff changeset
118 try:
172
ac92cdc45ceb not trying to write the same tree twice
Scott Chacon <schacon@gmail.com>
parents: 171
diff changeset
119 self.export_git_objects()
236
42ae65e6c1d1 save the map only once in export
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 235
diff changeset
120 self.export_hg_tags()
42ae65e6c1d1 save the map only once in export
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 235
diff changeset
121 self.update_references()
42ae65e6c1d1 save the map only once in export
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 235
diff changeset
122 finally:
42ae65e6c1d1 save the map only once in export
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 235
diff changeset
123 self.save_map()
97
f0628f5270b6 add gexport command
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 96
diff changeset
124
231
bdaec2a079ce initial support for 'hg outgoing'
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 230
diff changeset
125 def get_refs(self, remote):
bdaec2a079ce initial support for 'hg outgoing'
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 230
diff changeset
126 self.export_commits()
bdaec2a079ce initial support for 'hg outgoing'
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 230
diff changeset
127 client, path = self.get_transport_and_path(remote)
bdaec2a079ce initial support for 'hg outgoing'
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 230
diff changeset
128 old_refs = {}
bdaec2a079ce initial support for 'hg outgoing'
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 230
diff changeset
129 new_refs = {}
bdaec2a079ce initial support for 'hg outgoing'
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 230
diff changeset
130 def changed(refs):
bdaec2a079ce initial support for 'hg outgoing'
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 230
diff changeset
131 old_refs.update(refs)
bdaec2a079ce initial support for 'hg outgoing'
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 230
diff changeset
132 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
133 new_refs.update(self.get_changed_refs(refs, to_push, True))
bdaec2a079ce initial support for 'hg outgoing'
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 230
diff changeset
134 # don't push anything
bdaec2a079ce initial support for 'hg outgoing'
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 230
diff changeset
135 return {}
bdaec2a079ce initial support for 'hg outgoing'
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 230
diff changeset
136
bdaec2a079ce initial support for 'hg outgoing'
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 230
diff changeset
137 try:
bdaec2a079ce initial support for 'hg outgoing'
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 230
diff changeset
138 client.send_pack(path, changed, None)
243
53b731d2a3e2 outgoing: don't crash when there are unpulled changesets
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 242
diff changeset
139
53b731d2a3e2 outgoing: don't crash when there are unpulled changesets
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 242
diff changeset
140 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
141 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
142 new = [bin(self.map_hg_get(new_refs[ref])) for ref in changed_refs]
53b731d2a3e2 outgoing: don't crash when there are unpulled changesets
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 242
diff changeset
143 old = dict( (bin(self.map_hg_get(old_refs[r])), 1)
245
c6d268886405 fix crash in outgoing if there are new (git) branches
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 243
diff changeset
144 for r in changed_refs if r in old_refs)
231
bdaec2a079ce initial support for 'hg outgoing'
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 230
diff changeset
145
bdaec2a079ce initial support for 'hg outgoing'
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 230
diff changeset
146 return old, new
bdaec2a079ce initial support for 'hg outgoing'
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 230
diff changeset
147 except HangupException:
bdaec2a079ce initial support for 'hg outgoing'
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 230
diff changeset
148 raise hgutil.Abort("the remote end hung up unexpectedly")
bdaec2a079ce initial support for 'hg outgoing'
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 230
diff changeset
149
230
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
150 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
151 self.export_commits()
230
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
152 changed_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
153 remote_name = self.remote_name(remote)
40edc4b814e4 Reorganize push for more symmetry with fetch
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 195
diff changeset
154
40edc4b814e4 Reorganize push for more symmetry with fetch
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 195
diff changeset
155 if remote_name and changed_refs:
40edc4b814e4 Reorganize push for more symmetry with fetch
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 195
diff changeset
156 for ref, sha in changed_refs.iteritems():
293
8aaae306d46f git_handler: 80 columns cleanup
Augie Fackler <durin42@gmail.com>
parents: 292
diff changeset
157 self.ui.status(" %s::%s => GIT:%s\n" %
8aaae306d46f git_handler: 80 columns cleanup
Augie Fackler <durin42@gmail.com>
parents: 292
diff changeset
158 (remote_name, ref, sha[0:8]))
196
40edc4b814e4 Reorganize push for more symmetry with fetch
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 195
diff changeset
159
40edc4b814e4 Reorganize push for more symmetry with fetch
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 195
diff changeset
160 self.update_remote_branches(remote_name, changed_refs)
40edc4b814e4 Reorganize push for more symmetry with fetch
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 195
diff changeset
161
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
162 def clear(self):
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
163 mapfile = self.repo.join(self.mapfile)
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
164 if os.path.exists(self.gitdir):
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
165 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
166 for name in files:
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
167 os.remove(os.path.join(root, name))
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
168 for name in dirs:
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
169 os.rmdir(os.path.join(root, name))
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
170 os.rmdir(self.gitdir)
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
171 if os.path.exists(mapfile):
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
172 os.remove(mapfile)
124
9dafb9ac24ff hg bookmarks to local git branches
Ian Dees <undees@gmail.com>
parents: 118
diff changeset
173
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
174 ## CHANGESET CONVERSION METHODS
125
5b702bbf078f local git branches to remotes
Ian Dees <undees@gmail.com>
parents: 124
diff changeset
175
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
176 def export_git_objects(self):
142
ed884cfe3fa3 export: be more clean in what we're doing
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 141
diff changeset
177 self.ui.status(_("importing Hg objects into Git\n"))
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
178 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
179
190
6fbdf1afe032 Better reporting of the number of commits to convert
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 188
diff changeset
180 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
181 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
182 total = len(export)
6fbdf1afe032 Better reporting of the number of commits to convert
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 188
diff changeset
183 for i, rev in enumerate(export):
374
f008197045d3 progress: use gerund form for import
timeless <timeless@gmail.com>
parents: 369
diff changeset
184 util.progress(self.ui, 'importing', i, total=total)
159
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
185 ctx = self.repo.changectx(rev)
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
186 state = ctx.extra().get('hg-git', None)
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
187 if state == 'octopus':
293
8aaae306d46f git_handler: 80 columns cleanup
Augie Fackler <durin42@gmail.com>
parents: 292
diff changeset
188 self.ui.debug("revision %d is a part "
8aaae306d46f git_handler: 80 columns cleanup
Augie Fackler <durin42@gmail.com>
parents: 292
diff changeset
189 "of octopus explosion\n" % ctx.rev())
159
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
190 continue
190
6fbdf1afe032 Better reporting of the number of commits to convert
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 188
diff changeset
191 self.export_hg_commit(rev)
374
f008197045d3 progress: use gerund form for import
timeless <timeless@gmail.com>
parents: 369
diff changeset
192 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
193
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
194
24
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
195 # 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
196 # 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
197 # write the commit object (with metadata info)
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
198 def export_hg_commit(self, rev):
301
09116995c421 export_hg_commit: fix debug note
Tay Ray Chuan <rctay89@gmail.com>
parents: 288
diff changeset
199 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
200
203
104a4fd6a0af trying to fix some of the broken tests
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 199
diff changeset
201 oldenc = self.swap_out_encoding()
104a4fd6a0af trying to fix some of the broken tests
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 199
diff changeset
202
159
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
203 ctx = self.repo.changectx(rev)
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
204 extra = ctx.extra()
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
205
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
206 commit = Commit()
68
d28d3763eda3 Deal with hg authors missing email attributes.
Chris Wanstrath <chris@ozmm.org>
parents: 65
diff changeset
207
235
912d6a5837c8 reorganize export_hg_commit
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 234
diff changeset
208 (time, timezone) = ctx.date()
239
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
209 commit.author = self.get_git_author(ctx)
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
210 commit.author_time = int(time)
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
211 commit.author_timezone = -timezone
186
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
212
89
e35ed99fa691 committer info now being kept properly
Scott Chacon <schacon@gmail.com>
parents: 88
diff changeset
213 if 'committer' in extra:
131
dd6c77ec206c store commitdate in mercurial's internal format.
Dmitriy Taychenachev <dimichxp@gmail.com>
parents: 129
diff changeset
214 # fixup timezone
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
215 (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
216 commit.committer = name
16f671995881 deal correctly with old timezone format in extra committer
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 236
diff changeset
217 commit.commit_time = timestamp
16f671995881 deal correctly with old timezone format in extra committer
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 236
diff changeset
218
16f671995881 deal correctly with old timezone format in extra committer
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 236
diff changeset
219 # 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
220 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
221 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
222 # 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
223 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
224 timezone, neg_utc = timezone
361
4e1ac77815c3 fix typo -- my bad >.<
Mike Blume <mike@loggly.com>
parents: 360
diff changeset
225 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
226 else:
16f671995881 deal correctly with old timezone format in extra committer
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 236
diff changeset
227 timezone = -int(timezone)
16f671995881 deal correctly with old timezone format in extra committer
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 236
diff changeset
228 commit.commit_timezone = timezone
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
229 else:
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
230 commit.committer = commit.author
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
231 commit.commit_time = commit.author_time
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
232 commit.commit_timezone = commit.author_timezone
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
233
239
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
234 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
235 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
236 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
237 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
238 if 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
239 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
240
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
241 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
242
118
b3be536e3f50 handles git commit encoding fields now
Scott Chacon <schacon@gmail.com>
parents: 113
diff changeset
243 if 'encoding' in extra:
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
244 commit.encoding = extra['encoding']
89
e35ed99fa691 committer info now being kept properly
Scott Chacon <schacon@gmail.com>
parents: 88
diff changeset
245
239
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
246 tree_sha = commit_tree(self.git.object_store, self.iterblobs(ctx))
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
247 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
248
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
249 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
250 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
251
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
252 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
253 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
254
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
255 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
256 # 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
257 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
258
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
259 # check for git author pattern compliance
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
260 regex = re.compile('^(.*?) \<(.*?)\>(.*)$')
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
261 a = regex.match(author)
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
262
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
263 if a:
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
264 name = a.group(1)
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
265 email = a.group(2)
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
266 if len(a.group(3)) > 0:
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
267 name += ' ext:(' + urllib.quote(a.group(3)) + ')'
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
268 author = name + ' <' + email + '>'
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
269 else:
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
270 author = author + ' <none@none>'
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
271
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
272 if 'author' in ctx.extra():
307
7dfe8be21135 handle apply_delta() return value correctly
Tay Ray Chuan <rctay89@gmail.com>
parents: 302
diff changeset
273 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
274
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
275 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
276
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
277 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
278 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
279 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
280
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
281 parents = []
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
282 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
283 # 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
284 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
285 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
286 (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
287 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
288 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
289 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
290 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
291 else:
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
292 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
293
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
294 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
295
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
296 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
297 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
298
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
299 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
300 if 'message' in extra:
307
7dfe8be21135 handle apply_delta() return value correctly
Tay Ray Chuan <rctay89@gmail.com>
parents: 302
diff changeset
301 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
302
54
f6e11b9d7562 not adding HG extra info if commits were on the default branch
Scott Chacon <schacon@gmail.com>
parents: 53
diff changeset
303 # 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
304 add_extras = False
67
759ac56497e7 adding hg explicit file renames to the git commit message
Scott Chacon <schacon@gmail.com>
parents: 65
diff changeset
305 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
306 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
307 add_extras = True
67
759ac56497e7 adding hg explicit file renames to the git commit message
Scott Chacon <schacon@gmail.com>
parents: 65
diff changeset
308 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
309
239
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
310 renames = []
247
3c01e07b0252 look for renamed files only in files modified by the commit
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 245
diff changeset
311 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
312 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
313 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
314 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
315 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
316 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
317
67
759ac56497e7 adding hg explicit file renames to the git commit message
Scott Chacon <schacon@gmail.com>
parents: 65
diff changeset
318 if renames:
759ac56497e7 adding hg explicit file renames to the git commit message
Scott Chacon <schacon@gmail.com>
parents: 65
diff changeset
319 add_extras = True
759ac56497e7 adding hg explicit file renames to the git commit message
Scott Chacon <schacon@gmail.com>
parents: 65
diff changeset
320 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
321 extra_message += "rename : " + oldfile + " => " + newfile + "\n"
164
7e98757deadc author and extra data fixes
Scott Chacon <schacon@gmail.com>
parents: 162
diff changeset
322
7e98757deadc author and extra data fixes
Scott Chacon <schacon@gmail.com>
parents: 162
diff changeset
323 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
324 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
325 continue
7e98757deadc author and extra data fixes
Scott Chacon <schacon@gmail.com>
parents: 162
diff changeset
326 else:
181
8690377c3ce9 Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 179
diff changeset
327 add_extras = True
164
7e98757deadc author and extra data fixes
Scott Chacon <schacon@gmail.com>
parents: 162
diff changeset
328 extra_message += "extra : " + key + " : " + urllib.quote(value) + "\n"
7e98757deadc author and extra data fixes
Scott Chacon <schacon@gmail.com>
parents: 162
diff changeset
329
54
f6e11b9d7562 not adding HG extra info if commits were on the default branch
Scott Chacon <schacon@gmail.com>
parents: 53
diff changeset
330 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
331 message += "\n--HG--\n" + extra_message
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
332
239
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
333 return message
65
5ed8316d3cfa Start using reasonable ui.{status,debug,warn} calls instead of print.
Augie Fackler <durin42@gmail.com>
parents: 56
diff changeset
334
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
335 def iterblobs(self, ctx):
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
336 for f in ctx:
234
6f34aee64a3f readd blob caching (~25% improvement in gexport)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 233
diff changeset
337 fctx = ctx[f]
6f34aee64a3f readd blob caching (~25% improvement in gexport)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 233
diff changeset
338 blobid = self.map_git_get(hex(fctx.filenode()))
6f34aee64a3f readd blob caching (~25% improvement in gexport)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 233
diff changeset
339
6f34aee64a3f readd blob caching (~25% improvement in gexport)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 233
diff changeset
340 if not blobid:
6f34aee64a3f readd blob caching (~25% improvement in gexport)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 233
diff changeset
341 blob = Blob.from_string(fctx.data())
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
342 self.git.object_store.add_object(blob)
234
6f34aee64a3f readd blob caching (~25% improvement in gexport)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 233
diff changeset
343 self.map_set(blob.id, hex(fctx.filenode()))
6f34aee64a3f readd blob caching (~25% improvement in gexport)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 233
diff changeset
344 blobid = blob.id
6f34aee64a3f readd blob caching (~25% improvement in gexport)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 233
diff changeset
345
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
346 if 'l' in ctx.flags(f):
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
347 mode = 0120000
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
348 elif 'x' in ctx.flags(f):
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
349 mode = 0100755
23
ee217d3c6363 will now write all trees and blobs needed. all thats left is commits for basic data conversion
Scott Chacon <schacon@gmail.com>
parents: 22
diff changeset
350 else:
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
351 mode = 0100644
234
6f34aee64a3f readd blob caching (~25% improvement in gexport)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 233
diff changeset
352
6f34aee64a3f readd blob caching (~25% improvement in gexport)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 233
diff changeset
353 yield f, blobid, mode
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
354
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
355 def import_git_objects(self, remote_name=None, refs=None):
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
356 self.ui.status(_("importing Git objects into Hg\n"))
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
357 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
358
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
359 # import heads and fetched tags as remote references
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
360 todo = []
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
361 done = set()
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
362 convert_list = {}
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
363
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
364 # 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
365 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
366 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
367 refs = self.git.refs.as_dict()
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
368 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
369 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
370 # 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
371 # 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
372 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
373 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
374 while isinstance(obj, Tag):
337
6cea997ee302 enforce stricter matching for pull -r
Tay Ray Chuan <rctay89@gmail.com>
parents: 258
diff changeset
375 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
376 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
377 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
378 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
379 todo.append(sha)
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
380
284
12cfa77a2ab0 sort heads by commit date in topological sort
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 283
diff changeset
381 # sort by commit date
12cfa77a2ab0 sort heads by commit date in topological sort
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 283
diff changeset
382 def commitdate(sha):
12cfa77a2ab0 sort heads by commit date in topological sort
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 283
diff changeset
383 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
384 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
385
12cfa77a2ab0 sort heads by commit date in topological sort
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 283
diff changeset
386 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
387
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
388 # 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
389 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
390 seen = set(todo)
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
391 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
392 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
393 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
394 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
395 continue
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
396 assert isinstance(sha, str)
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
397 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
398 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
399 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
400 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
401 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
402 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
403 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
404 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
405 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
406 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
407 todo.pop()
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
408
190
6fbdf1afe032 Better reporting of the number of commits to convert
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 188
diff changeset
409 commits = [commit for commit in commits if not commit in self._map_git]
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
410 # import each of the commits, oldest first
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
411 total = len(commits)
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
412 for i, csha in enumerate(commits):
374
f008197045d3 progress: use gerund form for import
timeless <timeless@gmail.com>
parents: 369
diff changeset
413 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
414 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
415 self.import_git_commit(commit)
374
f008197045d3 progress: use gerund form for import
timeless <timeless@gmail.com>
parents: 369
diff changeset
416 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
417
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
418 def import_git_commit(self, commit):
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
419 self.ui.debug(_("importing: %s\n") % commit.id)
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
420
293
8aaae306d46f git_handler: 80 columns cleanup
Augie Fackler <durin42@gmail.com>
parents: 292
diff changeset
421 (strip_message, hg_renames,
8aaae306d46f git_handler: 80 columns cleanup
Augie Fackler <durin42@gmail.com>
parents: 292
diff changeset
422 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
423
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
424 # 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
425 files = self.get_files_changed(commit)
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
426
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
427 date = (commit.author_time, -commit.author_timezone)
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
428 text = strip_message
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
429
226
3b8804c59b63 drop untested commit_import_ctx (use commitctx instead).
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 225
diff changeset
430 origtext = text
186
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
431 try:
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
432 text.decode('utf-8')
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
433 except UnicodeDecodeError:
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
434 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
435
3b8804c59b63 drop untested commit_import_ctx (use commitctx instead).
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 225
diff changeset
436 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
437 if text + '\n' != origtext:
3b8804c59b63 drop untested commit_import_ctx (use commitctx instead).
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 225
diff changeset
438 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
439
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
440 author = commit.author
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
441
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
442 # convert extra data back to the end
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
443 if ' ext:' in commit.author:
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
444 regex = re.compile('^(.*?)\ ext:\((.*)\) <(.*)\>$')
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
445 m = regex.match(commit.author)
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
446 if m:
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
447 name = m.group(1)
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
448 ex = urllib.unquote(m.group(2))
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
449 email = m.group(3)
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
450 author = name + ' <' + email + '>' + ex
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
451
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
452 if ' <none@none>' in commit.author:
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
453 author = commit.author[:-12]
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
454
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
455 try:
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
456 author.decode('utf-8')
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
457 except UnicodeDecodeError:
225
cde57730faa7 store non utf-8 encoded author/commit message as deltas
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 224
diff changeset
458 origauthor = author
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
459 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
460 extra['author'] = create_delta(author, origauthor)
186
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
461
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
462 oldenc = self.swap_out_encoding()
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
463
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
464 def getfilectx(repo, memctx, f):
275
c2d6b1093e7e fix a bug when a directory is replaced with a file
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 261
diff changeset
465 delete, mode, sha = files[f]
c2d6b1093e7e fix a bug when a directory is replaced with a file
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 261
diff changeset
466 if delete:
c2d6b1093e7e fix a bug when a directory is replaced with a file
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 261
diff changeset
467 raise IOError
c2d6b1093e7e fix a bug when a directory is replaced with a file
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 261
diff changeset
468
c2d6b1093e7e fix a bug when a directory is replaced with a file
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 261
diff changeset
469 data = self.git[sha].data
c2d6b1093e7e fix a bug when a directory is replaced with a file
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 261
diff changeset
470 copied_path = hg_renames.get(f)
c2d6b1093e7e fix a bug when a directory is replaced with a file
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 261
diff changeset
471 e = self.convert_git_int_mode(mode)
c2d6b1093e7e fix a bug when a directory is replaced with a file
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 261
diff changeset
472
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
473 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
474
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
475 gparents = map(self.map_hg_get, commit.parents)
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
476 p1, p2 = (nullid, nullid)
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
477 octopus = False
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
478
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
479 if len(gparents) > 1:
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
480 # merge, possibly octopus
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
481 def commit_octopus(p1, p2):
275
c2d6b1093e7e fix a bug when a directory is replaced with a file
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 261
diff changeset
482 ctx = context.memctx(self.repo, (p1, p2), text, list(files), getfilectx,
186
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
483 author, date, {'hg-git': 'octopus'})
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
484 return hex(self.repo.commitctx(ctx))
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
485
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
486 octopus = len(gparents) > 2
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
487 p2 = gparents.pop()
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
488 p1 = gparents.pop()
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
489 while len(gparents) > 0:
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
490 p2 = commit_octopus(p1, p2)
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
491 p1 = gparents.pop()
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
492 else:
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
493 if gparents:
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
494 p1 = gparents.pop()
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
495
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
496 pa = None
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
497 if not (p2 == nullid):
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
498 node1 = self.repo.changectx(p1)
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
499 node2 = self.repo.changectx(p2)
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
500 pa = node1.ancestor(node2)
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
501
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
502 # if named branch, add to extra
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
503 if hg_branch:
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
504 extra['branch'] = hg_branch
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
505
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
506 # 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
507 if commit.author != commit.committer \
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
508 or commit.author_time != commit.commit_time \
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
509 or commit.author_timezone != commit.commit_timezone:
293
8aaae306d46f git_handler: 80 columns cleanup
Augie Fackler <durin42@gmail.com>
parents: 292
diff changeset
510 extra['committer'] = "%s %d %d" % (
8aaae306d46f git_handler: 80 columns cleanup
Augie Fackler <durin42@gmail.com>
parents: 292
diff changeset
511 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
512
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
513 if commit.encoding:
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
514 extra['encoding'] = commit.encoding
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
515
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
516 if hg_branch:
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
517 extra['branch'] = hg_branch
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
518
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
519 if octopus:
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
520 extra['hg-git'] ='octopus-done'
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
521
300
eec31dee258e Various hg 1.4 compat fixes.
Augie Fackler <durin42@gmail.com>
parents: 298
diff changeset
522 # 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
523 def repo_contains(n):
eec31dee258e Various hg 1.4 compat fixes.
Augie Fackler <durin42@gmail.com>
parents: 298
diff changeset
524 try:
eec31dee258e Various hg 1.4 compat fixes.
Augie Fackler <durin42@gmail.com>
parents: 298
diff changeset
525 return bool(self.repo.lookup(n))
eec31dee258e Various hg 1.4 compat fixes.
Augie Fackler <durin42@gmail.com>
parents: 298
diff changeset
526 except error.RepoLookupError:
eec31dee258e Various hg 1.4 compat fixes.
Augie Fackler <durin42@gmail.com>
parents: 298
diff changeset
527 return False
eec31dee258e Various hg 1.4 compat fixes.
Augie Fackler <durin42@gmail.com>
parents: 298
diff changeset
528
eec31dee258e Various hg 1.4 compat fixes.
Augie Fackler <durin42@gmail.com>
parents: 298
diff changeset
529 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
530 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
531 'please run hg git-cleanup'))
275
c2d6b1093e7e fix a bug when a directory is replaced with a file
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 261
diff changeset
532 ctx = context.memctx(self.repo, (p1, p2), text, list(files), getfilectx,
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
533 author, date, extra)
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
534
226
3b8804c59b63 drop untested commit_import_ctx (use commitctx instead).
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 225
diff changeset
535 node = self.repo.commitctx(ctx)
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
536
186
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
537 self.swap_out_encoding(oldenc)
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
538
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
539 # save changeset to mapping file
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
540 cs = hex(node)
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
541 self.map_set(commit.id, cs)
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
542
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
543 ## 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
544
230
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
545 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
546 client, path = self.get_transport_and_path(remote)
230
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
547 def changed(refs):
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
548 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
549 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
550
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
551 genpack = self.git.object_store.generate_pack_contents
26
a1a5391bc3c3 edit ssh command to quote the path, also convert tags properly on fetch
Scott Chacon <schacon@gmail.com>
parents: 25
diff changeset
552 try:
95
7de67fcb18b0 be better about internationalizing strings
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 94
diff changeset
553 self.ui.status(_("creating and sending data\n"))
47
3b62270c1fad writing some status output after a push, updating local bookmarks
Scott Chacon <schacon@gmail.com>
parents: 42
diff changeset
554 changed_refs = client.send_pack(path, changed, genpack)
207
c06ac5b982a9 add a test for pushing to git
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 204
diff changeset
555 return changed_refs
230
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
556 except HangupException:
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
557 raise hgutil.Abort("the remote end hung up unexpectedly")
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
558
230
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
559 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
560 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
561
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
562 #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
563 if refs.keys()[0] == 'capabilities^{}':
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
564 del new_refs['capabilities^{}']
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
565 if not self.local_heads():
bfe6fd2fdb9b push tip to master in an empty repository even if there are tags
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 247
diff changeset
566 tip = hex(self.repo.lookup('tip'))
268
6fded8e42858 git_handler: update for slight API change in bookmarks
Augie Fackler <durin42@gmail.com>
parents: 267
diff changeset
567 bookmarks.bookmark(self.ui, self.repo, 'master', tip, force=True)
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
568 bookmarks.setcurrent(self.repo, 'master')
bfe6fd2fdb9b push tip to master in an empty repository even if there are tags
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 247
diff changeset
569 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
570
230
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
571 for rev in revs:
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
572 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
573 if getattr(ctx, 'bookmarks', None):
b4f5f2729acb git_handler: update ctx label handling for bookmarks in core
Augie Fackler <durin42@gmail.com>
parents: 375
diff changeset
574 labels = lambda c: ctx.tags() + ctx.bookmarks()
b4f5f2729acb git_handler: update ctx label handling for bookmarks in core
Augie Fackler <durin42@gmail.com>
parents: 375
diff changeset
575 else:
b4f5f2729acb git_handler: update ctx label handling for bookmarks in core
Augie Fackler <durin42@gmail.com>
parents: 375
diff changeset
576 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
577 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
578
80544310834a fix handling of spaces in hg tag names
Dmitry Gladkov <dmitry.gladkov@gmail.com>
parents: 376
diff changeset
579 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
580 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
581
230
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
582 if not (heads or tags):
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
583 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
584 " it doesn't have a ref" % ctx)
149
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
585
310
53b0d608dcd5 when pushing, check if server is advertising annotated tags
Tay Ray Chuan <rctay89@gmail.com>
parents: 302
diff changeset
586 # 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
587 # 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
588 # list of these tags.
53b0d608dcd5 when pushing, check if server is advertising annotated tags
Tay Ray Chuan <rctay89@gmail.com>
parents: 302
diff changeset
589 #
53b0d608dcd5 when pushing, check if server is advertising annotated tags
Tay Ray Chuan <rctay89@gmail.com>
parents: 302
diff changeset
590 # 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
591 # 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
592 # 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
593 uptodate_annotated_tags = []
53b0d608dcd5 when pushing, check if server is advertising annotated tags
Tay Ray Chuan <rctay89@gmail.com>
parents: 302
diff changeset
594 for r in tags:
53b0d608dcd5 when pushing, check if server is advertising annotated tags
Tay Ray Chuan <rctay89@gmail.com>
parents: 302
diff changeset
595 ref = 'refs/tags/'+r
53b0d608dcd5 when pushing, check if server is advertising annotated tags
Tay Ray Chuan <rctay89@gmail.com>
parents: 302
diff changeset
596 # Check tag.
53b0d608dcd5 when pushing, check if server is advertising annotated tags
Tay Ray Chuan <rctay89@gmail.com>
parents: 302
diff changeset
597 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
598 continue
53b0d608dcd5 when pushing, check if server is advertising annotated tags
Tay Ray Chuan <rctay89@gmail.com>
parents: 302
diff changeset
599 try:
53b0d608dcd5 when pushing, check if server is advertising annotated tags
Tay Ray Chuan <rctay89@gmail.com>
parents: 302
diff changeset
600 # 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
601 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
602 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
603 continue
53b0d608dcd5 when pushing, check if server is advertising annotated tags
Tay Ray Chuan <rctay89@gmail.com>
parents: 302
diff changeset
604 except KeyError:
53b0d608dcd5 when pushing, check if server is advertising annotated tags
Tay Ray Chuan <rctay89@gmail.com>
parents: 302
diff changeset
605 continue
53b0d608dcd5 when pushing, check if server is advertising annotated tags
Tay Ray Chuan <rctay89@gmail.com>
parents: 302
diff changeset
606
53b0d608dcd5 when pushing, check if server is advertising annotated tags
Tay Ray Chuan <rctay89@gmail.com>
parents: 302
diff changeset
607 # 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
608 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
609
230
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
610 for r in heads + tags:
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
611 if r in heads:
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
612 ref = 'refs/heads/'+r
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
613 else:
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
614 ref = 'refs/tags/'+r
181
8690377c3ce9 Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 179
diff changeset
615
230
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
616 if ref not in refs:
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
617 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
618 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
619 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
620 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
621 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
622 else:
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
623 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
624 % (ref, ctx))
310
53b0d608dcd5 when pushing, check if server is advertising annotated tags
Tay Ray Chuan <rctay89@gmail.com>
parents: 302
diff changeset
625 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
626 # 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
627 pass
230
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
628 else:
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
629 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
630 "and merge before pushing" % ref)
126
705b88c9f3d1 remote branches to server
Ian Dees <undees@gmail.com>
parents: 125
diff changeset
631
230
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
632 return new_refs
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
633
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
634
232
0ba1aee0467c initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 231
diff changeset
635 def fetch_pack(self, remote_name, heads):
182
9bdd8e76bbab Remove remotes support (use the paths section in hgrc instead)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 181
diff changeset
636 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
637 graphwalker = self.git.get_graph_walker()
232
0ba1aee0467c initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 231
diff changeset
638 def determine_wants(refs):
0ba1aee0467c initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 231
diff changeset
639 if heads:
0ba1aee0467c initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 231
diff changeset
640 want = []
337
6cea997ee302 enforce stricter matching for pull -r
Tay Ray Chuan <rctay89@gmail.com>
parents: 258
diff changeset
641 # 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
642 # 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
643 stripped_refs = [
6cea997ee302 enforce stricter matching for pull -r
Tay Ray Chuan <rctay89@gmail.com>
parents: 258
diff changeset
644 (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
645 for r in refs]
232
0ba1aee0467c initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 231
diff changeset
646 for h in heads:
337
6cea997ee302 enforce stricter matching for pull -r
Tay Ray Chuan <rctay89@gmail.com>
parents: 258
diff changeset
647 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
648 if not r:
292
19f201d64a16 git_handler: fix % formatting in ref errors.
Augie Fackler <durin42@gmail.com>
parents: 288
diff changeset
649 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
650 elif len(r) == 1:
0ba1aee0467c initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 231
diff changeset
651 want.append(refs[r[0]])
0ba1aee0467c initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 231
diff changeset
652 else:
292
19f201d64a16 git_handler: fix % formatting in ref errors.
Augie Fackler <durin42@gmail.com>
parents: 288
diff changeset
653 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
654 else:
0ba1aee0467c initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 231
diff changeset
655 want = [sha for ref, sha in refs.iteritems()
0ba1aee0467c initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 231
diff changeset
656 if not ref.endswith('^{}')]
0ba1aee0467c initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 231
diff changeset
657 return want
5
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
658 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
659 try:
266
5347d8c94021 python 2.4 syntax fix
Antonin Amand <antonin.amand@gmail.com>
parents: 261
diff changeset
660 try:
293
8aaae306d46f git_handler: 80 columns cleanup
Augie Fackler <durin42@gmail.com>
parents: 292
diff changeset
661 return client.fetch_pack(path, determine_wants, graphwalker,
8aaae306d46f git_handler: 80 columns cleanup
Augie Fackler <durin42@gmail.com>
parents: 292
diff changeset
662 f.write, self.ui.status)
266
5347d8c94021 python 2.4 syntax fix
Antonin Amand <antonin.amand@gmail.com>
parents: 261
diff changeset
663 except HangupException:
5347d8c94021 python 2.4 syntax fix
Antonin Amand <antonin.amand@gmail.com>
parents: 261
diff changeset
664 raise hgutil.Abort("the remote end hung up unexpectedly")
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
665 finally:
5
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
666 commit()
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
667
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
668 ## REFERENCES HANDLING
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
669
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
670 def update_references(self):
195
e09d71dc4cb4 Drop importbranch/exportbranch options (exportbranch was really broken)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 194
diff changeset
671 heads = self.local_heads()
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
672
195
e09d71dc4cb4 Drop importbranch/exportbranch options (exportbranch was really broken)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 194
diff changeset
673 # 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
674 # Mercurial bookmark.
e09d71dc4cb4 Drop importbranch/exportbranch options (exportbranch was really broken)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 194
diff changeset
675 for key in heads:
230
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
676 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
677
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
678 def export_hg_tags(self):
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
679 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
680 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
681 tag = tag.replace(' ', '_')
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
682 self.git.refs['refs/tags/' + tag] = self.map_git_get(hex(sha))
212
174954c187e0 fix pushing tags to git (see issue 3 bb)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 210
diff changeset
683 self.tags[tag] = hex(sha)
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
684
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
685 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
686 try:
268
6fded8e42858 git_handler: update for slight API change in bookmarks
Augie Fackler <durin42@gmail.com>
parents: 267
diff changeset
687 if getattr(bookmarks, 'parse', None):
6fded8e42858 git_handler: update for slight API change in bookmarks
Augie Fackler <durin42@gmail.com>
parents: 267
diff changeset
688 bms = bookmarks.parse(self.repo)
6fded8e42858 git_handler: update for slight API change in bookmarks
Augie Fackler <durin42@gmail.com>
parents: 267
diff changeset
689 else:
6fded8e42858 git_handler: update for slight API change in bookmarks
Augie Fackler <durin42@gmail.com>
parents: 267
diff changeset
690 bms = self.repo._bookmarks
230
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
691 return dict([(bm, hex(bms[bm])) for bm in bms])
215
b5d4d1552765 add some annotations for test coverage
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 213
diff changeset
692 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
693 return {}
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
694
187
5f196f80ffb3 Store git tags in .hg/git-tags and let localtags be *local*
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 186
diff changeset
695 def import_tags(self, refs):
149
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
696 keys = refs.keys()
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
697 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
698 return
5f196f80ffb3 Store git tags in .hg/git-tags and let localtags be *local*
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 186
diff changeset
699 for k in keys[:]:
149
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
700 ref_name = k
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
701 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
702 if parts[0] == 'refs' and parts[1] == 'tags':
149
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
703 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
704 # 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
705 # the ones we are pulling
0ba1aee0467c initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 231
diff changeset
706 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
707 continue
149
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
708 if ref_name[-3:] == '^{}':
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
709 ref_name = ref_name[:-3]
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
710 if not ref_name in self.repo.tags():
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
711 obj = self.git.get_object(refs[k])
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
712 sha = None
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
713 if isinstance (obj, Commit): # lightweight
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
714 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
715 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
716 elif isinstance (obj, Tag): # annotated
337
6cea997ee302 enforce stricter matching for pull -r
Tay Ray Chuan <rctay89@gmail.com>
parents: 258
diff changeset
717 (obj_type, obj_sha) = obj.object
149
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
718 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
719 if isinstance (obj, Commit):
149
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
720 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
721 # 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
722 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
723 self.save_tags()
181
8690377c3ce9 Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 179
diff changeset
724
184
7bf98d3085f4 Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 183
diff changeset
725 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
726 try:
268
6fded8e42858 git_handler: update for slight API change in bookmarks
Augie Fackler <durin42@gmail.com>
parents: 267
diff changeset
727 oldbm = getattr(bookmarks, 'parse', None)
6fded8e42858 git_handler: update for slight API change in bookmarks
Augie Fackler <durin42@gmail.com>
parents: 267
diff changeset
728 if oldbm:
6fded8e42858 git_handler: update for slight API change in bookmarks
Augie Fackler <durin42@gmail.com>
parents: 267
diff changeset
729 bms = bookmarks.parse(self.repo)
6fded8e42858 git_handler: update for slight API change in bookmarks
Augie Fackler <durin42@gmail.com>
parents: 267
diff changeset
730 else:
6fded8e42858 git_handler: update for slight API change in bookmarks
Augie Fackler <durin42@gmail.com>
parents: 267
diff changeset
731 bms = self.repo._bookmarks
184
7bf98d3085f4 Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 183
diff changeset
732 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
733 if ref.startswith('refs/heads/')])
156
a507384308b2 Allow bookmarking a specific branch
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 155
diff changeset
734
a507384308b2 Allow bookmarking a specific branch
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 155
diff changeset
735 for head, sha in heads.iteritems():
232
0ba1aee0467c initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 231
diff changeset
736 # 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
737 # the ones we are pulling
0ba1aee0467c initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 231
diff changeset
738 if sha not in self.git.object_store:
0ba1aee0467c initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 231
diff changeset
739 continue
188
5d48a2310e16 Use mercurial.node.bin instead of dulwich.objects.hex_to_sha
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 187
diff changeset
740 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
741 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
742 # new branch
7bf98d3085f4 Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 183
diff changeset
743 bms[head] = hgsha
7bf98d3085f4 Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 183
diff changeset
744 else:
7bf98d3085f4 Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 183
diff changeset
745 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
746 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
747 # fast forward
7bf98d3085f4 Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 183
diff changeset
748 bms[head] = hgsha
156
a507384308b2 Allow bookmarking a specific branch
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 155
diff changeset
749 if heads:
268
6fded8e42858 git_handler: update for slight API change in bookmarks
Augie Fackler <durin42@gmail.com>
parents: 267
diff changeset
750 if oldbm:
6fded8e42858 git_handler: update for slight API change in bookmarks
Augie Fackler <durin42@gmail.com>
parents: 267
diff changeset
751 bookmarks.write(self.repo, bms)
6fded8e42858 git_handler: update for slight API change in bookmarks
Augie Fackler <durin42@gmail.com>
parents: 267
diff changeset
752 else:
6fded8e42858 git_handler: update for slight API change in bookmarks
Augie Fackler <durin42@gmail.com>
parents: 267
diff changeset
753 self.repo._bookmarks = bms
6fded8e42858 git_handler: update for slight API change in bookmarks
Augie Fackler <durin42@gmail.com>
parents: 267
diff changeset
754 bookmarks.write(self.repo)
161
134915637cf7 Merge branch 'octo' with octo merge code
Scott Chacon <schacon@gmail.com>
parents: 157 160
diff changeset
755
29
2a5c0bf0fef5 Another way of fixing no-bookmark issue, along with updated test.
Augie Fackler <durin42@gmail.com>
parents: 28
diff changeset
756 except AttributeError:
95
7de67fcb18b0 be better about internationalizing strings
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 94
diff changeset
757 self.ui.warn(_('creating bookmarks failed, do you have'
7de67fcb18b0 be better about internationalizing strings
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 94
diff changeset
758 ' 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
759
184
7bf98d3085f4 Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 183
diff changeset
760 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
761 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
762 tags = self.repo.gitrefs()
699088d9dd9f hgrepo: completely rework handing of remote refs marking
Augie Fackler <durin42@gmail.com>
parents: 361
diff changeset
763 # 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
764 # 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
765 # 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
766 for t in list(tags):
699088d9dd9f hgrepo: completely rework handing of remote refs marking
Augie Fackler <durin42@gmail.com>
parents: 361
diff changeset
767 if t.startswith(remote_name + '/'):
699088d9dd9f hgrepo: completely rework handing of remote refs marking
Augie Fackler <durin42@gmail.com>
parents: 361
diff changeset
768 del tags[t]
368
ae78f94f64fd Fix bug where remote ref map wrote out binary nodes.
Augie Fackler <durin42@gmail.com>
parents: 367
diff changeset
769 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
770 store = self.git.object_store
305
ad2ea8d6ef94 update_remote_branches: refactor head usage
Tay Ray Chuan <rctay89@gmail.com>
parents: 304
diff changeset
771 for ref_name, sha in refs.iteritems():
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
772 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
773 if sha not in store:
699088d9dd9f hgrepo: completely rework handing of remote refs marking
Augie Fackler <durin42@gmail.com>
parents: 361
diff changeset
774 continue
699088d9dd9f hgrepo: completely rework handing of remote refs marking
Augie Fackler <durin42@gmail.com>
parents: 361
diff changeset
775 hgsha = self.map_hg_get(sha)
305
ad2ea8d6ef94 update_remote_branches: refactor head usage
Tay Ray Chuan <rctay89@gmail.com>
parents: 304
diff changeset
776 head = ref_name[11:]
367
699088d9dd9f hgrepo: completely rework handing of remote refs marking
Augie Fackler <durin42@gmail.com>
parents: 361
diff changeset
777 tags['/'.join((remote_name, head))] = hgsha
699088d9dd9f hgrepo: completely rework handing of remote refs marking
Augie Fackler <durin42@gmail.com>
parents: 361
diff changeset
778 # TODO(durin42): what is this doing?
305
ad2ea8d6ef94 update_remote_branches: refactor head usage
Tay Ray Chuan <rctay89@gmail.com>
parents: 304
diff changeset
779 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
780 self.git.refs[new_ref] = sha
316
7e5ed21ceec1 git_handler: prefer () continuation to \ continuation.
Augie Fackler <durin42@gmail.com>
parents: 306
diff changeset
781 elif (ref_name.startswith('refs/tags')
7e5ed21ceec1 git_handler: prefer () continuation to \ continuation.
Augie Fackler <durin42@gmail.com>
parents: 306
diff changeset
782 and not ref_name.endswith('^{}')):
305
ad2ea8d6ef94 update_remote_branches: refactor head usage
Tay Ray Chuan <rctay89@gmail.com>
parents: 304
diff changeset
783 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
784
367
699088d9dd9f hgrepo: completely rework handing of remote refs marking
Augie Fackler <durin42@gmail.com>
parents: 361
diff changeset
785 tf = open(tagfile, 'wb')
699088d9dd9f hgrepo: completely rework handing of remote refs marking
Augie Fackler <durin42@gmail.com>
parents: 361
diff changeset
786 for tag, node in tags.iteritems():
699088d9dd9f hgrepo: completely rework handing of remote refs marking
Augie Fackler <durin42@gmail.com>
parents: 361
diff changeset
787 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
788 tf.close()
699088d9dd9f hgrepo: completely rework handing of remote refs marking
Augie Fackler <durin42@gmail.com>
parents: 361
diff changeset
789
196
40edc4b814e4 Reorganize push for more symmetry with fetch
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 195
diff changeset
790
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
791 ## UTILITY FUNCTIONS
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
792
53
5deb5cbd86aa respecting file modes on git import
Scott Chacon <schacon@gmail.com>
parents: 52
diff changeset
793 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
794 # TODO: make these into constants
53
5deb5cbd86aa respecting file modes on git import
Scott Chacon <schacon@gmail.com>
parents: 52
diff changeset
795 convert = {
121
0c94e860a0ed use octal numbers for modes.
Dmitriy Taychenachev <dimichxp@gmail.com>
parents: 120
diff changeset
796 0100644: '',
0c94e860a0ed use octal numbers for modes.
Dmitriy Taychenachev <dimichxp@gmail.com>
parents: 120
diff changeset
797 0100755: 'x',
0c94e860a0ed use octal numbers for modes.
Dmitriy Taychenachev <dimichxp@gmail.com>
parents: 120
diff changeset
798 0120000: 'l'}
53
5deb5cbd86aa respecting file modes on git import
Scott Chacon <schacon@gmail.com>
parents: 52
diff changeset
799 if mode in convert:
5deb5cbd86aa respecting file modes on git import
Scott Chacon <schacon@gmail.com>
parents: 52
diff changeset
800 return convert[mode]
5deb5cbd86aa respecting file modes on git import
Scott Chacon <schacon@gmail.com>
parents: 52
diff changeset
801 return ''
65
5ed8316d3cfa Start using reasonable ui.{status,debug,warn} calls instead of print.
Augie Fackler <durin42@gmail.com>
parents: 56
diff changeset
802
71
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
803 def extract_hg_metadata(self, message):
227
c4f6e6f24bf1 fix bug introduced by previous commit
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 226
diff changeset
804 split = message.split("\n--HG--\n", 1)
71
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
805 renames = {}
164
7e98757deadc author and extra data fixes
Scott Chacon <schacon@gmail.com>
parents: 162
diff changeset
806 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
807 branch = False
71
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
808 if len(split) == 2:
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
809 message, meta = split
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
810 lines = meta.split("\n")
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
811 for line in lines:
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
812 if line == '':
181
8690377c3ce9 Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 179
diff changeset
813 continue
8690377c3ce9 Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 179
diff changeset
814
71
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
815 command, data = line.split(" : ", 1)
181
8690377c3ce9 Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 179
diff changeset
816
71
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
817 if command == 'rename':
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
818 before, after = data.split(" => ", 1)
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
819 renames[after] = before
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
820 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
821 branch = data
164
7e98757deadc author and extra data fixes
Scott Chacon <schacon@gmail.com>
parents: 162
diff changeset
822 if command == 'extra':
7e98757deadc author and extra data fixes
Scott Chacon <schacon@gmail.com>
parents: 162
diff changeset
823 before, after = data.split(" : ", 1)
7e98757deadc author and extra data fixes
Scott Chacon <schacon@gmail.com>
parents: 162
diff changeset
824 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
825 return (message, renames, branch, extra)
181
8690377c3ce9 Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 179
diff changeset
826
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
827 def get_file(self, commit, f):
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
828 otree = self.git.tree(commit.tree)
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
829 parts = f.split('/')
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
830 for part in parts:
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
831 (mode, sha) = otree[part]
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
832 obj = self.git.get_object(sha)
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
833 if isinstance (obj, Blob):
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
834 return (mode, sha, obj._text)
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
835 elif isinstance(obj, Tree):
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
836 otree = obj
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
837
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
838 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
839 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
840 btree = None
c2d6b1093e7e fix a bug when a directory is replaced with a file
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 261
diff changeset
841
c2d6b1093e7e fix a bug when a directory is replaced with a file
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 261
diff changeset
842 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
843 btree = self.git[commit.parents[0]].tree
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
844
275
c2d6b1093e7e fix a bug when a directory is replaced with a file
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 261
diff changeset
845 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
846 files = {}
c2d6b1093e7e fix a bug when a directory is replaced with a file
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 261
diff changeset
847 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
848 # 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
849 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
850 if oldfile:
e08a22250fa9 Don't import git submodule files (we don't support them .. yet).
jeremy avnet <brainsik@saucelabs.com>
parents: 286
diff changeset
851 # 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
852 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
853 else:
e08a22250fa9 Don't import git submodule files (we don't support them .. yet).
jeremy avnet <brainsik@saucelabs.com>
parents: 286
diff changeset
854 continue
e08a22250fa9 Don't import git submodule files (we don't support them .. yet).
jeremy avnet <brainsik@saucelabs.com>
parents: 286
diff changeset
855 # 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
856 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
857 if newfile:
e08a22250fa9 Don't import git submodule files (we don't support them .. yet).
jeremy avnet <brainsik@saucelabs.com>
parents: 286
diff changeset
858 # 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
859 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
860 else:
e08a22250fa9 Don't import git submodule files (we don't support them .. yet).
jeremy avnet <brainsik@saucelabs.com>
parents: 286
diff changeset
861 continue
e08a22250fa9 Don't import git submodule files (we don't support them .. yet).
jeremy avnet <brainsik@saucelabs.com>
parents: 286
diff changeset
862
275
c2d6b1093e7e fix a bug when a directory is replaced with a file
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 261
diff changeset
863 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
864 file = oldfile
c2d6b1093e7e fix a bug when a directory is replaced with a file
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 261
diff changeset
865 delete = True
c2d6b1093e7e fix a bug when a directory is replaced with a file
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 261
diff changeset
866 else:
c2d6b1093e7e fix a bug when a directory is replaced with a file
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 261
diff changeset
867 file = newfile
c2d6b1093e7e fix a bug when a directory is replaced with a file
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 261
diff changeset
868 delete = False
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
869
275
c2d6b1093e7e fix a bug when a directory is replaced with a file
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 261
diff changeset
870 files[file] = (delete, newmode, newsha)
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
871
275
c2d6b1093e7e fix a bug when a directory is replaced with a file
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 261
diff changeset
872 return files
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
873
184
7bf98d3085f4 Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 183
diff changeset
874 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
875 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
876 if names:
7bf98d3085f4 Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 183
diff changeset
877 return names[0]
7bf98d3085f4 Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 183
diff changeset
878
186
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
879 # Stolen from hgsubversion
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
880 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
881 try:
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
882 from mercurial import encoding
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
883 old = encoding.encoding
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
884 encoding.encoding = new_encoding
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
885 except ImportError:
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
886 old = hgutil._encoding
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
887 hgutil._encoding = new_encoding
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
888 return old
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
889
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
890 def decode_guess(self, string, encoding):
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
891 # 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
892 if encoding:
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
893 try:
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
894 return string.decode(encoding).encode('utf-8')
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
895 except UnicodeDecodeError:
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
896 pass
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
897
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
898 try:
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
899 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
900 except UnicodeDecodeError:
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
901 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
902
5
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
903 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
904 # 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
905 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
906 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
907
285
5e5aee9b32d4 git_handler: slight style cleanup
Augie Fackler <durin42@gmail.com>
parents: 284
diff changeset
908 for handler, transport in (("git://", client.TCPGitClient),
5e5aee9b32d4 git_handler: slight style cleanup
Augie Fackler <durin42@gmail.com>
parents: 284
diff changeset
909 ("git@", client.SSHGitClient),
5e5aee9b32d4 git_handler: slight style cleanup
Augie Fackler <durin42@gmail.com>
parents: 284
diff changeset
910 ("git+ssh://", client.SSHGitClient)):
5
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
911 if uri.startswith(handler):
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
912 # We need to split around : or /, whatever comes first
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
913 hostpath = uri[len(handler):]
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
914 if (hostpath.find(':') > 0 and hostpath.find('/') > 0):
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
915 # we have both, whatever is first wins.
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
916 if hostpath.find(':') < hostpath.find('/'):
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
917 hostpath_seper = ':'
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
918 else:
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
919 hostpath_seper = '/'
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
920 elif hostpath.find(':') > 0:
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
921 hostpath_seper = ':'
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
922 else:
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
923 hostpath_seper = '/'
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
924
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
925 host, path = hostpath.split(hostpath_seper, 1)
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
926 if hostpath_seper == '/':
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
927 transportpath = '/' + path
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
928 else:
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
929 transportpath = path
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
930 return transport(host, thin_packs=False), transportpath
5
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
931 # 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
932 return client.SubprocessGitClient(thin_packs=False), uri