Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 2.0.3, 2.0.4, and 2.0.5

stable fileview: don't create an empty subrepo unintentionally

When a subrepo is missing from the working directory, viewing the revision
history of any revision where said repository had been modified (initialized,
changed or removed) would create an empty subrepo in the working directory.

The problem was due to the fact that calling ctx.sub(wfile) always creates an
empty repository.

Many of the places where we were calling ctx.sub() were unneeded, since we only
needed to call it to get the current status of the repository, which does not
make sense if the repository is missing or if we are not viewing the working
directory status.

This patch could be further improved as follows:

- Avoid calling ctx.sub() for non hg subrepos, which could be done by
checking: ctx.substate.get(wfile, subrepo.nullstate)[2] != 'hg'
- Let the user create (clone?) missing subrepos.

Changeset c6b34d8f25e5

Parent c329f685b548

by Angel Ezquerra

Changes to one file · Browse files at c6b34d8f25e5 Showing diff from parent c329f685b548 Diff from another changeset...

 
606
607
608
609
 
610
611
612
613
 
 
 
 
 
 
 
 
 
 
 
 
 
614
615
616
 
619
620
621
 
622
 
 
 
 
 
 
 
 
 
 
 
 
 
 
623
624
625
626
627
628
629
630
 
 
631
632
633
 
634
635
636
 
637
638
639
640
641
 
 
 
642
643
644
 
 
 
 
 
 
 
645
646
647
648
 
649
650
651
652
653
654
655
656
657
 
 
 
 
 
 
 
 
 
 
 
 
658
659
660
661
 
662
663
664
665
666
667
 
668
669
670
 
606
607
608
 
609
610
611
612
 
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
 
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
 
 
 
 
 
 
652
653
654
655
656
657
658
659
660
661
662
 
 
 
 
663
664
665
666
 
 
667
668
669
670
671
672
673
674
 
 
675
676
677
678
 
 
 
 
 
 
 
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
 
694
695
696
697
698
699
 
700
701
702
703
@@ -606,11 +606,23 @@
  try:   from mercurial import subrepo, commands   - def genSubrepoRevChangedDescription(sfrom, sto): + def genSubrepoRevChangedDescription(subrelpath, sfrom, sto):   """Generate a subrepository revision change description"""   out = []   opts = {'date':None, 'user':None, 'rev':[sfrom]} - if not sfrom: + subabspath = os.path.join(repo.root, subrelpath) + missingsub = not os.path.isdir(subabspath) + def isinitialrevision(rev): + return all([el == '0' for el in rev]) + if isinitialrevision(sfrom): + sfrom = '' + if isinitialrevision(sto): + sto = '' + if not sfrom and not sto: + sstatedesc = 'new' + out.append(_('Subrepo created and set to initial revision.') + u'\n\n') + return out, sstatedesc + elif not sfrom:   sstatedesc = 'new'   out.append(_('Subrepo initialized to revision:') + u'\n\n')   elif not sto: @@ -619,52 +631,73 @@
  return out, sstatedesc   else:   sstatedesc = 'changed' +   out.append(_('Revision has changed from:') + u'\n\n') + if missingsub: + out.append(hglib.tounicode(_('changeset: %s') % sfrom + '\n')) + else: + _ui.pushbuffer() + commands.log(_ui, srepo, **opts) + out.append(hglib.tounicode(_ui.popbuffer())) + + out.append(_('To:') + u'\n') + if missingsub: + stolog = _('changeset: %s') % sto + '\n\n' + stolog += _('Subrepository not found in working directory.') + '\n' + stolog += _('Further subrepository revision information cannot be retrieved.') + '\n' + else: + opts['rev'] = [sto]   _ui.pushbuffer()   commands.log(_ui, srepo, **opts) - out.append(hglib.tounicode(_ui.popbuffer())) - out.append(_('To:') + u'\n') - opts['rev'] = [sto] - _ui.pushbuffer() - commands.log(_ui, srepo, **opts) - stolog = _ui.popbuffer() + stolog = _ui.popbuffer() +   if not stolog:   stolog = _('Initial revision')   out.append(hglib.tounicode(stolog)) +   return out, sstatedesc     srev = ctx.substate.get(wfile, subrepo.nullstate)[1] + srepo = None   try: - sub = ctx.sub(wfile) - if isinstance(sub, subrepo.hgsubrepo): - srepo = sub._repo - sactual = srepo['.'].hex() + subabspath = os.path.join(repo.root, wfile) + if not os.path.isdir(subabspath): + sactual = ''   else: - self.error = _('Not a Mercurial subrepo, not previewable') - return + sub = ctx.sub(wfile) + if isinstance(sub, subrepo.hgsubrepo): + srepo = sub._repo + sactual = srepo['.'].hex() + else: + self.error = _('Not a Mercurial subrepo, not previewable') + return   except (util.Abort), e: - sub = ctx.p1().sub(wfile) - srepo = sub._repo   sactual = '' +   out = []   _ui = uimod.ui() - _ui.pushbuffer() - commands.status(_ui, srepo) - data = _ui.popbuffer() - if data: - out.append(_('File Status:') + u'\n') - out.append(hglib.tounicode(data)) - out.append(u'\n') + + if srepo is None or ctx.rev() is not None: + data = [] + else: + _ui.pushbuffer() + commands.status(_ui, srepo) + data = _ui.popbuffer() + if data: + out.append(_('File Status:') + u'\n') + out.append(hglib.tounicode(data)) + out.append(u'\n') +   sstatedesc = 'changed'   if ctx.rev() is not None:   sparent = ctx.p1().substate.get(wfile, subrepo.nullstate)[1] - subrepochange, sstatedesc = genSubrepoRevChangedDescription(sparent, srev) + subrepochange, sstatedesc = genSubrepoRevChangedDescription(wfile, sparent, srev)   out += subrepochange   else:   sstatedesc = 'dirty'   if srev != sactual:   subrepochange, sstatedesc = \ - genSubrepoRevChangedDescription(srev, sactual) + genSubrepoRevChangedDescription(wfile, srev, sactual)   out += subrepochange   if data:   sstatedesc += ' and dirty'