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

settings: use wconfig adapter for editing ini

Changeset bcb8ea68fb79

Parent 522c86e64fb8

by Yuya Nishihara

Changes to one file · Browse files at bcb8ea68fb79 Showing diff from parent 522c86e64fb8 Diff from another changeset...

 
12
13
14
15
 
16
17
18
 
672
673
674
 
675
676
677
 
748
749
750
751
752
753
754
755
 
756
757
758
 
774
775
776
777
778
779
 
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
 
803
804
805
806
 
 
807
808
809
810
811
812
813
814
815
816
817
818
819
 
 
 
 
 
 
820
821
822
 
828
829
830
831
832
833
 
834
835
836
 
12
13
14
 
15
16
17
18
 
672
673
674
675
676
677
678
 
749
750
751
 
 
 
 
 
752
753
754
755
 
771
772
773
 
 
 
774
775
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
776
777
778
779
780
781
782
783
 
 
 
 
 
 
 
 
 
 
 
 
784
785
786
787
788
789
790
791
792
 
798
799
800
 
 
 
801
802
803
804
@@ -12,7 +12,7 @@
   from mercurial import hg, ui, util, url, filemerge, error, extensions   -from tortoisehg.util import hglib, settings, paths +from tortoisehg.util import hglib, settings, paths, wconfig  from tortoisehg.hgqt.i18n import _  from tortoisehg.hgqt import qtlib   @@ -672,6 +672,7 @@
  def refresh(self, *args):   # refresh config values   self.ini = self.loadIniFile(self.rcpath) + self.readonly = not hasattr(self.ini, 'write')   self.fnedit.setText(self.fn)   for info, widgets in self.pages.values():   for row, (label, cpath, values, tooltip) in enumerate(info): @@ -748,11 +749,7 @@
  'Retrieve a value from the parsed config file'   # Presumes single section/key level depth   section, key = cpath.split('.', 1) - if section not in self.ini: - return None - if key not in self.ini[section]: - return None - return self.ini[section][key] + return self.ini.get(section, key)     def loadIniFile(self, rcpath):   for fn in rcpath: @@ -774,49 +771,22 @@
  ' mode.'), parent=self)   from mercurial import config   self.fn = rcpath[0] - cfg = config.config() - self.readonly = True - return cfg + return config.config()   self.fn = fn - 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: - from mercurial import config - cfg = config.config() - cfg.read(fn) - self.readonly = True - return cfg - except Exception, e: - qtlib.WarningMsgBox(_('Unable to parse a config file'), - _('%s\nReverting to read-only mode.') % str(e), - parent=self) - from mercurial import config - cfg = config.config() - cfg.read(fn) - self.readonly = True - return cfg + return wconfig.readfile(self.fn)     def recordNewValue(self, cpath, newvalue):   # 'newvalue' is in local encoding   section, key = cpath.split('.', 1) + if newvalue == self.ini.get(section, key): + return   if newvalue == None: - if section not in self.ini: - return - if key not in self.ini[section]: - return - del self.ini[section][key] - return - if section not in self.ini: - if hasattr(self.ini, '_new_namespace'): - self.ini._new_namespace(section) - else: - self.ini.new_namespace(section) - self.ini[section][key] = newvalue + try: + del self.ini[section][key] + except KeyError: + pass + else: + self.ini.set(section, key, newvalue)     def applyChanges(self):   if self.readonly: @@ -828,9 +798,7 @@
  self.recordNewValue(cpath, newvalue)     try: - f = util.atomictempfile(self.fn, 'w', createmode=None) - f.write(str(self.ini)) - f.rename() + wconfig.writefile(self.ini, self.fn)   except IOError, e:   qtlib.WarningMsgBox(_('Unable to write configuration file'),   str(e), parent=self)