~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to shelf.py

  • Committer: Michael Ellerman
  • Date: 2006-02-06 13:52:53 UTC
  • mto: (0.1.73 shelf-tmp)
  • mto: This revision was merged to the branch mainline in revision 334.
  • Revision ID: michael@ellerman.id.au-20060206135253-46d07a6db0239dbb
For the moment at least storing scads of stuff under .bzr isn't really
supported by the bzr API, so move the shelf back out of .bzr into .shelf.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
import os
4
4
import sys
5
5
from bzrlib.commands import Command
6
 
from bzrlib.branch import Branch
7
6
from bzrlib.errors import BzrCommandError
8
7
from hunk_selector import ShelveHunkSelector, UnshelveHunkSelector
9
8
from diffstat import DiffStat
10
9
from patchsource import PatchSource, FilePatchSource
11
10
 
 
11
BASE_DIR = '.shelf'
 
12
 
12
13
class Shelf(object):
13
 
    def __init__(self, location, name='default'):
14
 
        self.branch = Branch.open_containing(location)[0]
15
 
        base = self.branch.controlfilename('x-shelf')
16
 
        self.shelf_dir = os.path.join(base, name)
 
14
    def __init__(self, base, name='default'):
 
15
        self.base = base
 
16
        shelf_base = os.path.join(self.base, BASE_DIR)
 
17
        self.shelf_dir = os.path.join(shelf_base, name)
17
18
 
18
 
        # FIXME surely there's an easier way to do this?
19
 
        t = self.branch._transport
20
 
        for dir in [base, self.shelf_dir]:
21
 
            if not t.has(dir):
22
 
                t.mkdir(dir)
 
19
        for dir in [shelf_base, self.shelf_dir]:
 
20
            if not os.path.isdir(dir):
 
21
                os.mkdir(dir)
23
22
 
24
23
    def __path(self, idx):
25
24
        return os.path.join(self.shelf_dir, '%.2d' % idx)
57
56
        shelf = self.last_shelf()
58
57
 
59
58
        if shelf is None:
60
 
            raise BzrCommandError("No shelf found in branch '%s'" % \
61
 
                self.branch.base)
 
59
            raise BzrCommandError("No shelf found in '%s'" % self.base)
62
60
 
63
61
        patches = FilePatchSource(shelf).readpatches()
64
62
        if pick_hunks:
77
75
        else:
78
76
            print >>sys.stderr, ""
79
77
 
80
 
        pipe = os.popen('patch -d %s -s -p0' % self.branch.base, 'w')
 
78
        pipe = os.popen('patch -d %s -s -p0' % self.base, 'w')
81
79
        for patch in to_unshelve:
82
80
            pipe.write(str(patch))
83
81
        pipe.flush()
120
118
        shelf.close()
121
119
 
122
120
        print >>sys.stderr, "Reverting shelved patches"
123
 
        pipe = os.popen('patch -d %s -sR -p0' % self.branch.base, 'w')
 
121
        pipe = os.popen('patch -d %s -sR -p0' % self.base, 'w')
124
122
        for patch in to_shelve:
125
123
            pipe.write(str(patch))
126
124
        pipe.flush()