Kiln » TortoiseHg » TortoiseHg
Clone URL:  
hginit.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# hginit.py - TortoiseHg dialog to initialize a repo # # Copyright 2008 Steve Borho <steve@borho.org> # # This software may be used and distributed according to the terms of the # GNU General Public License version 2, incorporated herein by reference. import os import gtk from mercurial import hg, ui, util, error from tortoisehg.util.i18n import _ from tortoisehg.util import hglib, shlib from tortoisehg.hgtk import dialog, gtklib class InitDialog(gtk.Dialog): """ Dialog to initialize a Mercurial repo """ def __init__(self, repos=[]): """ Initialize the Dialog """ gtk.Dialog.__init__(self, title=_('TortoiseHg Init')) gtklib.set_tortoise_icon(self, 'menucreaterepos.ico') gtklib.set_tortoise_keys(self) self.set_resizable(False) self.set_has_separator(False) self.connect('response', self.dialog_response) # add buttons self.add_button(_('Create'), gtk.RESPONSE_OK) self.add_button(gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE) self.cwd = os.getcwd() # preconditioning info path = os.path.abspath(repos and repos[0] or self.cwd) if not os.path.isdir(path): path = os.path.dirname(path) self.dest_path = path # layout table table = gtklib.LayoutTable() self.vbox.pack_start(table, True, True, 2) # init destination self.destentry = gtk.Entry() self.destentry.set_size_request(260, -1) self.destentry.size_request() self.destentry.set_text(hglib.toutf(self.dest_path)) self.destentry.grab_focus() self.destentry.set_position(-1) self.destentry.connect('activate', lambda b: self.response(gtk.RESPONSE_OK)) destbrowse = gtk.Button(_('Browse...')) destbrowse.connect('clicked', self.dest_clicked) table.add_row(_('Destination:'), self.destentry, 0, destbrowse) # options self.optspfiles = gtk.CheckButton( _('Add special files (.hgignore, ...)')) self.optoldrepo = gtk.CheckButton( _('Make repo compatible with Mercurial 1.0')) self.optrunci = gtk.CheckButton(_('Run Commit after init')) table.add_row(self.optspfiles, xpad=2) table.add_row(self.optoldrepo, xpad=2) table.add_row(self.optrunci, xpad=2) # set option states self.optspfiles.set_active(True) try: usefncache = ui.ui().configbool('format', 'usefncache', True) self.optoldrepo.set_active(not usefncache) except: pass self.optrunci.set_active(False) def dialog_response(self, dialog, response_id): # Create button if response_id == gtk.RESPONSE_OK: gtklib.idle_add_single_call(self.init) # Cancel button or dialog closing by the user elif response_id in (gtk.RESPONSE_CLOSE, gtk.RESPONSE_DELETE_EVENT): return # close dialog else: raise _('unexpected response id: %s') % response_id self.run() # don't close dialog def dest_clicked(self, button): """ select destination folder to init """ response = gtklib.NativeFolderSelectDialog( initial=self.cwd, title=_('Select Destination Folder')).run() if response: self.destentry.set_text(response) self.destentry.set_position(-1) def init(self): # gather input data dest = hglib.fromutf(self.destentry.get_text()) # verify input if dest == '': dialog.error_dialog(self, _('Destination path is empty'), _('Please enter the directory path')) self.destentry.grab_focus() return False # start u = ui.ui() # fncache is the new default repo format in Mercurial 1.1 if self.optoldrepo.get_active(): u.setconfig('format', 'usefncache', 'False') try: hg.repository(u, dest, create=1) except error.RepoError, inst: dialog.error_dialog(self, _('Unable to create new repository'), hglib.toutf(str(inst))) return False except util.Abort, inst: dialog.error_dialog(self, _('Error when creating repository'), hglib.toutf(str(inst))) return False except: import traceback dialog.error_dialog(self, _('Error when creating repository'), traceback.format_exc()) return False # create the .hg* file, mainly to workaround # Explorer's problem in creating files with name # begins with a dot. if self.optspfiles.get_active(): hgignore = os.path.join(dest, '.hgignore') if not os.path.exists(hgignore): try: open(hgignore, 'wb') except: pass shlib.shell_notify([dest]) if self.optrunci.get_active(): self.emit_stop_by_name('response') self.emit_stop_by_name('destroy') self.hide() os.chdir(dest) from tortoisehg.hgtk.commit import run as cirun win = cirun(ui.ui()) win.display() win.show_all() win.connect('destroy', gtk.main_quit) else: self.response(gtk.RESPONSE_CLOSE) def run(ui, *pats, **opts): return InitDialog(pats)