Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 1.9, 1.9.1, and 1.9.2

sync: saving URLs now works

Our sync dialog only supports saving alias/url pairs to the repo
config file. I've decided simpler is better here.

Changeset cfb74e87f48a

Parent 630ef3ed1f08

by Steve Borho

Changes to one file · Browse files at cfb74e87f48a Showing diff from parent 630ef3ed1f08 Diff from another changeset...

 
13
14
15
16
 
17
18
19
20
21
 
 
 
 
 
 
 
 
 
22
23
24
 
114
115
116
117
 
118
119
120
 
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
162
163
164
165
166
167
168
169
 
263
264
265
 
266
267
268
 
288
289
290
 
291
292
293
 
316
317
318
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
319
320
321
 
361
362
363
 
 
 
 
 
 
364
365
366
 
 
 
 
 
367
368
369
 
456
457
458
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
459
460
461
 
13
14
15
 
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
 
123
124
125
 
126
127
128
129
 
132
133
134
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135
136
137
 
231
232
233
234
235
236
237
 
257
258
259
260
261
262
263
 
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
 
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
 
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
@@ -13,12 +13,21 @@
 from PyQt4.QtCore import *  from PyQt4.QtGui import *   -from mercurial import url, config +from mercurial import config, url, util    from tortoisehg.util import hglib  from tortoisehg.hgqt.i18n import _  from tortoisehg.hgqt import qtlib   +try: + import iniparse + # Monkypatch this regex to prevent iniparse from considering + # 'rem' as a comment + iniparse.ini.CommentLine.regex = \ + re.compile(r'^(?P<csep>[%;#])(?P<comment>.*)$') +except ImportError: + iniparse = None +  _schemes = ['local', 'ssh', 'http', 'https']    class SyncWidget(QWidget): @@ -114,7 +123,7 @@
    def refresh(self):   fn = os.path.join(self.root, '.hg', 'hgrc') - cfg = self.loadIniFile([fn]) + fn, cfg = loadIniFile([fn], self)   self.paths = {}   if 'paths' not in cfg:   return @@ -123,47 +132,6 @@
  tm = PathsModel(self.paths, self)   self.tv.setModel(tm)   - def loadIniFile(self, rcpath): - for fn in rcpath: - if os.path.exists(fn): - break - else: - for fn in rcpath: - # Try to create a file from rcpath - try: - f = open(fn, 'w') - f.write('# Generated by TortoiseHg setting dialog\n') - f.close() - break - except EnvironmentError: - pass - else: - qtlib.WarningMsgBox(_('Unable to create a config file'), - _('Insufficient access rights.'), parent=self) - fn = rcpath[0] - cfg = config.config() - return cfg - try: - import iniparse - # Monkypatch this regex to prevent iniparse from considering - # 'rem' as a comment - iniparse.ini.CommentLine.regex = \ - re.compile(r'^(?P<csep>[%;#])(?P<comment>.*)$') - return iniparse.INIConfig(file(fn), optionxformvalue=None) - except ImportError: - cfg = config.config() - cfg.read(fn) - return cfg - except Exception, e: - qtlib.WarningMsgBox(_('Unable to parse a config file'), - hglib.tounicode(e), parent=self) - cfg = config.config() - try: - cfg.read(fn) - except: - pass - return cfg -   def refreshUrl(self):   'User has changed schema/host/port/path'   if self.updateInProgress: @@ -263,6 +231,7 @@
  dialog = SaveDialog(self.root, alias, url, self)   if dialog.exec_() == QDialog.Accepted:   self.curalias = unicode(dialog.aliasentry.text()) + self.refresh()     def authclicked(self):   host = unicode(self.hostentry.text()) @@ -288,6 +257,7 @@
  url = self.currentUrl(False)   print 'hg push', url   +  class SaveDialog(QDialog):   def __init__(self, root, alias, url, parent):   super(SaveDialog, self).__init__(parent) @@ -316,6 +286,30 @@
  QTimer.singleShot(0, lambda:self.aliasentry.setFocus())     def accept(self): + if iniparse is None: + qtlib.WarningMsgBox(_('Unable to save an URL'), + _('Iniparse must be installed.'), parent=self) + return + fn = os.path.join(self.root, '.hg', 'hgrc') + fn, cfg = loadIniFile([fn], self) + if fn is None: + return + if 'paths' not in cfg: + cfg.new_namespace('paths') + alias = hglib.fromunicode(self.aliasentry.text()) + path = hglib.fromunicode(self.urlentry.text()) + if alias in cfg['paths']: + if not qtlib.QuestionMsgBox(_('Confirm URL replace'), + _('%s already exists, replace URL?') % alias): + return + cfg['paths'][alias] = path + try: + f = util.atomictempfile(fn, 'w', createmode=None) + f.write(str(cfg)) + f.rename() + except IOError, e: + qtlib.WarningMsgBox(_('Unable to write configuration file'), + hglib.tounicode(e), parent=self)   super(SaveDialog, self).accept()     def reject(self): @@ -361,9 +355,20 @@
  pass     def saveInRepo(self): + if iniparse is None: + qtlib.WarningMsgBox(_('Unable to save authentication'), + _('Iniparse must be installed.'), parent=self) + return + fn = os.path.join(self.root, '.hg', 'hgrc') + fn, cfg = loadIniFile([fn], self)   super(AuthDialog, self).accept()     def saveGlobal(self): + if iniparse is None: + qtlib.WarningMsgBox(_('Unable to save authentication'), + _('Iniparse must be installed.'), parent=self) + return + fn, cfg = loadIniFile(util.user_rcpath(), self)   super(AuthDialog, self).accept()     def reject(self): @@ -456,6 +461,38 @@
  return self.rows[index.row()][2]     +def loadIniFile(rcpath, parent): + for fn in rcpath: + if os.path.exists(fn): + break + else: + for fn in rcpath: + # Try to create a file from rcpath + try: + f = open(fn, 'w') + f.write('# Generated by TortoiseHg\n') + f.close() + break + except EnvironmentError: + pass + else: + qtlib.WarningMsgBox(_('Unable to create a config file'), + _('Insufficient access rights.'), parent=parent) + return None, {} + try: + if iniparse: + return fn, iniparse.INIConfig(file(fn), optionxformvalue=None) + else: + cfg = config.config() + cfg.read(fn) + return cfg + except Exception, e: + qtlib.WarningMsgBox(_('Unable to parse a config file'), + hglib.tounicode(e), parent=parent) + return None, {} + + +  def run(ui, *pats, **opts):   from tortoisehg.util import paths   return SyncWidget(paths.find_root(), **opts)