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
# 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 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=_('Create a new repository'), buttons=(gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE)) gtklib.set_tortoise_icon(self, 'menucreaterepos.ico') gtklib.set_tortoise_keys(self) self.set_resizable(False) self.set_has_separator(False) # add create button createbutton = gtk.Button(_('Create')) createbutton.connect('clicked', lambda b: self.init()) self.action_area.pack_end(createbutton) self.cwd = os.getcwd() # preconditioning info self.dest_path = os.path.abspath(repos and repos[0] or self.cwd) # copy from 'thgconfig.py' table = gtk.Table(1, 2) self.vbox.pack_start(table, True, True, 2) def addrow(*widgets): row = table.get_property('n-rows') table.set_property('n-rows', row + 1) if len(widgets) == 1: col = table.get_property('n-columns') table.attach(widgets[0], 0, col, row, row + 1, gtk.FILL|gtk.EXPAND, 0, 2, 2) else: for col, widget in enumerate(widgets): flag = gtk.FILL if col == 0 else gtk.FILL|gtk.EXPAND table.attach(widget, col, col + 1, row, row + 1, flag, 0, 4, 2) # init destination lbl = gtk.Label(_('Destination:')) destbox = gtk.HBox() 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.init()) destbox.pack_start(self.destentry, True, True, 2) destbrowse = gtk.Button(_('Browse...')) destbrowse.connect('clicked', self.dest_clicked) destbox.pack_start(destbrowse, False, False, 2) addrow(lbl, destbox) # options self.optspfiles = gtk.CheckButton( _('Add special files (.hgignore, ...)')) self.optoldrepo = gtk.CheckButton( _('Make repo compatible with Mercurial 1.0')) addrow(self.optspfiles) addrow(self.optoldrepo) # set option states self.optspfiles.set_active(True) try: usefncache = ui.ui().configbool('format', 'usefncache', True) self.optoldrepo.set_active(not usefncache) except: pass def dest_clicked(self, button): """ select destination folder to clone """ 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 hglib.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]) dialog.info_dialog(self, _('New repository created'), _('in directory %s') % hglib.toutf(os.path.abspath(dest))) self.response(gtk.RESPONSE_OK) def run(ui, *pats, **opts): return InitDialog(pats)