~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to shelf.py

  • Committer: Aaron Bentley
  • Date: 2005-10-27 04:45:06 UTC
  • Revision ID: aaron.bentley@utoronto.ca-20051027044506-45f616c07537a1da
Got the shell basics working properly

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
    pass
19
19
 
20
20
class Shelf(object):
21
 
    def __init__(self, location, name='default'):
 
21
    def __init__(self, location):
22
22
        self.branch = Branch.open_containing(location)[0]
23
 
        base = self.branch.controlfilename('x-shelf')
24
 
        self.shelf_dir = os.path.join(base, name)
25
 
 
26
 
        # FIXME surely there's an easier way to do this?
27
 
        t = self.branch._transport
28
 
        for dir in [base, self.shelf_dir]:
29
 
            if not t.has(dir):
30
 
                t.mkdir(dir)
31
 
 
32
 
    def __path(self, idx):
33
 
        return os.path.join(self.shelf_dir, '%.2d' % idx)
 
23
 
 
24
    def shelf_suffix(self, index):
 
25
        if index == 0:
 
26
            return ""
 
27
        else:
 
28
            return "-%d" % index
34
29
 
35
30
    def next_shelf(self):
36
 
        index = 0
37
 
        while True:
38
 
            name = self.__path(index)
 
31
        def name_sequence():
 
32
            i = 0
 
33
            while True:
 
34
                yield self.shelf_suffix(i)
 
35
                i = i + 1
 
36
 
 
37
        stem = os.path.join(self.branch.base, '.bzr-shelf')
 
38
        for end in name_sequence():
 
39
            name = stem + end
39
40
            if not os.path.exists(name):
40
41
                return name
41
 
            index += 1
42
42
 
43
43
    def last_shelf(self):
44
 
        shelves = os.listdir(self.shelf_dir)
45
 
        indexes = [int(f) for f in shelves]
46
 
        indexes.sort()
 
44
        stem = os.path.join(self.branch.base, '.bzr-shelf')
 
45
        shelves = glob.glob(stem)
 
46
        shelves.extend(glob.glob(stem + '-*'))
 
47
        def shelf_index(name):
 
48
            if name == stem:
 
49
                return 0
 
50
            return int(name[len(stem)+1:])
 
51
        shelvenums = [shelf_index(f) for f in shelves]
 
52
        shelvenums.sort()
47
53
 
48
 
        if len(indexes) == 0:
 
54
        if len(shelvenums) == 0:
49
55
            return None
50
 
 
51
 
        return self.__path(indexes[-1])
 
56
        return stem + self.shelf_suffix(shelvenums[-1])
52
57
 
53
58
    def get_shelf_message(self, shelf):
54
59
        prefix = "# shelf: "
92
97
        out.seek(0)
93
98
        return out.readlines()
94
99
 
95
 
    def shelve(self, pick_hunks=False, message=None, revision=None,
 
100
    def shelve(self, all_hunks=False, message=None, revision=None,
96
101
             file_list=None):
97
102
        patches = parse_patches(self.get_patches(revision, file_list))
98
103
 
99
 
        if pick_hunks:
 
104
        if not all_hunks:
100
105
            try:
101
106
                patches = HunkSelector(patches).select()
102
107
            except QuitException: