Merge lp:~jelmer/brz/lockdir-yaml into lp:brz

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: no longer in the source branch.
Merge reported by: The Breezy Bot
Merged at revision: not available
Proposed branch: lp:~jelmer/brz/lockdir-yaml
Merge into: lp:brz
Prerequisite: lp:~jelmer/brz/rio-to-yaml
Diff against target: 94 lines (+11/-14)
2 files modified
breezy/lockdir.py (+10/-13)
breezy/tests/test_lockdir.py (+1/-1)
To merge this branch: bzr merge lp:~jelmer/brz/lockdir-yaml
Reviewer Review Type Date Requested Status
Jelmer Vernooij Approve
Review via email: mp+426495@code.launchpad.net

Commit message

Use yaml rather than rio for lock directories.

Description of the change

Use yaml rather than rio for lock directories.

To post a comment you must log in.
Revision history for this message
Jelmer Vernooij (jelmer) :
review: Approve
Revision history for this message
The Breezy Bot (the-breezy-bot) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'breezy/lockdir.py'
--- breezy/lockdir.py 2020-02-18 01:57:45 +0000
+++ breezy/lockdir.py 2022-07-07 15:49:09 +0000
@@ -109,6 +109,7 @@
109109
110import os110import os
111import time111import time
112import yaml
112113
113from . import (114from . import (
114 config,115 config,
@@ -116,7 +117,6 @@
116 errors,117 errors,
117 lock,118 lock,
118 osutils,119 osutils,
119 rio,
120 ui,120 ui,
121 urlutils,121 urlutils,
122 )122 )
@@ -713,8 +713,6 @@
713 read back by any process with access to the lockdir. It can be used, for713 read back by any process with access to the lockdir. It can be used, for
714 example, to tell the user who holds the lock, or to try to detect whether714 example, to tell the user who holds the lock, or to try to detect whether
715 the lock holder is still alive.715 the lock holder is still alive.
716
717 Prior to bzr 2.4 a simple dict was used instead of an object.
718 """716 """
719717
720 def __init__(self, info_dict):718 def __init__(self, info_dict):
@@ -765,7 +763,7 @@
765 """763 """
766 info = dict(764 info = dict(
767 hostname=get_host_name(),765 hostname=get_host_name(),
768 pid=str(os.getpid()),766 pid=os.getpid(),
769 nonce=rand_chars(20).encode('ascii'),767 nonce=rand_chars(20).encode('ascii'),
770 start_time=str(int(time.time())),768 start_time=str(int(time.time())),
771 user=get_username_for_lock_info(),769 user=get_username_for_lock_info(),
@@ -775,27 +773,26 @@
775 return cls(info)773 return cls(info)
776774
777 def to_bytes(self):775 def to_bytes(self):
778 s = rio.Stanza(**self.info_dict)776 return yaml.dump(self.info_dict).encode('utf-8')
779 return s.to_string()
780777
781 @classmethod778 @classmethod
782 def from_info_file_bytes(cls, info_file_bytes):779 def from_info_file_bytes(cls, info_file_bytes):
783 """Construct from the contents of the held file."""780 """Construct from the contents of the held file."""
784 lines = osutils.split_lines(info_file_bytes)
785 try:781 try:
786 stanza = rio.read_stanza(lines)782 ret = yaml.safe_load(info_file_bytes)
787 except ValueError as e:783 except yaml.reader.ReaderError as e:
784 lines = osutils.split_lines(info_file_bytes)
788 mutter('Corrupt lock info file: %r', lines)785 mutter('Corrupt lock info file: %r', lines)
789 raise LockCorrupt("could not parse lock info file: " + str(e),786 raise LockCorrupt("could not parse lock info file: " + str(e),
790 lines)787 lines)
791 if stanza is None:788 if ret is None:
792 # see bug 185013; we fairly often end up with the info file being789 # see bug 185013; we fairly often end up with the info file being
793 # empty after an interruption; we could log a message here but790 # empty after an interruption; we could log a message here but
794 # there may not be much we can say791 # there may not be much we can say
795 return cls({})792 return cls({})
796 else:793 else:
797 ret = stanza.as_dict()794 if isinstance(ret['nonce'], str):
798 ret['nonce'] = ret['nonce'].encode('ascii')795 ret['nonce'] = ret['nonce'].encode('ascii')
799 return cls(ret)796 return cls(ret)
800797
801 def __hash__(self):798 def __hash__(self):
@@ -814,7 +811,7 @@
814 """True if this process seems to be the current lock holder."""811 """True if this process seems to be the current lock holder."""
815 return (812 return (
816 self.get('hostname') == get_host_name()813 self.get('hostname') == get_host_name()
817 and self.get('pid') == str(os.getpid())814 and self.get('pid') == os.getpid()
818 and self.get('user') == get_username_for_lock_info())815 and self.get('user') == get_username_for_lock_info())
819816
820 def is_lock_holder_known_dead(self):817 def is_lock_holder_known_dead(self):
821818
=== modified file 'breezy/tests/test_lockdir.py'
--- breezy/tests/test_lockdir.py 2020-02-07 02:14:30 +0000
+++ breezy/tests/test_lockdir.py 2022-07-07 15:49:09 +0000
@@ -429,7 +429,7 @@
429 finally:429 finally:
430 ld1.unlock()430 ld1.unlock()
431 self.assertEqual(info_list['user'], u'jrandom@example.com')431 self.assertEqual(info_list['user'], u'jrandom@example.com')
432 self.assertContainsRe(info_list['pid'], '^\\d+$')432 self.assertIsInstance(info_list['pid'], int)
433 self.assertContainsRe(info_list['time_ago'], '^\\d+ seconds? ago$')433 self.assertContainsRe(info_list['time_ago'], '^\\d+ seconds? ago$')
434434
435 def test_lock_without_email(self):435 def test_lock_without_email(self):

Subscribers

People subscribed via source and target branches