mercurial/streamclone.py
changeset 5396 5105b119edd2
parent 4959 97b734fb9c6f
child 5456 a58d415b272e
equal deleted inserted replaced
5395:e73a83af7926 5396:5105b119edd2
     4 #
     4 #
     5 # This software may be used and distributed according to the terms
     5 # This software may be used and distributed according to the terms
     6 # of the GNU General Public License, incorporated herein by reference.
     6 # of the GNU General Public License, incorporated herein by reference.
     7 
     7 
     8 from i18n import _
     8 from i18n import _
     9 import os, stat, util, lock
     9 import os, osutil, stat, util, lock
    10 
    10 
    11 # if server supports streaming clone, it advertises "stream"
    11 # if server supports streaming clone, it advertises "stream"
    12 # capability with value that is version+flags of repo it is serving.
    12 # capability with value that is version+flags of repo it is serving.
    13 # client only streams if it can read that repo format.
    13 # client only streams if it can read that repo format.
    14 
    14 
    17     walk in natural (sorted) order.
    17     walk in natural (sorted) order.
    18     yields 2-tuples: name of .d or .i file, size of file.'''
    18     yields 2-tuples: name of .d or .i file, size of file.'''
    19 
    19 
    20     strip_count = len(root) + len(os.sep)
    20     strip_count = len(root) + len(os.sep)
    21     def walk(path, recurse):
    21     def walk(path, recurse):
    22         ents = os.listdir(path)
    22         for e, kind, st in osutil.listdir(path, stat=True):
    23         ents.sort()
       
    24         for e in ents:
       
    25             pe = os.path.join(path, e)
    23             pe = os.path.join(path, e)
    26             st = os.lstat(pe)
    24             if kind == stat.S_IFDIR:
    27             if stat.S_ISDIR(st.st_mode):
       
    28                 if recurse:
    25                 if recurse:
    29                     for x in walk(pe, True):
    26                     for x in walk(pe, True):
    30                         yield x
    27                         yield x
    31             else:
    28             else:
    32                 if not stat.S_ISREG(st.st_mode) or len(e) < 2:
    29                 if kind != stat.S_IFREG or len(e) < 2:
    33                     continue
    30                     continue
    34                 sfx = e[-2:]
    31                 sfx = e[-2:]
    35                 if sfx in ('.d', '.i'):
    32                 if sfx in ('.d', '.i'):
    36                     yield pe[strip_count:], st.st_size
    33                     yield pe[strip_count:], st.st_size
    37     # write file data first
    34     # write file data first