annotate __init__.py @ 136:74385b613bb7

rename export to export_commits for future consitency We cannot name the reverse 'import' since that is a reserved keyword in python, so add the '_commits' suffix.
author Sverre Rabbelier <sverre@rabbelier.nl>
date Fri, 15 May 2009 00:43:38 +0200
parents 324a1ad9212a
children 5aefcbf1e50c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
06366111af3c initial import of the hg-git bridging extension for mercurial
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
1 # git.py - git server bridge
06366111af3c initial import of the hg-git bridging extension for mercurial
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
2 #
06366111af3c initial import of the hg-git bridging extension for mercurial
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
3 # Copyright 2008 Scott Chacon <schacon at gmail dot com>
06366111af3c initial import of the hg-git bridging extension for mercurial
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
4 # also some code (and help) borrowed from durin42
06366111af3c initial import of the hg-git bridging extension for mercurial
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
5 #
06366111af3c initial import of the hg-git bridging extension for mercurial
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
6 # This software may be used and distributed according to the terms
06366111af3c initial import of the hg-git bridging extension for mercurial
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
7 # of the GNU General Public License, incorporated herein by reference.
06366111af3c initial import of the hg-git bridging extension for mercurial
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
8
06366111af3c initial import of the hg-git bridging extension for mercurial
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
9 '''push and pull from a Git server
06366111af3c initial import of the hg-git bridging extension for mercurial
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
10
06366111af3c initial import of the hg-git bridging extension for mercurial
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
11 This extension lets you communicate (push and pull) with a Git server.
06366111af3c initial import of the hg-git bridging extension for mercurial
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
12 This way you can use Git hosting for your project or collaborate with a
06366111af3c initial import of the hg-git bridging extension for mercurial
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
13 project that is in Git. A bridger of worlds, this plugin be.
06366111af3c initial import of the hg-git bridging extension for mercurial
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
14
06366111af3c initial import of the hg-git bridging extension for mercurial
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
15 '''
06366111af3c initial import of the hg-git bridging extension for mercurial
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
16
98
209a434734ed don't import everything and the kitchen sink
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 97
diff changeset
17 from mercurial import commands
209a434734ed don't import everything and the kitchen sink
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 97
diff changeset
18 from mercurial import hg
0
06366111af3c initial import of the hg-git bridging extension for mercurial
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
19 from mercurial.i18n import _
5
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents: 4
diff changeset
20 from git_handler import GitHandler
0
06366111af3c initial import of the hg-git bridging extension for mercurial
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
21
60
05a96f7750ad add support for `hg clone git://github.com/defunkt/facebox.git`
Chris Wanstrath <chris@ozmm.org>
parents: 59
diff changeset
22 # support for `hg clone git://github.com/defunkt/facebox.git`
05a96f7750ad add support for `hg clone git://github.com/defunkt/facebox.git`
Chris Wanstrath <chris@ozmm.org>
parents: 59
diff changeset
23 import gitrepo
05a96f7750ad add support for `hg clone git://github.com/defunkt/facebox.git`
Chris Wanstrath <chris@ozmm.org>
parents: 59
diff changeset
24 hg.schemes['git'] = gitrepo
05a96f7750ad add support for `hg clone git://github.com/defunkt/facebox.git`
Chris Wanstrath <chris@ozmm.org>
parents: 59
diff changeset
25
0
06366111af3c initial import of the hg-git bridging extension for mercurial
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
26 def gclone(ui, git_url, hg_repo_path=None):
16
58cd05129119 moved init into git_handler
Scott Chacon <schacon@gmail.com>
parents: 14
diff changeset
27 # determine new repo name
0
06366111af3c initial import of the hg-git bridging extension for mercurial
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
28 if not hg_repo_path:
06366111af3c initial import of the hg-git bridging extension for mercurial
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
29 hg_repo_path = hg.defaultdest(git_url)
06366111af3c initial import of the hg-git bridging extension for mercurial
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
30 if hg_repo_path.endswith('.git'):
06366111af3c initial import of the hg-git bridging extension for mercurial
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
31 hg_repo_path = hg_repo_path[:-4]
06366111af3c initial import of the hg-git bridging extension for mercurial
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
32 hg_repo_path += '-hg'
2
c43c02cc803a added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents: 1
diff changeset
33 dest_repo = hg.repository(ui, hg_repo_path, create=True)
0
06366111af3c initial import of the hg-git bridging extension for mercurial
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
34
2
c43c02cc803a added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents: 1
diff changeset
35 # fetch the initial git data
5
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents: 4
diff changeset
36 git = GitHandler(dest_repo, ui)
12
227b11d75844 updates bookmarks and beginnings of seperate remotes support
Scott Chacon <schacon@gmail.com>
parents: 11
diff changeset
37 git.remote_add('origin', git_url)
227b11d75844 updates bookmarks and beginnings of seperate remotes support
Scott Chacon <schacon@gmail.com>
parents: 11
diff changeset
38 git.fetch('origin')
2
c43c02cc803a added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents: 1
diff changeset
39
c43c02cc803a added dulwich library and got the script to call it for clone
Scott Chacon <schacon@gmail.com>
parents: 1
diff changeset
40 # checkout the tip
13
01f28d40cb6a checks out the HEAD node from a clone
Scott Chacon <schacon@gmail.com>
parents: 12
diff changeset
41 node = git.remote_head('origin')
01f28d40cb6a checks out the HEAD node from a clone
Scott Chacon <schacon@gmail.com>
parents: 12
diff changeset
42 hg.update(dest_repo, node)
0
06366111af3c initial import of the hg-git bridging extension for mercurial
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
43
39
173e738d0da4 remote management tools
Scott Chacon <schacon@gmail.com>
parents: 17
diff changeset
44 def gpush(ui, repo, remote_name='origin', branch=None):
17
ace0f6ed65a1 setting up for upload-pack functionality
Scott Chacon <schacon@gmail.com>
parents: 16
diff changeset
45 git = GitHandler(repo, ui)
ace0f6ed65a1 setting up for upload-pack functionality
Scott Chacon <schacon@gmail.com>
parents: 16
diff changeset
46 git.push(remote_name)
39
173e738d0da4 remote management tools
Scott Chacon <schacon@gmail.com>
parents: 17
diff changeset
47
97
f0628f5270b6 add gexport command
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 63
diff changeset
48 def gexport(ui, repo):
f0628f5270b6 add gexport command
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 63
diff changeset
49 git = GitHandler(repo, ui)
136
74385b613bb7 rename export to export_commits for future consitency
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 134
diff changeset
50 git.export_commits()
97
f0628f5270b6 add gexport command
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 63
diff changeset
51
39
173e738d0da4 remote management tools
Scott Chacon <schacon@gmail.com>
parents: 17
diff changeset
52 def gremote(ui, repo, *args):
173e738d0da4 remote management tools
Scott Chacon <schacon@gmail.com>
parents: 17
diff changeset
53 git = GitHandler(repo, ui)
173e738d0da4 remote management tools
Scott Chacon <schacon@gmail.com>
parents: 17
diff changeset
54
173e738d0da4 remote management tools
Scott Chacon <schacon@gmail.com>
parents: 17
diff changeset
55 if len(args) == 0:
173e738d0da4 remote management tools
Scott Chacon <schacon@gmail.com>
parents: 17
diff changeset
56 git.remote_list()
134
324a1ad9212a gremote: do not die on wrong number of args
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 98
diff changeset
57 elif len(args) < 2:
324a1ad9212a gremote: do not die on wrong number of args
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 98
diff changeset
58 repo.ui.warn(_("must supply an action and a remote\n"))
39
173e738d0da4 remote management tools
Scott Chacon <schacon@gmail.com>
parents: 17
diff changeset
59 else:
173e738d0da4 remote management tools
Scott Chacon <schacon@gmail.com>
parents: 17
diff changeset
60 verb = args[0]
173e738d0da4 remote management tools
Scott Chacon <schacon@gmail.com>
parents: 17
diff changeset
61 nick = args[1]
173e738d0da4 remote management tools
Scott Chacon <schacon@gmail.com>
parents: 17
diff changeset
62
173e738d0da4 remote management tools
Scott Chacon <schacon@gmail.com>
parents: 17
diff changeset
63 if verb == 'add':
134
324a1ad9212a gremote: do not die on wrong number of args
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 98
diff changeset
64 if len(args) == 3:
39
173e738d0da4 remote management tools
Scott Chacon <schacon@gmail.com>
parents: 17
diff changeset
65 git.remote_add(nick, args[2])
173e738d0da4 remote management tools
Scott Chacon <schacon@gmail.com>
parents: 17
diff changeset
66 else:
173e738d0da4 remote management tools
Scott Chacon <schacon@gmail.com>
parents: 17
diff changeset
67 repo.ui.warn(_("must supply a url to add as a remote\n"))
173e738d0da4 remote management tools
Scott Chacon <schacon@gmail.com>
parents: 17
diff changeset
68 elif verb == 'rm':
173e738d0da4 remote management tools
Scott Chacon <schacon@gmail.com>
parents: 17
diff changeset
69 git.remote_remove(nick)
173e738d0da4 remote management tools
Scott Chacon <schacon@gmail.com>
parents: 17
diff changeset
70 elif verb == 'show':
173e738d0da4 remote management tools
Scott Chacon <schacon@gmail.com>
parents: 17
diff changeset
71 git.remote_show(nick)
173e738d0da4 remote management tools
Scott Chacon <schacon@gmail.com>
parents: 17
diff changeset
72 else:
173e738d0da4 remote management tools
Scott Chacon <schacon@gmail.com>
parents: 17
diff changeset
73 repo.ui.warn(_("unrecognized command to gremote\n"))
40
f5b000ec7100 added gclear command to remove all the git data
Scott Chacon <schacon@gmail.com>
parents: 39
diff changeset
74
f5b000ec7100 added gclear command to remove all the git data
Scott Chacon <schacon@gmail.com>
parents: 39
diff changeset
75 def gclear(ui, repo):
f5b000ec7100 added gclear command to remove all the git data
Scott Chacon <schacon@gmail.com>
parents: 39
diff changeset
76 repo.ui.status(_("clearing out the git cache data\n"))
f5b000ec7100 added gclear command to remove all the git data
Scott Chacon <schacon@gmail.com>
parents: 39
diff changeset
77 git = GitHandler(repo, ui)
f5b000ec7100 added gclear command to remove all the git data
Scott Chacon <schacon@gmail.com>
parents: 39
diff changeset
78 git.clear()
59
19d714ee9941 gfetch should access repo when printing, not dest_repo
Chris Wanstrath <chris@ozmm.org>
parents: 40
diff changeset
79
56
5185af4e649a hg gfetch now works
Scott Chacon <schacon@gmail.com>
parents: 40
diff changeset
80 def gfetch(ui, repo, remote_name='origin'):
59
19d714ee9941 gfetch should access repo when printing, not dest_repo
Chris Wanstrath <chris@ozmm.org>
parents: 40
diff changeset
81 repo.ui.status(_("pulling from git url\n"))
56
5185af4e649a hg gfetch now works
Scott Chacon <schacon@gmail.com>
parents: 40
diff changeset
82 git = GitHandler(repo, ui)
5185af4e649a hg gfetch now works
Scott Chacon <schacon@gmail.com>
parents: 40
diff changeset
83 git.fetch(remote_name)
59
19d714ee9941 gfetch should access repo when printing, not dest_repo
Chris Wanstrath <chris@ozmm.org>
parents: 40
diff changeset
84
0
06366111af3c initial import of the hg-git bridging extension for mercurial
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
85 commands.norepo += " gclone"
06366111af3c initial import of the hg-git bridging extension for mercurial
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
86 cmdtable = {
06366111af3c initial import of the hg-git bridging extension for mercurial
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
87 "gclone":
39
173e738d0da4 remote management tools
Scott Chacon <schacon@gmail.com>
parents: 17
diff changeset
88 (gclone, [],
173e738d0da4 remote management tools
Scott Chacon <schacon@gmail.com>
parents: 17
diff changeset
89 _('Clone a git repository into an hg repository.'),
0
06366111af3c initial import of the hg-git bridging extension for mercurial
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
90 ),
06366111af3c initial import of the hg-git bridging extension for mercurial
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
91 "gpush":
17
ace0f6ed65a1 setting up for upload-pack functionality
Scott Chacon <schacon@gmail.com>
parents: 16
diff changeset
92 (gpush, [], _('hg gpush remote')),
97
f0628f5270b6 add gexport command
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 63
diff changeset
93 "gexport":
f0628f5270b6 add gexport command
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 63
diff changeset
94 (gexport, [], _('hg gexport')),
39
173e738d0da4 remote management tools
Scott Chacon <schacon@gmail.com>
parents: 17
diff changeset
95 "gfetch":
173e738d0da4 remote management tools
Scott Chacon <schacon@gmail.com>
parents: 17
diff changeset
96 (gfetch, [],
173e738d0da4 remote management tools
Scott Chacon <schacon@gmail.com>
parents: 17
diff changeset
97 #[('m', 'merge', None, _('merge automatically'))],
173e738d0da4 remote management tools
Scott Chacon <schacon@gmail.com>
parents: 17
diff changeset
98 _('hg gfetch remote')),
173e738d0da4 remote management tools
Scott Chacon <schacon@gmail.com>
parents: 17
diff changeset
99 "gremote":
173e738d0da4 remote management tools
Scott Chacon <schacon@gmail.com>
parents: 17
diff changeset
100 (gremote, [], _('hg gremote add remote (url)')),
40
f5b000ec7100 added gclear command to remove all the git data
Scott Chacon <schacon@gmail.com>
parents: 39
diff changeset
101 "gclear":
f5b000ec7100 added gclear command to remove all the git data
Scott Chacon <schacon@gmail.com>
parents: 39
diff changeset
102 (gclear, [], _('Clears out the Git cached data')),
5
d6c443a91b18 refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents: 4
diff changeset
103 }