~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to shelf.py

  • Committer: Michael Ellerman
  • Date: 2006-02-11 03:58:56 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-20060211035856-90f2c7c3784f4998
Add shelf command with subcommand "list" which lists the shelf contents.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
            if not os.path.isdir(dir):
23
23
                os.mkdir(dir)
24
24
 
 
25
    def log(self, msg):
 
26
        print >>sys.stderr, msg
 
27
 
 
28
    def list(self):
 
29
        self.log("Patches on shelf '%s':" % self.name)
 
30
        for patch in self.__list():
 
31
            msg = self.get_patch_message(self.__path(patch))
 
32
            if msg is None:
 
33
                msg = "No message saved with patch."
 
34
            self.log(' %.2d: %s' % (patch, msg))
 
35
 
25
36
    def __path(self, idx):
26
37
        return os.path.join(self.shelf_dir, '%.2d' % idx)
27
38
 
33
44
                return name
34
45
            index += 1
35
46
 
36
 
    def last_patch(self):
 
47
    def __list(self):
37
48
        patches = os.listdir(self.shelf_dir)
38
49
        patches = [int(f) for f in patches]
39
50
        patches.sort()
 
51
        return patches
 
52
 
 
53
    def last_patch(self):
 
54
        patches = self.__list()
40
55
 
41
56
        if len(patches) == 0:
42
57
            return None
43
58
 
44
59
        return self.__path(patches[-1])
45
60
 
46
 
    def get_patch_message(self, patch):
 
61
    def get_patch_message(self, patch_path):
 
62
        patch = open(patch_path, 'r').read()
 
63
 
47
64
        if not patch.startswith(self.MESSAGE_PREFIX):
48
65
            return None
49
66
        return patch[len(self.MESSAGE_PREFIX):patch.index('\n')]
73
90
            raise CommandError('Nothing to unshelve')
74
91
 
75
92
        print >>sys.stderr, "Reapplying shelved patches",
76
 
        message = self.get_patch_message(open(patch_name, 'r').read())
 
93
        message = self.get_patch_message(patch_name)
77
94
        if message is not None:
78
95
            print >>sys.stderr, '"%s"' % message
79
96
        else: