annotate hggit/git_handler.py @ 260:6977263c4d80

Merge with abderrahim.
author Augie Fackler <durin42@gmail.com>
date Sun, 25 Oct 2009 10:55:12 -0500
parents git_handler.py@1590c97d7af0 git_handler.py@505d7cdca198
children 29e5072ddaab
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
181
8690377c3ce9 Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 179
diff changeset
1 import os, sys, math, urllib, re
76
aa2dadf04144 fixed the topo sorting and added a unit test
Scott Chacon <schacon@gmail.com>
parents: 75
diff changeset
2 import toposort
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
3
230
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
4 from dulwich.errors import HangupException
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
5 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
6 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
7 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
8 from dulwich.repo import Repo
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
9
5
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
10 from hgext import bookmarks
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
11 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
12 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
13 from mercurial import context, util as hgutil
e414c72d3ec9 fix compatibility with mercurial 1.1
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 221
diff changeset
14
e414c72d3ec9 fix compatibility with mercurial 1.1
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 221
diff changeset
15 try:
e414c72d3ec9 fix compatibility with mercurial 1.1
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 221
diff changeset
16 from mercurial.error import RepoError
e414c72d3ec9 fix compatibility with mercurial 1.1
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 221
diff changeset
17 except ImportError:
e414c72d3ec9 fix compatibility with mercurial 1.1
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 221
diff changeset
18 from mercurial.repo import RepoError
e414c72d3ec9 fix compatibility with mercurial 1.1
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 221
diff changeset
19
24
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
20
5
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
21 class GitHandler(object):
19
2be9c0bd88af Warn, but don't fail when bookmarks is not enabled.
Augie Fackler <durin42@gmail.com>
parents: 17
diff changeset
22
5
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
23 def __init__(self, dest_repo, ui):
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
24 self.repo = dest_repo
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
25 self.ui = ui
105
41e76444105c make git-mapfile and git-configfile constants
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 104
diff changeset
26 self.mapfile = 'git-mapfile'
187
5f196f80ffb3 Store git tags in .hg/git-tags and let localtags be *local*
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 186
diff changeset
27 self.tagsfile = 'git-tags'
133
f2dfb2bed724 Allow storing the git directory intree
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 118
diff changeset
28
f2dfb2bed724 Allow storing the git directory intree
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 118
diff changeset
29 if ui.config('git', 'intree'):
f2dfb2bed724 Allow storing the git directory intree
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 118
diff changeset
30 self.gitdir = self.repo.wjoin('.git')
f2dfb2bed724 Allow storing the git directory intree
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 118
diff changeset
31 else:
f2dfb2bed724 Allow storing the git directory intree
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 118
diff changeset
32 self.gitdir = self.repo.join('git')
f2dfb2bed724 Allow storing the git directory intree
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 118
diff changeset
33
184
7bf98d3085f4 Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 183
diff changeset
34 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
35
7
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
36 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
37 self.load_tags()
19
2be9c0bd88af Warn, but don't fail when bookmarks is not enabled.
Augie Fackler <durin42@gmail.com>
parents: 17
diff changeset
38
2be9c0bd88af Warn, but don't fail when bookmarks is not enabled.
Augie Fackler <durin42@gmail.com>
parents: 17
diff changeset
39 # make the git data directory
16
58cd05129119 moved init into git_handler
Scott Chacon <schacon@gmail.com>
parents: 14
diff changeset
40 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
41 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
42 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
43 else:
106
3aa2f6caed16 make the gitdir a constant
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 105
diff changeset
44 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
45 self.git = Repo.init_bare(self.gitdir)
7
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
46
14
36e94e805fa7 added basic config file for remembering remote urls
Scott Chacon <schacon@gmail.com>
parents: 13
diff changeset
47 ## FILE LOAD AND SAVE METHODS
36e94e805fa7 added basic config file for remembering remote urls
Scott Chacon <schacon@gmail.com>
parents: 13
diff changeset
48
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
49 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
50 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
51 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
52
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 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
54 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
55
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
56 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
57 return self._map_hg.get(hgsha)
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
58
7
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
59 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
60 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
61 self._map_hg = {}
105
41e76444105c make git-mapfile and git-configfile constants
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 104
diff changeset
62 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
63 for line in self.repo.opener(self.mapfile):
7
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
64 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
65 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
66 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
67
7
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
68 def save_map(self):
105
41e76444105c make git-mapfile and git-configfile constants
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 104
diff changeset
69 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
70 for hgsha, gitsha in sorted(self._map_hg.iteritems()):
7
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
71 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
72 file.rename()
19
2be9c0bd88af Warn, but don't fail when bookmarks is not enabled.
Augie Fackler <durin42@gmail.com>
parents: 17
diff changeset
73
187
5f196f80ffb3 Store git tags in .hg/git-tags and let localtags be *local*
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 186
diff changeset
74
5f196f80ffb3 Store git tags in .hg/git-tags and let localtags be *local*
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 186
diff changeset
75 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
76 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
77 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
78 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
79 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
80 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
81
5f196f80ffb3 Store git tags in .hg/git-tags and let localtags be *local*
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 186
diff changeset
82 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
83 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
84 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
85 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
86 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
87 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
88
14
36e94e805fa7 added basic config file for remembering remote urls
Scott Chacon <schacon@gmail.com>
parents: 13
diff changeset
89 ## END FILE LOAD AND SAVE METHODS
7
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
90
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
91 ## COMMANDS METHODS
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
92
137
5aefcbf1e50c add a gimport command
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 136
diff changeset
93 def import_commits(self, remote_name):
5aefcbf1e50c add a gimport command
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 136
diff changeset
94 self.import_git_objects(remote_name)
5aefcbf1e50c add a gimport command
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 136
diff changeset
95 self.save_map()
5aefcbf1e50c add a gimport command
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 136
diff changeset
96
232
0ba1aee0467c initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 231
diff changeset
97 def fetch(self, remote, heads):
236
42ae65e6c1d1 save the map only once in export
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 235
diff changeset
98 self.export_commits()
232
0ba1aee0467c initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 231
diff changeset
99 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
100 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
101
56
5185af4e649a hg gfetch now works
Scott Chacon <schacon@gmail.com>
parents: 54
diff changeset
102 if refs:
149
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
103 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
104 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
105 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
106 if remote_name:
7bf98d3085f4 Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 183
diff changeset
107 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
108 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
109 # intial cloning
7bf98d3085f4 Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 183
diff changeset
110 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
111 else:
40edc4b814e4 Reorganize push for more symmetry with fetch
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 195
diff changeset
112 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
113
7
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
114 self.save_map()
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
115
236
42ae65e6c1d1 save the map only once in export
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 235
diff changeset
116 def export_commits(self):
42ae65e6c1d1 save the map only once in export
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 235
diff changeset
117 try:
172
ac92cdc45ceb not trying to write the same tree twice
Scott Chacon <schacon@gmail.com>
parents: 171
diff changeset
118 self.export_git_objects()
236
42ae65e6c1d1 save the map only once in export
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 235
diff changeset
119 self.export_hg_tags()
42ae65e6c1d1 save the map only once in export
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 235
diff changeset
120 self.update_references()
42ae65e6c1d1 save the map only once in export
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 235
diff changeset
121 finally:
42ae65e6c1d1 save the map only once in export
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 235
diff changeset
122 self.save_map()
97
f0628f5270b6 add gexport command
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 96
diff changeset
123
231
bdaec2a079ce initial support for 'hg outgoing'
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 230
diff changeset
124 def get_refs(self, remote):
bdaec2a079ce initial support for 'hg outgoing'
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 230
diff changeset
125 self.export_commits()
bdaec2a079ce initial support for 'hg outgoing'
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 230
diff changeset
126 client, path = self.get_transport_and_path(remote)
bdaec2a079ce initial support for 'hg outgoing'
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 230
diff changeset
127 old_refs = {}
bdaec2a079ce initial support for 'hg outgoing'
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 230
diff changeset
128 new_refs = {}
bdaec2a079ce initial support for 'hg outgoing'
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 230
diff changeset
129 def changed(refs):
bdaec2a079ce initial support for 'hg outgoing'
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 230
diff changeset
130 old_refs.update(refs)
bdaec2a079ce initial support for 'hg outgoing'
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 230
diff changeset
131 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
132 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
133 # don't push anything
bdaec2a079ce initial support for 'hg outgoing'
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 230
diff changeset
134 return {}
bdaec2a079ce initial support for 'hg outgoing'
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 230
diff changeset
135
bdaec2a079ce initial support for 'hg outgoing'
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 230
diff changeset
136 try:
bdaec2a079ce initial support for 'hg outgoing'
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 230
diff changeset
137 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
138
53b731d2a3e2 outgoing: don't crash when there are unpulled changesets
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 242
diff changeset
139 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
140 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
141 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
142 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
143 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
144
bdaec2a079ce initial support for 'hg outgoing'
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 230
diff changeset
145 return old, new
bdaec2a079ce initial support for 'hg outgoing'
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 230
diff changeset
146 except HangupException:
bdaec2a079ce initial support for 'hg outgoing'
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 230
diff changeset
147 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
148
230
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
149 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
150 self.export_commits()
230
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
151 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
152 remote_name = self.remote_name(remote)
40edc4b814e4 Reorganize push for more symmetry with fetch
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 195
diff changeset
153
40edc4b814e4 Reorganize push for more symmetry with fetch
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 195
diff changeset
154 if remote_name and changed_refs:
40edc4b814e4 Reorganize push for more symmetry with fetch
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 195
diff changeset
155 for ref, sha in changed_refs.iteritems():
40edc4b814e4 Reorganize push for more symmetry with fetch
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 195
diff changeset
156 self.ui.status(" "+ remote_name + "::" + ref + " => GIT:" + sha[0:8] + "\n")
40edc4b814e4 Reorganize push for more symmetry with fetch
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 195
diff changeset
157
40edc4b814e4 Reorganize push for more symmetry with fetch
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 195
diff changeset
158 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
159
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
160 def clear(self):
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
161 mapfile = self.repo.join(self.mapfile)
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
162 if os.path.exists(self.gitdir):
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
163 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
164 for name in files:
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
165 os.remove(os.path.join(root, name))
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
166 for name in dirs:
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
167 os.rmdir(os.path.join(root, name))
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
168 os.rmdir(self.gitdir)
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
169 if os.path.exists(mapfile):
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
170 os.remove(mapfile)
124
9dafb9ac24ff hg bookmarks to local git branches
Ian Dees <undees@gmail.com>
parents: 118
diff changeset
171
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
172 ## CHANGESET CONVERSION METHODS
125
5b702bbf078f local git branches to remotes
Ian Dees <undees@gmail.com>
parents: 124
diff changeset
173
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
174 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
175 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
176 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
177
190
6fbdf1afe032 Better reporting of the number of commits to convert
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 188
diff changeset
178 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
179 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
180 total = len(export)
148
201d30003120 Splitting the if statement up since python didn't like that.
Nick Quaranto <nick@quaran.to>
parents: 147
diff changeset
181 if total:
201d30003120 Splitting the if statement up since python didn't like that.
Nick Quaranto <nick@quaran.to>
parents: 147
diff changeset
182 magnitude = int(math.log(total, 10)) + 1
201d30003120 Splitting the if statement up since python didn't like that.
Nick Quaranto <nick@quaran.to>
parents: 147
diff changeset
183 else:
201d30003120 Splitting the if statement up since python didn't like that.
Nick Quaranto <nick@quaran.to>
parents: 147
diff changeset
184 magnitude = 1
190
6fbdf1afe032 Better reporting of the number of commits to convert
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 188
diff changeset
185 for i, rev in enumerate(export):
99
541571f2e429 add progress indication during export
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 97
diff changeset
186 if i%100 == 0:
541571f2e429 add progress indication during export
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 97
diff changeset
187 self.ui.status(_("at: %*d/%d\n") % (magnitude, i, total))
181
8690377c3ce9 Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 179
diff changeset
188
159
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
189 ctx = self.repo.changectx(rev)
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
190 state = ctx.extra().get('hg-git', None)
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
191 if state == 'octopus':
203
104a4fd6a0af trying to fix some of the broken tests
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 199
diff changeset
192 self.ui.debug("revision %d is a part of octopus explosion\n" % ctx.rev())
159
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
193 continue
190
6fbdf1afe032 Better reporting of the number of commits to convert
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 188
diff changeset
194 self.export_hg_commit(rev)
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
195
24
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
196 # 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
197 # 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
198 # 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
199 def export_hg_commit(self, rev):
181
8690377c3ce9 Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 179
diff changeset
200 self.ui.note(_("converting revision %s\n") % rev)
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
201
203
104a4fd6a0af trying to fix some of the broken tests
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 199
diff changeset
202 oldenc = self.swap_out_encoding()
104a4fd6a0af trying to fix some of the broken tests
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 199
diff changeset
203
159
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
204 ctx = self.repo.changectx(rev)
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
205 extra = ctx.extra()
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
206
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
207 commit = Commit()
68
d28d3763eda3 Deal with hg authors missing email attributes.
Chris Wanstrath <chris@ozmm.org>
parents: 65
diff changeset
208
235
912d6a5837c8 reorganize export_hg_commit
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 234
diff changeset
209 (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
210 commit.author = self.get_git_author(ctx)
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
211 commit.author_time = int(time)
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
212 commit.author_timezone = -timezone
186
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
213
89
e35ed99fa691 committer info now being kept properly
Scott Chacon <schacon@gmail.com>
parents: 88
diff changeset
214 if 'committer' in extra:
131
dd6c77ec206c store commitdate in mercurial's internal format.
Dmitriy Taychenachev <dimichxp@gmail.com>
parents: 129
diff changeset
215 # fixup timezone
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
216 (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
217 commit.committer = name
16f671995881 deal correctly with old timezone format in extra committer
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 236
diff changeset
218 commit.commit_time = timestamp
16f671995881 deal correctly with old timezone format in extra committer
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 236
diff changeset
219
16f671995881 deal correctly with old timezone format in extra committer
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 236
diff changeset
220 # 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
221 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
222 timezone = parse_timezone(timezone)
16f671995881 deal correctly with old timezone format in extra committer
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 236
diff changeset
223 else:
16f671995881 deal correctly with old timezone format in extra committer
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 236
diff changeset
224 timezone = -int(timezone)
16f671995881 deal correctly with old timezone format in extra committer
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 236
diff changeset
225 commit.commit_timezone = timezone
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
226 else:
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
227 commit.committer = commit.author
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
228 commit.commit_time = commit.author_time
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
229 commit.commit_timezone = commit.author_timezone
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
230
239
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
231 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
232 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
233 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
234 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
235 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
236 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
237
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
238 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
239
118
b3be536e3f50 handles git commit encoding fields now
Scott Chacon <schacon@gmail.com>
parents: 113
diff changeset
240 if 'encoding' in extra:
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
241 commit.encoding = extra['encoding']
89
e35ed99fa691 committer info now being kept properly
Scott Chacon <schacon@gmail.com>
parents: 88
diff changeset
242
239
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
243 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
244 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
245
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
246 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
247 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
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.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
250 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
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 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
253 # 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
254 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
255
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
256 # 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
257 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
258 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
259
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
260 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
261 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
262 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
263 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
264 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
265 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
266 else:
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
267 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
268
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
269 if 'author' in 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
270 author = apply_delta(author, ctx.extra()['author'])
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 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
273
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
274 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
275 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
276 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
277
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
278 parents = []
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
279 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
280 # 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
281 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
282 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
283 (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
284 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
285 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
286 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
287 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
288 else:
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
289 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
290
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
291 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
292
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
293 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
294 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
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 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
297 if 'message' in 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 message = apply_delta(message, extra['message'])
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
299
54
f6e11b9d7562 not adding HG extra info if commits were on the default branch
Scott Chacon <schacon@gmail.com>
parents: 53
diff changeset
300 # 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
301 add_extras = False
67
759ac56497e7 adding hg explicit file renames to the git commit message
Scott Chacon <schacon@gmail.com>
parents: 65
diff changeset
302 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
303 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
304 add_extras = True
67
759ac56497e7 adding hg explicit file renames to the git commit message
Scott Chacon <schacon@gmail.com>
parents: 65
diff changeset
305 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
306
239
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
307 renames = []
247
3c01e07b0252 look for renamed files only in files modified by the commit
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 245
diff changeset
308 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
309 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
310 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
311 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
312 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
313 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
314
67
759ac56497e7 adding hg explicit file renames to the git commit message
Scott Chacon <schacon@gmail.com>
parents: 65
diff changeset
315 if renames:
759ac56497e7 adding hg explicit file renames to the git commit message
Scott Chacon <schacon@gmail.com>
parents: 65
diff changeset
316 add_extras = True
759ac56497e7 adding hg explicit file renames to the git commit message
Scott Chacon <schacon@gmail.com>
parents: 65
diff changeset
317 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
318 extra_message += "rename : " + oldfile + " => " + newfile + "\n"
164
7e98757deadc author and extra data fixes
Scott Chacon <schacon@gmail.com>
parents: 162
diff changeset
319
7e98757deadc author and extra data fixes
Scott Chacon <schacon@gmail.com>
parents: 162
diff changeset
320 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
321 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
322 continue
7e98757deadc author and extra data fixes
Scott Chacon <schacon@gmail.com>
parents: 162
diff changeset
323 else:
181
8690377c3ce9 Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 179
diff changeset
324 add_extras = True
164
7e98757deadc author and extra data fixes
Scott Chacon <schacon@gmail.com>
parents: 162
diff changeset
325 extra_message += "extra : " + key + " : " + urllib.quote(value) + "\n"
7e98757deadc author and extra data fixes
Scott Chacon <schacon@gmail.com>
parents: 162
diff changeset
326
54
f6e11b9d7562 not adding HG extra info if commits were on the default branch
Scott Chacon <schacon@gmail.com>
parents: 53
diff changeset
327 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
328 message += "\n--HG--\n" + extra_message
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
329
239
c5e5e7849803 split out get_git_author, get_git_parents and get_git_message
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 238
diff changeset
330 return message
65
5ed8316d3cfa Start using reasonable ui.{status,debug,warn} calls instead of print.
Augie Fackler <durin42@gmail.com>
parents: 56
diff changeset
331
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
332 def iterblobs(self, ctx):
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
333 for f in ctx:
234
6f34aee64a3f readd blob caching (~25% improvement in gexport)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 233
diff changeset
334 fctx = ctx[f]
6f34aee64a3f readd blob caching (~25% improvement in gexport)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 233
diff changeset
335 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
336
6f34aee64a3f readd blob caching (~25% improvement in gexport)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 233
diff changeset
337 if not blobid:
6f34aee64a3f readd blob caching (~25% improvement in gexport)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 233
diff changeset
338 blob = Blob.from_string(fctx.data())
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
339 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
340 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
341 blobid = blob.id
6f34aee64a3f readd blob caching (~25% improvement in gexport)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 233
diff changeset
342
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
343 if 'l' in ctx.flags(f):
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
344 mode = 0120000
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
345 elif 'x' in ctx.flags(f):
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
346 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
347 else:
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
348 mode = 0100644
234
6f34aee64a3f readd blob caching (~25% improvement in gexport)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 233
diff changeset
349
6f34aee64a3f readd blob caching (~25% improvement in gexport)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 233
diff changeset
350 yield f, blobid, mode
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
351
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
352 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
353 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
354 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
355
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
356 # import heads and fetched tags as remote references
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
357 todo = []
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
358 done = set()
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
359 convert_list = {}
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
360
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
361 # get a list of all the head shas
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
362 if refs:
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
363 for head, sha in refs.iteritems():
232
0ba1aee0467c initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 231
diff changeset
364 # refs contains all the refs in the server, not just the ones
0ba1aee0467c initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 231
diff changeset
365 # we are pulling
0ba1aee0467c initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 231
diff changeset
366 if sha in self.git.object_store:
0ba1aee0467c initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 231
diff changeset
367 todo.append(sha)
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
368 else:
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
369 todo = self.git.refs.values()[:]
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
370
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
371 # traverse the heads getting a list of all the unique commits
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
372 while todo:
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
373 sha = todo.pop()
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
374 assert isinstance(sha, str)
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
375 if sha in done:
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
376 continue
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
377 done.add(sha)
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
378 obj = self.git.get_object(sha)
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
379 if isinstance (obj, Commit):
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
380 convert_list[sha] = obj
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
381 todo.extend([p for p in obj.parents if p not in done])
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
382 if isinstance(obj, Tag):
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
383 (obj_type, obj_sha) = obj.get_object()
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
384 obj = self.git.get_object(obj_sha)
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
385 if isinstance (obj, Commit):
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
386 convert_list[sha] = obj
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
387 todo.extend([p for p in obj.parents if p not in done])
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
388
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
389 # sort the commits
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
390 commits = toposort.TopoSort(convert_list).items()
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
391
190
6fbdf1afe032 Better reporting of the number of commits to convert
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 188
diff changeset
392 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
393 # import each of the commits, oldest first
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
394 total = len(commits)
216
8d961ea5fc5a Making compatible with Python 2.4
Michael J. Pedersen <mpedersen@datapipe.com>
parents: 215
diff changeset
395 if total:
8d961ea5fc5a Making compatible with Python 2.4
Michael J. Pedersen <mpedersen@datapipe.com>
parents: 215
diff changeset
396 magnitude = int(math.log(total, 10)) + 1
8d961ea5fc5a Making compatible with Python 2.4
Michael J. Pedersen <mpedersen@datapipe.com>
parents: 215
diff changeset
397 else:
8d961ea5fc5a Making compatible with Python 2.4
Michael J. Pedersen <mpedersen@datapipe.com>
parents: 215
diff changeset
398 magnitude = 1
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
399 for i, csha in enumerate(commits):
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
400 if i%100 == 0:
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
401 self.ui.status(_("at: %*d/%d\n") % (magnitude, i, total))
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
402 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
403 self.import_git_commit(commit)
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
404
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
405 def import_git_commit(self, commit):
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
406 self.ui.debug(_("importing: %s\n") % commit.id)
213
61471faeb7fd small cleanups (tabs, s/TODO :/TODO:/ and dead code)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 212
diff changeset
407 # TODO: Do something less coarse-grained than try/except on the
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
408 # get_file call for removed files
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
409
204
4734153365ac revert the changes made in 405a915bf352 and 8bfa8aa6b68f
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 203
diff changeset
410 (strip_message, hg_renames, 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
411
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
412 # 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
413 files = self.get_files_changed(commit)
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
414
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
415 date = (commit.author_time, -commit.author_timezone)
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
416 text = strip_message
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
417
226
3b8804c59b63 drop untested commit_import_ctx (use commitctx instead).
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 225
diff changeset
418 origtext = text
186
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
419 try:
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
420 text.decode('utf-8')
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
421 except UnicodeDecodeError:
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
422 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
423
3b8804c59b63 drop untested commit_import_ctx (use commitctx instead).
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 225
diff changeset
424 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
425 if text + '\n' != origtext:
3b8804c59b63 drop untested commit_import_ctx (use commitctx instead).
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 225
diff changeset
426 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
427
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
428 author = commit.author
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
429
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
430 # convert extra data back to the end
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
431 if ' ext:' in commit.author:
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
432 regex = re.compile('^(.*?)\ ext:\((.*)\) <(.*)\>$')
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
433 m = regex.match(commit.author)
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
434 if m:
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
435 name = m.group(1)
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
436 ex = urllib.unquote(m.group(2))
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
437 email = m.group(3)
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
438 author = name + ' <' + email + '>' + ex
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 if ' <none@none>' in commit.author:
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
441 author = commit.author[:-12]
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
442
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
443 try:
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
444 author.decode('utf-8')
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
445 except UnicodeDecodeError:
225
cde57730faa7 store non utf-8 encoded author/commit message as deltas
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 224
diff changeset
446 origauthor = author
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
447 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
448 extra['author'] = create_delta(author, origauthor)
186
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
449
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
450 oldenc = self.swap_out_encoding()
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
451
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
452 def getfilectx(repo, memctx, f):
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
453 try:
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
454 (mode, sha, data) = self.get_file(commit, f)
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
455 e = self.convert_git_int_mode(mode)
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
456 except (TypeError, KeyError):
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
457 raise IOError()
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
458 if f in hg_renames:
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
459 copied_path = hg_renames[f]
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
460 else:
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
461 copied_path = None
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
462 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
463
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
464 gparents = map(self.map_hg_get, commit.parents)
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
465 p1, p2 = (nullid, nullid)
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
466 octopus = False
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
467
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
468 if len(gparents) > 1:
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
469 # merge, possibly octopus
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
470 def commit_octopus(p1, p2):
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
471 ctx = context.memctx(self.repo, (p1, p2), text, files, getfilectx,
186
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
472 author, date, {'hg-git': 'octopus'})
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
473 return hex(self.repo.commitctx(ctx))
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 octopus = len(gparents) > 2
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
476 p2 = gparents.pop()
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
477 p1 = gparents.pop()
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
478 while len(gparents) > 0:
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
479 p2 = commit_octopus(p1, p2)
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
480 p1 = gparents.pop()
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
481 else:
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
482 if gparents:
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
483 p1 = gparents.pop()
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
484
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
485 files = list(set(files))
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
486
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
487 pa = None
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
488 if not (p2 == nullid):
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
489 node1 = self.repo.changectx(p1)
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
490 node2 = self.repo.changectx(p2)
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
491 pa = node1.ancestor(node2)
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
492
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
493 # if named branch, add to extra
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
494 if hg_branch:
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
495 extra['branch'] = hg_branch
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
496
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
497 # 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
498 if commit.author != commit.committer \
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
499 or commit.author_time != commit.commit_time \
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
500 or commit.author_timezone != commit.commit_timezone:
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
501 extra['committer'] = "%s %d %d" % (commit.committer, commit.commit_time, -commit.commit_timezone)
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
502
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
503 if commit.encoding:
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
504 extra['encoding'] = commit.encoding
183
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 hg_branch:
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
507 extra['branch'] = hg_branch
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
508
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
509 if octopus:
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
510 extra['hg-git'] ='octopus-done'
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
511
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
512 ctx = context.memctx(self.repo, (p1, p2), text, files, getfilectx,
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
513 author, date, extra)
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
514
226
3b8804c59b63 drop untested commit_import_ctx (use commitctx instead).
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 225
diff changeset
515 node = self.repo.commitctx(ctx)
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
516
186
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
517 self.swap_out_encoding(oldenc)
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
518
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
519 # save changeset to mapping file
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
520 cs = hex(node)
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
521 self.map_set(commit.id, cs)
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
522
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
523 ## 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
524
230
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
525 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
526 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
527 def changed(refs):
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
528 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
529 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
530
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
531 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
532 try:
95
7de67fcb18b0 be better about internationalizing strings
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 94
diff changeset
533 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
534 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
535 return changed_refs
230
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
536 except HangupException:
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
537 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
538
230
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
539 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
540 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
541
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
542 #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
543 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
544 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
545 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
546 tip = hex(self.repo.lookup('tip'))
bfe6fd2fdb9b push tip to master in an empty repository even if there are tags
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 247
diff changeset
547 bookmarks.bookmark(self.ui, self.repo, 'master', tip)
bfe6fd2fdb9b push tip to master in an empty repository even if there are tags
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 247
diff changeset
548 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
549 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
550
230
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
551 for rev in revs:
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
552 ctx = self.repo[rev]
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
553 heads = [t for t in ctx.tags() if t in self.local_heads()]
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
554 tags = [t for t in ctx.tags() if t in self.tags]
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
555
230
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
556 if not (heads or tags):
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
557 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
558 " it doesn't have a ref" % ctx)
149
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
559
230
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
560 for r in heads + tags:
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
561 if r in heads:
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
562 ref = 'refs/heads/'+r
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
563 else:
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
564 ref = 'refs/tags/'+r
181
8690377c3ce9 Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 179
diff changeset
565
230
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
566 if ref not in refs:
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
567 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
568 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
569 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
570 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
571 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
572 else:
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
573 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
574 % (ref, ctx))
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
575 else:
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
576 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
577 "and merge before pushing" % ref)
126
705b88c9f3d1 remote branches to server
Ian Dees <undees@gmail.com>
parents: 125
diff changeset
578
230
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
579 return new_refs
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
580
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
581
232
0ba1aee0467c initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 231
diff changeset
582 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
583 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
584 graphwalker = self.git.get_graph_walker()
232
0ba1aee0467c initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 231
diff changeset
585 def determine_wants(refs):
0ba1aee0467c initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 231
diff changeset
586 if heads:
0ba1aee0467c initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 231
diff changeset
587 want = []
0ba1aee0467c initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 231
diff changeset
588 for h in heads:
0ba1aee0467c initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 231
diff changeset
589 r = [ref for ref in refs if ref.endswith('/'+h)]
0ba1aee0467c initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 231
diff changeset
590 if not r:
0ba1aee0467c initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 231
diff changeset
591 raise hgutil.Abort("ref %s not found on remote server")
0ba1aee0467c initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 231
diff changeset
592 elif len(r) == 1:
0ba1aee0467c initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 231
diff changeset
593 want.append(refs[r[0]])
0ba1aee0467c initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 231
diff changeset
594 else:
0ba1aee0467c initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 231
diff changeset
595 raise hgutil.Abort("ambiguous reference %s: %r"%(h, r))
0ba1aee0467c initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 231
diff changeset
596 else:
0ba1aee0467c initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 231
diff changeset
597 want = [sha for ref, sha in refs.iteritems()
0ba1aee0467c initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 231
diff changeset
598 if not ref.endswith('^{}')]
0ba1aee0467c initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 231
diff changeset
599 return want
5
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
600 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
601 try:
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
602 return client.fetch_pack(path, determine_wants, graphwalker, f.write, self.ui.status)
230
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
603 except HangupException:
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
604 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
605 finally:
5
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
606 commit()
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
607
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
608 ## REFERENCES HANDLING
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
609
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
610 def update_references(self):
195
e09d71dc4cb4 Drop importbranch/exportbranch options (exportbranch was really broken)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 194
diff changeset
611 heads = self.local_heads()
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
612
195
e09d71dc4cb4 Drop importbranch/exportbranch options (exportbranch was really broken)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 194
diff changeset
613 # 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
614 # Mercurial bookmark.
e09d71dc4cb4 Drop importbranch/exportbranch options (exportbranch was really broken)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 194
diff changeset
615 for key in heads:
230
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
616 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
617
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
618 def export_hg_tags(self):
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
619 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
620 if self.repo.tagtype(tag) in ('global', 'git'):
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
621 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
622 self.tags[tag] = hex(sha)
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
623
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
624 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
625 try:
a5c53e94d92b Do not depend on the cache git repository for reference pushing
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 190
diff changeset
626 bms = bookmarks.parse(self.repo)
230
51e4d6ebbc40 rework pushing to support --rev and --force options
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 229
diff changeset
627 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
628 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
629 return {}
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
630
187
5f196f80ffb3 Store git tags in .hg/git-tags and let localtags be *local*
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 186
diff changeset
631 def import_tags(self, refs):
149
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
632 keys = refs.keys()
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
633 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
634 return
5f196f80ffb3 Store git tags in .hg/git-tags and let localtags be *local*
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 186
diff changeset
635 for k in keys[:]:
149
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
636 ref_name = k
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
637 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
638 if parts[0] == 'refs' and parts[1] == 'tags':
149
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
639 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
640 # 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
641 # the ones we are pulling
0ba1aee0467c initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 231
diff changeset
642 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
643 continue
149
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
644 if ref_name[-3:] == '^{}':
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
645 ref_name = ref_name[:-3]
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
646 if not ref_name in self.repo.tags():
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
647 obj = self.git.get_object(refs[k])
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
648 sha = None
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
649 if isinstance (obj, Commit): # lightweight
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
650 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
651 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
652 elif isinstance (obj, Tag): # annotated
149
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
653 (obj_type, obj_sha) = obj.get_object()
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
654 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
655 if isinstance (obj, Commit):
149
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
656 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
657 # 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
658 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
659 self.save_tags()
181
8690377c3ce9 Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 179
diff changeset
660
184
7bf98d3085f4 Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 183
diff changeset
661 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
662 try:
47
3b62270c1fad writing some status output after a push, updating local bookmarks
Scott Chacon <schacon@gmail.com>
parents: 42
diff changeset
663 bms = bookmarks.parse(self.repo)
184
7bf98d3085f4 Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 183
diff changeset
664 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
665 if ref.startswith('refs/heads/')])
156
a507384308b2 Allow bookmarking a specific branch
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 155
diff changeset
666
a507384308b2 Allow bookmarking a specific branch
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 155
diff changeset
667 for head, sha in heads.iteritems():
232
0ba1aee0467c initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 231
diff changeset
668 # 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
669 # the ones we are pulling
0ba1aee0467c initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 231
diff changeset
670 if sha not in self.git.object_store:
0ba1aee0467c initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 231
diff changeset
671 continue
188
5d48a2310e16 Use mercurial.node.bin instead of dulwich.objects.hex_to_sha
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 187
diff changeset
672 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
673 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
674 # new branch
7bf98d3085f4 Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 183
diff changeset
675 bms[head] = hgsha
7bf98d3085f4 Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 183
diff changeset
676 else:
7bf98d3085f4 Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 183
diff changeset
677 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
678 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
679 # fast forward
7bf98d3085f4 Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 183
diff changeset
680 bms[head] = hgsha
156
a507384308b2 Allow bookmarking a specific branch
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 155
diff changeset
681 if heads:
a507384308b2 Allow bookmarking a specific branch
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 155
diff changeset
682 bookmarks.write(self.repo, bms)
161
134915637cf7 Merge branch 'octo' with octo merge code
Scott Chacon <schacon@gmail.com>
parents: 157 160
diff changeset
683
29
2a5c0bf0fef5 Another way of fixing no-bookmark issue, along with updated test.
Augie Fackler <durin42@gmail.com>
parents: 28
diff changeset
684 except AttributeError:
95
7de67fcb18b0 be better about internationalizing strings
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 94
diff changeset
685 self.ui.warn(_('creating bookmarks failed, do you have'
7de67fcb18b0 be better about internationalizing strings
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 94
diff changeset
686 ' 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
687
184
7bf98d3085f4 Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 183
diff changeset
688 def update_remote_branches(self, remote_name, refs):
7bf98d3085f4 Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 183
diff changeset
689 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
690 if ref.startswith('refs/heads/')])
7bf98d3085f4 Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 183
diff changeset
691
7bf98d3085f4 Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 183
diff changeset
692 for head, sha in heads.iteritems():
232
0ba1aee0467c initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 231
diff changeset
693 # refs contains all the refs in the server, not just the ones
0ba1aee0467c initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 231
diff changeset
694 # we are pulling
0ba1aee0467c initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 231
diff changeset
695 if sha not in self.git.object_store:
0ba1aee0467c initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 231
diff changeset
696 continue
188
5d48a2310e16 Use mercurial.node.bin instead of dulwich.objects.hex_to_sha
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 187
diff changeset
697 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
698 tag = '%s/%s' % (remote_name, head)
7bf98d3085f4 Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 183
diff changeset
699 self.repo.tag(tag, hgsha, '', True, None, None)
7bf98d3085f4 Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 183
diff changeset
700
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
701 for ref_name in refs:
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
702 if ref_name.startswith('refs/heads'):
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
703 new_ref = 'refs/remotes/%s/%s' % (remote_name, ref_name[10:])
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
704 self.git.refs[new_ref] = refs[ref_name]
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
705 elif ref_name.startswith('refs/tags'):
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
706 self.git.refs[ref_name] = refs[ref_name]
196
40edc4b814e4 Reorganize push for more symmetry with fetch
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 195
diff changeset
707
40edc4b814e4 Reorganize push for more symmetry with fetch
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 195
diff changeset
708
183
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
709 ## UTILITY FUNCTIONS
469e80d3142a Reorder methods by their functionality.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
710
53
5deb5cbd86aa respecting file modes on git import
Scott Chacon <schacon@gmail.com>
parents: 52
diff changeset
711 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
712 # TODO: make these into constants
53
5deb5cbd86aa respecting file modes on git import
Scott Chacon <schacon@gmail.com>
parents: 52
diff changeset
713 convert = {
121
0c94e860a0ed use octal numbers for modes.
Dmitriy Taychenachev <dimichxp@gmail.com>
parents: 120
diff changeset
714 0100644: '',
0c94e860a0ed use octal numbers for modes.
Dmitriy Taychenachev <dimichxp@gmail.com>
parents: 120
diff changeset
715 0100755: 'x',
0c94e860a0ed use octal numbers for modes.
Dmitriy Taychenachev <dimichxp@gmail.com>
parents: 120
diff changeset
716 0120000: 'l'}
53
5deb5cbd86aa respecting file modes on git import
Scott Chacon <schacon@gmail.com>
parents: 52
diff changeset
717 if mode in convert:
5deb5cbd86aa respecting file modes on git import
Scott Chacon <schacon@gmail.com>
parents: 52
diff changeset
718 return convert[mode]
5deb5cbd86aa respecting file modes on git import
Scott Chacon <schacon@gmail.com>
parents: 52
diff changeset
719 return ''
65
5ed8316d3cfa Start using reasonable ui.{status,debug,warn} calls instead of print.
Augie Fackler <durin42@gmail.com>
parents: 56
diff changeset
720
71
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
721 def extract_hg_metadata(self, message):
227
c4f6e6f24bf1 fix bug introduced by previous commit
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 226
diff changeset
722 split = message.split("\n--HG--\n", 1)
71
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
723 renames = {}
164
7e98757deadc author and extra data fixes
Scott Chacon <schacon@gmail.com>
parents: 162
diff changeset
724 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
725 branch = False
71
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
726 if len(split) == 2:
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
727 message, meta = split
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
728 lines = meta.split("\n")
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
729 for line in lines:
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
730 if line == '':
181
8690377c3ce9 Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 179
diff changeset
731 continue
8690377c3ce9 Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 179
diff changeset
732
71
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
733 command, data = line.split(" : ", 1)
181
8690377c3ce9 Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 179
diff changeset
734
71
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
735 if command == 'rename':
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
736 before, after = data.split(" => ", 1)
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
737 renames[after] = before
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
738 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
739 branch = data
164
7e98757deadc author and extra data fixes
Scott Chacon <schacon@gmail.com>
parents: 162
diff changeset
740 if command == 'extra':
7e98757deadc author and extra data fixes
Scott Chacon <schacon@gmail.com>
parents: 162
diff changeset
741 before, after = data.split(" : ", 1)
7e98757deadc author and extra data fixes
Scott Chacon <schacon@gmail.com>
parents: 162
diff changeset
742 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
743 return (message, renames, branch, extra)
181
8690377c3ce9 Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 179
diff changeset
744
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
745 def get_file(self, commit, f):
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
746 otree = self.git.tree(commit.tree)
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
747 parts = f.split('/')
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
748 for part in parts:
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
749 (mode, sha) = otree[part]
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
750 obj = self.git.get_object(sha)
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
751 if isinstance (obj, Blob):
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
752 return (mode, sha, obj._text)
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
753 elif isinstance(obj, Tree):
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
754 otree = obj
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
755
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
756 def get_files_changed(self, commit):
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
757 def filenames(basetree, comptree, prefix):
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
758 basefiles = set()
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
759 changes = list()
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
760 csha = None
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
761 cmode = None
229
f2c2061aacd1 work around a bug in dulwich 0.3.3
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 228
diff changeset
762 if basetree is not None:
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
763 for (bmode, bname, bsha) in basetree.entries():
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
764 if bmode == 0160000: # TODO: properly handle submodules
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
765 continue
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
766 basefiles.add(bname)
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
767 bobj = self.git.get_object(bsha)
229
f2c2061aacd1 work around a bug in dulwich 0.3.3
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 228
diff changeset
768 if comptree is not None:
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
769 if bname in comptree:
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
770 (cmode, csha) = comptree[bname]
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
771 else:
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
772 (cmode, csha) = (None, None)
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
773 if not ((csha == bsha) and (cmode == bmode)):
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
774 if isinstance (bobj, Blob):
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
775 changes.append (prefix + bname)
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
776 elif isinstance(bobj, Tree):
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
777 ctree = None
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
778 if csha:
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
779 ctree = self.git.get_object(csha)
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
780 changes.extend(filenames(bobj,
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
781 ctree,
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
782 prefix + bname + '/'))
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
783
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
784 # handle removals
229
f2c2061aacd1 work around a bug in dulwich 0.3.3
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 228
diff changeset
785 if comptree is not None:
224
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
786 for (bmode, bname, bsha) in comptree.entries():
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
787 if bmode == 0160000: # TODO: handle submodles
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
788 continue
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
789 if bname not in basefiles:
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
790 bobj = self.git.get_object(bsha)
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
791 if isinstance(bobj, Blob):
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
792 changes.append(prefix + bname)
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
793 elif isinstance(bobj, Tree):
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
794 changes.extend(filenames(None, bobj,
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
795 prefix + bname + '/'))
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
796 return changes
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
797
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
798 all_changes = list()
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
799 otree = self.git.tree(commit.tree)
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
800 if len(commit.parents) == 0:
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
801 all_changes = filenames(otree, None, '')
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
802 for parent in commit.parents:
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
803 pcommit = self.git.commit(parent)
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
804 ptree = self.git.tree(pcommit.tree)
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
805 all_changes.extend(filenames(otree, ptree, ''))
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
806
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
807 return all_changes
80d67ae190df port to upstream dulwich
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 222
diff changeset
808
184
7bf98d3085f4 Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 183
diff changeset
809 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
810 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
811 if names:
7bf98d3085f4 Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 183
diff changeset
812 return names[0]
7bf98d3085f4 Fix remote branch hadling to use the hgrc [paths] section
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 183
diff changeset
813
186
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
814 # Stolen from hgsubversion
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
815 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
816 try:
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
817 from mercurial import encoding
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
818 old = encoding.encoding
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
819 encoding.encoding = new_encoding
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
820 except ImportError:
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
821 old = hgutil._encoding
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
822 hgutil._encoding = new_encoding
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
823 return old
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
824
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
825 def decode_guess(self, string, encoding):
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
826 # 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
827 if encoding:
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
828 try:
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
829 return string.decode(encoding).encode('utf-8')
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
830 except UnicodeDecodeError:
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
831 pass
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
832
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
833 try:
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
834 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
835 except UnicodeDecodeError:
f4caf22b87cd Handle git repositories with legacy encodings.
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 184
diff changeset
836 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
837
5
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
838 def get_transport_and_path(self, uri):
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
839 from dulwich.client import TCPGitClient, SSHGitClient, SubprocessGitClient
35
562fc51b991e we did the same thing, not sure why it conflicted
Scott Chacon <schacon@gmail.com>
parents: 29
diff changeset
840 for handler, transport in (("git://", TCPGitClient), ("git@", SSHGitClient), ("git+ssh://", SSHGitClient)):
5
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
841 if uri.startswith(handler):
215
b5d4d1552765 add some annotations for test coverage
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 213
diff changeset
842 host, path = uri[len(handler):].split("/", 1)
233
57f860801ab0 disable thin packs as they aren't handled correctly
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 232
diff changeset
843 return transport(host, thin_packs=False), '/' + path
5
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
844 # if its not git or git+ssh, try a local url..
233
57f860801ab0 disable thin packs as they aren't handled correctly
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 232
diff changeset
845 return SubprocessGitClient(thin_packs=False), uri