~ubuntu-branches/debian/jessie/bzr-git/jessie

« back to all changes in this revision

Viewing changes to workingtree.py

  • Committer: Package Import Robot
  • Author(s): Jelmer Vernooij
  • Date: 2011-12-15 19:06:37 UTC
  • mfrom: (1.1.25)
  • Revision ID: package-import@ubuntu.com-20111215190637-cd1n2iathdjg1u97
Tags: 0.6.6-1
* Use DEP5 format for copyright file.
* New upstream release.
 + Copes with new `possible_transports` argument for Branch.open added in
   bzr 2.5b4. Closes: #652178
 + Copes with removal of global options in bzr 2.5b4. LP: #903639
 + Fixes support for directories in `bzr add`. LP: #894195

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
    conflicts as _mod_conflicts,
44
44
    ignores,
45
45
    inventory,
46
 
    lockable_files,
47
 
    lockdir,
 
46
    lock,
48
47
    osutils,
49
48
    trace,
50
49
    transport,
83
82
        self.mapping = self.repository.get_mapping()
84
83
        self._branch = branch
85
84
        self._transport = bzrdir.transport
86
 
 
87
 
        self.controldir = self.bzrdir.transport.local_abspath('bzr')
88
 
 
89
 
        try:
90
 
            os.makedirs(self.controldir)
91
 
            os.makedirs(os.path.join(self.controldir, 'lock'))
92
 
        except OSError:
93
 
            pass
94
 
 
95
 
        self._control_files = lockable_files.LockableFiles(
96
 
            transport.get_transport(self.controldir), 'lock', lockdir.LockDir)
97
85
        self._format = GitWorkingTreeFormat()
98
86
        self.index = index
99
87
        self._versioned_dirs = None
102
90
        self._detect_case_handling()
103
91
        self._reset_data()
104
92
        self._fileid_map = self._basis_fileid_map.copy()
 
93
        self._lock_mode = None
 
94
        self._lock_count = 0
 
95
 
 
96
    def lock_read(self):
 
97
        """Lock the repository for read operations.
 
98
 
 
99
        :return: A bzrlib.lock.LogicalLockResult.
 
100
        """
 
101
        if not self._lock_mode:
 
102
            self._lock_mode = 'r'
 
103
            self._lock_count = 1
 
104
        else:
 
105
            self._lock_count += 1
 
106
        self.branch.lock_read()
 
107
        return lock.LogicalLockResult(self.unlock)
 
108
 
 
109
    def lock_tree_write(self):
 
110
        if not self._lock_mode:
 
111
            self._lock_mode = 'w'
 
112
            self._lock_count = 1
 
113
        elif self._lock_mode == 'r':
 
114
            raise errors.ReadOnlyError(self)
 
115
        else:
 
116
            self._lock_count +=1
 
117
        self.branch.lock_read()
 
118
        return lock.LogicalLockResult(self.unlock)
 
119
 
 
120
    def lock_write(self, token=None):
 
121
        if not self._lock_mode:
 
122
            self._lock_mode = 'w'
 
123
            self._lock_count = 1
 
124
        elif self._lock_mode == 'r':
 
125
            raise errors.ReadOnlyError(self)
 
126
        else:
 
127
            self._lock_count +=1
 
128
        self.branch.lock_write()
 
129
        return lock.LogicalLockResult(self.unlock)
 
130
 
 
131
    def is_locked(self):
 
132
        return self._lock_count >= 1
 
133
 
 
134
    def get_physical_lock_status(self):
 
135
        return False
 
136
 
 
137
    def unlock(self):
 
138
        if not self._lock_count:
 
139
            return lock.cant_unlock_not_held(self)
 
140
        self._cleanup()
 
141
        self._lock_count -= 1
 
142
        if self._lock_count > 0:
 
143
            return
 
144
        self._lock_mode = None
 
145
        self.branch.unlock()
105
146
 
106
147
    def _detect_case_handling(self):
107
148
        try:
308
349
                    user_dirs.append(subp)
309
350
                else:
310
351
                    if action is not None:
311
 
                        file_id = action()
 
352
                        file_id = action(self, None, filepath, kind)
312
353
                    else:
313
354
                        file_id = None
314
355
                    if save:
385
426
        """
386
427
        return set(self._iter_files_recursive()) - set(self.index)
387
428
 
388
 
    def unlock(self):
389
 
        # non-implementation specific cleanup
390
 
        self._cleanup()
391
 
 
392
 
        # reverse order of locking.
393
 
        try:
394
 
            return self._control_files.unlock()
395
 
        finally:
396
 
            self.branch.unlock()
397
 
 
398
429
    def flush(self):
399
430
        # TODO: Maybe this should only write on dirty ?
400
 
        if self._control_files._lock_mode != 'w':
 
431
        if self._lock_mode != 'w':
401
432
            raise errors.NotWriteLocked(self)
402
433
        self.index.write()
403
434