hgext/convert/git.py
changeset 47012 d55b71393907
parent 46819 d4ba4d51f85f
child 47128 bea4717415c0
equal deleted inserted replaced
46992:5fa019ceb499 47012:d55b71393907
     7 from __future__ import absolute_import
     7 from __future__ import absolute_import
     8 
     8 
     9 import os
     9 import os
    10 
    10 
    11 from mercurial.i18n import _
    11 from mercurial.i18n import _
    12 from mercurial.node import nullhex
    12 from mercurial.node import sha1nodeconstants
    13 from mercurial import (
    13 from mercurial import (
    14     config,
    14     config,
    15     error,
    15     error,
    16     pycompat,
    16     pycompat,
    17 )
    17 )
   190                 if ret:
   190                 if ret:
   191                     raise error.Abort(_(b'cannot retrieve git head "%s"') % rev)
   191                     raise error.Abort(_(b'cannot retrieve git head "%s"') % rev)
   192         return heads
   192         return heads
   193 
   193 
   194     def catfile(self, rev, ftype):
   194     def catfile(self, rev, ftype):
   195         if rev == nullhex:
   195         if rev == sha1nodeconstants.nullhex:
   196             raise IOError
   196             raise IOError
   197         self.catfilepipe[0].write(rev + b'\n')
   197         self.catfilepipe[0].write(rev + b'\n')
   198         self.catfilepipe[0].flush()
   198         self.catfilepipe[0].flush()
   199         info = self.catfilepipe[1].readline().split()
   199         info = self.catfilepipe[1].readline().split()
   200         if info[1] != ftype:
   200         if info[1] != ftype:
   212         # read the trailing newline
   212         # read the trailing newline
   213         self.catfilepipe[1].read(1)
   213         self.catfilepipe[1].read(1)
   214         return data
   214         return data
   215 
   215 
   216     def getfile(self, name, rev):
   216     def getfile(self, name, rev):
   217         if rev == nullhex:
   217         if rev == sha1nodeconstants.nullhex:
   218             return None, None
   218             return None, None
   219         if name == b'.hgsub':
   219         if name == b'.hgsub':
   220             data = b'\n'.join([m.hgsub() for m in self.submoditer()])
   220             data = b'\n'.join([m.hgsub() for m in self.submoditer()])
   221             mode = b''
   221             mode = b''
   222         elif name == b'.hgsubstate':
   222         elif name == b'.hgsubstate':
   226             data = self.catfile(rev, b"blob")
   226             data = self.catfile(rev, b"blob")
   227             mode = self.modecache[(name, rev)]
   227             mode = self.modecache[(name, rev)]
   228         return data, mode
   228         return data, mode
   229 
   229 
   230     def submoditer(self):
   230     def submoditer(self):
   231         null = nullhex
   231         null = sha1nodeconstants.nullhex
   232         for m in sorted(self.submodules, key=lambda p: p.path):
   232         for m in sorted(self.submodules, key=lambda p: p.path):
   233             if m.node != null:
   233             if m.node != null:
   234                 yield m
   234                 yield m
   235 
   235 
   236     def parsegitmodules(self, content):
   236     def parsegitmodules(self, content):
   315                     return
   315                     return
   316 
   316 
   317                 subexists[0] = True
   317                 subexists[0] = True
   318                 if entry[4] == b'D' or renamesource:
   318                 if entry[4] == b'D' or renamesource:
   319                     subdeleted[0] = True
   319                     subdeleted[0] = True
   320                     changes.append((b'.hgsub', nullhex))
   320                     changes.append((b'.hgsub', sha1nodeconstants.nullhex))
   321                 else:
   321                 else:
   322                     changes.append((b'.hgsub', b''))
   322                     changes.append((b'.hgsub', b''))
   323             elif entry[1] == b'160000' or entry[0] == b':160000':
   323             elif entry[1] == b'160000' or entry[0] == b':160000':
   324                 if not skipsubmodules:
   324                 if not skipsubmodules:
   325                     subexists[0] = True
   325                     subexists[0] = True
   326             else:
   326             else:
   327                 if renamesource:
   327                 if renamesource:
   328                     h = nullhex
   328                     h = sha1nodeconstants.nullhex
   329                 self.modecache[(f, h)] = (p and b"x") or (s and b"l") or b""
   329                 self.modecache[(f, h)] = (p and b"x") or (s and b"l") or b""
   330                 changes.append((f, h))
   330                 changes.append((f, h))
   331 
   331 
   332         while i < lcount:
   332         while i < lcount:
   333             l = difftree[i]
   333             l = difftree[i]
   360                         copies[fdest] = f
   360                         copies[fdest] = f
   361             entry = None
   361             entry = None
   362 
   362 
   363         if subexists[0]:
   363         if subexists[0]:
   364             if subdeleted[0]:
   364             if subdeleted[0]:
   365                 changes.append((b'.hgsubstate', nullhex))
   365                 changes.append((b'.hgsubstate', sha1nodeconstants.nullhex))
   366             else:
   366             else:
   367                 self.retrievegitmodules(version)
   367                 self.retrievegitmodules(version)
   368                 changes.append((b'.hgsubstate', b''))
   368                 changes.append((b'.hgsubstate', b''))
   369         return (changes, copies, set())
   369         return (changes, copies, set())
   370 
   370