Merge lp:~cjwatson/turnip/enable-reflog into lp:turnip

Proposed by Colin Watson on 2015-05-01
Status: Merged
Merged at revision: 156
Proposed branch: lp:~cjwatson/turnip/enable-reflog
Merge into: lp:turnip
Diff against target: 116 lines (+60/-2)
3 files modified
turnip/pack/git.py (+4/-2)
turnip/pack/helpers.py (+13/-0)
turnip/pack/tests/test_helpers.py (+43/-0)
To merge this branch: bzr merge lp:~cjwatson/turnip/enable-reflog
Reviewer Review Type Date Requested Status
William Grant code 2015-05-01 Approve on 2015-05-06
Review via email: mp+258084@code.launchpad.net

Commit Message

Set core.logallrefupdates to true before any write operation.

Description of the Change

Set core.logallrefupdates to true before any write operation.

To post a comment you must log in.
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'turnip/pack/git.py'
2--- turnip/pack/git.py 2015-04-14 16:41:23 +0000
3+++ turnip/pack/git.py 2015-05-01 21:20:57 +0000
4@@ -25,6 +25,7 @@
5 decode_request,
6 encode_packet,
7 encode_request,
8+ ensure_config,
9 ensure_hooks,
10 INCOMPLETE_PKT,
11 )
12@@ -330,8 +331,9 @@
13
14 env = {}
15 if subcmd == b'receive-pack' and self.factory.hookrpc_handler:
16- # This is a write operation, so prepare hooks, the hook RPC
17- # server, and the environment variables that link them up.
18+ # This is a write operation, so prepare config, hooks, the hook
19+ # RPC server, and the environment variables that link them up.
20+ ensure_config(path)
21 self.hookrpc_key = str(uuid.uuid4())
22 self.factory.hookrpc_handler.registerKey(
23 self.hookrpc_key, raw_pathname, [])
24
25=== modified file 'turnip/pack/helpers.py'
26--- turnip/pack/helpers.py 2015-04-26 15:44:21 +0000
27+++ turnip/pack/helpers.py 2015-05-01 21:20:57 +0000
28@@ -13,6 +13,8 @@
29 NamedTemporaryFile,
30 )
31
32+from pygit2 import Repository
33+
34 import turnip.pack.hooks
35
36
37@@ -96,6 +98,17 @@
38 return command + b' ' + b'\0'.join(bits) + b'\0'
39
40
41+def ensure_config(repo_root):
42+ """Put a repository's configuration into the desired state.
43+
44+ pygit2.Config handles locking itself, so we don't need to think too hard
45+ about concurrency.
46+ """
47+
48+ config = Repository(repo_root).config
49+ config['core.logallrefupdates'] = True
50+
51+
52 def ensure_hooks(repo_root):
53 """Put a repository's hooks into the desired state.
54
55
56=== modified file 'turnip/pack/tests/test_helpers.py'
57--- turnip/pack/tests/test_helpers.py 2015-04-26 15:44:21 +0000
58+++ turnip/pack/tests/test_helpers.py 2015-05-01 21:20:57 +0000
59@@ -7,8 +7,14 @@
60 import hashlib
61 import os.path
62 import stat
63+from textwrap import dedent
64+import time
65
66 from fixtures import TempDir
67+from pygit2 import (
68+ Config,
69+ init_repository,
70+ )
71 from testtools import TestCase
72
73 from turnip.pack import helpers
74@@ -161,6 +167,43 @@
75 b'Metacharacter in arguments')
76
77
78+class TestEnsureConfig(TestCase):
79+ """Test repository configuration maintenance."""
80+
81+ def setUp(self):
82+ super(TestEnsureConfig, self).setUp()
83+ self.repo_dir = self.useFixture(TempDir()).path
84+ init_repository(self.repo_dir, bare=True)
85+ self.config_path = os.path.join(self.repo_dir, 'config')
86+
87+ def assertWritesCorrectConfig(self):
88+ helpers.ensure_config(self.repo_dir)
89+ config = Config(path=self.config_path)
90+ self.assertTrue(config['core.logallrefupdates'])
91+
92+ def test_writes_new(self):
93+ self.assertWritesCorrectConfig()
94+
95+ def test_preserves_existing(self):
96+ # If the configuration file is already in the correct state, then
97+ # the file is left unchanged; for efficiency we do not even write
98+ # out a new file. (Currently, pygit2/libgit2 take care of this; if
99+ # they ever stop doing so then we should take extra care ourselves.)
100+ helpers.ensure_config(self.repo_dir)
101+ now = time.time()
102+ os.utime(self.config_path, (now - 60, now - 60))
103+ self.assertWritesCorrectConfig()
104+ self.assertEqual(now - 60, os.stat(self.config_path).st_mtime)
105+
106+ def test_fixes_incorrect(self):
107+ with open(self.config_path, 'w') as f:
108+ f.write(dedent("""\
109+ [core]
110+ \tlogallrefupdates = false
111+ """))
112+ self.assertWritesCorrectConfig()
113+
114+
115 class TestEnsureHooks(TestCase):
116 """Test repository hook maintenance."""
117

Subscribers

People subscribed via source and target branches

to all changes: