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
1=== modified file 'breezy/lockdir.py'
2--- breezy/lockdir.py 2020-02-18 01:57:45 +0000
3+++ breezy/lockdir.py 2022-07-07 15:49:09 +0000
4@@ -109,6 +109,7 @@
5
6 import os
7 import time
8+import yaml
9
10 from . import (
11 config,
12@@ -116,7 +117,6 @@
13 errors,
14 lock,
15 osutils,
16- rio,
17 ui,
18 urlutils,
19 )
20@@ -713,8 +713,6 @@
21 read back by any process with access to the lockdir. It can be used, for
22 example, to tell the user who holds the lock, or to try to detect whether
23 the lock holder is still alive.
24-
25- Prior to bzr 2.4 a simple dict was used instead of an object.
26 """
27
28 def __init__(self, info_dict):
29@@ -765,7 +763,7 @@
30 """
31 info = dict(
32 hostname=get_host_name(),
33- pid=str(os.getpid()),
34+ pid=os.getpid(),
35 nonce=rand_chars(20).encode('ascii'),
36 start_time=str(int(time.time())),
37 user=get_username_for_lock_info(),
38@@ -775,27 +773,26 @@
39 return cls(info)
40
41 def to_bytes(self):
42- s = rio.Stanza(**self.info_dict)
43- return s.to_string()
44+ return yaml.dump(self.info_dict).encode('utf-8')
45
46 @classmethod
47 def from_info_file_bytes(cls, info_file_bytes):
48 """Construct from the contents of the held file."""
49- lines = osutils.split_lines(info_file_bytes)
50 try:
51- stanza = rio.read_stanza(lines)
52- except ValueError as e:
53+ ret = yaml.safe_load(info_file_bytes)
54+ except yaml.reader.ReaderError as e:
55+ lines = osutils.split_lines(info_file_bytes)
56 mutter('Corrupt lock info file: %r', lines)
57 raise LockCorrupt("could not parse lock info file: " + str(e),
58 lines)
59- if stanza is None:
60+ if ret is None:
61 # see bug 185013; we fairly often end up with the info file being
62 # empty after an interruption; we could log a message here but
63 # there may not be much we can say
64 return cls({})
65 else:
66- ret = stanza.as_dict()
67- ret['nonce'] = ret['nonce'].encode('ascii')
68+ if isinstance(ret['nonce'], str):
69+ ret['nonce'] = ret['nonce'].encode('ascii')
70 return cls(ret)
71
72 def __hash__(self):
73@@ -814,7 +811,7 @@
74 """True if this process seems to be the current lock holder."""
75 return (
76 self.get('hostname') == get_host_name()
77- and self.get('pid') == str(os.getpid())
78+ and self.get('pid') == os.getpid()
79 and self.get('user') == get_username_for_lock_info())
80
81 def is_lock_holder_known_dead(self):
82
83=== modified file 'breezy/tests/test_lockdir.py'
84--- breezy/tests/test_lockdir.py 2020-02-07 02:14:30 +0000
85+++ breezy/tests/test_lockdir.py 2022-07-07 15:49:09 +0000
86@@ -429,7 +429,7 @@
87 finally:
88 ld1.unlock()
89 self.assertEqual(info_list['user'], u'jrandom@example.com')
90- self.assertContainsRe(info_list['pid'], '^\\d+$')
91+ self.assertIsInstance(info_list['pid'], int)
92 self.assertContainsRe(info_list['time_ago'], '^\\d+ seconds? ago$')
93
94 def test_lock_without_email(self):

Subscribers

People subscribed via source and target branches