annotate git_handler.py @ 181:8690377c3ce9

Various cleanups (mostly whitespace and imports)
author Abderrahim Kitouni <a.kitouni@gmail.com>
date Fri, 05 Jun 2009 11:56:22 +0100
parents c5c63783ace0
children 9bdd8e76bbab
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
5
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
3 from dulwich.repo import Repo
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
4 from dulwich.client import SimpleFetchGraphWalker
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
5 from hgext import bookmarks
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
6 from mercurial.i18n import _
181
8690377c3ce9 Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 179
diff changeset
7 from mercurial.node import hex, nullid
8690377c3ce9 Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 179
diff changeset
8 from mercurial import context
172
ac92cdc45ceb not trying to write the same tree twice
Scott Chacon <schacon@gmail.com>
parents: 171
diff changeset
9 from dulwich.misc import make_sha
38
f0daee676e10 successful push to an upstream git server - BOOYAH!
Scott Chacon <schacon@gmail.com>
parents: 37
diff changeset
10 from dulwich.objects import (
f0daee676e10 successful push to an upstream git server - BOOYAH!
Scott Chacon <schacon@gmail.com>
parents: 37
diff changeset
11 Blob,
f0daee676e10 successful push to an upstream git server - BOOYAH!
Scott Chacon <schacon@gmail.com>
parents: 37
diff changeset
12 Commit,
f0daee676e10 successful push to an upstream git server - BOOYAH!
Scott Chacon <schacon@gmail.com>
parents: 37
diff changeset
13 Tag,
f0daee676e10 successful push to an upstream git server - BOOYAH!
Scott Chacon <schacon@gmail.com>
parents: 37
diff changeset
14 Tree,
129
ed4e8c2cd016 cleanup dates handling.
Dmitriy Taychenachev <dimichxp@gmail.com>
parents: 118
diff changeset
15 hex_to_sha,
ed4e8c2cd016 cleanup dates handling.
Dmitriy Taychenachev <dimichxp@gmail.com>
parents: 118
diff changeset
16 format_timezone,
38
f0daee676e10 successful push to an upstream git server - BOOYAH!
Scott Chacon <schacon@gmail.com>
parents: 37
diff changeset
17 )
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
18
24
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
19
5
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
20 class GitHandler(object):
19
2be9c0bd88af Warn, but don't fail when bookmarks is not enabled.
Augie Fackler <durin42@gmail.com>
parents: 17
diff changeset
21
5
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
22 def __init__(self, dest_repo, ui):
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
23 self.repo = dest_repo
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
24 self.ui = ui
105
41e76444105c make git-mapfile and git-configfile constants
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 104
diff changeset
25 self.mapfile = 'git-mapfile'
41e76444105c make git-mapfile and git-configfile constants
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 104
diff changeset
26 self.configfile = 'git-config'
133
f2dfb2bed724 Allow storing the git directory intree
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 118
diff changeset
27
f2dfb2bed724 Allow storing the git directory intree
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 118
diff changeset
28 if ui.config('git', 'intree'):
f2dfb2bed724 Allow storing the git directory intree
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 118
diff changeset
29 self.gitdir = self.repo.wjoin('.git')
f2dfb2bed724 Allow storing the git directory intree
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 118
diff changeset
30 else:
f2dfb2bed724 Allow storing the git directory intree
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 118
diff changeset
31 self.gitdir = self.repo.join('git')
f2dfb2bed724 Allow storing the git directory intree
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 118
diff changeset
32
141
a989866eead8 Make it possible to limit what branches are imported
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 140
diff changeset
33 self.importbranch = ui.config('git', 'importbranch')
155
6db38267e2e8 make the export branch customizable
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 143
diff changeset
34 self.exportbranch = ui.config('git', 'exportbranch', 'refs/heads/master')
156
a507384308b2 Allow bookmarking a specific branch
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 155
diff changeset
35 self.bookbranch = ui.config('git', 'bookbranch', '')
141
a989866eead8 Make it possible to limit what branches are imported
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 140
diff changeset
36
16
58cd05129119 moved init into git_handler
Scott Chacon <schacon@gmail.com>
parents: 14
diff changeset
37 self.init_if_missing()
7
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
38 self.load_git()
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
39 self.load_map()
14
36e94e805fa7 added basic config file for remembering remote urls
Scott Chacon <schacon@gmail.com>
parents: 13
diff changeset
40 self.load_config()
19
2be9c0bd88af Warn, but don't fail when bookmarks is not enabled.
Augie Fackler <durin42@gmail.com>
parents: 17
diff changeset
41
2be9c0bd88af Warn, but don't fail when bookmarks is not enabled.
Augie Fackler <durin42@gmail.com>
parents: 17
diff changeset
42 # make the git data directory
16
58cd05129119 moved init into git_handler
Scott Chacon <schacon@gmail.com>
parents: 14
diff changeset
43 def init_if_missing(self):
106
3aa2f6caed16 make the gitdir a constant
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 105
diff changeset
44 if not os.path.exists(self.gitdir):
3aa2f6caed16 make the gitdir a constant
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 105
diff changeset
45 os.mkdir(self.gitdir)
3aa2f6caed16 make the gitdir a constant
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 105
diff changeset
46 Repo.init_bare(self.gitdir)
19
2be9c0bd88af Warn, but don't fail when bookmarks is not enabled.
Augie Fackler <durin42@gmail.com>
parents: 17
diff changeset
47
7
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
48 def load_git(self):
106
3aa2f6caed16 make the gitdir a constant
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 105
diff changeset
49 self.git = Repo(self.gitdir)
7
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
50
14
36e94e805fa7 added basic config file for remembering remote urls
Scott Chacon <schacon@gmail.com>
parents: 13
diff changeset
51 ## FILE LOAD AND SAVE METHODS
36e94e805fa7 added basic config file for remembering remote urls
Scott Chacon <schacon@gmail.com>
parents: 13
diff changeset
52
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
53 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
54 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
55 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
56
13b9a020e382 gpush coming along. will now write blobs it doesn't have yet to git repo.
Scott Chacon <schacon@gmail.com>
parents: 19
diff changeset
57 def map_hg_get(self, gitsha):
94
b88d6b214914 strip redundant module path and dict accessing
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 92
diff changeset
58 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
59
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 def map_git_get(self, hgsha):
94
b88d6b214914 strip redundant module path and dict accessing
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 92
diff changeset
61 return self._map_hg.get(hgsha)
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
62
7
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
63 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
64 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
65 self._map_hg = {}
105
41e76444105c make git-mapfile and git-configfile constants
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 104
diff changeset
66 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
67 for line in self.repo.opener(self.mapfile):
7
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
68 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
69 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
70 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
71
7
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
72 def save_map(self):
105
41e76444105c make git-mapfile and git-configfile constants
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 104
diff changeset
73 file = self.repo.opener(self.mapfile, 'w+', atomictemp=True)
100
e17d9eea44ab sort the mapfile before writing
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 99
diff changeset
74 for gitsha, hgsha in sorted(self._map_git.iteritems()):
7
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
75 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
76 file.rename()
19
2be9c0bd88af Warn, but don't fail when bookmarks is not enabled.
Augie Fackler <durin42@gmail.com>
parents: 17
diff changeset
77
14
36e94e805fa7 added basic config file for remembering remote urls
Scott Chacon <schacon@gmail.com>
parents: 13
diff changeset
78 def load_config(self):
36e94e805fa7 added basic config file for remembering remote urls
Scott Chacon <schacon@gmail.com>
parents: 13
diff changeset
79 self._config = {}
105
41e76444105c make git-mapfile and git-configfile constants
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 104
diff changeset
80 if os.path.exists(self.repo.join(self.configfile)):
41e76444105c make git-mapfile and git-configfile constants
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 104
diff changeset
81 for line in self.repo.opener(self.configfile):
14
36e94e805fa7 added basic config file for remembering remote urls
Scott Chacon <schacon@gmail.com>
parents: 13
diff changeset
82 key, value = line.strip().split(' ', 1)
36e94e805fa7 added basic config file for remembering remote urls
Scott Chacon <schacon@gmail.com>
parents: 13
diff changeset
83 self._config[key] = value
19
2be9c0bd88af Warn, but don't fail when bookmarks is not enabled.
Augie Fackler <durin42@gmail.com>
parents: 17
diff changeset
84
14
36e94e805fa7 added basic config file for remembering remote urls
Scott Chacon <schacon@gmail.com>
parents: 13
diff changeset
85 def save_config(self):
105
41e76444105c make git-mapfile and git-configfile constants
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 104
diff changeset
86 file = self.repo.opener(self.configfile, 'w+', atomictemp=True)
14
36e94e805fa7 added basic config file for remembering remote urls
Scott Chacon <schacon@gmail.com>
parents: 13
diff changeset
87 for key, value in self._config.iteritems():
36e94e805fa7 added basic config file for remembering remote urls
Scott Chacon <schacon@gmail.com>
parents: 13
diff changeset
88 file.write("%s %s\n" % (key, value))
104
7e345078425e use atomictemp to prevent corruption on ctrl-c
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 103
diff changeset
89 file.rename()
19
2be9c0bd88af Warn, but don't fail when bookmarks is not enabled.
Augie Fackler <durin42@gmail.com>
parents: 17
diff changeset
90
14
36e94e805fa7 added basic config file for remembering remote urls
Scott Chacon <schacon@gmail.com>
parents: 13
diff changeset
91
36e94e805fa7 added basic config file for remembering remote urls
Scott Chacon <schacon@gmail.com>
parents: 13
diff changeset
92 ## END FILE LOAD AND SAVE METHODS
7
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
93
137
5aefcbf1e50c add a gimport command
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 136
diff changeset
94 def import_commits(self, remote_name):
5aefcbf1e50c add a gimport command
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 136
diff changeset
95 self.import_git_objects(remote_name)
5aefcbf1e50c add a gimport command
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 136
diff changeset
96 self.save_map()
5aefcbf1e50c add a gimport command
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 136
diff changeset
97
12
227b11d75844 updates bookmarks and beginnings of seperate remotes support
Scott Chacon <schacon@gmail.com>
parents: 11
diff changeset
98 def fetch(self, remote_name):
179
c5c63783ace0 Initial clone/pull/push support for git repositories
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 177
diff changeset
99 remote_name = self.remote_name_from_url(remote_name)
95
7de67fcb18b0 be better about internationalizing strings
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 94
diff changeset
100 self.ui.status(_("fetching from : %s\n") % remote_name)
5
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
101 self.export_git_objects()
56
5185af4e649a hg gfetch now works
Scott Chacon <schacon@gmail.com>
parents: 54
diff changeset
102 refs = self.fetch_pack(remote_name)
5185af4e649a hg gfetch now works
Scott Chacon <schacon@gmail.com>
parents: 54
diff changeset
103 if refs:
149
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
104 self.import_git_objects(remote_name, refs)
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
105 self.import_local_tags(refs)
7
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
106 self.save_map()
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
107
172
ac92cdc45ceb not trying to write the same tree twice
Scott Chacon <schacon@gmail.com>
parents: 171
diff changeset
108 def export_commits(self, export_objects=True):
ac92cdc45ceb not trying to write the same tree twice
Scott Chacon <schacon@gmail.com>
parents: 171
diff changeset
109 if export_objects:
ac92cdc45ceb not trying to write the same tree twice
Scott Chacon <schacon@gmail.com>
parents: 171
diff changeset
110 self.export_git_objects()
147
366052cae03c started tag support
Scott Chacon <schacon@gmail.com>
parents: 118
diff changeset
111 self.export_hg_tags()
97
f0628f5270b6 add gexport command
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 96
diff changeset
112 self.update_references()
f0628f5270b6 add gexport command
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 96
diff changeset
113 self.save_map()
f0628f5270b6 add gexport command
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 96
diff changeset
114
17
ace0f6ed65a1 setting up for upload-pack functionality
Scott Chacon <schacon@gmail.com>
parents: 16
diff changeset
115 def push(self, remote_name):
179
c5c63783ace0 Initial clone/pull/push support for git repositories
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 177
diff changeset
116 remote_name = self.remote_name_from_url(remote_name)
166
405a915bf352 remove rename detection, add explicit changelog recording on merges
Scott Chacon <schacon@gmail.com>
parents: 165
diff changeset
117 self.fetch(remote_name) # get and convert objects if they already exist
95
7de67fcb18b0 be better about internationalizing strings
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 94
diff changeset
118 self.ui.status(_("pushing to : %s\n") % remote_name)
172
ac92cdc45ceb not trying to write the same tree twice
Scott Chacon <schacon@gmail.com>
parents: 171
diff changeset
119 self.export_commits(False)
125
5b702bbf078f local git branches to remotes
Ian Dees <undees@gmail.com>
parents: 124
diff changeset
120 self.update_remote_references(remote_name)
17
ace0f6ed65a1 setting up for upload-pack functionality
Scott Chacon <schacon@gmail.com>
parents: 16
diff changeset
121 self.upload_pack(remote_name)
19
2be9c0bd88af Warn, but don't fail when bookmarks is not enabled.
Augie Fackler <durin42@gmail.com>
parents: 17
diff changeset
122
12
227b11d75844 updates bookmarks and beginnings of seperate remotes support
Scott Chacon <schacon@gmail.com>
parents: 11
diff changeset
123 def remote_add(self, remote_name, git_url):
14
36e94e805fa7 added basic config file for remembering remote urls
Scott Chacon <schacon@gmail.com>
parents: 13
diff changeset
124 self._config['remote.' + remote_name + '.url'] = git_url
36e94e805fa7 added basic config file for remembering remote urls
Scott Chacon <schacon@gmail.com>
parents: 13
diff changeset
125 self.save_config()
19
2be9c0bd88af Warn, but don't fail when bookmarks is not enabled.
Augie Fackler <durin42@gmail.com>
parents: 17
diff changeset
126
39
173e738d0da4 remote management tools
Scott Chacon <schacon@gmail.com>
parents: 38
diff changeset
127 def remote_remove(self, remote_name):
173e738d0da4 remote management tools
Scott Chacon <schacon@gmail.com>
parents: 38
diff changeset
128 key = 'remote.' + remote_name + '.url'
173e738d0da4 remote management tools
Scott Chacon <schacon@gmail.com>
parents: 38
diff changeset
129 if key in self._config:
173e738d0da4 remote management tools
Scott Chacon <schacon@gmail.com>
parents: 38
diff changeset
130 del self._config[key]
173e738d0da4 remote management tools
Scott Chacon <schacon@gmail.com>
parents: 38
diff changeset
131 self.save_config()
173e738d0da4 remote management tools
Scott Chacon <schacon@gmail.com>
parents: 38
diff changeset
132
173e738d0da4 remote management tools
Scott Chacon <schacon@gmail.com>
parents: 38
diff changeset
133 def remote_show(self, remote_name):
173e738d0da4 remote management tools
Scott Chacon <schacon@gmail.com>
parents: 38
diff changeset
134 key = 'remote.' + remote_name + '.url'
173e738d0da4 remote management tools
Scott Chacon <schacon@gmail.com>
parents: 38
diff changeset
135 if key in self._config:
173e738d0da4 remote management tools
Scott Chacon <schacon@gmail.com>
parents: 38
diff changeset
136 name = self._config[key]
181
8690377c3ce9 Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 179
diff changeset
137 self.ui.status(_("URL for %s : %s\n") % (remote_name, name))
39
173e738d0da4 remote management tools
Scott Chacon <schacon@gmail.com>
parents: 38
diff changeset
138 else:
95
7de67fcb18b0 be better about internationalizing strings
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 94
diff changeset
139 self.ui.status(_("No remote named : %s\n") % remote_name)
39
173e738d0da4 remote management tools
Scott Chacon <schacon@gmail.com>
parents: 38
diff changeset
140
173e738d0da4 remote management tools
Scott Chacon <schacon@gmail.com>
parents: 38
diff changeset
141 def remote_list(self):
173e738d0da4 remote management tools
Scott Chacon <schacon@gmail.com>
parents: 38
diff changeset
142 for key, value in self._config.iteritems():
173e738d0da4 remote management tools
Scott Chacon <schacon@gmail.com>
parents: 38
diff changeset
143 if key[0:6] == 'remote':
65
5ed8316d3cfa Start using reasonable ui.{status,debug,warn} calls instead of print.
Augie Fackler <durin42@gmail.com>
parents: 56
diff changeset
144 self.ui.status('%s\t%s\n' % (key, value, ))
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
145
12
227b11d75844 updates bookmarks and beginnings of seperate remotes support
Scott Chacon <schacon@gmail.com>
parents: 11
diff changeset
146 def remote_name_to_url(self, remote_name):
14
36e94e805fa7 added basic config file for remembering remote urls
Scott Chacon <schacon@gmail.com>
parents: 13
diff changeset
147 return self._config['remote.' + remote_name + '.url']
19
2be9c0bd88af Warn, but don't fail when bookmarks is not enabled.
Augie Fackler <durin42@gmail.com>
parents: 17
diff changeset
148
179
c5c63783ace0 Initial clone/pull/push support for git repositories
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 177
diff changeset
149 def remote_name_from_url(self, remote):
c5c63783ace0 Initial clone/pull/push support for git repositories
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 177
diff changeset
150 if 'remote.' + remote + '.url' in self._config:
c5c63783ace0 Initial clone/pull/push support for git repositories
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 177
diff changeset
151 return remote
c5c63783ace0 Initial clone/pull/push support for git repositories
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 177
diff changeset
152 if remote in self._config.values():
c5c63783ace0 Initial clone/pull/push support for git repositories
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 177
diff changeset
153 return [key[7:-4] for key in self._config
c5c63783ace0 Initial clone/pull/push support for git repositories
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 177
diff changeset
154 if self._config[key] == remote][0]
c5c63783ace0 Initial clone/pull/push support for git repositories
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 177
diff changeset
155
24
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
156 def update_references(self):
124
9dafb9ac24ff hg bookmarks to local git branches
Ian Dees <undees@gmail.com>
parents: 118
diff changeset
157 try:
9dafb9ac24ff hg bookmarks to local git branches
Ian Dees <undees@gmail.com>
parents: 118
diff changeset
158 # We only care about bookmarks of the form 'name',
9dafb9ac24ff hg bookmarks to local git branches
Ian Dees <undees@gmail.com>
parents: 118
diff changeset
159 # not 'remote/name'.
9dafb9ac24ff hg bookmarks to local git branches
Ian Dees <undees@gmail.com>
parents: 118
diff changeset
160 def is_local_ref(item): return item[0].count('/') == 0
9dafb9ac24ff hg bookmarks to local git branches
Ian Dees <undees@gmail.com>
parents: 118
diff changeset
161 bms = bookmarks.parse(self.repo)
9dafb9ac24ff hg bookmarks to local git branches
Ian Dees <undees@gmail.com>
parents: 118
diff changeset
162 bms = dict(filter(is_local_ref, bms.items()))
9dafb9ac24ff hg bookmarks to local git branches
Ian Dees <undees@gmail.com>
parents: 118
diff changeset
163
9dafb9ac24ff hg bookmarks to local git branches
Ian Dees <undees@gmail.com>
parents: 118
diff changeset
164 # Create a local Git branch name for each
9dafb9ac24ff hg bookmarks to local git branches
Ian Dees <undees@gmail.com>
parents: 118
diff changeset
165 # Mercurial bookmark.
9dafb9ac24ff hg bookmarks to local git branches
Ian Dees <undees@gmail.com>
parents: 118
diff changeset
166 for key in bms:
9dafb9ac24ff hg bookmarks to local git branches
Ian Dees <undees@gmail.com>
parents: 118
diff changeset
167 hg_sha = hex(bms[key])
9dafb9ac24ff hg bookmarks to local git branches
Ian Dees <undees@gmail.com>
parents: 118
diff changeset
168 git_sha = self.map_git_get(hg_sha)
9dafb9ac24ff hg bookmarks to local git branches
Ian Dees <undees@gmail.com>
parents: 118
diff changeset
169 self.git.set_ref('refs/heads/' + key, git_sha)
9dafb9ac24ff hg bookmarks to local git branches
Ian Dees <undees@gmail.com>
parents: 118
diff changeset
170 except AttributeError:
9dafb9ac24ff hg bookmarks to local git branches
Ian Dees <undees@gmail.com>
parents: 118
diff changeset
171 # No bookmarks extension
9dafb9ac24ff hg bookmarks to local git branches
Ian Dees <undees@gmail.com>
parents: 118
diff changeset
172 pass
9dafb9ac24ff hg bookmarks to local git branches
Ian Dees <undees@gmail.com>
parents: 118
diff changeset
173
25
88e9e9e1caf1 will now set the current tip() as your git 'master' branch for packfile upload
Scott Chacon <schacon@gmail.com>
parents: 24
diff changeset
174 c = self.map_git_get(hex(self.repo.changelog.tip()))
155
6db38267e2e8 make the export branch customizable
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 143
diff changeset
175 self.git.set_ref(self.exportbranch, c)
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
176
147
366052cae03c started tag support
Scott Chacon <schacon@gmail.com>
parents: 118
diff changeset
177 def export_hg_tags(self):
149
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
178 for tag, sha in self.repo.tags().iteritems():
153
4e7c50f8b60a dont export funky tags we import for convenience, dont push tags already on the server
Scott Chacon <schacon@gmail.com>
parents: 150
diff changeset
179 if tag[-3:] == '^{}':
4e7c50f8b60a dont export funky tags we import for convenience, dont push tags already on the server
Scott Chacon <schacon@gmail.com>
parents: 150
diff changeset
180 continue
149
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
181 if tag == 'tip':
181
8690377c3ce9 Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 179
diff changeset
182 continue
149
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
183 self.git.set_ref('refs/tags/' + tag, self.map_git_get(hex(sha)))
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
184
126
705b88c9f3d1 remote branches to server
Ian Dees <undees@gmail.com>
parents: 125
diff changeset
185 # Make sure there's a refs/remotes/remote_name/name
705b88c9f3d1 remote branches to server
Ian Dees <undees@gmail.com>
parents: 125
diff changeset
186 # for every refs/heads/name
125
5b702bbf078f local git branches to remotes
Ian Dees <undees@gmail.com>
parents: 124
diff changeset
187 def update_remote_references(self, remote_name):
126
705b88c9f3d1 remote branches to server
Ian Dees <undees@gmail.com>
parents: 125
diff changeset
188 self.git.set_remote_refs(self.local_heads(), remote_name)
705b88c9f3d1 remote branches to server
Ian Dees <undees@gmail.com>
parents: 125
diff changeset
189
705b88c9f3d1 remote branches to server
Ian Dees <undees@gmail.com>
parents: 125
diff changeset
190 def local_heads(self):
125
5b702bbf078f local git branches to remotes
Ian Dees <undees@gmail.com>
parents: 124
diff changeset
191 def is_local_head(item): return item[0].startswith('refs/heads')
5b702bbf078f local git branches to remotes
Ian Dees <undees@gmail.com>
parents: 124
diff changeset
192 refs = self.git.get_refs()
126
705b88c9f3d1 remote branches to server
Ian Dees <undees@gmail.com>
parents: 125
diff changeset
193 return dict(filter(is_local_head, refs.items()))
125
5b702bbf078f local git branches to remotes
Ian Dees <undees@gmail.com>
parents: 124
diff changeset
194
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
195 def export_git_objects(self):
177
88fdcb23294e only look for renames if the file has changed
Scott Chacon <schacon@gmail.com>
parents: 176
diff changeset
196 self.previous_entries = {}
172
ac92cdc45ceb not trying to write the same tree twice
Scott Chacon <schacon@gmail.com>
parents: 171
diff changeset
197 self.written_trees = {}
142
ed884cfe3fa3 export: be more clean in what we're doing
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 141
diff changeset
198 self.ui.status(_("importing Hg objects into Git\n"))
99
541571f2e429 add progress indication during export
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 97
diff changeset
199 total = len(self.repo.changelog)
148
201d30003120 Splitting the if statement up since python didn't like that.
Nick Quaranto <nick@quaran.to>
parents: 147
diff changeset
200 if total:
201d30003120 Splitting the if statement up since python didn't like that.
Nick Quaranto <nick@quaran.to>
parents: 147
diff changeset
201 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
202 else:
201d30003120 Splitting the if statement up since python didn't like that.
Nick Quaranto <nick@quaran.to>
parents: 147
diff changeset
203 magnitude = 1
99
541571f2e429 add progress indication during export
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 97
diff changeset
204 for i, rev in enumerate(self.repo.changelog):
541571f2e429 add progress indication during export
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 97
diff changeset
205 if i%100 == 0:
541571f2e429 add progress indication during export
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 97
diff changeset
206 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
207
159
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
208 ctx = self.repo.changectx(rev)
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
209 state = ctx.extra().get('hg-git', None)
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
210 if state == 'octopus':
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
211 self.ui.debug("revision %d is a part of octopus explosion\n" % rev)
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
212 continue
102
302df8a2a8d0 major speedup in the already-converted case
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 101
diff changeset
213 pgit_sha, already_written = self.export_hg_commit(rev)
302df8a2a8d0 major speedup in the already-converted case
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 101
diff changeset
214 if not already_written:
302df8a2a8d0 major speedup in the already-converted case
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 101
diff changeset
215 self.save_map()
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
216
24
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
217 # 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
218 # 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
219 # 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
220 def export_hg_commit(self, rev):
159
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
221 def is_octopus_part(ctx):
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
222 return ctx.extra().get('hg-git', None) in set(['octopus', 'octopus-done'])
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
223
24
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
224 # return if we've already processed this
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
225 node = self.repo.changelog.lookup(rev)
24
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
226 phgsha = hex(node)
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
227 pgit_sha = self.map_git_get(phgsha)
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
228 if pgit_sha:
102
302df8a2a8d0 major speedup in the already-converted case
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 101
diff changeset
229 return pgit_sha, True
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
230
181
8690377c3ce9 Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 179
diff changeset
231 self.ui.note(_("converting revision %s\n") % rev)
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
232
24
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
233 # make sure parents are converted first
159
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
234 ctx = self.repo.changectx(rev)
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
235 extra = ctx.extra()
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
236
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
237 parents = []
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
238 if extra.get('hg-git', None) == 'octopus-done':
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
239 # implode octopus parents
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
240 part = ctx
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
241 while is_octopus_part(part):
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
242 (p1, p2) = part.parents()
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
243 assert not is_octopus_part(p1)
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
244 parents.append(p1)
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
245 part = p2
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
246 parents.append(p2)
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
247 else:
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
248 parents = ctx.parents()
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
249
24
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
250 for parent in parents:
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
251 p_rev = parent.rev()
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
252 hgsha = hex(parent.node())
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
253 git_sha = self.map_git_get(hgsha)
37
7046d792dfcd fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents: 35
diff changeset
254 if not p_rev == -1:
7046d792dfcd fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents: 35
diff changeset
255 if not git_sha:
7046d792dfcd fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents: 35
diff changeset
256 self.export_hg_commit(p_rev)
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
257
67
759ac56497e7 adding hg explicit file renames to the git commit message
Scott Chacon <schacon@gmail.com>
parents: 65
diff changeset
258 tree_sha, renames = self.write_git_tree(ctx)
181
8690377c3ce9 Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 179
diff changeset
259
24
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
260 commit = {}
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
261 commit['tree'] = tree_sha
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
262 (time, timezone) = ctx.date()
68
d28d3763eda3 Deal with hg authors missing email attributes.
Chris Wanstrath <chris@ozmm.org>
parents: 65
diff changeset
263
d28d3763eda3 Deal with hg authors missing email attributes.
Chris Wanstrath <chris@ozmm.org>
parents: 65
diff changeset
264 # hg authors might not have emails
d28d3763eda3 Deal with hg authors missing email attributes.
Chris Wanstrath <chris@ozmm.org>
parents: 65
diff changeset
265 author = ctx.user()
181
8690377c3ce9 Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 179
diff changeset
266
169
d67d00738298 fix message stripping and malformed user info
Scott Chacon <schacon@gmail.com>
parents: 168
diff changeset
267 # check for git author pattern compliance
d67d00738298 fix message stripping and malformed user info
Scott Chacon <schacon@gmail.com>
parents: 168
diff changeset
268 regex = re.compile('^(.*?) \<(.*?)\>(.*)$')
d67d00738298 fix message stripping and malformed user info
Scott Chacon <schacon@gmail.com>
parents: 168
diff changeset
269 a = regex.match(author)
d67d00738298 fix message stripping and malformed user info
Scott Chacon <schacon@gmail.com>
parents: 168
diff changeset
270
d67d00738298 fix message stripping and malformed user info
Scott Chacon <schacon@gmail.com>
parents: 168
diff changeset
271 if a:
d67d00738298 fix message stripping and malformed user info
Scott Chacon <schacon@gmail.com>
parents: 168
diff changeset
272 name = a.group(1)
d67d00738298 fix message stripping and malformed user info
Scott Chacon <schacon@gmail.com>
parents: 168
diff changeset
273 email = a.group(2)
d67d00738298 fix message stripping and malformed user info
Scott Chacon <schacon@gmail.com>
parents: 168
diff changeset
274 if len(a.group(3)) > 0:
d67d00738298 fix message stripping and malformed user info
Scott Chacon <schacon@gmail.com>
parents: 168
diff changeset
275 name += ' ext:(' + urllib.quote(a.group(3)) + ')'
d67d00738298 fix message stripping and malformed user info
Scott Chacon <schacon@gmail.com>
parents: 168
diff changeset
276 author = name + ' <' + email + '>'
d67d00738298 fix message stripping and malformed user info
Scott Chacon <schacon@gmail.com>
parents: 168
diff changeset
277 else:
68
d28d3763eda3 Deal with hg authors missing email attributes.
Chris Wanstrath <chris@ozmm.org>
parents: 65
diff changeset
278 author = author + ' <none@none>'
129
ed4e8c2cd016 cleanup dates handling.
Dmitriy Taychenachev <dimichxp@gmail.com>
parents: 118
diff changeset
279 commit['author'] = author + ' ' + str(int(time)) + ' ' + format_timezone(-timezone)
24
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
280 message = ctx.description()
80
0e0a2d20deed added a missing newline back to git conversion
Scott Chacon <schacon@gmail.com>
parents: 79
diff changeset
281 commit['message'] = ctx.description() + "\n"
65
5ed8316d3cfa Start using reasonable ui.{status,debug,warn} calls instead of print.
Augie Fackler <durin42@gmail.com>
parents: 56
diff changeset
282
89
e35ed99fa691 committer info now being kept properly
Scott Chacon <schacon@gmail.com>
parents: 88
diff changeset
283 if 'committer' in extra:
131
dd6c77ec206c store commitdate in mercurial's internal format.
Dmitriy Taychenachev <dimichxp@gmail.com>
parents: 129
diff changeset
284 # fixup timezone
dd6c77ec206c store commitdate in mercurial's internal format.
Dmitriy Taychenachev <dimichxp@gmail.com>
parents: 129
diff changeset
285 (name_timestamp, timezone) = extra['committer'].rsplit(' ', 1)
140
6701ab807bf5 Deal with invalid timezones in extra commiter
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 138
diff changeset
286 try:
6701ab807bf5 Deal with invalid timezones in extra commiter
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 138
diff changeset
287 timezone = format_timezone(-int(timezone))
6701ab807bf5 Deal with invalid timezones in extra commiter
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 138
diff changeset
288 commit['committer'] = '%s %s' % (name_timestamp, timezone)
6701ab807bf5 Deal with invalid timezones in extra commiter
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 138
diff changeset
289 except ValueError:
6701ab807bf5 Deal with invalid timezones in extra commiter
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 138
diff changeset
290 self.ui.warn(_("Ignoring committer in extra, invalid timezone in r%s: '%s'.\n") % (rev, timezone))
118
b3be536e3f50 handles git commit encoding fields now
Scott Chacon <schacon@gmail.com>
parents: 113
diff changeset
291 if 'encoding' in extra:
b3be536e3f50 handles git commit encoding fields now
Scott Chacon <schacon@gmail.com>
parents: 113
diff changeset
292 commit['encoding'] = extra['encoding']
89
e35ed99fa691 committer info now being kept properly
Scott Chacon <schacon@gmail.com>
parents: 88
diff changeset
293
54
f6e11b9d7562 not adding HG extra info if commits were on the default branch
Scott Chacon <schacon@gmail.com>
parents: 53
diff changeset
294 # 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
295 add_extras = False
67
759ac56497e7 adding hg explicit file renames to the git commit message
Scott Chacon <schacon@gmail.com>
parents: 65
diff changeset
296 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
297 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
298 add_extras = True
67
759ac56497e7 adding hg explicit file renames to the git commit message
Scott Chacon <schacon@gmail.com>
parents: 65
diff changeset
299 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
300
67
759ac56497e7 adding hg explicit file renames to the git commit message
Scott Chacon <schacon@gmail.com>
parents: 65
diff changeset
301 if renames:
759ac56497e7 adding hg explicit file renames to the git commit message
Scott Chacon <schacon@gmail.com>
parents: 65
diff changeset
302 add_extras = True
759ac56497e7 adding hg explicit file renames to the git commit message
Scott Chacon <schacon@gmail.com>
parents: 65
diff changeset
303 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
304 extra_message += "rename : " + oldfile + " => " + newfile + "\n"
164
7e98757deadc author and extra data fixes
Scott Chacon <schacon@gmail.com>
parents: 162
diff changeset
305
7e98757deadc author and extra data fixes
Scott Chacon <schacon@gmail.com>
parents: 162
diff changeset
306 for key, value in extra.iteritems():
165
cb922a0ca22d almost got everything working
Scott Chacon <schacon@gmail.com>
parents: 164
diff changeset
307 if key in ['committer', 'encoding', 'branch', 'hg-git']:
164
7e98757deadc author and extra data fixes
Scott Chacon <schacon@gmail.com>
parents: 162
diff changeset
308 continue
7e98757deadc author and extra data fixes
Scott Chacon <schacon@gmail.com>
parents: 162
diff changeset
309 else:
181
8690377c3ce9 Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 179
diff changeset
310 add_extras = True
164
7e98757deadc author and extra data fixes
Scott Chacon <schacon@gmail.com>
parents: 162
diff changeset
311 extra_message += "extra : " + key + " : " + urllib.quote(value) + "\n"
7e98757deadc author and extra data fixes
Scott Chacon <schacon@gmail.com>
parents: 162
diff changeset
312
166
405a915bf352 remove rename detection, add explicit changelog recording on merges
Scott Chacon <schacon@gmail.com>
parents: 165
diff changeset
313 # save file context listing on merge commit
405a915bf352 remove rename detection, add explicit changelog recording on merges
Scott Chacon <schacon@gmail.com>
parents: 165
diff changeset
314 if (len(parents) > 1):
405a915bf352 remove rename detection, add explicit changelog recording on merges
Scott Chacon <schacon@gmail.com>
parents: 165
diff changeset
315 add_extras = True
168
8bfa8aa6b68f added empty changelog handling
Scott Chacon <schacon@gmail.com>
parents: 166
diff changeset
316 if len(ctx.files()) > 0:
8bfa8aa6b68f added empty changelog handling
Scott Chacon <schacon@gmail.com>
parents: 166
diff changeset
317 for filenm in ctx.files():
8bfa8aa6b68f added empty changelog handling
Scott Chacon <schacon@gmail.com>
parents: 166
diff changeset
318 extra_message += "files : " + filenm + "\n"
8bfa8aa6b68f added empty changelog handling
Scott Chacon <schacon@gmail.com>
parents: 166
diff changeset
319 else: # hack for 'fetch' extension idiocy
8bfa8aa6b68f added empty changelog handling
Scott Chacon <schacon@gmail.com>
parents: 166
diff changeset
320 extra_message += "emptychangelog : true\n"
165
cb922a0ca22d almost got everything working
Scott Chacon <schacon@gmail.com>
parents: 164
diff changeset
321
54
f6e11b9d7562 not adding HG extra info if commits were on the default branch
Scott Chacon <schacon@gmail.com>
parents: 53
diff changeset
322 if add_extras:
80
0e0a2d20deed added a missing newline back to git conversion
Scott Chacon <schacon@gmail.com>
parents: 79
diff changeset
323 commit['message'] += "\n--HG--\n" + extra_message
65
5ed8316d3cfa Start using reasonable ui.{status,debug,warn} calls instead of print.
Augie Fackler <durin42@gmail.com>
parents: 56
diff changeset
324
24
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
325 commit['parents'] = []
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
326 for parent in parents:
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
327 hgsha = hex(parent.node())
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
328 git_sha = self.map_git_get(hgsha)
37
7046d792dfcd fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents: 35
diff changeset
329 if git_sha:
7046d792dfcd fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents: 35
diff changeset
330 commit['parents'].append(git_sha)
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
331
24
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
332 commit_sha = self.git.write_commit_hash(commit) # writing new blobs to git
41f4e0a85d15 fully converts hg changeset/manifest/files to git commits/trees/blobs
Scott Chacon <schacon@gmail.com>
parents: 23
diff changeset
333 self.map_set(commit_sha, phgsha)
102
302df8a2a8d0 major speedup in the already-converted case
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 101
diff changeset
334 return commit_sha, False
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
335
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
336 def write_git_tree(self, ctx):
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
337 trees = {}
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
338 man = ctx.manifest()
177
88fdcb23294e only look for renames if the file has changed
Scott Chacon <schacon@gmail.com>
parents: 176
diff changeset
339 ctx_id = hex(ctx.node())
88fdcb23294e only look for renames if the file has changed
Scott Chacon <schacon@gmail.com>
parents: 176
diff changeset
340
67
759ac56497e7 adding hg explicit file renames to the git commit message
Scott Chacon <schacon@gmail.com>
parents: 65
diff changeset
341 renames = []
171
88e413d853ee fixed serious speed issue with rename detection
Scott Chacon <schacon@gmail.com>
parents: 169
diff changeset
342 for filenm, nodesha in man.iteritems():
88e413d853ee fixed serious speed issue with rename detection
Scott Chacon <schacon@gmail.com>
parents: 169
diff changeset
343 file_id = hex(nodesha)
177
88fdcb23294e only look for renames if the file has changed
Scott Chacon <schacon@gmail.com>
parents: 176
diff changeset
344 if ctx_id not in self.previous_entries:
88fdcb23294e only look for renames if the file has changed
Scott Chacon <schacon@gmail.com>
parents: 176
diff changeset
345 self.previous_entries[ctx_id] = {}
88fdcb23294e only look for renames if the file has changed
Scott Chacon <schacon@gmail.com>
parents: 176
diff changeset
346 self.previous_entries[ctx_id][filenm] = file_id
88fdcb23294e only look for renames if the file has changed
Scott Chacon <schacon@gmail.com>
parents: 176
diff changeset
347
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
348 # write blob if not in our git database
177
88fdcb23294e only look for renames if the file has changed
Scott Chacon <schacon@gmail.com>
parents: 176
diff changeset
349 fctx = ctx.filectx(filenm)
88fdcb23294e only look for renames if the file has changed
Scott Chacon <schacon@gmail.com>
parents: 176
diff changeset
350
88fdcb23294e only look for renames if the file has changed
Scott Chacon <schacon@gmail.com>
parents: 176
diff changeset
351 same_as_last = False
88fdcb23294e only look for renames if the file has changed
Scott Chacon <schacon@gmail.com>
parents: 176
diff changeset
352 for par in ctx.parents():
88fdcb23294e only look for renames if the file has changed
Scott Chacon <schacon@gmail.com>
parents: 176
diff changeset
353 par_id = hex(par.node())
88fdcb23294e only look for renames if the file has changed
Scott Chacon <schacon@gmail.com>
parents: 176
diff changeset
354 if par_id in self.previous_entries:
88fdcb23294e only look for renames if the file has changed
Scott Chacon <schacon@gmail.com>
parents: 176
diff changeset
355 if filenm in self.previous_entries[par_id]:
88fdcb23294e only look for renames if the file has changed
Scott Chacon <schacon@gmail.com>
parents: 176
diff changeset
356 if self.previous_entries[par_id][filenm] == file_id:
88fdcb23294e only look for renames if the file has changed
Scott Chacon <schacon@gmail.com>
parents: 176
diff changeset
357 same_as_last = True
88fdcb23294e only look for renames if the file has changed
Scott Chacon <schacon@gmail.com>
parents: 176
diff changeset
358 if not same_as_last:
171
88e413d853ee fixed serious speed issue with rename detection
Scott Chacon <schacon@gmail.com>
parents: 169
diff changeset
359 rename = fctx.renamed()
88e413d853ee fixed serious speed issue with rename detection
Scott Chacon <schacon@gmail.com>
parents: 169
diff changeset
360 if rename:
88e413d853ee fixed serious speed issue with rename detection
Scott Chacon <schacon@gmail.com>
parents: 169
diff changeset
361 filerename, sha = rename
177
88fdcb23294e only look for renames if the file has changed
Scott Chacon <schacon@gmail.com>
parents: 176
diff changeset
362 renames.append((filerename, filenm))
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
363 is_exec = 'x' in fctx.flags()
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
364 is_link = 'l' in fctx.flags()
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
365 blob_sha = self.map_git_get(file_id)
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
366 if not blob_sha:
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
367 blob_sha = self.git.write_blob(fctx.data()) # writing new blobs to git
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
368 self.map_set(blob_sha, file_id)
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
369
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
370 parts = filenm.split('/')
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
371 if len(parts) > 1:
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
372 # get filename and path for leading subdir
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
373 filepath = parts[-1:][0]
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
374 dirpath = "/".join([v for v in parts[0:-1]]) + '/'
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
375
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
376 # get subdir name and path for parent dir
54
f6e11b9d7562 not adding HG extra info if commits were on the default branch
Scott Chacon <schacon@gmail.com>
parents: 53
diff changeset
377 parpath = '/'
f6e11b9d7562 not adding HG extra info if commits were on the default branch
Scott Chacon <schacon@gmail.com>
parents: 53
diff changeset
378 nparpath = '/'
f6e11b9d7562 not adding HG extra info if commits were on the default branch
Scott Chacon <schacon@gmail.com>
parents: 53
diff changeset
379 for part in parts[0:-1]:
f6e11b9d7562 not adding HG extra info if commits were on the default branch
Scott Chacon <schacon@gmail.com>
parents: 53
diff changeset
380 if nparpath == '/':
f6e11b9d7562 not adding HG extra info if commits were on the default branch
Scott Chacon <schacon@gmail.com>
parents: 53
diff changeset
381 nparpath = part + '/'
f6e11b9d7562 not adding HG extra info if commits were on the default branch
Scott Chacon <schacon@gmail.com>
parents: 53
diff changeset
382 else:
f6e11b9d7562 not adding HG extra info if commits were on the default branch
Scott Chacon <schacon@gmail.com>
parents: 53
diff changeset
383 nparpath += part + '/'
65
5ed8316d3cfa Start using reasonable ui.{status,debug,warn} calls instead of print.
Augie Fackler <durin42@gmail.com>
parents: 56
diff changeset
384
54
f6e11b9d7562 not adding HG extra info if commits were on the default branch
Scott Chacon <schacon@gmail.com>
parents: 53
diff changeset
385 treeentry = ['tree', part + '/', nparpath]
65
5ed8316d3cfa Start using reasonable ui.{status,debug,warn} calls instead of print.
Augie Fackler <durin42@gmail.com>
parents: 56
diff changeset
386
54
f6e11b9d7562 not adding HG extra info if commits were on the default branch
Scott Chacon <schacon@gmail.com>
parents: 53
diff changeset
387 if parpath not in trees:
f6e11b9d7562 not adding HG extra info if commits were on the default branch
Scott Chacon <schacon@gmail.com>
parents: 53
diff changeset
388 trees[parpath] = []
f6e11b9d7562 not adding HG extra info if commits were on the default branch
Scott Chacon <schacon@gmail.com>
parents: 53
diff changeset
389 if treeentry not in trees[parpath]:
f6e11b9d7562 not adding HG extra info if commits were on the default branch
Scott Chacon <schacon@gmail.com>
parents: 53
diff changeset
390 trees[parpath].append( treeentry )
65
5ed8316d3cfa Start using reasonable ui.{status,debug,warn} calls instead of print.
Augie Fackler <durin42@gmail.com>
parents: 56
diff changeset
391
54
f6e11b9d7562 not adding HG extra info if commits were on the default branch
Scott Chacon <schacon@gmail.com>
parents: 53
diff changeset
392 parpath = nparpath
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
393
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
394 # set file entry
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
395 fileentry = ['blob', filepath, blob_sha, is_exec, is_link]
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
396 if dirpath not in trees:
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
397 trees[dirpath] = []
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
398 trees[dirpath].append(fileentry)
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
399
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
400 else:
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
401 fileentry = ['blob', parts[0], blob_sha, is_exec, is_link]
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
402 if '/' not in trees:
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
403 trees['/'] = []
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
404 trees['/'].append(fileentry)
65
5ed8316d3cfa Start using reasonable ui.{status,debug,warn} calls instead of print.
Augie Fackler <durin42@gmail.com>
parents: 56
diff changeset
405
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
406 dirs = trees.keys()
122
76a0e1ee7cf7 don't fail while exporting commit with empty working tree. +test.
Dmitriy Taychenachev <dimichxp@gmail.com>
parents: 121
diff changeset
407 if dirs:
76a0e1ee7cf7 don't fail while exporting commit with empty working tree. +test.
Dmitriy Taychenachev <dimichxp@gmail.com>
parents: 121
diff changeset
408 # sort by tree depth, so we write the deepest trees first
76a0e1ee7cf7 don't fail while exporting commit with empty working tree. +test.
Dmitriy Taychenachev <dimichxp@gmail.com>
parents: 121
diff changeset
409 dirs.sort(lambda a, b: len(b.split('/'))-len(a.split('/')))
76a0e1ee7cf7 don't fail while exporting commit with empty working tree. +test.
Dmitriy Taychenachev <dimichxp@gmail.com>
parents: 121
diff changeset
410 dirs.remove('/')
76a0e1ee7cf7 don't fail while exporting commit with empty working tree. +test.
Dmitriy Taychenachev <dimichxp@gmail.com>
parents: 121
diff changeset
411 dirs.append('/')
76a0e1ee7cf7 don't fail while exporting commit with empty working tree. +test.
Dmitriy Taychenachev <dimichxp@gmail.com>
parents: 121
diff changeset
412 else:
76a0e1ee7cf7 don't fail while exporting commit with empty working tree. +test.
Dmitriy Taychenachev <dimichxp@gmail.com>
parents: 121
diff changeset
413 # manifest is empty => make empty root tree
76a0e1ee7cf7 don't fail while exporting commit with empty working tree. +test.
Dmitriy Taychenachev <dimichxp@gmail.com>
parents: 121
diff changeset
414 trees['/'] = []
76a0e1ee7cf7 don't fail while exporting commit with empty working tree. +test.
Dmitriy Taychenachev <dimichxp@gmail.com>
parents: 121
diff changeset
415 dirs = ['/']
181
8690377c3ce9 Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 179
diff changeset
416
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
417 # write all the trees
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
418 tree_sha = None
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
419 tree_shas = {}
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
420 for dirnm in dirs:
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
421 tree_data = []
172
ac92cdc45ceb not trying to write the same tree twice
Scott Chacon <schacon@gmail.com>
parents: 171
diff changeset
422 sha_group = []
176
814499406d4c fix to previously written tree hash calculation
Scott Chacon <schacon@gmail.com>
parents: 174
diff changeset
423
814499406d4c fix to previously written tree hash calculation
Scott Chacon <schacon@gmail.com>
parents: 174
diff changeset
424 # calculating a sha for the tree, so we don't write it twice
814499406d4c fix to previously written tree hash calculation
Scott Chacon <schacon@gmail.com>
parents: 174
diff changeset
425 listsha = make_sha()
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
426 for entry in trees[dirnm]:
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
427 # replace tree path with tree SHA
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
428 if entry[0] == 'tree':
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
429 sha = tree_shas[entry[2]]
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
430 entry[2] = sha
176
814499406d4c fix to previously written tree hash calculation
Scott Chacon <schacon@gmail.com>
parents: 174
diff changeset
431 listsha.update(entry[1])
814499406d4c fix to previously written tree hash calculation
Scott Chacon <schacon@gmail.com>
parents: 174
diff changeset
432 listsha.update(entry[2])
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
433 tree_data.append(entry)
172
ac92cdc45ceb not trying to write the same tree twice
Scott Chacon <schacon@gmail.com>
parents: 171
diff changeset
434 listsha = listsha.hexdigest()
181
8690377c3ce9 Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 179
diff changeset
435
172
ac92cdc45ceb not trying to write the same tree twice
Scott Chacon <schacon@gmail.com>
parents: 171
diff changeset
436 if listsha in self.written_trees:
176
814499406d4c fix to previously written tree hash calculation
Scott Chacon <schacon@gmail.com>
parents: 174
diff changeset
437 tree_sha = self.written_trees[listsha]
814499406d4c fix to previously written tree hash calculation
Scott Chacon <schacon@gmail.com>
parents: 174
diff changeset
438 tree_shas[dirnm] = tree_sha
172
ac92cdc45ceb not trying to write the same tree twice
Scott Chacon <schacon@gmail.com>
parents: 171
diff changeset
439 else:
ac92cdc45ceb not trying to write the same tree twice
Scott Chacon <schacon@gmail.com>
parents: 171
diff changeset
440 tree_sha = self.git.write_tree_array(tree_data) # writing new trees to git
ac92cdc45ceb not trying to write the same tree twice
Scott Chacon <schacon@gmail.com>
parents: 171
diff changeset
441 tree_shas[dirnm] = tree_sha
ac92cdc45ceb not trying to write the same tree twice
Scott Chacon <schacon@gmail.com>
parents: 171
diff changeset
442 self.written_trees[listsha] = tree_sha
181
8690377c3ce9 Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 179
diff changeset
443
67
759ac56497e7 adding hg explicit file renames to the git commit message
Scott Chacon <schacon@gmail.com>
parents: 65
diff changeset
444 return (tree_sha, renames) # should be the last root tree sha
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
445
13
01f28d40cb6a checks out the HEAD node from a clone
Scott Chacon <schacon@gmail.com>
parents: 12
diff changeset
446 def remote_head(self, remote_name):
01f28d40cb6a checks out the HEAD node from a clone
Scott Chacon <schacon@gmail.com>
parents: 12
diff changeset
447 for head, sha in self.git.remote_refs(remote_name).iteritems():
01f28d40cb6a checks out the HEAD node from a clone
Scott Chacon <schacon@gmail.com>
parents: 12
diff changeset
448 if head == 'HEAD':
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
449 return self.map_hg_get(sha)
13
01f28d40cb6a checks out the HEAD node from a clone
Scott Chacon <schacon@gmail.com>
parents: 12
diff changeset
450 return None
19
2be9c0bd88af Warn, but don't fail when bookmarks is not enabled.
Augie Fackler <durin42@gmail.com>
parents: 17
diff changeset
451
17
ace0f6ed65a1 setting up for upload-pack functionality
Scott Chacon <schacon@gmail.com>
parents: 16
diff changeset
452 def upload_pack(self, remote_name):
26
a1a5391bc3c3 edit ssh command to quote the path, also convert tags properly on fetch
Scott Chacon <schacon@gmail.com>
parents: 25
diff changeset
453 git_url = self.remote_name_to_url(remote_name)
a1a5391bc3c3 edit ssh command to quote the path, also convert tags properly on fetch
Scott Chacon <schacon@gmail.com>
parents: 25
diff changeset
454 client, path = self.get_transport_and_path(git_url)
37
7046d792dfcd fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents: 35
diff changeset
455 changed = self.get_changed_refs
26
a1a5391bc3c3 edit ssh command to quote the path, also convert tags properly on fetch
Scott Chacon <schacon@gmail.com>
parents: 25
diff changeset
456 genpack = self.generate_pack_contents
a1a5391bc3c3 edit ssh command to quote the path, also convert tags properly on fetch
Scott Chacon <schacon@gmail.com>
parents: 25
diff changeset
457 try:
95
7de67fcb18b0 be better about internationalizing strings
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 94
diff changeset
458 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
459 changed_refs = client.send_pack(path, changed, genpack)
52
87d462a6b796 pushing nothing works better
Scott Chacon <schacon@gmail.com>
parents: 51
diff changeset
460 if changed_refs:
87d462a6b796 pushing nothing works better
Scott Chacon <schacon@gmail.com>
parents: 51
diff changeset
461 new_refs = {}
88
52b4be85151d fixed some small compatability issues with the dulwich update
Scott Chacon <schacon@gmail.com>
parents: 80
diff changeset
462 for ref, sha in changed_refs.iteritems():
52b4be85151d fixed some small compatability issues with the dulwich update
Scott Chacon <schacon@gmail.com>
parents: 80
diff changeset
463 self.ui.status(" "+ remote_name + "::" + ref + " => GIT:" + sha[0:8] + "\n")
52b4be85151d fixed some small compatability issues with the dulwich update
Scott Chacon <schacon@gmail.com>
parents: 80
diff changeset
464 new_refs[ref] = sha
52
87d462a6b796 pushing nothing works better
Scott Chacon <schacon@gmail.com>
parents: 51
diff changeset
465 self.git.set_remote_refs(new_refs, remote_name)
87d462a6b796 pushing nothing works better
Scott Chacon <schacon@gmail.com>
parents: 51
diff changeset
466 self.update_hg_bookmarks(remote_name)
26
a1a5391bc3c3 edit ssh command to quote the path, also convert tags properly on fetch
Scott Chacon <schacon@gmail.com>
parents: 25
diff changeset
467 except:
96
0cec7b1e07ff add a few more TODO's
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 95
diff changeset
468 # TODO : remove try/except or do something useful here
26
a1a5391bc3c3 edit ssh command to quote the path, also convert tags properly on fetch
Scott Chacon <schacon@gmail.com>
parents: 25
diff changeset
469 raise
37
7046d792dfcd fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents: 35
diff changeset
470
42
fcfb4db848e1 added hack for pushing first branch
Scott Chacon <schacon@gmail.com>
parents: 40
diff changeset
471 # TODO : for now, we'll just push all heads that match remote heads
37
7046d792dfcd fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents: 35
diff changeset
472 # * we should have specified push, tracking branches and --all
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
473 # takes a dict of refs:shas from the server and returns what should be
37
7046d792dfcd fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents: 35
diff changeset
474 # pushed up
7046d792dfcd fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents: 35
diff changeset
475 def get_changed_refs(self, refs):
7046d792dfcd fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents: 35
diff changeset
476 keys = refs.keys()
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
477
88
52b4be85151d fixed some small compatability issues with the dulwich update
Scott Chacon <schacon@gmail.com>
parents: 80
diff changeset
478 changed = {}
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
479 if not keys:
37
7046d792dfcd fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents: 35
diff changeset
480 return None
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
481
42
fcfb4db848e1 added hack for pushing first branch
Scott Chacon <schacon@gmail.com>
parents: 40
diff changeset
482 # TODO : this is a huge hack
fcfb4db848e1 added hack for pushing first branch
Scott Chacon <schacon@gmail.com>
parents: 40
diff changeset
483 if keys[0] == 'capabilities^{}': # nothing on the server yet - first push
88
52b4be85151d fixed some small compatability issues with the dulwich update
Scott Chacon <schacon@gmail.com>
parents: 80
diff changeset
484 changed['refs/heads/master'] = self.git.ref('master')
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
485
149
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
486 tags = self.git.get_tags()
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
487 for tag, sha in tags.iteritems():
153
4e7c50f8b60a dont export funky tags we import for convenience, dont push tags already on the server
Scott Chacon <schacon@gmail.com>
parents: 150
diff changeset
488 tag_name = 'refs/tags/' + tag
4e7c50f8b60a dont export funky tags we import for convenience, dont push tags already on the server
Scott Chacon <schacon@gmail.com>
parents: 150
diff changeset
489 if tag_name not in refs:
4e7c50f8b60a dont export funky tags we import for convenience, dont push tags already on the server
Scott Chacon <schacon@gmail.com>
parents: 150
diff changeset
490 changed[tag_name] = sha
149
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
491
37
7046d792dfcd fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents: 35
diff changeset
492 for ref_name in keys:
7046d792dfcd fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents: 35
diff changeset
493 parts = ref_name.split('/')
7046d792dfcd fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents: 35
diff changeset
494 if parts[0] == 'refs': # strip off 'refs/heads'
7046d792dfcd fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents: 35
diff changeset
495 if parts[1] == 'heads':
7046d792dfcd fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents: 35
diff changeset
496 head = "/".join([v for v in parts[2:]])
7046d792dfcd fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents: 35
diff changeset
497 local_ref = self.git.ref(ref_name)
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
498 if local_ref:
37
7046d792dfcd fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents: 35
diff changeset
499 if not local_ref == refs[ref_name]:
88
52b4be85151d fixed some small compatability issues with the dulwich update
Scott Chacon <schacon@gmail.com>
parents: 80
diff changeset
500 changed[ref_name] = local_ref
181
8690377c3ce9 Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 179
diff changeset
501
126
705b88c9f3d1 remote branches to server
Ian Dees <undees@gmail.com>
parents: 125
diff changeset
502 # Also push any local branches not on the server yet
705b88c9f3d1 remote branches to server
Ian Dees <undees@gmail.com>
parents: 125
diff changeset
503 for head in self.local_heads():
705b88c9f3d1 remote branches to server
Ian Dees <undees@gmail.com>
parents: 125
diff changeset
504 if not head in refs:
705b88c9f3d1 remote branches to server
Ian Dees <undees@gmail.com>
parents: 125
diff changeset
505 ref = self.git.ref(head)
705b88c9f3d1 remote branches to server
Ian Dees <undees@gmail.com>
parents: 125
diff changeset
506 changed[head] = ref
705b88c9f3d1 remote branches to server
Ian Dees <undees@gmail.com>
parents: 125
diff changeset
507
37
7046d792dfcd fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents: 35
diff changeset
508 return changed
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
509
37
7046d792dfcd fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents: 35
diff changeset
510 # takes a list of shas the server wants and shas the server has
7046d792dfcd fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents: 35
diff changeset
511 # and generates a list of commit shas we need to push up
7046d792dfcd fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents: 35
diff changeset
512 def generate_pack_contents(self, want, have):
7046d792dfcd fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents: 35
diff changeset
513 graph_walker = SimpleFetchGraphWalker(want, self.git.get_parents)
7046d792dfcd fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents: 35
diff changeset
514 next = graph_walker.next()
77
d7b8768d005a reapplying defunkts changes
Scott Chacon <schacon@gmail.com>
parents: 76
diff changeset
515 shas = set()
37
7046d792dfcd fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents: 35
diff changeset
516 while next:
7046d792dfcd fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents: 35
diff changeset
517 if next in have:
7046d792dfcd fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents: 35
diff changeset
518 graph_walker.ack(next)
7046d792dfcd fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents: 35
diff changeset
519 else:
77
d7b8768d005a reapplying defunkts changes
Scott Chacon <schacon@gmail.com>
parents: 76
diff changeset
520 shas.add(next)
37
7046d792dfcd fix bug where it was not writing the git object names properly
Scott Chacon <schacon@gmail.com>
parents: 35
diff changeset
521 next = graph_walker.next()
181
8690377c3ce9 Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 179
diff changeset
522
77
d7b8768d005a reapplying defunkts changes
Scott Chacon <schacon@gmail.com>
parents: 76
diff changeset
523 seen = []
181
8690377c3ce9 Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 179
diff changeset
524
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
525 # so now i have the shas, need to turn them into a list of
38
f0daee676e10 successful push to an upstream git server - BOOYAH!
Scott Chacon <schacon@gmail.com>
parents: 37
diff changeset
526 # tuples (sha, path) for ALL the objects i'm sending
f0daee676e10 successful push to an upstream git server - BOOYAH!
Scott Chacon <schacon@gmail.com>
parents: 37
diff changeset
527 # TODO : don't send blobs or trees they already have
f0daee676e10 successful push to an upstream git server - BOOYAH!
Scott Chacon <schacon@gmail.com>
parents: 37
diff changeset
528 def get_objects(tree, path):
f0daee676e10 successful push to an upstream git server - BOOYAH!
Scott Chacon <schacon@gmail.com>
parents: 37
diff changeset
529 changes = list()
f0daee676e10 successful push to an upstream git server - BOOYAH!
Scott Chacon <schacon@gmail.com>
parents: 37
diff changeset
530 changes.append((tree, path))
f0daee676e10 successful push to an upstream git server - BOOYAH!
Scott Chacon <schacon@gmail.com>
parents: 37
diff changeset
531 for (mode, name, sha) in tree.entries():
121
0c94e860a0ed use octal numbers for modes.
Dmitriy Taychenachev <dimichxp@gmail.com>
parents: 120
diff changeset
532 if mode == 0160000: # TODO : properly handle submodules and document what 57344 means
38
f0daee676e10 successful push to an upstream git server - BOOYAH!
Scott Chacon <schacon@gmail.com>
parents: 37
diff changeset
533 continue
77
d7b8768d005a reapplying defunkts changes
Scott Chacon <schacon@gmail.com>
parents: 76
diff changeset
534 if sha in seen:
d7b8768d005a reapplying defunkts changes
Scott Chacon <schacon@gmail.com>
parents: 76
diff changeset
535 continue
181
8690377c3ce9 Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 179
diff changeset
536
38
f0daee676e10 successful push to an upstream git server - BOOYAH!
Scott Chacon <schacon@gmail.com>
parents: 37
diff changeset
537 obj = self.git.get_object(sha)
77
d7b8768d005a reapplying defunkts changes
Scott Chacon <schacon@gmail.com>
parents: 76
diff changeset
538 seen.append(sha)
76
aa2dadf04144 fixed the topo sorting and added a unit test
Scott Chacon <schacon@gmail.com>
parents: 75
diff changeset
539 if isinstance (obj, Blob):
38
f0daee676e10 successful push to an upstream git server - BOOYAH!
Scott Chacon <schacon@gmail.com>
parents: 37
diff changeset
540 changes.append((obj, path + name))
f0daee676e10 successful push to an upstream git server - BOOYAH!
Scott Chacon <schacon@gmail.com>
parents: 37
diff changeset
541 elif isinstance(obj, Tree):
77
d7b8768d005a reapplying defunkts changes
Scott Chacon <schacon@gmail.com>
parents: 76
diff changeset
542 changes.extend(get_objects(obj, path + name + '/'))
38
f0daee676e10 successful push to an upstream git server - BOOYAH!
Scott Chacon <schacon@gmail.com>
parents: 37
diff changeset
543 return changes
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
544
38
f0daee676e10 successful push to an upstream git server - BOOYAH!
Scott Chacon <schacon@gmail.com>
parents: 37
diff changeset
545 objects = []
f0daee676e10 successful push to an upstream git server - BOOYAH!
Scott Chacon <schacon@gmail.com>
parents: 37
diff changeset
546 for commit_sha in shas:
f0daee676e10 successful push to an upstream git server - BOOYAH!
Scott Chacon <schacon@gmail.com>
parents: 37
diff changeset
547 commit = self.git.commit(commit_sha)
f0daee676e10 successful push to an upstream git server - BOOYAH!
Scott Chacon <schacon@gmail.com>
parents: 37
diff changeset
548 objects.append((commit, 'commit'))
f0daee676e10 successful push to an upstream git server - BOOYAH!
Scott Chacon <schacon@gmail.com>
parents: 37
diff changeset
549 tree = self.git.get_object(commit.tree)
f0daee676e10 successful push to an upstream git server - BOOYAH!
Scott Chacon <schacon@gmail.com>
parents: 37
diff changeset
550 objects.extend( get_objects(tree, '/') )
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
551
38
f0daee676e10 successful push to an upstream git server - BOOYAH!
Scott Chacon <schacon@gmail.com>
parents: 37
diff changeset
552 return objects
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
553
12
227b11d75844 updates bookmarks and beginnings of seperate remotes support
Scott Chacon <schacon@gmail.com>
parents: 11
diff changeset
554 def fetch_pack(self, remote_name):
227b11d75844 updates bookmarks and beginnings of seperate remotes support
Scott Chacon <schacon@gmail.com>
parents: 11
diff changeset
555 git_url = self.remote_name_to_url(remote_name)
5
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
556 client, path = self.get_transport_and_path(git_url)
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
557 graphwalker = SimpleFetchGraphWalker(self.git.heads().values(), self.git.get_parents)
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
558 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
559 try:
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
560 determine_wants = self.git.object_store.determine_wants_all
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
561 refs = client.fetch_pack(path, determine_wants, graphwalker, f.write, sys.stdout.write)
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
562 f.close()
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
563 commit()
56
5185af4e649a hg gfetch now works
Scott Chacon <schacon@gmail.com>
parents: 54
diff changeset
564 if refs:
5185af4e649a hg gfetch now works
Scott Chacon <schacon@gmail.com>
parents: 54
diff changeset
565 self.git.set_remote_refs(refs, remote_name)
5185af4e649a hg gfetch now works
Scott Chacon <schacon@gmail.com>
parents: 54
diff changeset
566 else:
5185af4e649a hg gfetch now works
Scott Chacon <schacon@gmail.com>
parents: 54
diff changeset
567 self.ui.status(_("nothing new on the server\n"))
5185af4e649a hg gfetch now works
Scott Chacon <schacon@gmail.com>
parents: 54
diff changeset
568 return refs
181
8690377c3ce9 Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 179
diff changeset
569 finally:
5
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
570 f.close()
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
571
149
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
572 # take refs just fetched, add local tags for all tags not in .hgtags
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
573 def import_local_tags(self, refs):
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
574 keys = refs.keys()
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
575 if not keys:
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
576 return None
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
577 for k in keys[0:]:
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
578 ref_name = k
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
579 parts = k.split('/')
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
580 if (parts[0] == 'refs' and parts[1] == 'tags'):
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
581 ref_name = "/".join([v for v in parts[2:]])
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
582 if ref_name[-3:] == '^{}':
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
583 ref_name = ref_name[:-3]
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
584 if not ref_name in self.repo.tags():
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
585 obj = self.git.get_object(refs[k])
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
586 sha = None
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
587 if isinstance (obj, Commit): # lightweight
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
588 sha = self.map_hg_get(refs[k])
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
589 if isinstance (obj, Tag): # annotated
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
590 (obj_type, obj_sha) = obj.get_object()
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
591 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
592 if isinstance (obj, Commit):
149
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
593 sha = self.map_hg_get(obj_sha)
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
594 if sha:
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
595 self.repo.tag(ref_name, hex_to_sha(sha), '', True, None, None)
181
8690377c3ce9 Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 179
diff changeset
596
150
4b63e8425565 merged in tag support branch
Scott Chacon <schacon@gmail.com>
parents: 149 143
diff changeset
597 def import_git_objects(self, remote_name=None, refs=None):
5
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
598 self.ui.status(_("importing Git objects into Hg\n"))
149
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
599 # import heads and fetched tags as remote references
5
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
600 todo = []
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
601 done = set()
9
7e776864b301 sorts the commits topologically before converting
Scott Chacon <schacon@gmail.com>
parents: 8
diff changeset
602 convert_list = {}
137
5aefcbf1e50c add a gimport command
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 136
diff changeset
603
6
c77197123d95 importing basic, mostly stubbed changesets
Scott Chacon <schacon@gmail.com>
parents: 5
diff changeset
604 # get a list of all the head shas
181
8690377c3ce9 Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 179
diff changeset
605 if refs:
150
4b63e8425565 merged in tag support branch
Scott Chacon <schacon@gmail.com>
parents: 149 143
diff changeset
606 for head, sha in refs.iteritems():
5
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
607 todo.append(sha)
137
5aefcbf1e50c add a gimport command
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 136
diff changeset
608 else:
150
4b63e8425565 merged in tag support branch
Scott Chacon <schacon@gmail.com>
parents: 149 143
diff changeset
609 if remote_name:
4b63e8425565 merged in tag support branch
Scott Chacon <schacon@gmail.com>
parents: 149 143
diff changeset
610 todo = self.git.remote_refs(remote_name).values()[:]
4b63e8425565 merged in tag support branch
Scott Chacon <schacon@gmail.com>
parents: 149 143
diff changeset
611 elif self.importbranch:
4b63e8425565 merged in tag support branch
Scott Chacon <schacon@gmail.com>
parents: 149 143
diff changeset
612 branches = self.importbranch.split(',')
4b63e8425565 merged in tag support branch
Scott Chacon <schacon@gmail.com>
parents: 149 143
diff changeset
613 todo = [self.git.ref(i.strip()) for i in branches]
4b63e8425565 merged in tag support branch
Scott Chacon <schacon@gmail.com>
parents: 149 143
diff changeset
614 else:
4b63e8425565 merged in tag support branch
Scott Chacon <schacon@gmail.com>
parents: 149 143
diff changeset
615 todo = self.git.heads().values()[:]
19
2be9c0bd88af Warn, but don't fail when bookmarks is not enabled.
Augie Fackler <durin42@gmail.com>
parents: 17
diff changeset
616
6
c77197123d95 importing basic, mostly stubbed changesets
Scott Chacon <schacon@gmail.com>
parents: 5
diff changeset
617 # traverse the heads getting a list of all the unique commits
5
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
618 while todo:
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
619 sha = todo.pop()
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
620 assert isinstance(sha, str)
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
621 if sha in done:
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
622 continue
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
623 done.add(sha)
149
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
624 obj = self.git.get_object(sha)
181
8690377c3ce9 Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 179
diff changeset
625 if isinstance (obj, Commit):
149
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
626 convert_list[sha] = obj
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
627 todo.extend([p for p in obj.parents if p not in done])
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
628 if isinstance(obj, Tag):
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
629 (obj_type, obj_sha) = obj.get_object()
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
630 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
631 if isinstance (obj, Commit):
149
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
632 convert_list[sha] = obj
eb1fcdb8fc9b added basic tag support
Scott Chacon <schacon@gmail.com>
parents: 148
diff changeset
633 todo.extend([p for p in obj.parents if p not in done])
19
2be9c0bd88af Warn, but don't fail when bookmarks is not enabled.
Augie Fackler <durin42@gmail.com>
parents: 17
diff changeset
634
2be9c0bd88af Warn, but don't fail when bookmarks is not enabled.
Augie Fackler <durin42@gmail.com>
parents: 17
diff changeset
635 # sort the commits
78
71b07e16004f fix, but im not sure its fixed yet
Scott Chacon <schacon@gmail.com>
parents: 77
diff changeset
636 commits = toposort.TopoSort(convert_list).items()
181
8690377c3ce9 Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 179
diff changeset
637
6
c77197123d95 importing basic, mostly stubbed changesets
Scott Chacon <schacon@gmail.com>
parents: 5
diff changeset
638 # import each of the commits, oldest first
135
421c992c058b import_git_objects: add progress indicator
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 133
diff changeset
639 total = len(commits)
421c992c058b import_git_objects: add progress indicator
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 133
diff changeset
640 magnitude = int(math.log(total, 10)) + 1 if total else 1
421c992c058b import_git_objects: add progress indicator
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 133
diff changeset
641 for i, csha in enumerate(commits):
421c992c058b import_git_objects: add progress indicator
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 133
diff changeset
642 if i%100 == 0:
421c992c058b import_git_objects: add progress indicator
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 133
diff changeset
643 self.ui.status(_("at: %*d/%d\n") % (magnitude, i, total))
113
d862b6a4fbd4 adding rename detection to already imported objects
Scott Chacon <schacon@gmail.com>
parents: 112
diff changeset
644 commit = convert_list[csha]
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
645 if not self.map_hg_get(csha): # it's already here
56
5185af4e649a hg gfetch now works
Scott Chacon <schacon@gmail.com>
parents: 54
diff changeset
646 self.import_git_commit(commit)
143
c2b9280708ec only update bookmarks if importing from a remote
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 142
diff changeset
647
47
3b62270c1fad writing some status output after a push, updating local bookmarks
Scott Chacon <schacon@gmail.com>
parents: 42
diff changeset
648 self.update_hg_bookmarks(remote_name)
3b62270c1fad writing some status output after a push, updating local bookmarks
Scott Chacon <schacon@gmail.com>
parents: 42
diff changeset
649
3b62270c1fad writing some status output after a push, updating local bookmarks
Scott Chacon <schacon@gmail.com>
parents: 42
diff changeset
650 def update_hg_bookmarks(self, remote_name):
29
2a5c0bf0fef5 Another way of fixing no-bookmark issue, along with updated test.
Augie Fackler <durin42@gmail.com>
parents: 28
diff changeset
651 try:
47
3b62270c1fad writing some status output after a push, updating local bookmarks
Scott Chacon <schacon@gmail.com>
parents: 42
diff changeset
652 bms = bookmarks.parse(self.repo)
159
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
653 if remote_name:
156
a507384308b2 Allow bookmarking a specific branch
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 155
diff changeset
654 heads = self.git.remote_refs(remote_name)
159
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
655 else:
156
a507384308b2 Allow bookmarking a specific branch
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 155
diff changeset
656 branches = self.bookbranch.split(',')
a507384308b2 Allow bookmarking a specific branch
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 155
diff changeset
657 heads = dict((i, self.git.ref(i.strip())) for i in branches)
a507384308b2 Allow bookmarking a specific branch
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 155
diff changeset
658
a507384308b2 Allow bookmarking a specific branch
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 155
diff changeset
659 base_name = (remote_name + '/') if remote_name else ''
a507384308b2 Allow bookmarking a specific branch
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 155
diff changeset
660
a507384308b2 Allow bookmarking a specific branch
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 155
diff changeset
661 for head, sha in heads.iteritems():
a507384308b2 Allow bookmarking a specific branch
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 155
diff changeset
662 if not sha:
a507384308b2 Allow bookmarking a specific branch
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 155
diff changeset
663 self.ui.warn(_("Could not resolve head %s.\n") % head)
a507384308b2 Allow bookmarking a specific branch
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 155
diff changeset
664 continue
47
3b62270c1fad writing some status output after a push, updating local bookmarks
Scott Chacon <schacon@gmail.com>
parents: 42
diff changeset
665 hgsha = hex_to_sha(self.map_hg_get(sha))
3b62270c1fad writing some status output after a push, updating local bookmarks
Scott Chacon <schacon@gmail.com>
parents: 42
diff changeset
666 if not head == 'HEAD':
156
a507384308b2 Allow bookmarking a specific branch
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 155
diff changeset
667 bms[base_name + head] = hgsha
a507384308b2 Allow bookmarking a specific branch
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 155
diff changeset
668 if heads:
a507384308b2 Allow bookmarking a specific branch
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 155
diff changeset
669 bookmarks.write(self.repo, bms)
161
134915637cf7 Merge branch 'octo' with octo merge code
Scott Chacon <schacon@gmail.com>
parents: 157 160
diff changeset
670
29
2a5c0bf0fef5 Another way of fixing no-bookmark issue, along with updated test.
Augie Fackler <durin42@gmail.com>
parents: 28
diff changeset
671 except AttributeError:
95
7de67fcb18b0 be better about internationalizing strings
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 94
diff changeset
672 self.ui.warn(_('creating bookmarks failed, do you have'
7de67fcb18b0 be better about internationalizing strings
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 94
diff changeset
673 ' 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
674
53
5deb5cbd86aa respecting file modes on git import
Scott Chacon <schacon@gmail.com>
parents: 52
diff changeset
675 def convert_git_int_mode(self, mode):
96
0cec7b1e07ff add a few more TODO's
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 95
diff changeset
676 # TODO : make these into constants
53
5deb5cbd86aa respecting file modes on git import
Scott Chacon <schacon@gmail.com>
parents: 52
diff changeset
677 convert = {
121
0c94e860a0ed use octal numbers for modes.
Dmitriy Taychenachev <dimichxp@gmail.com>
parents: 120
diff changeset
678 0100644: '',
0c94e860a0ed use octal numbers for modes.
Dmitriy Taychenachev <dimichxp@gmail.com>
parents: 120
diff changeset
679 0100755: 'x',
0c94e860a0ed use octal numbers for modes.
Dmitriy Taychenachev <dimichxp@gmail.com>
parents: 120
diff changeset
680 0120000: 'l'}
53
5deb5cbd86aa respecting file modes on git import
Scott Chacon <schacon@gmail.com>
parents: 52
diff changeset
681 if mode in convert:
5deb5cbd86aa respecting file modes on git import
Scott Chacon <schacon@gmail.com>
parents: 52
diff changeset
682 return convert[mode]
5deb5cbd86aa respecting file modes on git import
Scott Chacon <schacon@gmail.com>
parents: 52
diff changeset
683 return ''
65
5ed8316d3cfa Start using reasonable ui.{status,debug,warn} calls instead of print.
Augie Fackler <durin42@gmail.com>
parents: 56
diff changeset
684
71
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
685 def extract_hg_metadata(self, message):
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
686 split = message.split("\n\n--HG--\n", 1)
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
687 renames = {}
164
7e98757deadc author and extra data fixes
Scott Chacon <schacon@gmail.com>
parents: 162
diff changeset
688 extra = {}
166
405a915bf352 remove rename detection, add explicit changelog recording on merges
Scott Chacon <schacon@gmail.com>
parents: 165
diff changeset
689 files = []
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
690 branch = False
71
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
691 if len(split) == 2:
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
692 message, meta = split
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
693 lines = meta.split("\n")
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
694 for line in lines:
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
695 if line == '':
181
8690377c3ce9 Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 179
diff changeset
696 continue
8690377c3ce9 Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 179
diff changeset
697
71
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
698 command, data = line.split(" : ", 1)
181
8690377c3ce9 Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 179
diff changeset
699
71
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
700 if command == 'rename':
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
701 before, after = data.split(" => ", 1)
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
702 renames[after] = before
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
703 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
704 branch = data
166
405a915bf352 remove rename detection, add explicit changelog recording on merges
Scott Chacon <schacon@gmail.com>
parents: 165
diff changeset
705 if command == 'files':
405a915bf352 remove rename detection, add explicit changelog recording on merges
Scott Chacon <schacon@gmail.com>
parents: 165
diff changeset
706 files.append(data)
168
8bfa8aa6b68f added empty changelog handling
Scott Chacon <schacon@gmail.com>
parents: 166
diff changeset
707 if command == 'emptychangelog':
8bfa8aa6b68f added empty changelog handling
Scott Chacon <schacon@gmail.com>
parents: 166
diff changeset
708 files = False
164
7e98757deadc author and extra data fixes
Scott Chacon <schacon@gmail.com>
parents: 162
diff changeset
709 if command == 'extra':
7e98757deadc author and extra data fixes
Scott Chacon <schacon@gmail.com>
parents: 162
diff changeset
710 before, after = data.split(" : ", 1)
7e98757deadc author and extra data fixes
Scott Chacon <schacon@gmail.com>
parents: 162
diff changeset
711 extra[before] = urllib.unquote(after)
166
405a915bf352 remove rename detection, add explicit changelog recording on merges
Scott Chacon <schacon@gmail.com>
parents: 165
diff changeset
712 return (message, renames, branch, files, extra)
181
8690377c3ce9 Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 179
diff changeset
713
5
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
714 def import_git_commit(self, commit):
95
7de67fcb18b0 be better about internationalizing strings
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 94
diff changeset
715 self.ui.debug(_("importing: %s\n") % commit.id)
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
716 # TODO : Do something less coarse-grained than try/except on the
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
717 # get_file call for removed files
164
7e98757deadc author and extra data fixes
Scott Chacon <schacon@gmail.com>
parents: 162
diff changeset
718
166
405a915bf352 remove rename detection, add explicit changelog recording on merges
Scott Chacon <schacon@gmail.com>
parents: 165
diff changeset
719 (strip_message, hg_renames, hg_branch, force_files, extra) = self.extract_hg_metadata(commit.message)
181
8690377c3ce9 Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 179
diff changeset
720
159
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
721 # get a list of the changed, added, removed files
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
722 files = self.git.get_files_changed(commit)
181
8690377c3ce9 Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 179
diff changeset
723
159
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
724 date = (commit.author_time, -commit.author_timezone)
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
725 text = strip_message
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
726
6
c77197123d95 importing basic, mostly stubbed changesets
Scott Chacon <schacon@gmail.com>
parents: 5
diff changeset
727 def getfilectx(repo, memctx, f):
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
728 try:
53
5deb5cbd86aa respecting file modes on git import
Scott Chacon <schacon@gmail.com>
parents: 52
diff changeset
729 (mode, sha, data) = self.git.get_file(commit, f)
5deb5cbd86aa respecting file modes on git import
Scott Chacon <schacon@gmail.com>
parents: 52
diff changeset
730 e = self.convert_git_int_mode(mode)
92
6305f274fc63 fixed subtree issue and zero padding issue
Scott Chacon <schacon@gmail.com>
parents: 90
diff changeset
731 except TypeError:
50
d274092e3b24 Hacky implementation of file removals.
Augie Fackler <durin42@gmail.com>
parents: 42
diff changeset
732 raise IOError()
71
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
733 if f in hg_renames:
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
734 copied_path = hg_renames[f]
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
735 else:
19053d11d520 explicit renames converting both ways now
Scott Chacon <schacon@gmail.com>
parents: 70
diff changeset
736 copied_path = None
67
759ac56497e7 adding hg explicit file renames to the git commit message
Scott Chacon <schacon@gmail.com>
parents: 65
diff changeset
737 return context.memfilectx(f, data, 'l' in e, 'x' in e, copied_path)
19
2be9c0bd88af Warn, but don't fail when bookmarks is not enabled.
Augie Fackler <durin42@gmail.com>
parents: 17
diff changeset
738
159
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
739 gparents = map(self.map_hg_get, commit.parents)
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
740 p1, p2 = (nullid, nullid)
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
741 octopus = False
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
742
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
743 if len(gparents) > 1:
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
744 # merge, possibly octopus
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
745 def commit_octopus(p1, p2):
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
746 ctx = context.memctx(self.repo, (p1, p2), text, files, getfilectx,
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
747 commit.author, date, {'hg-git': 'octopus'})
168
8bfa8aa6b68f added empty changelog handling
Scott Chacon <schacon@gmail.com>
parents: 166
diff changeset
748 return hex(self.repo.commitctx(ctx))
6
c77197123d95 importing basic, mostly stubbed changesets
Scott Chacon <schacon@gmail.com>
parents: 5
diff changeset
749
159
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
750 octopus = len(gparents) > 2
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
751 p2 = gparents.pop()
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
752 p1 = gparents.pop()
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
753 while len(gparents) > 0:
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
754 p2 = commit_octopus(p1, p2)
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
755 p1 = gparents.pop()
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
756 else:
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
757 if gparents:
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
758 p1 = gparents.pop()
181
8690377c3ce9 Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 179
diff changeset
759
165
cb922a0ca22d almost got everything working
Scott Chacon <schacon@gmail.com>
parents: 164
diff changeset
760 files = list(set(files))
6
c77197123d95 importing basic, mostly stubbed changesets
Scott Chacon <schacon@gmail.com>
parents: 5
diff changeset
761
165
cb922a0ca22d almost got everything working
Scott Chacon <schacon@gmail.com>
parents: 164
diff changeset
762 pa = None
162
cb38ac7f9373 moved file rename code back to proper indent
Scott Chacon <schacon@gmail.com>
parents: 161
diff changeset
763 if not (p2 == nullid):
165
cb922a0ca22d almost got everything working
Scott Chacon <schacon@gmail.com>
parents: 164
diff changeset
764 node1 = self.repo.changectx(p1)
cb922a0ca22d almost got everything working
Scott Chacon <schacon@gmail.com>
parents: 164
diff changeset
765 node2 = self.repo.changectx(p2)
cb922a0ca22d almost got everything working
Scott Chacon <schacon@gmail.com>
parents: 164
diff changeset
766 pa = node1.ancestor(node2)
cb922a0ca22d almost got everything working
Scott Chacon <schacon@gmail.com>
parents: 164
diff changeset
767
164
7e98757deadc author and extra data fixes
Scott Chacon <schacon@gmail.com>
parents: 162
diff changeset
768 author = commit.author
162
cb38ac7f9373 moved file rename code back to proper indent
Scott Chacon <schacon@gmail.com>
parents: 161
diff changeset
769
169
d67d00738298 fix message stripping and malformed user info
Scott Chacon <schacon@gmail.com>
parents: 168
diff changeset
770 # convert extra data back to the end
d67d00738298 fix message stripping and malformed user info
Scott Chacon <schacon@gmail.com>
parents: 168
diff changeset
771 if ' ext:' in commit.author:
d67d00738298 fix message stripping and malformed user info
Scott Chacon <schacon@gmail.com>
parents: 168
diff changeset
772 regex = re.compile('^(.*?)\ ext:\((.*)\) <(.*)\>$')
d67d00738298 fix message stripping and malformed user info
Scott Chacon <schacon@gmail.com>
parents: 168
diff changeset
773 m = regex.match(commit.author)
d67d00738298 fix message stripping and malformed user info
Scott Chacon <schacon@gmail.com>
parents: 168
diff changeset
774 if m:
d67d00738298 fix message stripping and malformed user info
Scott Chacon <schacon@gmail.com>
parents: 168
diff changeset
775 name = m.group(1)
d67d00738298 fix message stripping and malformed user info
Scott Chacon <schacon@gmail.com>
parents: 168
diff changeset
776 ex = urllib.unquote(m.group(2))
d67d00738298 fix message stripping and malformed user info
Scott Chacon <schacon@gmail.com>
parents: 168
diff changeset
777 email = m.group(3)
d67d00738298 fix message stripping and malformed user info
Scott Chacon <schacon@gmail.com>
parents: 168
diff changeset
778 author = name + ' <' + email + '>' + ex
181
8690377c3ce9 Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 179
diff changeset
779
164
7e98757deadc author and extra data fixes
Scott Chacon <schacon@gmail.com>
parents: 162
diff changeset
780 if ' <none@none>' in commit.author:
7e98757deadc author and extra data fixes
Scott Chacon <schacon@gmail.com>
parents: 162
diff changeset
781 author = commit.author[:-12]
89
e35ed99fa691 committer info now being kept properly
Scott Chacon <schacon@gmail.com>
parents: 88
diff changeset
782
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
783 # if named branch, add to extra
7b4cf18c896b readded yet another piece of code that disappeared at some point, recovering branches properly
Scott Chacon <schacon@gmail.com>
parents: 78
diff changeset
784 if hg_branch:
7b4cf18c896b readded yet another piece of code that disappeared at some point, recovering branches properly
Scott Chacon <schacon@gmail.com>
parents: 78
diff changeset
785 extra['branch'] = hg_branch
89
e35ed99fa691 committer info now being kept properly
Scott Chacon <schacon@gmail.com>
parents: 88
diff changeset
786
e35ed99fa691 committer info now being kept properly
Scott Chacon <schacon@gmail.com>
parents: 88
diff changeset
787 # if committer is different than author, add it to extra
e35ed99fa691 committer info now being kept properly
Scott Chacon <schacon@gmail.com>
parents: 88
diff changeset
788 if not commit._author_raw == commit._committer_raw:
131
dd6c77ec206c store commitdate in mercurial's internal format.
Dmitriy Taychenachev <dimichxp@gmail.com>
parents: 129
diff changeset
789 extra['committer'] = "%s %d %d" % (commit.committer, commit.commit_time, -commit.commit_timezone)
89
e35ed99fa691 committer info now being kept properly
Scott Chacon <schacon@gmail.com>
parents: 88
diff changeset
790
118
b3be536e3f50 handles git commit encoding fields now
Scott Chacon <schacon@gmail.com>
parents: 113
diff changeset
791 if commit._encoding:
b3be536e3f50 handles git commit encoding fields now
Scott Chacon <schacon@gmail.com>
parents: 113
diff changeset
792 extra['encoding'] = commit._encoding
b3be536e3f50 handles git commit encoding fields now
Scott Chacon <schacon@gmail.com>
parents: 113
diff changeset
793
89
e35ed99fa691 committer info now being kept properly
Scott Chacon <schacon@gmail.com>
parents: 88
diff changeset
794 if hg_branch:
e35ed99fa691 committer info now being kept properly
Scott Chacon <schacon@gmail.com>
parents: 88
diff changeset
795 extra['branch'] = hg_branch
118
b3be536e3f50 handles git commit encoding fields now
Scott Chacon <schacon@gmail.com>
parents: 113
diff changeset
796
159
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
797 if octopus:
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
798 extra['hg-git'] ='octopus-done'
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
799
6
c77197123d95 importing basic, mostly stubbed changesets
Scott Chacon <schacon@gmail.com>
parents: 5
diff changeset
800 ctx = context.memctx(self.repo, (p1, p2), text, files, getfilectx,
164
7e98757deadc author and extra data fixes
Scott Chacon <schacon@gmail.com>
parents: 162
diff changeset
801 author, date, extra)
181
8690377c3ce9 Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 179
diff changeset
802
168
8bfa8aa6b68f added empty changelog handling
Scott Chacon <schacon@gmail.com>
parents: 166
diff changeset
803 node = self.repo.commit_import_ctx(ctx, pa, force_files)
7
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
804
89992b6d2eef mapping parents properly now
Scott Chacon <schacon@gmail.com>
parents: 6
diff changeset
805 # save changeset to mapping file
159
85eae64ca9e2 applied octopatch from dimichxp
Scott Chacon <schacon@gmail.com>
parents: 138
diff changeset
806 cs = hex(node)
181
8690377c3ce9 Various cleanups (mostly whitespace and imports)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 179
diff changeset
807 self.map_set(commit.id, cs)
19
2be9c0bd88af Warn, but don't fail when bookmarks is not enabled.
Augie Fackler <durin42@gmail.com>
parents: 17
diff changeset
808
5
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
809 def check_bookmarks(self):
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
810 if self.ui.config('extensions', 'hgext.bookmarks') is not None:
65
5ed8316d3cfa Start using reasonable ui.{status,debug,warn} calls instead of print.
Augie Fackler <durin42@gmail.com>
parents: 56
diff changeset
811 self.ui.warn("YOU NEED TO SETUP BOOKMARKS\n")
5
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
812
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
813 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
814 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
815 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
816 if uri.startswith(handler):
26
a1a5391bc3c3 edit ssh command to quote the path, also convert tags properly on fetch
Scott Chacon <schacon@gmail.com>
parents: 25
diff changeset
817 if handler == 'git@':
28
b258ef16ae37 Fix non-ssh URI parsing.
Augie Fackler <durin42@gmail.com>
parents: 26
diff changeset
818 host, path = uri[len(handler):].split(":", 1)
26
a1a5391bc3c3 edit ssh command to quote the path, also convert tags properly on fetch
Scott Chacon <schacon@gmail.com>
parents: 25
diff changeset
819 host = 'git@' + host
28
b258ef16ae37 Fix non-ssh URI parsing.
Augie Fackler <durin42@gmail.com>
parents: 26
diff changeset
820 else:
35
562fc51b991e we did the same thing, not sure why it conflicted
Scott Chacon <schacon@gmail.com>
parents: 29
diff changeset
821 host, path = uri[len(handler):].split("/", 1)
26
a1a5391bc3c3 edit ssh command to quote the path, also convert tags properly on fetch
Scott Chacon <schacon@gmail.com>
parents: 25
diff changeset
822 return transport(host), '/' + path
5
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
823 # if its not git or git+ssh, try a local url..
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
824 return SubprocessGitClient(), uri
9
7e776864b301 sorts the commits topologically before converting
Scott Chacon <schacon@gmail.com>
parents: 8
diff changeset
825
40
f5b000ec7100 added gclear command to remove all the git data
Scott Chacon <schacon@gmail.com>
parents: 39
diff changeset
826 def clear(self):
105
41e76444105c make git-mapfile and git-configfile constants
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 104
diff changeset
827 mapfile = self.repo.join(self.mapfile)
106
3aa2f6caed16 make the gitdir a constant
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 105
diff changeset
828 if os.path.exists(self.gitdir):
3aa2f6caed16 make the gitdir a constant
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 105
diff changeset
829 for root, dirs, files in os.walk(self.gitdir, topdown=False):
40
f5b000ec7100 added gclear command to remove all the git data
Scott Chacon <schacon@gmail.com>
parents: 39
diff changeset
830 for name in files:
f5b000ec7100 added gclear command to remove all the git data
Scott Chacon <schacon@gmail.com>
parents: 39
diff changeset
831 os.remove(os.path.join(root, name))
f5b000ec7100 added gclear command to remove all the git data
Scott Chacon <schacon@gmail.com>
parents: 39
diff changeset
832 for name in dirs:
f5b000ec7100 added gclear command to remove all the git data
Scott Chacon <schacon@gmail.com>
parents: 39
diff changeset
833 os.rmdir(os.path.join(root, name))
106
3aa2f6caed16 make the gitdir a constant
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 105
diff changeset
834 os.rmdir(self.gitdir)
40
f5b000ec7100 added gclear command to remove all the git data
Scott Chacon <schacon@gmail.com>
parents: 39
diff changeset
835 if os.path.exists(mapfile):
f5b000ec7100 added gclear command to remove all the git data
Scott Chacon <schacon@gmail.com>
parents: 39
diff changeset
836 os.remove(mapfile)