2015-02-28 15:25:21 -08:00
|
|
|
import os
|
2015-02-28 14:25:24 -08:00
|
|
|
|
|
|
|
from peru import cache
|
|
|
|
from peru import rule
|
|
|
|
|
|
|
|
import shared
|
2018-07-18 17:06:31 -04:00
|
|
|
from shared import COLON
|
2015-02-28 14:25:24 -08:00
|
|
|
|
|
|
|
|
rewrite the cache to be asynchronous
We've been seeing "Task X took Y seconds" warnings in our tests for a
long time, especially on Windows. Running git commands synchronously
blocks other tasks from running, like display redrawing. It's bad
practice in an async program.
One of the barriers to async-ifying the cache code earlier was that many
commands relied on having exclusive ownership of the index file while
they were running. For example, 1) read a tree into the index, 2) merge
another tree into some subdirectory, 3) write out the result. If any
other git commands ran in the middle of that, it would screw up the
result. So we need to rewrite every cache function to use its own
temporary index file, if we want them to run in parallel.
The reason I'm finally getting around to this now, is that I'm trying to
reduce the number of git commands that run in a no-op sync. One of the
optimizations I'm going to want to do, is to reuse the index file from
the last sync, so that we don't need a `read-tree` and an `update-index`
just to set us up for `diff-files`. But the plumbing to do that right is
pretty much the same as what we should be doing to run every git command
with its own index anyway. So let's just bite the bullet and do that
now, and then reusing index files will be easy after that.
2015-11-21 15:34:29 -05:00
|
|
|
class RuleTest(shared.PeruTest):
|
|
|
|
@shared.make_synchronous
|
2018-10-03 15:01:08 -04:00
|
|
|
async def setUp(self):
|
2015-02-28 14:25:24 -08:00
|
|
|
self.cache_dir = shared.create_dir()
|
2018-10-03 15:01:08 -04:00
|
|
|
self.cache = await cache.Cache(self.cache_dir)
|
2018-07-18 14:28:41 -04:00
|
|
|
# Include a leading colon to test that we prepend ./ to pathspecs.
|
2018-07-18 17:06:31 -04:00
|
|
|
self.content = {'a': 'foo', 'b/c': 'bar', COLON + 'd': 'baz'}
|
2015-02-28 14:25:24 -08:00
|
|
|
self.content_dir = shared.create_dir(self.content)
|
2018-10-03 15:01:08 -04:00
|
|
|
self.content_tree = await self.cache.import_tree(self.content_dir)
|
|
|
|
self.entries = await self.cache.ls_tree(
|
rewrite the cache to be asynchronous
We've been seeing "Task X took Y seconds" warnings in our tests for a
long time, especially on Windows. Running git commands synchronously
blocks other tasks from running, like display redrawing. It's bad
practice in an async program.
One of the barriers to async-ifying the cache code earlier was that many
commands relied on having exclusive ownership of the index file while
they were running. For example, 1) read a tree into the index, 2) merge
another tree into some subdirectory, 3) write out the result. If any
other git commands ran in the middle of that, it would screw up the
result. So we need to rewrite every cache function to use its own
temporary index file, if we want them to run in parallel.
The reason I'm finally getting around to this now, is that I'm trying to
reduce the number of git commands that run in a no-op sync. One of the
optimizations I'm going to want to do, is to reuse the index file from
the last sync, so that we don't need a `read-tree` and an `update-index`
just to set us up for `diff-files`. But the plumbing to do that right is
pretty much the same as what we should be doing to run every git command
with its own index anyway. So let's just bite the bullet and do that
now, and then reusing index files will be easy after that.
2015-11-21 15:34:29 -05:00
|
|
|
self.content_tree, recursive=True)
|
2015-02-28 14:25:24 -08:00
|
|
|
|
rewrite the cache to be asynchronous
We've been seeing "Task X took Y seconds" warnings in our tests for a
long time, especially on Windows. Running git commands synchronously
blocks other tasks from running, like display redrawing. It's bad
practice in an async program.
One of the barriers to async-ifying the cache code earlier was that many
commands relied on having exclusive ownership of the index file while
they were running. For example, 1) read a tree into the index, 2) merge
another tree into some subdirectory, 3) write out the result. If any
other git commands ran in the middle of that, it would screw up the
result. So we need to rewrite every cache function to use its own
temporary index file, if we want them to run in parallel.
The reason I'm finally getting around to this now, is that I'm trying to
reduce the number of git commands that run in a no-op sync. One of the
optimizations I'm going to want to do, is to reuse the index file from
the last sync, so that we don't need a `read-tree` and an `update-index`
just to set us up for `diff-files`. But the plumbing to do that right is
pretty much the same as what we should be doing to run every git command
with its own index anyway. So let's just bite the bullet and do that
now, and then reusing index files will be easy after that.
2015-11-21 15:34:29 -05:00
|
|
|
@shared.make_synchronous
|
2018-10-03 15:01:08 -04:00
|
|
|
async def test_copy(self):
|
2015-02-28 14:25:24 -08:00
|
|
|
# A file copied into a directory should be placed into that directory.
|
|
|
|
# A directory or file copied into a file should overwrite that file.
|
|
|
|
copies = {'a': ['x', 'b', 'b/c'], 'b': ['a', 'y']}
|
2018-10-03 15:10:48 -04:00
|
|
|
tree = await rule.copy_files(self.cache, self.content_tree, copies)
|
|
|
|
await shared.assert_tree_contents(
|
|
|
|
self.cache, tree, {
|
|
|
|
'a/c': 'bar',
|
|
|
|
'b/a': 'foo',
|
|
|
|
'b/c': 'foo',
|
|
|
|
'x': 'foo',
|
|
|
|
'y/c': 'bar',
|
|
|
|
COLON + 'd': 'baz',
|
|
|
|
})
|
2015-02-28 14:25:24 -08:00
|
|
|
|
rewrite the cache to be asynchronous
We've been seeing "Task X took Y seconds" warnings in our tests for a
long time, especially on Windows. Running git commands synchronously
blocks other tasks from running, like display redrawing. It's bad
practice in an async program.
One of the barriers to async-ifying the cache code earlier was that many
commands relied on having exclusive ownership of the index file while
they were running. For example, 1) read a tree into the index, 2) merge
another tree into some subdirectory, 3) write out the result. If any
other git commands ran in the middle of that, it would screw up the
result. So we need to rewrite every cache function to use its own
temporary index file, if we want them to run in parallel.
The reason I'm finally getting around to this now, is that I'm trying to
reduce the number of git commands that run in a no-op sync. One of the
optimizations I'm going to want to do, is to reuse the index file from
the last sync, so that we don't need a `read-tree` and an `update-index`
just to set us up for `diff-files`. But the plumbing to do that right is
pretty much the same as what we should be doing to run every git command
with its own index anyway. So let's just bite the bullet and do that
now, and then reusing index files will be easy after that.
2015-11-21 15:34:29 -05:00
|
|
|
@shared.make_synchronous
|
2018-10-03 15:01:08 -04:00
|
|
|
async def test_move(self):
|
2015-02-28 14:25:24 -08:00
|
|
|
# Same semantics as copy above. Also, make sure that move deletes move
|
|
|
|
# sources, but does not delete sources that were overwritten by the
|
|
|
|
# target of another move.
|
|
|
|
moves = {'a': 'b', 'b': 'a'}
|
2018-10-03 15:01:08 -04:00
|
|
|
tree = await rule.move_files(self.cache, self.content_tree, moves)
|
|
|
|
await shared.assert_tree_contents(self.cache, tree, {
|
2015-02-28 14:25:24 -08:00
|
|
|
'a/c': 'bar',
|
|
|
|
'b/a': 'foo',
|
2018-10-03 15:10:48 -04:00
|
|
|
COLON + 'd': 'baz',
|
2015-02-28 14:25:24 -08:00
|
|
|
})
|
2015-02-28 15:25:21 -08:00
|
|
|
|
2016-04-25 09:27:14 -04:00
|
|
|
@shared.make_synchronous
|
2018-10-03 15:01:08 -04:00
|
|
|
async def test_drop(self):
|
2018-10-03 15:10:48 -04:00
|
|
|
drop_dir = await rule.drop_files(self.cache, self.content_tree, ['b'])
|
|
|
|
await shared.assert_tree_contents(self.cache, drop_dir, {
|
|
|
|
'a': 'foo',
|
|
|
|
COLON + 'd': 'baz'
|
|
|
|
})
|
2016-04-25 09:27:14 -04:00
|
|
|
|
2018-10-03 15:10:48 -04:00
|
|
|
drop_file = await rule.drop_files(self.cache, self.content_tree, ['a'])
|
|
|
|
await shared.assert_tree_contents(self.cache, drop_file, {
|
|
|
|
'b/c': 'bar',
|
|
|
|
COLON + 'd': 'baz'
|
|
|
|
})
|
2018-07-18 14:28:41 -04:00
|
|
|
|
2018-10-03 15:10:48 -04:00
|
|
|
drop_colon = await rule.drop_files(self.cache, self.content_tree,
|
|
|
|
[COLON + 'd'])
|
|
|
|
await shared.assert_tree_contents(self.cache, drop_colon, {
|
|
|
|
'a': 'foo',
|
|
|
|
'b/c': 'bar'
|
|
|
|
})
|
2016-04-25 09:27:14 -04:00
|
|
|
|
2018-10-03 15:10:48 -04:00
|
|
|
globs = await rule.drop_files(self.cache, self.content_tree,
|
|
|
|
['**/c', '**/a'])
|
|
|
|
await shared.assert_tree_contents(self.cache, globs,
|
|
|
|
{COLON + 'd': 'baz'})
|
2016-04-25 09:27:14 -04:00
|
|
|
|
rewrite the cache to be asynchronous
We've been seeing "Task X took Y seconds" warnings in our tests for a
long time, especially on Windows. Running git commands synchronously
blocks other tasks from running, like display redrawing. It's bad
practice in an async program.
One of the barriers to async-ifying the cache code earlier was that many
commands relied on having exclusive ownership of the index file while
they were running. For example, 1) read a tree into the index, 2) merge
another tree into some subdirectory, 3) write out the result. If any
other git commands ran in the middle of that, it would screw up the
result. So we need to rewrite every cache function to use its own
temporary index file, if we want them to run in parallel.
The reason I'm finally getting around to this now, is that I'm trying to
reduce the number of git commands that run in a no-op sync. One of the
optimizations I'm going to want to do, is to reuse the index file from
the last sync, so that we don't need a `read-tree` and an `update-index`
just to set us up for `diff-files`. But the plumbing to do that right is
pretty much the same as what we should be doing to run every git command
with its own index anyway. So let's just bite the bullet and do that
now, and then reusing index files will be easy after that.
2015-11-21 15:34:29 -05:00
|
|
|
@shared.make_synchronous
|
2018-10-03 15:01:08 -04:00
|
|
|
async def test_pick(self):
|
2018-10-03 15:10:48 -04:00
|
|
|
pick_dir = await rule.pick_files(self.cache, self.content_tree, ['b'])
|
|
|
|
await shared.assert_tree_contents(self.cache, pick_dir, {'b/c': 'bar'})
|
|
|
|
|
|
|
|
pick_file = await rule.pick_files(self.cache, self.content_tree, ['a'])
|
|
|
|
await shared.assert_tree_contents(self.cache, pick_file, {'a': 'foo'})
|
|
|
|
|
|
|
|
pick_colon = await rule.pick_files(self.cache, self.content_tree,
|
|
|
|
[COLON + 'd'])
|
|
|
|
await shared.assert_tree_contents(self.cache, pick_colon,
|
|
|
|
{COLON + 'd': 'baz'})
|
|
|
|
|
|
|
|
globs = await rule.pick_files(self.cache, self.content_tree,
|
|
|
|
['**/c', '**/a'])
|
|
|
|
await shared.assert_tree_contents(self.cache, globs, {
|
|
|
|
'a': 'foo',
|
|
|
|
'b/c': 'bar'
|
|
|
|
})
|
2015-02-28 15:25:21 -08:00
|
|
|
|
rewrite the cache to be asynchronous
We've been seeing "Task X took Y seconds" warnings in our tests for a
long time, especially on Windows. Running git commands synchronously
blocks other tasks from running, like display redrawing. It's bad
practice in an async program.
One of the barriers to async-ifying the cache code earlier was that many
commands relied on having exclusive ownership of the index file while
they were running. For example, 1) read a tree into the index, 2) merge
another tree into some subdirectory, 3) write out the result. If any
other git commands ran in the middle of that, it would screw up the
result. So we need to rewrite every cache function to use its own
temporary index file, if we want them to run in parallel.
The reason I'm finally getting around to this now, is that I'm trying to
reduce the number of git commands that run in a no-op sync. One of the
optimizations I'm going to want to do, is to reuse the index file from
the last sync, so that we don't need a `read-tree` and an `update-index`
just to set us up for `diff-files`. But the plumbing to do that right is
pretty much the same as what we should be doing to run every git command
with its own index anyway. So let's just bite the bullet and do that
now, and then reusing index files will be easy after that.
2015-11-21 15:34:29 -05:00
|
|
|
@shared.make_synchronous
|
2018-10-03 15:01:08 -04:00
|
|
|
async def test_executable(self):
|
2018-10-03 15:10:48 -04:00
|
|
|
exe = await rule.make_files_executable(self.cache, self.content_tree,
|
|
|
|
['b/*'])
|
2015-02-28 15:25:21 -08:00
|
|
|
new_content_dir = shared.create_dir()
|
2018-10-03 15:01:08 -04:00
|
|
|
await self.cache.export_tree(exe, new_content_dir)
|
2015-03-28 19:33:55 -04:00
|
|
|
shared.assert_contents(new_content_dir, self.content)
|
|
|
|
shared.assert_not_executable(os.path.join(new_content_dir, 'a'))
|
|
|
|
shared.assert_executable(os.path.join(new_content_dir, 'b/c'))
|
2015-03-03 15:29:09 -08:00
|
|
|
|
rewrite the cache to be asynchronous
We've been seeing "Task X took Y seconds" warnings in our tests for a
long time, especially on Windows. Running git commands synchronously
blocks other tasks from running, like display redrawing. It's bad
practice in an async program.
One of the barriers to async-ifying the cache code earlier was that many
commands relied on having exclusive ownership of the index file while
they were running. For example, 1) read a tree into the index, 2) merge
another tree into some subdirectory, 3) write out the result. If any
other git commands ran in the middle of that, it would screw up the
result. So we need to rewrite every cache function to use its own
temporary index file, if we want them to run in parallel.
The reason I'm finally getting around to this now, is that I'm trying to
reduce the number of git commands that run in a no-op sync. One of the
optimizations I'm going to want to do, is to reuse the index file from
the last sync, so that we don't need a `read-tree` and an `update-index`
just to set us up for `diff-files`. But the plumbing to do that right is
pretty much the same as what we should be doing to run every git command
with its own index anyway. So let's just bite the bullet and do that
now, and then reusing index files will be easy after that.
2015-11-21 15:34:29 -05:00
|
|
|
@shared.make_synchronous
|
2018-10-03 15:01:08 -04:00
|
|
|
async def test_export(self):
|
2018-10-03 15:10:48 -04:00
|
|
|
b = await rule.get_export_tree(self.cache, self.content_tree, 'b')
|
2018-10-03 15:01:08 -04:00
|
|
|
await shared.assert_tree_contents(self.cache, b, {'c': 'bar'})
|