annotate tests/test_pull.py @ 1233:0d0132cba155

editor: fix edge case with in memory file-store size limit There are a few cases where we will set a single file into to the editor's FileStore object more than once. Notably, for copied and then modified files, we will set it at least twice. Three times if editing fails (which it can for symlinks). If we pass the in-memory storage limit in between the first (or second if editing fails) time we set the file and the last time we set the file, we will write the data to the in memory store the first time and the file store the last time. We didn't remove it form the in-memory store though, and we always prefer reading from the in-memory store. This means we can sometimes end up with the wrong version of a file. This is fairly unlikely to happen in normal use since you need to hit the memory limit between two writes to the store for the same file. We only write a file multiple times if a) the file (and not one of it's parent directories) is copied and then modified or b) editing fails. From what I can tell, it's only common for editing to fail for symlinks, and they ten to be relatively small data that is unlikely to push over the limit. Finally, the default limit is 100MB which I would expect to be most often either well over (source code) or well under (binaries or automated changes) the size of the changes files in a single commit. The easiest way to reproduce this is to set the in-memory cache size to 0 and then commit a copied and modified symlink. The empty-string version from the failed editing will be the one that persists. I happened to stumble upon this while trying (and failing) to test a bug-fix for a related bug with identical symptoms (empty simlink). I have seen this in the wild, once, but couldn't reproduce it at the time. The repo in question is quite large and quite active, so I am quite confident in my estimation that this is a real, but very rare, problem. The test changes attached to this was mneant to test a related bug, but turned out not to actually cover the bug in question. They did trigger this bug though, and are worthwhile to test, so I kept them.
author David Schleimer <dschleimer@fb.com>
date Mon, 07 Apr 2014 17:51:59 -0700
parents 61d4fb78370b
children 74e82a7da393
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
283
521d9c1bb11d Implement -u/--update support when pulling.
Martijn Pieters <mj@zopatista.com>
parents:
diff changeset
1 import test_util
521d9c1bb11d Implement -u/--update support when pulling.
Martijn Pieters <mj@zopatista.com>
parents:
diff changeset
2
521d9c1bb11d Implement -u/--update support when pulling.
Martijn Pieters <mj@zopatista.com>
parents:
diff changeset
3 import os.path
521d9c1bb11d Implement -u/--update support when pulling.
Martijn Pieters <mj@zopatista.com>
parents:
diff changeset
4 import subprocess
821
f28e0f54a6ef svnmeta: store youngest revision pulled from subversion
Augie Fackler <durin42@gmail.com>
parents: 812
diff changeset
5 from mercurial import node
283
521d9c1bb11d Implement -u/--update support when pulling.
Martijn Pieters <mj@zopatista.com>
parents:
diff changeset
6 from mercurial import ui
331
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 283
diff changeset
7 from mercurial import util as hgutil
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 283
diff changeset
8 from mercurial import commands
908
c4ee11a5d04c pull: add a hgsubversion.unsafeskip option to omit unwanted revs
Bryan O'Sullivan <bryano@fb.com>
parents: 868
diff changeset
9 from hgsubversion import verify
283
521d9c1bb11d Implement -u/--update support when pulling.
Martijn Pieters <mj@zopatista.com>
parents:
diff changeset
10
521d9c1bb11d Implement -u/--update support when pulling.
Martijn Pieters <mj@zopatista.com>
parents:
diff changeset
11 class TestPull(test_util.TestBase):
521d9c1bb11d Implement -u/--update support when pulling.
Martijn Pieters <mj@zopatista.com>
parents:
diff changeset
12 def setUp(self):
521d9c1bb11d Implement -u/--update support when pulling.
Martijn Pieters <mj@zopatista.com>
parents:
diff changeset
13 super(TestPull, self).setUp()
521d9c1bb11d Implement -u/--update support when pulling.
Martijn Pieters <mj@zopatista.com>
parents:
diff changeset
14
908
c4ee11a5d04c pull: add a hgsubversion.unsafeskip option to omit unwanted revs
Bryan O'Sullivan <bryano@fb.com>
parents: 868
diff changeset
15 def _loadupdate(self, fixture_name, *args, **kwargs):
c4ee11a5d04c pull: add a hgsubversion.unsafeskip option to omit unwanted revs
Bryan O'Sullivan <bryano@fb.com>
parents: 868
diff changeset
16 kwargs = kwargs.copy()
1068
cd35f6739669 test_pull: use stupid mode metaclass
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 1044
diff changeset
17 kwargs.update(noupdate=False)
908
c4ee11a5d04c pull: add a hgsubversion.unsafeskip option to omit unwanted revs
Bryan O'Sullivan <bryano@fb.com>
parents: 868
diff changeset
18 repo, repo_path = self.load_and_fetch(fixture_name, *args, **kwargs)
868
cc1c870f1758 test_util: pass repo_path to _add_svn_rev() explicitely
Patrick Mezard <patrick@mezard.eu>
parents: 865
diff changeset
19 return repo, repo_path
283
521d9c1bb11d Implement -u/--update support when pulling.
Martijn Pieters <mj@zopatista.com>
parents:
diff changeset
20
521d9c1bb11d Implement -u/--update support when pulling.
Martijn Pieters <mj@zopatista.com>
parents:
diff changeset
21 def test_nochanges(self):
865
04729f3a3d17 test_util: merge load_fixture_and_fetch() into TestBase method
Patrick Mezard <patrick@mezard.eu>
parents: 821
diff changeset
22 self._loadupdate('single_rev.svndump')
331
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 283
diff changeset
23 state = self.repo.parents()
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 283
diff changeset
24 commands.pull(self.repo.ui, self.repo)
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 283
diff changeset
25 self.assertEqual(state, self.repo.parents())
283
521d9c1bb11d Implement -u/--update support when pulling.
Martijn Pieters <mj@zopatista.com>
parents:
diff changeset
26
521d9c1bb11d Implement -u/--update support when pulling.
Martijn Pieters <mj@zopatista.com>
parents:
diff changeset
27 def test_onerevision_noupdate(self):
868
cc1c870f1758 test_util: pass repo_path to _add_svn_rev() explicitely
Patrick Mezard <patrick@mezard.eu>
parents: 865
diff changeset
28 repo, repo_path = self._loadupdate('single_rev.svndump')
283
521d9c1bb11d Implement -u/--update support when pulling.
Martijn Pieters <mj@zopatista.com>
parents:
diff changeset
29 state = repo.parents()
868
cc1c870f1758 test_util: pass repo_path to _add_svn_rev() explicitely
Patrick Mezard <patrick@mezard.eu>
parents: 865
diff changeset
30 self.add_svn_rev(repo_path, {'trunk/alpha': 'Changed'})
331
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 283
diff changeset
31 commands.pull(self.repo.ui, repo)
283
521d9c1bb11d Implement -u/--update support when pulling.
Martijn Pieters <mj@zopatista.com>
parents:
diff changeset
32 self.assertEqual(state, repo.parents())
521d9c1bb11d Implement -u/--update support when pulling.
Martijn Pieters <mj@zopatista.com>
parents:
diff changeset
33 self.assertTrue('tip' not in repo[None].tags())
808
b64173a27ce8 test_pull: clean up whitespace
Augie Fackler <durin42@gmail.com>
parents: 689
diff changeset
34
283
521d9c1bb11d Implement -u/--update support when pulling.
Martijn Pieters <mj@zopatista.com>
parents:
diff changeset
35 def test_onerevision_doupdate(self):
868
cc1c870f1758 test_util: pass repo_path to _add_svn_rev() explicitely
Patrick Mezard <patrick@mezard.eu>
parents: 865
diff changeset
36 repo, repo_path = self._loadupdate('single_rev.svndump')
283
521d9c1bb11d Implement -u/--update support when pulling.
Martijn Pieters <mj@zopatista.com>
parents:
diff changeset
37 state = repo.parents()
868
cc1c870f1758 test_util: pass repo_path to _add_svn_rev() explicitely
Patrick Mezard <patrick@mezard.eu>
parents: 865
diff changeset
38 self.add_svn_rev(repo_path, {'trunk/alpha': 'Changed'})
331
75f082b5897e Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 283
diff changeset
39 commands.pull(self.repo.ui, repo, update=True)
283
521d9c1bb11d Implement -u/--update support when pulling.
Martijn Pieters <mj@zopatista.com>
parents:
diff changeset
40 self.failIfEqual(state, repo.parents())
521d9c1bb11d Implement -u/--update support when pulling.
Martijn Pieters <mj@zopatista.com>
parents:
diff changeset
41 self.assertTrue('tip' in repo[None].tags())
521d9c1bb11d Implement -u/--update support when pulling.
Martijn Pieters <mj@zopatista.com>
parents:
diff changeset
42
521d9c1bb11d Implement -u/--update support when pulling.
Martijn Pieters <mj@zopatista.com>
parents:
diff changeset
43 def test_onerevision_divergent(self):
868
cc1c870f1758 test_util: pass repo_path to _add_svn_rev() explicitely
Patrick Mezard <patrick@mezard.eu>
parents: 865
diff changeset
44 repo, repo_path = self._loadupdate('single_rev.svndump')
283
521d9c1bb11d Implement -u/--update support when pulling.
Martijn Pieters <mj@zopatista.com>
parents:
diff changeset
45 self.commitchanges((('alpha', 'alpha', 'Changed another way'),))
521d9c1bb11d Implement -u/--update support when pulling.
Martijn Pieters <mj@zopatista.com>
parents:
diff changeset
46 state = repo.parents()
868
cc1c870f1758 test_util: pass repo_path to _add_svn_rev() explicitely
Patrick Mezard <patrick@mezard.eu>
parents: 865
diff changeset
47 self.add_svn_rev(repo_path, {'trunk/alpha': 'Changed one way'})
812
8c7447b4b004 test_pull: commands.pull() no longer aborts when crossing branches
Patrick Mezard <pmezard@gmail.com>
parents: 808
diff changeset
48 try:
8c7447b4b004 test_pull: commands.pull() no longer aborts when crossing branches
Patrick Mezard <pmezard@gmail.com>
parents: 808
diff changeset
49 commands.pull(self.repo.ui, repo, update=True)
8c7447b4b004 test_pull: commands.pull() no longer aborts when crossing branches
Patrick Mezard <pmezard@gmail.com>
parents: 808
diff changeset
50 except hgutil.Abort:
8c7447b4b004 test_pull: commands.pull() no longer aborts when crossing branches
Patrick Mezard <pmezard@gmail.com>
parents: 808
diff changeset
51 # hg < 1.9 raised when crossing branches
8c7447b4b004 test_pull: commands.pull() no longer aborts when crossing branches
Patrick Mezard <pmezard@gmail.com>
parents: 808
diff changeset
52 pass
283
521d9c1bb11d Implement -u/--update support when pulling.
Martijn Pieters <mj@zopatista.com>
parents:
diff changeset
53 self.assertEqual(state, repo.parents())
521d9c1bb11d Implement -u/--update support when pulling.
Martijn Pieters <mj@zopatista.com>
parents:
diff changeset
54 self.assertTrue('tip' not in repo[None].tags())
521d9c1bb11d Implement -u/--update support when pulling.
Martijn Pieters <mj@zopatista.com>
parents:
diff changeset
55 self.assertEqual(len(repo.heads()), 2)
521d9c1bb11d Implement -u/--update support when pulling.
Martijn Pieters <mj@zopatista.com>
parents:
diff changeset
56
821
f28e0f54a6ef svnmeta: store youngest revision pulled from subversion
Augie Fackler <durin42@gmail.com>
parents: 812
diff changeset
57 def test_tag_repull_doesnt_happen(self):
868
cc1c870f1758 test_util: pass repo_path to _add_svn_rev() explicitely
Patrick Mezard <patrick@mezard.eu>
parents: 865
diff changeset
58 repo = self._loadupdate('branchtagcollision.svndump')[0]
821
f28e0f54a6ef svnmeta: store youngest revision pulled from subversion
Augie Fackler <durin42@gmail.com>
parents: 812
diff changeset
59 oldheads = map(node.hex, repo.heads())
f28e0f54a6ef svnmeta: store youngest revision pulled from subversion
Augie Fackler <durin42@gmail.com>
parents: 812
diff changeset
60 commands.pull(repo.ui, repo)
f28e0f54a6ef svnmeta: store youngest revision pulled from subversion
Augie Fackler <durin42@gmail.com>
parents: 812
diff changeset
61 self.assertEqual(oldheads, map(node.hex, repo.heads()))
f28e0f54a6ef svnmeta: store youngest revision pulled from subversion
Augie Fackler <durin42@gmail.com>
parents: 812
diff changeset
62
1170
61d4fb78370b pull: fix pull when phases.new-commit=secret
Augie Fackler <raf@durin42.com>
parents: 1068
diff changeset
63 def test_pull_with_secret_default(self):
61d4fb78370b pull: fix pull when phases.new-commit=secret
Augie Fackler <raf@durin42.com>
parents: 1068
diff changeset
64 repo = self._loadupdate('branchtagcollision.svndump',
61d4fb78370b pull: fix pull when phases.new-commit=secret
Augie Fackler <raf@durin42.com>
parents: 1068
diff changeset
65 config={'phases.new-commit': 'secret'})[0]
61d4fb78370b pull: fix pull when phases.new-commit=secret
Augie Fackler <raf@durin42.com>
parents: 1068
diff changeset
66 oldheads = map(node.hex, repo.heads())
61d4fb78370b pull: fix pull when phases.new-commit=secret
Augie Fackler <raf@durin42.com>
parents: 1068
diff changeset
67 commands.pull(repo.ui, repo)
61d4fb78370b pull: fix pull when phases.new-commit=secret
Augie Fackler <raf@durin42.com>
parents: 1068
diff changeset
68 self.assertEqual(oldheads, map(node.hex, repo.heads()))
61d4fb78370b pull: fix pull when phases.new-commit=secret
Augie Fackler <raf@durin42.com>
parents: 1068
diff changeset
69
908
c4ee11a5d04c pull: add a hgsubversion.unsafeskip option to omit unwanted revs
Bryan O'Sullivan <bryano@fb.com>
parents: 868
diff changeset
70 def test_skip_basic(self):
c4ee11a5d04c pull: add a hgsubversion.unsafeskip option to omit unwanted revs
Bryan O'Sullivan <bryano@fb.com>
parents: 868
diff changeset
71 repo, repo_path = self._loadupdate('single_rev.svndump')
c4ee11a5d04c pull: add a hgsubversion.unsafeskip option to omit unwanted revs
Bryan O'Sullivan <bryano@fb.com>
parents: 868
diff changeset
72 self.add_svn_rev(repo_path, {'trunk/alpha': 'Changed'})
c4ee11a5d04c pull: add a hgsubversion.unsafeskip option to omit unwanted revs
Bryan O'Sullivan <bryano@fb.com>
parents: 868
diff changeset
73 self.add_svn_rev(repo_path, {'trunk/beta': 'More changed'})
c4ee11a5d04c pull: add a hgsubversion.unsafeskip option to omit unwanted revs
Bryan O'Sullivan <bryano@fb.com>
parents: 868
diff changeset
74 self.add_svn_rev(repo_path, {'trunk/gamma': 'Even more changeder'})
c4ee11a5d04c pull: add a hgsubversion.unsafeskip option to omit unwanted revs
Bryan O'Sullivan <bryano@fb.com>
parents: 868
diff changeset
75 repo.ui.setconfig('hgsubversion', 'unsafeskip', '3 4')
c4ee11a5d04c pull: add a hgsubversion.unsafeskip option to omit unwanted revs
Bryan O'Sullivan <bryano@fb.com>
parents: 868
diff changeset
76 commands.pull(repo.ui, repo)
c4ee11a5d04c pull: add a hgsubversion.unsafeskip option to omit unwanted revs
Bryan O'Sullivan <bryano@fb.com>
parents: 868
diff changeset
77 tip = repo['tip'].rev()
c4ee11a5d04c pull: add a hgsubversion.unsafeskip option to omit unwanted revs
Bryan O'Sullivan <bryano@fb.com>
parents: 868
diff changeset
78 self.assertEqual(tip, 1)
c4ee11a5d04c pull: add a hgsubversion.unsafeskip option to omit unwanted revs
Bryan O'Sullivan <bryano@fb.com>
parents: 868
diff changeset
79 self.assertEquals(verify.verify(repo.ui, repo, rev=tip), 1)
c4ee11a5d04c pull: add a hgsubversion.unsafeskip option to omit unwanted revs
Bryan O'Sullivan <bryano@fb.com>
parents: 868
diff changeset
80
c4ee11a5d04c pull: add a hgsubversion.unsafeskip option to omit unwanted revs
Bryan O'Sullivan <bryano@fb.com>
parents: 868
diff changeset
81 def test_skip_delete_restore(self):
c4ee11a5d04c pull: add a hgsubversion.unsafeskip option to omit unwanted revs
Bryan O'Sullivan <bryano@fb.com>
parents: 868
diff changeset
82 repo, repo_path = self._loadupdate('delete_restore_trunk.svndump',
c4ee11a5d04c pull: add a hgsubversion.unsafeskip option to omit unwanted revs
Bryan O'Sullivan <bryano@fb.com>
parents: 868
diff changeset
83 rev=2)
c4ee11a5d04c pull: add a hgsubversion.unsafeskip option to omit unwanted revs
Bryan O'Sullivan <bryano@fb.com>
parents: 868
diff changeset
84 repo.ui.setconfig('hgsubversion', 'unsafeskip', '3 4')
c4ee11a5d04c pull: add a hgsubversion.unsafeskip option to omit unwanted revs
Bryan O'Sullivan <bryano@fb.com>
parents: 868
diff changeset
85 commands.pull(repo.ui, repo)
c4ee11a5d04c pull: add a hgsubversion.unsafeskip option to omit unwanted revs
Bryan O'Sullivan <bryano@fb.com>
parents: 868
diff changeset
86 tip = repo['tip'].rev()
c4ee11a5d04c pull: add a hgsubversion.unsafeskip option to omit unwanted revs
Bryan O'Sullivan <bryano@fb.com>
parents: 868
diff changeset
87 self.assertEqual(tip, 1)
c4ee11a5d04c pull: add a hgsubversion.unsafeskip option to omit unwanted revs
Bryan O'Sullivan <bryano@fb.com>
parents: 868
diff changeset
88 self.assertEquals(verify.verify(repo.ui, repo, rev=tip), 0)