[merge] LockDir: use put_file_non_atomic instead of append_file
Martin Pool
mbp at canonical.com
Sat Sep 9 01:43:05 BST 2006
On 8 Sep 2006, John Arbash Meinel <john at arbash-meinel.com> wrote:
> The attached bundle just changes LockDir to use the new
> 'put_file_non_atomic()' since it saves an extra round trip with sftp.
>
> When locking a remote directory, this saves a round trip for each lock.
> So in the common case, this saves 2 round trips. (For me, this is 200+ms
> when committing or pushing to Launchpad).
Because we don't need to stat the file to tell how long it will be?
+1
> === modified file bzrlib/lockdir.py
> --- bzrlib/lockdir.py
> +++ bzrlib/lockdir.py
> @@ -203,11 +203,11 @@
> sio = StringIO()
> self._prepare_info(sio)
> sio.seek(0)
> - # append will create a new file; we use append rather than put
> - # because we don't want to write to a temporary file and rename
> - # into place, because that's going to happen to the whole
> - # directory
> - self.transport.append_file(tmpname + self.__INFO_NAME, sio)
> + # We use put_file_non_atomic because we just created a new unique
> + # directory so we don't have to worry about files existing there.
> + # We'll rename the whole directory into place to get atomic
> + # properties
> + self.transport.put_file_non_atomic(tmpname + self.__INFO_NAME, sio)
>
> self.transport.rename(tmpname, self._held_dir)
> self._lock_held = True
Presumably this could use put_bytes_non_atomic to be a bit simpler?
--
Martin
More information about the bazaar
mailing list