Mercurial > python-hglib
comparison hglib/client.py @ 51:c52383a550fb
client: add summary command
author | Idan Kamara <idankk86@gmail.com> |
---|---|
date | Thu, 18 Aug 2011 16:23:43 +0300 |
parents | bd7dfd94b0d9 |
children | 18f72b255553 |
comparison
equal
deleted
inserted
replaced
50:bd7dfd94b0d9 | 51:c52383a550fb |
---|---|
638 name, rev = line.rsplit(' ', 1) | 638 name, rev = line.rsplit(' ', 1) |
639 rev, node = rev.split(':') | 639 rev, node = rev.split(':') |
640 t.append((name.rstrip(), int(rev), node, taglocal)) | 640 t.append((name.rstrip(), int(rev), node, taglocal)) |
641 return t | 641 return t |
642 | 642 |
643 def summary(self, remote=False): | |
644 """ | |
645 Return a dictionary with a brief summary of the working directory state, | |
646 including parents, branch, commit status, and available updates. | |
647 | |
648 'parent' : a list of (rev, node, tags, message) | |
649 'branch' : the current branch | |
650 'commit' : True if the working directory is clean, False otherwise | |
651 'update' : number of available updates, | |
652 ['remote' : (in, in bookmarks, out, out bookmarks),] | |
653 ['mq': (applied, unapplied) mq patches,] | |
654 | |
655 unparsed entries will be of them form key : value | |
656 """ | |
657 args = cmdbuilder('summary', remote=remote) | |
658 | |
659 out = self.rawcommand(args).splitlines() | |
660 | |
661 d = {} | |
662 while out: | |
663 line = out.pop(0) | |
664 name, value = line.split(': ', 1) | |
665 | |
666 if name == 'parent': | |
667 parent, tags = value.split(' ', 1) | |
668 rev, node = parent.split(':') | |
669 | |
670 if tags: | |
671 tags = tags.replace(' (empty repository)', '') | |
672 else: | |
673 tags = None | |
674 | |
675 value = d.get(name, []) | |
676 | |
677 if rev == '-1': | |
678 value.append((int(rev), node, tags, None)) | |
679 else: | |
680 message = out.pop(0)[1:] | |
681 value.append((int(rev), node, tags, message)) | |
682 elif name == 'branch': | |
683 pass | |
684 elif name == 'commit': | |
685 value = value == '(clean)' | |
686 elif name == 'update': | |
687 if value == '(current)': | |
688 value = 0 | |
689 else: | |
690 value = int(value.split(' ', 1)[0]) | |
691 elif remote and name == 'remote': | |
692 if value == '(synced)': | |
693 value = 0, 0, 0, 0 | |
694 else: | |
695 inc = incb = out_ = outb = 0 | |
696 | |
697 for v in value.split(', '): | |
698 count, v = v.split(' ', 1) | |
699 if v == 'outgoing': | |
700 out_ = int(count) | |
701 elif v.endswith('incoming'): | |
702 inc = int(count) | |
703 elif v == 'incoming bookmarks': | |
704 incb = int(count) | |
705 elif v == 'outgoing bookmarks': | |
706 outb = int(count) | |
707 | |
708 value = inc, incb, out_, outb | |
709 elif name == 'mq': | |
710 applied = unapplied = 0 | |
711 for v in value.split(', '): | |
712 count, v = v.split(' ', 1) | |
713 if v == 'applied': | |
714 applied = int(count) | |
715 elif v == 'unapplied': | |
716 unapplied = int(count) | |
717 value = applied, unapplied | |
718 | |
719 d[name] = value | |
720 | |
721 return d | |
722 | |
643 def tip(self): | 723 def tip(self): |
644 args = cmdbuilder('tip', template=templates.changeset) | 724 args = cmdbuilder('tip', template=templates.changeset) |
645 out = self.rawcommand(args) | 725 out = self.rawcommand(args) |
646 out = out.split('\0') | 726 out = out.split('\0') |
647 | 727 |