~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to prepare_shelf.py

  • Committer: Aaron Bentley
  • Date: 2008-10-05 18:13:52 UTC
  • mto: (0.15.1 unshelve)
  • mto: This revision was merged to the branch mainline in revision 3820.
  • Revision ID: aaron@aaronbentley.com-20081005181352-dyz7x2ssg08yri3n
Implement shelf creator

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2008 Aaron Bentley <aaron@aaronbentley.com>
 
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
 
 
17
 
 
18
from bzrlib import transform
 
19
 
 
20
 
 
21
class ShelfCreator(object):
 
22
 
 
23
    def __init__(self, work_tree):
 
24
        self.work_tree = work_tree
 
25
        self.work_transform = transform.TreeTransform(work_tree)
 
26
        self.base_tree = work_tree.basis_tree()
 
27
        self.shelf_transform = transform.TransformPreview(self.base_tree)
 
28
        self.renames = {}
 
29
        self.iter_changes = work_tree.iter_changes(self.base_tree)
 
30
 
 
31
    def __iter__(self):
 
32
        for (file_id, paths, changed, versioned, parents, names, kind,
 
33
             executable) in self.iter_changes:
 
34
            if names[0] != names[1] or parents[0] != parents[1]:
 
35
                self.renames[file_id] = (names, parents)
 
36
                yield ('rename', file_id) + paths
 
37
 
 
38
    def shelve_rename(self, file_id):
 
39
        names, parents = self.renames[file_id]
 
40
        w_trans_id = self.work_transform.trans_id_file_id(file_id)
 
41
        work_parent = self.work_transform.trans_id_file_id(parents[0])
 
42
        self.work_transform.adjust_path(names[0], work_parent, w_trans_id)
 
43
 
 
44
        s_trans_id = self.shelf_transform.trans_id_file_id(file_id)
 
45
        shelf_parent = self.shelf_transform.trans_id_file_id(parents[1])
 
46
        self.shelf_transform.adjust_path(names[1], shelf_parent, s_trans_id)
 
47
 
 
48
    def finalize(self):
 
49
        self.work_transform.finalize()
 
50
        self.shelf_transform.finalize()