Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 1.0, 1.0.1, and 1.0.2

thgimport, hgtk: add 'import' command

Changeset ed5fa2459c32

Parent 1ad2db3a600b

by Yuki KODAMA

Changes to 2 files · Browse files at ed5fa2459c32 Showing diff from parent 1ad2db3a600b Diff from another changeset...

 
441
442
443
 
 
 
 
 
444
445
446
 
719
720
721
 
 
 
 
722
723
724
 
441
442
443
444
445
446
447
448
449
450
451
 
724
725
726
727
728
729
730
731
732
733
@@ -441,6 +441,11 @@
  return   gtkrun(run, ui, *pats, **opts)   +def thgimport(ui, *pats, **opts): + """import patches to repository/patch queue""" + from tortoisehg.hgtk.thgimport import run + gtkrun(run, ui, *pats, **opts) +  ### help management, adapted from mercurial.commands.help_()  def help_(ui, name=None, with_version=False, alias=None):   """show help for a command, extension, or list of commands @@ -719,6 +724,10 @@
  ('hgtk archive')),   "^strip": (strip, [], ('hgtk strip [REV]')),   "^browse": (browse, [], ('hgtk browse [REV]')), + "^import": (thgimport, + [('', 'repo', False, _('import to the repository')), + ('', 'mq', False, _('import to the patch queue (MQ)'))], + _('hgtk import [OPTION] [SOURCE]...')),  }    if os.name == 'nt':
 
10
11
12
13
 
14
15
16
 
20
21
22
23
24
 
 
 
 
 
25
26
27
28
29
 
30
31
32
 
41
42
43
44
 
45
46
47
 
51
52
53
 
 
 
54
55
56
 
64
65
66
 
 
 
 
 
67
68
69
 
101
102
103
104
 
105
106
107
 
 
108
109
110
111
112
113
 
 
 
 
 
 
 
114
115
116
 
140
141
142
143
 
144
145
 
146
147
148
 
159
160
161
 
 
 
 
162
163
164
 
315
316
317
318
 
319
320
321
 
353
354
355
356
 
 
357
 
 
358
359
 
360
361
362
 
376
377
378
 
 
 
 
 
 
 
 
 
10
11
12
 
13
14
15
16
 
20
21
22
 
 
23
24
25
26
27
28
29
30
31
 
32
33
34
35
 
44
45
46
 
47
48
49
50
 
54
55
56
57
58
59
60
61
62
 
70
71
72
73
74
75
76
77
78
79
80
 
112
113
114
 
115
116
 
 
117
118
119
120
121
122
 
 
123
124
125
126
127
128
129
130
131
132
 
156
157
158
 
159
160
 
161
162
163
164
 
175
176
177
178
179
180
181
182
183
184
 
335
336
337
 
338
339
340
341
 
373
374
375
 
376
377
378
379
380
381
 
382
383
384
385
 
399
400
401
402
403
404
405
406
407
408
409
@@ -10,7 +10,7 @@
 import gobject  import tempfile   -from mercurial import hg, ui +from mercurial import hg, ui, error    from tortoisehg.util.i18n import _  from tortoisehg.util import hglib, paths, settings @@ -20,13 +20,16 @@
 MODE_NORMAL = 'normal'  MODE_WORKING = 'working'   -DEST_ID = 0 -DEST_LABEL = 1 +COL_NAME = 0 +COL_LABEL = 1 + +DEST_REPO = 'repo' +DEST_MQ = 'mq'    class ImportDialog(gtk.Dialog):   """ Dialog to import patches """   - def __init__(self, repo=None): + def __init__(self, repo=None, dest=DEST_REPO, sources=None):   """ Initialize the Dialog """   gtk.Dialog.__init__(self)   gtklib.set_tortoise_icon(self, 'menuimport.ico') @@ -41,7 +44,7 @@
  if not repo:   try:   repo = hg.repository(ui.ui(), path=paths.find_root()) - except hglib.RepoError: + except error.RepoError:   gtklib.idle_add_single_call(self.destroy)   return   self.repo = repo @@ -51,6 +54,9 @@
  self.clipboard = gtk.Clipboard()   self.tempfiles = []   + if not self.mqloaded and dest == DEST_MQ: + dest = DEST_REPO +   # persistent settings   self.settings = settings.Settings('import')   self.recent = self.settings.mrul('src_paths') @@ -64,6 +70,11 @@
  self.src_combo = gtk.ComboBoxEntry(self.src_list, 0)   self.files_btn = gtk.Button(_('Browse...'))   + ## set given sources (but preview later) + if sources: + src = os.pathsep.join(sources) + self.src_combo.child.set_text(src) +   ## other sources   menubtn = gtk.ToggleButton()   menubtn.set_focus_on_click(False) @@ -101,16 +112,21 @@
  table.add_row(_('Preview:'), self.infobox, padding=False)     ## dest combo - self.dest_model = gtk.ListStore(gobject.TYPE_STRING, # dest id + self.dest_model = gtk.ListStore(gobject.TYPE_STRING, # dest name   gobject.TYPE_STRING) # dest label - for row in {'repo': _('Repository'), - 'mq': _('Patch Queue')}.items(): + for row in {DEST_REPO: _('Repository'), + DEST_MQ: _('Patch Queue')}.items():   self.dest_model.append(row)   self.dest_combo = gtk.ComboBox(self.dest_model)   cell = gtk.CellRendererText()   self.dest_combo.pack_start(cell, True) - self.dest_combo.add_attribute(cell, 'text', DEST_LABEL) - self.dest_combo.set_active(0) + self.dest_combo.add_attribute(cell, 'text', COL_LABEL) + + for row in self.dest_model: + name, label = self.dest_model[row.path] + if name == dest: + self.dest_combo.set_active_iter(row.iter) + break     ## patch preview   self.cslist = cslist.ChangesetList() @@ -140,9 +156,9 @@
    # prepare to show   self.cslist.clear() - gtklib.idle_add_single_call(self.after_init) + gtklib.idle_add_single_call(self.after_init, sources)   - def after_init(self): + def after_init(self, sources):   if self.mqloaded:   # dest combo   self.dest_combo.show_all() @@ -159,6 +175,10 @@
  self.abortbtn = self.add_button(_('Abort'), gtk.RESPONSE_CANCEL)   self.abortbtn.hide()   + # start preview + if sources: + self.preview() +   def files_clicked(self, button):   initdir = self.get_initial_dir()   result = gtklib.NativeSaveFileDialogWrapper(title=_('Select Patches'), @@ -315,7 +335,7 @@
    def get_dest(self):   iter = self.dest_combo.get_active_iter() - return self.dest_model.get(iter, DEST_ID)[0] + return self.dest_model.get(iter, COL_NAME)[0]     def preview(self, queue=False):   files = self.get_filepaths() @@ -353,10 +373,13 @@
  if not files:   return   - if 'repo' == self.get_dest(): + dest = self.get_dest() + if DEST_REPO == dest:   cmd = 'import' + elif DEST_MQ == dest: + cmd = 'qimport'   else: - cmd = 'qimport' + raise _('unexpected destination name: %s') % dest   cmdline = ['hg', cmd, '--verbose']   cmdline.extend(files)   @@ -376,3 +399,11 @@
  self.cmd.set_result(_('Failed to import'), style='error')   self.switch_to(MODE_WORKING)   self.cmd.execute(cmdline, cmd_done) + +def run(ui, *pats, **opts): + dest = opts.get('mq', False) and DEST_MQ or DEST_REPO + sources = [] + for item in pats: + if os.path.exists(item): + sources.append(os.path.abspath(item)) + return ImportDialog(dest=dest, sources=sources)