[PATCH 5 of 5] reporegistry: removed another unuseful "else" wrapping in addSubrepo()

3 views
Skip to first unread message

Antonio Muci

unread,
Jun 9, 2023, 3:17:21 AM6/9/23
to thg...@googlegroups.com, a....@inwind.it
# HG changeset patch
# User Antonio Muci <a....@inwind.it>
# Date 1686294800 -7200
# Fri Jun 09 09:13:20 2023 +0200
# Node ID fd7397adfaa4fa501eba5d126cbb5b9165d85bac
# Parent 4292d53b4a0473b6c61d657832ec18eec2c1b0b6
reporegistry: removed another unuseful "else" wrapping in addSubrepo()

Same as earlier: the main logic of the function was wrapped in an "else" that
was taken every time.

No functional changes.

diff --git a/tortoisehg/hgqt/reporegistry.py b/tortoisehg/hgqt/reporegistry.py
--- a/tortoisehg/hgqt/reporegistry.py
+++ b/tortoisehg/hgqt/reporegistry.py
@@ -671,69 +671,68 @@ class RepoRegistryView(QDockWidget):
'as: "%s"') % (sroot, root, hglib.tounicode(srelroot)),
parent=self)
return
- else:
- # Read the current .hgsub file contents
- lines = []
- hasHgsub = os.path.exists(repo.wjoin(b'.hgsub'))
- if hasHgsub:
- try:
- with repo.wvfs(b'.hgsub', b'r') as fsub:
- lines = fsub.readlines()
- except:
- qtlib.WarningMsgBox(
- _('Failed to add subrepository'),
- _('Cannot open the .hgsub file in:<br><br>%s') \
- % root, parent=self)
- return
-
- # Make sure that the selected subrepo (or one of its
- # subrepos!) is not already on the .hgsub file
- linesep = b''
- # On Windows case is unimportant, while on posix it is
- srelrootnormcase = os.path.normcase(srelroot)
- for line in lines:
- spath = line.split(b"=")[0].strip()
- if not spath:
- continue
- uline = hglib.tounicode(line)
- if not linesep:
- linesep = hglib.fromunicode(hglib.getLineSeparator(uline))
- spath = util.pconvert(spath)
- if os.path.normcase(spath) == srelrootnormcase:
- qtlib.WarningMsgBox(
- _('Failed to add repository'),
- _('The .hgsub file already contains the '
- 'line:<br><br>%s') % uline, parent=self)
- return
- if not linesep:
- linesep = pycompat.oslinesep
-
- # Append the new subrepo to the end of the .hgsub file
- lines.append(b'%s = %s' % (srelroot, srelroot))
- lines = [line.strip(linesep) for line in lines]
-
- # and update the .hgsub file
+ # Read the current .hgsub file contents
+ lines = []
+ hasHgsub = os.path.exists(repo.wjoin(b'.hgsub'))
+ if hasHgsub:
try:
- with repo.wvfs(b'.hgsub', b'w') as fsub:
- fsub.write(linesep.join(lines) + linesep)
-
- if not hasHgsub:
- commands.add(hglib.loadui(),
- repo, repo.wjoin(b'.hgsub'))
- qtlib.InfoMsgBox(
- _('Subrepo added to .hgsub file'),
- _('The selected subrepo:<br><br><i>%s</i><br><br>'
- 'has been added to the .hgsub file of the repository:<br><br><i>%s</i><br><br>'
- 'Remember that in order to finish adding the '
- 'subrepo <i>you must still <u>commit</u></i> the '
- 'changes to the .hgsub file in order to confirm '
- 'the addition of the subrepo.') \
- % (hglib.tounicode(srelroot), root), parent=self)
+ with repo.wvfs(b'.hgsub', b'r') as fsub:
+ lines = fsub.readlines()
except:
qtlib.WarningMsgBox(
+ _('Failed to add subrepository'),
+ _('Cannot open the .hgsub file in:<br><br>%s') \
+ % root, parent=self)
+ return
+
+ # Make sure that the selected subrepo (or one of its
+ # subrepos!) is not already on the .hgsub file
+ linesep = b''
+ # On Windows case is unimportant, while on posix it is
+ srelrootnormcase = os.path.normcase(srelroot)
+ for line in lines:
+ spath = line.split(b"=")[0].strip()
+ if not spath:
+ continue
+ uline = hglib.tounicode(line)
+ if not linesep:
+ linesep = hglib.fromunicode(hglib.getLineSeparator(uline))
+ spath = util.pconvert(spath)
+ if os.path.normcase(spath) == srelrootnormcase:
+ qtlib.WarningMsgBox(
_('Failed to add repository'),
- _('Cannot update the .hgsub file in:<br><br>%s') \
- % root, parent=self)
+ _('The .hgsub file already contains the '
+ 'line:<br><br>%s') % uline, parent=self)
+ return
+ if not linesep:
+ linesep = pycompat.oslinesep
+
+ # Append the new subrepo to the end of the .hgsub file
+ lines.append(b'%s = %s' % (srelroot, srelroot))
+ lines = [line.strip(linesep) for line in lines]
+
+ # and update the .hgsub file
+ try:
+ with repo.wvfs(b'.hgsub', b'w') as fsub:
+ fsub.write(linesep.join(lines) + linesep)
+
+ if not hasHgsub:
+ commands.add(hglib.loadui(),
+ repo, repo.wjoin(b'.hgsub'))
+ qtlib.InfoMsgBox(
+ _('Subrepo added to .hgsub file'),
+ _('The selected subrepo:<br><br><i>%s</i><br><br>'
+ 'has been added to the .hgsub file of the repository:<br><br><i>%s</i><br><br>'
+ 'Remember that in order to finish adding the '
+ 'subrepo <i>you must still <u>commit</u></i> the '
+ 'changes to the .hgsub file in order to confirm '
+ 'the addition of the subrepo.') \
+ % (hglib.tounicode(srelroot), root), parent=self)
+ except:
+ qtlib.WarningMsgBox(
+ _('Failed to add repository'),
+ _('Cannot update the .hgsub file in:<br><br>%s') \
+ % root, parent=self)

def removeSubrepo(self):
'menu action handler for removing an existing subrepository'

Reply all
Reply to author
Forward
0 new messages