/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/dirstate.py

  • Committer: Vincent Ladeuil
  • Date: 2011-11-24 15:48:29 UTC
  • mfrom: (6289 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6337.
  • Revision ID: v.ladeuil+lp@free.fr-20111124154829-avowjpsxdl8yp2vz
merge trunk resolving conflicts

Show diffs side-by-side

added added

removed removed

Lines of Context:
219
219
"""
220
220
 
221
221
import bisect
222
 
import binascii
223
222
import errno
224
223
import operator
225
224
import os
226
225
from stat import S_IEXEC
227
226
import stat
228
 
import struct
229
227
import sys
230
228
import time
231
229
import zlib
251
249
ERROR_DIRECTORY = 267
252
250
 
253
251
 
254
 
if not getattr(struct, '_compile', None):
255
 
    # Cannot pre-compile the dirstate pack_stat
256
 
    def pack_stat(st, _encode=binascii.b2a_base64, _pack=struct.pack):
257
 
        """Convert stat values into a packed representation."""
258
 
        return _encode(_pack('>LLLLLL', st.st_size & 0xFFFFFFFF,
259
 
            int(st.st_mtime) & 0xFFFFFFFF, int(st.st_ctime) & 0xFFFFFFFF,
260
 
            st.st_dev & 0xFFFFFFFF, st.st_ino & 0xFFFFFFFF,
261
 
            st.st_mode))[:-1]
262
 
else:
263
 
    # compile the struct compiler we need, so as to only do it once
264
 
    from _struct import Struct
265
 
    _compiled_pack = Struct('>LLLLLL').pack
266
 
    def pack_stat(st, _encode=binascii.b2a_base64, _pack=_compiled_pack):
267
 
        """Convert stat values into a packed representation."""
268
 
        # jam 20060614 it isn't really worth removing more entries if we
269
 
        # are going to leave it in packed form.
270
 
        # With only st_mtime and st_mode filesize is 5.5M and read time is 275ms
271
 
        # With all entries, filesize is 5.9M and read time is maybe 280ms
272
 
        # well within the noise margin
273
 
 
274
 
        # base64 encoding always adds a final newline, so strip it off
275
 
        # The current version
276
 
        return _encode(_pack(st.st_size, int(st.st_mtime), int(st.st_ctime),
277
 
            st.st_dev, st.st_ino & 0xFFFFFFFF, st.st_mode))[:-1]
278
 
        # This is 0.060s / 1.520s faster by not encoding as much information
279
 
        # return _encode(_pack('>LL', int(st.st_mtime), st.st_mode))[:-1]
280
 
        # This is not strictly faster than _encode(_pack())[:-1]
281
 
        # return '%X.%X.%X.%X.%X.%X' % (
282
 
        #      st.st_size, int(st.st_mtime), int(st.st_ctime),
283
 
        #      st.st_dev, st.st_ino, st.st_mode)
284
 
        # Similar to the _encode(_pack('>LL'))
285
 
        # return '%X.%X' % (int(st.st_mtime), st.st_mode)
286
 
 
287
 
 
288
 
def _unpack_stat(packed_stat):
289
 
    """Turn a packed_stat back into the stat fields.
290
 
 
291
 
    This is meant as a debugging tool, should not be used in real code.
292
 
    """
293
 
    (st_size, st_mtime, st_ctime, st_dev, st_ino,
294
 
     st_mode) = struct.unpack('>LLLLLL', binascii.a2b_base64(packed_stat))
295
 
    return dict(st_size=st_size, st_mtime=st_mtime, st_ctime=st_ctime,
296
 
                st_dev=st_dev, st_ino=st_ino, st_mode=st_mode)
297
 
 
298
 
 
299
252
class SHA1Provider(object):
300
253
    """An interface for getting sha1s of a file."""
301
254
 
1897
1850
                    file_id, "This parent is not a directory.")
1898
1851
 
1899
1852
    def _observed_sha1(self, entry, sha1, stat_value,
1900
 
        _stat_to_minikind=_stat_to_minikind, _pack_stat=pack_stat):
 
1853
        _stat_to_minikind=_stat_to_minikind):
1901
1854
        """Note the sha1 of a file.
1902
1855
 
1903
1856
        :param entry: The entry the sha1 is for.
1909
1862
        except KeyError:
1910
1863
            # Unhandled kind
1911
1864
            return None
1912
 
        packed_stat = _pack_stat(stat_value)
1913
1865
        if minikind == 'f':
1914
1866
            if self._cutoff_time is None:
1915
1867
                self._sha_cutoff_time()
1916
1868
            if (stat_value.st_mtime < self._cutoff_time
1917
1869
                and stat_value.st_ctime < self._cutoff_time):
1918
1870
                entry[1][0] = ('f', sha1, stat_value.st_size, entry[1][0][3],
1919
 
                               packed_stat)
 
1871
                               pack_stat(stat_value))
1920
1872
                self._mark_modified([entry])
1921
1873
 
1922
1874
    def _sha_cutoff_time(self):
2475
2427
            raise errors.BzrError('missing num_entries line')
2476
2428
        self._num_entries = int(num_entries_line[len('num_entries: '):-1])
2477
2429
 
2478
 
    def sha1_from_stat(self, path, stat_result, _pack_stat=pack_stat):
 
2430
    def sha1_from_stat(self, path, stat_result):
2479
2431
        """Find a sha1 given a stat lookup."""
2480
 
        return self._get_packed_stat_index().get(_pack_stat(stat_result), None)
 
2432
        return self._get_packed_stat_index().get(pack_stat(stat_result), None)
2481
2433
 
2482
2434
    def _get_packed_stat_index(self):
2483
2435
        """Get a packed_stat index of self._dirblocks."""
3398
3350
 
3399
3351
 
3400
3352
def py_update_entry(state, entry, abspath, stat_value,
3401
 
                 _stat_to_minikind=DirState._stat_to_minikind,
3402
 
                 _pack_stat=pack_stat):
 
3353
                 _stat_to_minikind=DirState._stat_to_minikind):
3403
3354
    """Update the entry based on what is actually on disk.
3404
3355
 
3405
3356
    This function only calculates the sha if it needs to - if the entry is
3418
3369
    except KeyError:
3419
3370
        # Unhandled kind
3420
3371
        return None
3421
 
    packed_stat = _pack_stat(stat_value)
 
3372
    packed_stat = pack_stat(stat_value)
3422
3373
    (saved_minikind, saved_link_or_sha1, saved_file_size,
3423
3374
     saved_executable, saved_packed_stat) = entry[1][0]
3424
3375
 
4297
4248
        _bisect_path_left,
4298
4249
        _bisect_path_right,
4299
4250
        cmp_by_dirs,
 
4251
        pack_stat,
4300
4252
        ProcessEntryC as _process_entry,
4301
4253
        update_entry as update_entry,
4302
4254
        )
4308
4260
        _bisect_path_left,
4309
4261
        _bisect_path_right,
4310
4262
        cmp_by_dirs,
 
4263
        pack_stat,
4311
4264
        )
4312
4265
    # FIXME: It would be nice to be able to track moved lines so that the
4313
4266
    # corresponding python code can be moved to the _dirstate_helpers_py