/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/fetch_ghosts.py

  • Committer: Gustav Hartvigsson
  • Date: 2021-01-09 21:36:27 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20210109213627-h1xwcutzy9m7a99b
Added 'Case Preserving Working Tree Use Cases' from Canonical Wiki

* Addod a page from the Canonical Bazaar wiki
  with information on the scmeatics of case
  perserving filesystems an a case insensitive
  filesystem works.
  
  * Needs re-work, but this will do as it is the
    same inforamoton as what was on the linked
    page in the currint documentation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2005 by Aaron Bentley
 
2
 
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; either version 2 of the License, or
 
6
# (at your option) any later version.
 
7
#
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
 
 
17
import contextlib
 
18
 
 
19
from .branch import Branch
 
20
from .trace import note
 
21
from .errors import NoSuchRevision, CommandError
 
22
 
 
23
 
 
24
class GhostFetcher(object):
 
25
 
 
26
    @classmethod
 
27
    def from_cmdline(cls, other):
 
28
        this_branch = Branch.open_containing('.')[0]
 
29
        if other is None:
 
30
            other = this_branch.get_parent()
 
31
            if other is None:
 
32
                raise CommandError('No branch specified and no location'
 
33
                                      ' saved.')
 
34
            else:
 
35
                note("Using saved location %s.", other)
 
36
        other_branch = Branch.open_containing(other)[0]
 
37
        return cls(this_branch, other_branch)
 
38
 
 
39
    def __init__(self, this_branch, other_branch):
 
40
        self.this_branch = this_branch
 
41
        self.other_branch = other_branch
 
42
 
 
43
    def run(self):
 
44
        lock_other = self.this_branch.base != self.other_branch.base
 
45
        with contextlib.ExitStack() as exit_stack:
 
46
            exit_stack.enter_context(self.this_branch.lock_write())
 
47
            if lock_other:
 
48
                exit_stack.enter_context(self.other_branch.lock_read())
 
49
            return self._run_locked()
 
50
 
 
51
    def iter_ghosts(self):
 
52
        """Find all ancestors that aren't stored in this branch."""
 
53
        seen = set()
 
54
        lines = [self.this_branch.last_revision()]
 
55
        if lines[0] is None:
 
56
            return
 
57
        while len(lines) > 0:
 
58
            new_lines = []
 
59
            for line in lines:
 
60
                if line in seen:
 
61
                    continue
 
62
                seen.add(line)
 
63
                try:
 
64
                    revision = self.this_branch.repository.get_revision(line)
 
65
                    new_lines.extend(revision.parent_ids)
 
66
                except NoSuchRevision:
 
67
                    yield line
 
68
            lines = new_lines
 
69
 
 
70
    def _run_locked(self):
 
71
        installed = []
 
72
        failed = []
 
73
        if self.this_branch.last_revision() is None:
 
74
            print("No revisions in branch.")
 
75
            return
 
76
        # Because iter_ghosts tests for existence after our last fetch
 
77
        # is complete, it won't falsely report an ancestor as a ghost.
 
78
        # Yay iterators!
 
79
        ghosts = self.iter_ghosts()
 
80
        for revision in ghosts:
 
81
            try:
 
82
                self.this_branch.fetch(self.other_branch, revision)
 
83
                installed.append(revision)
 
84
            except NoSuchRevision:
 
85
                failed.append(revision)
 
86
        return installed, failed