예제 #1
0
    def test_tree_statusxml_specific_files(self):
        """Tests branch status with given specific files"""
        wt = self.make_branch_and_tree('.')
        b = wt.branch

        self.build_tree(['directory/','directory/hello.c',
            'bye.c','test.c','dir2/'])
        wt.add('directory')
        wt.add('test.c')
        wt.commit('testing')

        xml_status = create_xml(wt, {'unknown':[('file','bye.c', {}),
            ('directory', 'dir2', {}), ('file', 'directory/hello.c', {})]})
        self.assertStatus(xml_status, wt)

        tof = StringIO()
        show_tree_status_xml(wt, specific_files=['bye.c','test.c','absent.c'], to_file=tof)
        log_xml = fromstring(tof.getvalue())
        nonexistents = log_xml.findall('nonexistents/nonexistent')
        unknowns = log_xml.findall('unknown')
        self.assertEquals(1, len(nonexistents))
        self.assertEquals(1, len(unknowns))

        self.assertStatus(create_xml(wt, {'unknown':[('file',
            'directory/hello.c', {})]}), wt, specific_files=['directory'])

        self.assertStatus(create_xml(wt, {'unknown':[('directory',
            'dir2', {})]}), wt, specific_files=['dir2'])

        revs = [RevisionSpec.from_string('0'), RevisionSpec.from_string('1')]
        self.assertStatus(create_xml(wt, {'added':[('file', 'test.c', {})]}),
            wt, revs, specific_files=['test.c'])
예제 #2
0
    def test_branch_status_revisions(self):
        """Tests branch status with revisions"""
        wt = self.make_branch_and_tree('.')

        self.build_tree(['hello.c', 'bye.c'])
        wt.add('hello.c')
        wt.add('bye.c')
        wt.commit('Test message')

        revs = [RevisionSpec.from_string('0')]
        self.assertStatus([
                'added:\n',
                '  bye.c\n',
                '  hello.c\n'
            ],
            wt,
            revision=revs)

        self.build_tree(['more.c'])
        wt.add('more.c')
        wt.commit('Another test message')

        revs.append(RevisionSpec.from_string('1'))
        self.assertStatus([
                'added:\n',
                '  bye.c\n',
                '  hello.c\n',
            ],
            wt,
            revision=revs)
예제 #3
0
    def test_branch_status_revisions(self):
        """Tests branch status with revisions"""
        wt = self.make_branch_and_tree('.')

        self.build_tree(['hello.c', 'bye.c'])
        wt.add('hello.c')
        wt.add('bye.c')
        wt.commit('Test message')

        revs = [RevisionSpec.from_string('0')]
        self.assertStatus(['added:\n', '  bye.c\n', '  hello.c\n'],
                          wt,
                          revision=revs)

        self.build_tree(['more.c'])
        wt.add('more.c')
        wt.commit('Another test message')

        revs.append(RevisionSpec.from_string('1'))
        self.assertStatus([
            'added:\n',
            '  bye.c\n',
            '  hello.c\n',
        ],
                          wt,
                          revision=revs)
예제 #4
0
    def test_tree_status_specific_files(self):
        """Tests branch status with given specific files"""
        wt = self.make_branch_and_tree('.')
        b = wt.branch

        self.build_tree(
            ['directory/', 'directory/hello.c', 'bye.c', 'test.c', 'dir2/'])
        wt.add('directory')
        wt.add('test.c')
        wt.commit('testing')

        self.assertStatus(
            ['unknown:\n', '  bye.c\n', '  dir2/\n', '  directory/hello.c\n'],
            wt)

        self.assertStatus(
            ['?   bye.c\n', '?   dir2/\n', '?   directory/hello.c\n'],
            wt,
            short=True)

        tof = StringIO()
        self.assertRaises(errors.PathsDoNotExist,
                          show_tree_status,
                          wt,
                          specific_files=['bye.c', 'test.c', 'absent.c'],
                          to_file=tof)

        tof = StringIO()
        show_tree_status(wt, specific_files=['directory'], to_file=tof)
        tof.seek(0)
        self.assertEquals(tof.readlines(),
                          ['unknown:\n', '  directory/hello.c\n'])
        tof = StringIO()
        show_tree_status(wt,
                         specific_files=['directory'],
                         to_file=tof,
                         short=True)
        tof.seek(0)
        self.assertEquals(tof.readlines(), ['?   directory/hello.c\n'])

        tof = StringIO()
        show_tree_status(wt, specific_files=['dir2'], to_file=tof)
        tof.seek(0)
        self.assertEquals(tof.readlines(), ['unknown:\n', '  dir2/\n'])
        tof = StringIO()
        show_tree_status(wt, specific_files=['dir2'], to_file=tof, short=True)
        tof.seek(0)
        self.assertEquals(tof.readlines(), ['?   dir2/\n'])

        tof = StringIO()
        revs = [RevisionSpec.from_string('0'), RevisionSpec.from_string('1')]
        show_tree_status(wt,
                         specific_files=['test.c'],
                         to_file=tof,
                         short=True,
                         revision=revs)
        tof.seek(0)
        self.assertEquals(tof.readlines(), ['+N  test.c\n'])
예제 #5
0
 def tests_revision_to_revision(self):
     """doing a status between two revision trees should work."""
     tree = self.make_branch_and_tree('.')
     r1_id = tree.commit('one', allow_pointless=True)
     r2_id = tree.commit('two', allow_pointless=True)
     r2_tree = tree.branch.repository.revision_tree(r2_id)
     output = StringIO()
     show_tree_status(tree, to_file=output,
                  revision=[RevisionSpec.from_string("revid:%s" % r1_id),
                            RevisionSpec.from_string("revid:%s" % r2_id)])
예제 #6
0
 def tests_revision_to_revision(self):
     """doing a status between two revision trees should work."""
     tree = self.make_branch_and_tree('.')
     r1_id = tree.commit('one', allow_pointless=True)
     r2_id = tree.commit('two', allow_pointless=True)
     r2_tree = tree.branch.repository.revision_tree(r2_id)
     output = StringIO()
     show_tree_status(tree, to_file=output,
                  revision=[RevisionSpec.from_string("revid:%s" % r1_id),
                            RevisionSpec.from_string("revid:%s" % r2_id)])
예제 #7
0
 def test_from_string_dotted_decimal(self):
     self.assertRaises(errors.NoSuchRevisionSpec, RevisionSpec.from_string,
                       '-1.1')
     self.assertRaises(errors.NoSuchRevisionSpec, RevisionSpec.from_string,
                       '.1')
     self.assertRaises(errors.NoSuchRevisionSpec, RevisionSpec.from_string,
                       '1..1')
     self.assertRaises(errors.NoSuchRevisionSpec, RevisionSpec.from_string,
                       '1.2..1')
     self.assertRaises(errors.NoSuchRevisionSpec, RevisionSpec.from_string,
                       '1.')
     self.assertIsInstance(RevisionSpec.from_string('1.1'),
                           RevisionSpec_revno)
     self.assertIsInstance(RevisionSpec.from_string('1.1.3'),
                           RevisionSpec_revno)
예제 #8
0
    def test_line_log_single_merge_revision(self):
        wt = self.make_branch_and_memory_tree('.')
        wt.lock_write()
        try:
            wt.add('')
            wt.commit('rev-1',
                      rev_id='rev-1',
                      timestamp=1132586655,
                      timezone=36000,
                      committer='Joe Foo <*****@*****.**>')
            wt.commit('rev-merged',
                      rev_id='rev-2a',
                      timestamp=1132586700,
                      timezone=36000,
                      committer='Joe Foo <*****@*****.**>')
            wt.set_parent_ids(['rev-1', 'rev-2a'])
            wt.branch.set_last_revision_info(1, 'rev-1')
            wt.commit('rev-2',
                      rev_id='rev-2b',
                      timestamp=1132586800,
                      timezone=36000,
                      committer='Joe Foo <*****@*****.**>')
            logfile = self.make_utf8_encoded_stringio()
            formatter = LineLogFormatter(to_file=logfile)
            revspec = RevisionSpec.from_string('1.1.1')
            wtb = wt.branch
            rev = revspec.in_history(wtb)
            show_log(wtb, formatter, start_revision=rev, end_revision=rev)
            self.assertEqualDiff(
                logfile.getvalue(), """\
1.1.1: Joe Foo 2005-11-22 rev-merged
""")
        finally:
            wt.unlock()
예제 #9
0
파일: test_log.py 프로젝트: c0ns0le/cygwin
    def test_line_log_single_merge_revision(self):
        wt = self.make_branch_and_memory_tree('.')
        wt.lock_write()
        try:
            wt.add('')
            wt.commit('rev-1', rev_id='rev-1',
                      timestamp=1132586655, timezone=36000,
                      committer='Joe Foo <*****@*****.**>')
            wt.commit('rev-merged', rev_id='rev-2a',
                      timestamp=1132586700, timezone=36000,
                      committer='Joe Foo <*****@*****.**>')
            wt.set_parent_ids(['rev-1', 'rev-2a'])
            wt.branch.set_last_revision_info(1, 'rev-1')
            wt.commit('rev-2', rev_id='rev-2b',
                      timestamp=1132586800, timezone=36000,
                      committer='Joe Foo <*****@*****.**>')
            logfile = self.make_utf8_encoded_stringio()
            formatter = LineLogFormatter(to_file=logfile)
            revspec = RevisionSpec.from_string('1.1.1')
            wtb = wt.branch
            rev = revspec.in_history(wtb)
            show_log(wtb, formatter, start_revision=rev, end_revision=rev)
            self.assertEqualDiff(logfile.getvalue(), """\
1.1.1: Joe Foo 2005-11-22 rev-merged
""")
        finally:
            wt.unlock()
예제 #10
0
 def test_as_revision_id_uncommitted(self):
     spec = RevisionSpec.from_string('annotate:annotate-tree/file1:3')
     e = self.assertRaises(errors.InvalidRevisionSpec,
                           spec.as_revision_id, self.tree.branch)
     self.assertContainsRe(str(e),
         r"Requested revision: \'annotate:annotate-tree/file1:3\' does not"
         " exist in branch: .*\nLine 3 has not been committed.")
예제 #11
0
파일: test_log.py 프로젝트: c0ns0le/cygwin
 def test_merges_nonsupporting_formatter(self):
     """Tests that show_log will raise if the formatter doesn't
     support merge revisions."""
     wt = self.make_branch_and_memory_tree('.')
     wt.lock_write()
     try:
         wt.add('')
         wt.commit('rev-1', rev_id='rev-1',
                   timestamp=1132586655, timezone=36000,
                   committer='Joe Foo <*****@*****.**>')
         wt.commit('rev-merged', rev_id='rev-2a',
                   timestamp=1132586700, timezone=36000,
                   committer='Joe Foo <*****@*****.**>')
         wt.set_parent_ids(['rev-1', 'rev-2a'])
         wt.branch.set_last_revision_info(1, 'rev-1')
         wt.commit('rev-2', rev_id='rev-2b',
                   timestamp=1132586800, timezone=36000,
                   committer='Joe Foo <*****@*****.**>')
         logfile = self.make_utf8_encoded_stringio()
         formatter = ShortLogFormatter(to_file=logfile)
         wtb = wt.branch
         lf = LogCatcher()
         revspec = RevisionSpec.from_string('1.1.1')
         rev = revspec.in_history(wtb)
         self.assertRaises(BzrCommandError, show_log, wtb, lf,
                           start_revision=rev, end_revision=rev)
     finally:
         wt.unlock()
예제 #12
0
 def test_no_such_file_with_colon(self):
     spec = RevisionSpec.from_string('annotate:annotate-tree/fi:le2:1')
     e = self.assertRaises(errors.InvalidRevisionSpec,
                           spec.as_revision_id, self.tree.branch)
     self.assertContainsRe(str(e),
         r"Requested revision: \'annotate:annotate-tree/fi:le2:1\' does not"
         " exist in branch: .*\nFile 'fi:le2' is not versioned")
예제 #13
0
 def test_invalid_line(self):
     spec = RevisionSpec.from_string('annotate:annotate-tree/file1:q')
     e = self.assertRaises(errors.InvalidRevisionSpec,
                           spec.as_revision_id, self.tree.branch)
     self.assertContainsRe(str(e),
         r"Requested revision: \'annotate:annotate-tree/file1:q\' does not"
         " exist in branch: .*\nNo such line: q")
예제 #14
0
 def get_file_content(self, filename, revision):
   rev_spec = RevisionSpec.from_string(revision)
   tree = rev_spec.as_tree(self.branch)
   file_id = tree.path2id(unicode(filename, 'utf8'))
   if file_id == None:
     return None
   content = tree.get_file_text(file_id)
   return content
 def test_invalid_line(self):
     spec = RevisionSpec.from_string('annotate:annotate-tree/file1:q')
     e = self.assertRaises(errors.InvalidRevisionSpec, spec.as_revision_id,
                           self.tree.branch)
     self.assertContainsRe(
         str(e),
         r"Requested revision: \'annotate:annotate-tree/file1:q\' does not"
         " exist in branch: .*\nNo such line: q")
 def test_as_revision_id_uncommitted(self):
     spec = RevisionSpec.from_string('annotate:annotate-tree/file1:3')
     e = self.assertRaises(errors.InvalidRevisionSpec, spec.as_revision_id,
                           self.tree.branch)
     self.assertContainsRe(
         str(e),
         r"Requested revision: \'annotate:annotate-tree/file1:3\' does not"
         " exist in branch: .*\nLine 3 has not been committed.")
 def test_no_such_file_with_colon(self):
     spec = RevisionSpec.from_string('annotate:annotate-tree/fi:le2:1')
     e = self.assertRaises(errors.InvalidRevisionSpec, spec.as_revision_id,
                           self.tree.branch)
     self.assertContainsRe(
         str(e),
         r"Requested revision: \'annotate:annotate-tree/fi:le2:1\' does not"
         " exist in branch: .*\nFile 'fi:le2' is not versioned")
예제 #18
0
파일: aubazaar.py 프로젝트: skeept/dotvim
def g_revid(repo, rev):
    try:
        if isinstance(rev, int) or isinstance(rev, long):
            return repo.branch.get_rev_id(rev)
        else:
            return RevisionSpec.from_string(rev).in_history(repo.branch).rev_id
    except (NoSuchRevision, InvalidRevisionSpec):
        vim_throw('norev', rev, repo.basedir)
예제 #19
0
def g_revid(repo, rev):
    try:
        if isinstance(rev, int) or isinstance(rev, long):
            return repo.branch.get_rev_id(rev)
        else:
            return RevisionSpec.from_string(rev).in_history(repo.branch).rev_id
    except (NoSuchRevision, InvalidRevisionSpec):
        vim_throw('norev', rev, repo.basedir)
예제 #20
0
파일: bzr.py 프로젝트: ejucovy/sven
    def log(self, uri, rev=None):
        """
        Return the changelog of data stored at or under @param:uri
        as of time @param:rev in JSON-listing format.
        
        @raise:ResourceUnchanged
        etc.
        """

        from bzrlib.log import LogFormatter

        def get_formatter(lst):
            class ListLogFormatter(LogFormatter):
                def __init__(self, *args, **kw):
                    LogFormatter.__init__(self, *args, **kw)
                    self._loglist = lst
                def log_revision(self, revision):
                    revno = int(revision.revno)
                    author = revision.rev.committer  # @@@ what about get_apparent_authors?
                    message = revision.rev.message.rstrip('\r\n')
                    timestamp = revision.rev.timestamp
                    self._loglist.append(dict(version=revno,
                                              author=author,
                                              message=message,
                                              timestamp=timestamp,
                                              id=uri,
                                              revprops=revision.rev.properties))
            return ListLogFormatter

        from bzrlib.builtins import cmd_log
        from bzrlib.revisionspec import RevisionSpec

        log = cmd_log()
        log.outf = None

        foo = []

        absolute_uri = os.path.join(self.checkout_dir, self.normalized(uri))

        log.run(file_list=[absolute_uri],
                revision=rev and [RevisionSpec.from_string("1"),
                                  RevisionSpec.from_string(str(rev))] or None,
                log_format = get_formatter(foo),
                )

        return [dict(href=uri, fields=i) for i in foo]
예제 #21
0
 def get_file_content(self, filename, revision):
     rev_spec = RevisionSpec.from_string(revision)
     tree = rev_spec.as_tree(self.branch)
     file_id = tree.path2id(unicode(filename, 'utf8'))
     if file_id == None:
         return None
     content = tree.get_file_text(file_id)
     return content
예제 #22
0
    def test_tree_statusxml_specific_files(self):
        """Tests branch status with given specific files"""
        wt = self.make_branch_and_tree('.')
        b = wt.branch

        self.build_tree(
            ['directory/', 'directory/hello.c', 'bye.c', 'test.c', 'dir2/'])
        wt.add('directory')
        wt.add('test.c')
        wt.commit('testing')

        xml_status = create_xml(
            wt, {
                'unknown': [('file', 'bye.c', {}), ('directory', 'dir2', {}),
                            ('file', 'directory/hello.c', {})]
            })
        self.assertStatus(xml_status, wt)

        tof = StringIO()
        show_tree_status_xml(wt,
                             specific_files=['bye.c', 'test.c', 'absent.c'],
                             to_file=tof)
        log_xml = fromstring(tof.getvalue())
        nonexistents = log_xml.findall('nonexistents/nonexistent')
        unknowns = log_xml.findall('unknown')
        self.assertEquals(1, len(nonexistents))
        self.assertEquals(1, len(unknowns))

        self.assertStatus(create_xml(
            wt, {'unknown': [('file', 'directory/hello.c', {})]}),
                          wt,
                          specific_files=['directory'])

        self.assertStatus(create_xml(wt,
                                     {'unknown': [('directory', 'dir2', {})]}),
                          wt,
                          specific_files=['dir2'])

        revs = [RevisionSpec.from_string('0'), RevisionSpec.from_string('1')]
        self.assertStatus(create_xml(wt, {'added': [('file', 'test.c', {})]}),
                          wt,
                          revs,
                          specific_files=['test.c'])
def revision_info(branch, rev_str):
    branch.lock_read()
    try:
        rev_spec = RevisionSpec.from_string(rev_str)
        revision_id = rev_spec.as_revision_id(branch)
        dotted_revno = branch.revision_id_to_dotted_revno(revision_id)
        revno = '.'.join(str(i) for i in dotted_revno)
        return revno, revision_id
    finally:
        branch.unlock()
예제 #24
0
 def test_as_revision_id(self):
     self.assertAsRevisionId('r1', 'mainline:1')
     self.assertAsRevisionId('r2', 'mainline:1.1.1')
     self.assertAsRevisionId('r2', 'mainline:revid:alt_r2')
     spec = RevisionSpec.from_string('mainline:revid:alt_r22')
     e = self.assertRaises(errors.InvalidRevisionSpec,
                           spec.as_revision_id, self.tree.branch)
     self.assertContainsRe(str(e),
         "Requested revision: 'mainline:revid:alt_r22' does not exist in"
         " branch: ")
예제 #25
0
파일: bzr.py 프로젝트: ezc/mercurial
 def getheads(self):
     if not self.rev:
         return [self.branch.last_revision()]
     try:
         r = RevisionSpec.from_string(self.rev)
         info = r.in_history(self.branch)
     except errors.BzrError:
         raise util.Abort(
             _('%s is not a valid revision in current branch') % self.rev)
     return [info.rev_id]
예제 #26
0
def get_revision_id(revision, from_branch, tip=False):
    """Return revision id for a revision number and a branch.

    If the revision is empty, the revision_id will be None.

    If ``tip`` is True, the revision value will be ignored.
    """
    if not tip and revision:
        spec = RevisionSpec.from_string(revision)
        return spec.as_revision_id(from_branch)
예제 #27
0
 def getheads(self):
     if not self.rev:
         return [self.branch.last_revision()]
     try:
         r = RevisionSpec.from_string(self.rev)
         info = r.in_history(self.branch)
     except errors.BzrError:
         raise util.Abort(_('%s is not a valid revision in current branch')
                          % self.rev)
     return [info.rev_id]
예제 #28
0
def get_revision_id(revision, from_branch, tip=False):
    """Return revision id for a revision number and a branch.

    If the revision is empty, the revision_id will be None.

    If ``tip`` is True, the revision value will be ignored.
    """
    if not tip and revision:
        spec = RevisionSpec.from_string(revision)
        return spec.as_revision_id(from_branch)
 def test_as_revision_id(self):
     self.assertAsRevisionId('r1', 'mainline:1')
     self.assertAsRevisionId('r2', 'mainline:1.1.1')
     self.assertAsRevisionId('r2', 'mainline:revid:alt_r2')
     spec = RevisionSpec.from_string('mainline:revid:alt_r22')
     e = self.assertRaises(errors.InvalidRevisionSpec, spec.as_revision_id,
                           self.tree.branch)
     self.assertContainsRe(
         str(e),
         "Requested revision: 'mainline:revid:alt_r22' does not exist in"
         " branch: ")
예제 #30
0
    def test_branch_statusxml_revisions(self):
        """Tests branch status with revisions"""
        wt = self.make_branch_and_tree('.')

        self.build_tree(['hello.c', 'bye.c'])
        wt.add('hello.c')
        wt.add('bye.c')
        wt.commit('Test message')

        revs = [RevisionSpec.from_string('0')]
        two_added = create_xml(wt, {'added':[('file', 'bye.c', {}),
            ('file', 'hello.c', {})]})
        self.assertStatus(two_added, wt, revision=revs)

        self.build_tree(['more.c'])
        wt.add('more.c')
        wt.commit('Another test message')

        revs.append(RevisionSpec.from_string('1'))
        self.assertStatus(two_added, wt, revision=revs)
예제 #31
0
    def test_branch_statusxml_revisions(self):
        """Tests branch status with revisions"""
        wt = self.make_branch_and_tree('.')

        self.build_tree(['hello.c', 'bye.c'])
        wt.add('hello.c')
        wt.add('bye.c')
        wt.commit('Test message')

        revs = [RevisionSpec.from_string('0')]
        two_added = create_xml(
            wt, {'added': [('file', 'bye.c', {}), ('file', 'hello.c', {})]})
        self.assertStatus(two_added, wt, revision=revs)

        self.build_tree(['more.c'])
        wt.add('more.c')
        wt.commit('Another test message')

        revs.append(RevisionSpec.from_string('1'))
        self.assertStatus(two_added, wt, revision=revs)
예제 #32
0
 def test_pre_status_hook(self):
     """Ensure that pre_status hook is invoked with the right args.
     """
     calls = []
     _mod_status.hooks.install_named_hook('pre_status', calls.append, None)
     self.assertLength(0, calls)
     tree = self.make_branch_and_tree('.')
     r1_id = tree.commit('one', allow_pointless=True)
     r2_id = tree.commit('two', allow_pointless=True)
     r2_tree = tree.branch.repository.revision_tree(r2_id)
     output = StringIO()
     show_tree_status(tree, to_file=output,
         revision=[RevisionSpec.from_string("revid:%s" % r1_id),
             RevisionSpec.from_string("revid:%s" % r2_id)])
     self.assertLength(1, calls)
     params = calls[0]
     self.assertIsInstance(params, _mod_status.StatusHookParams)
     attrs = ['old_tree', 'new_tree', 'to_file', 'versioned',
         'show_ids', 'short', 'verbose', 'specific_files']
     for a in attrs:
         self.assertTrue(hasattr(params, a),
             'Attribute "%s" not found in StatusHookParam' % a)
예제 #33
0
파일: bzr.py 프로젝트: socialplanning/sven
    def revisions(self, uri):
        """
        revisions at which this file changed
        """
        uri = self.normalized(uri)

        x = self.client
        path = x.path2id(uri)
        if not path:
            raise NoSuchResource(uri)

        from bzrlib.log import LogFormatter

        def get_formatter(lst):
            class ListLogFormatter(LogFormatter):

                supports_merge_revisions = True
                preferred_levels = 1
                supports_delta = True
                supports_tags = True
                supports_diff = True

                def __init__(self, *args, **kw):
                    LogFormatter.__init__(self, *args, **kw)
                    self._loglist = lst

                def log_revision(self, revision):
                    self._loglist.append(int(revision.revno))

            return ListLogFormatter

        from bzrlib.builtins import cmd_log
        from bzrlib.revisionspec import RevisionSpec

        log = cmd_log()
        log.outf = None

        foo = []

        rev = None

        absolute_uri = os.path.join(self.checkout_dir, uri)

        log.run(
            file_list=[absolute_uri],
            revision=rev and [RevisionSpec.from_string(str(rev))] or None,
            log_format=get_formatter(foo),
            verbose=True,
        )

        return foo
예제 #34
0
파일: bzr.py 프로젝트: socialplanning/sven
    def revisions(self, uri):
        """
        revisions at which this file changed
        """
        uri = self.normalized(uri)

        x = self.client
        path = x.path2id(uri)
        if not path:
            raise NoSuchResource(uri)

        from bzrlib.log import LogFormatter

        def get_formatter(lst):
            class ListLogFormatter(LogFormatter):

                supports_merge_revisions = True
                preferred_levels = 1
                supports_delta = True
                supports_tags = True
                supports_diff = True

                def __init__(self, *args, **kw):
                    LogFormatter.__init__(self, *args, **kw)
                    self._loglist = lst
                def log_revision(self, revision):
                    self._loglist.append(int(revision.revno))
            return ListLogFormatter

        from bzrlib.builtins import cmd_log
        from bzrlib.revisionspec import RevisionSpec

        log = cmd_log()
        log.outf = None

        foo = []

        rev = None

        absolute_uri = os.path.join(self.checkout_dir, uri)

        log.run(file_list=[absolute_uri],
                revision=rev and [RevisionSpec.from_string(str(rev))] or None,
                log_format = get_formatter(foo),
                verbose=True,
                )

        return foo
예제 #35
0
파일: uncommit.py 프로젝트: biji/qbzr
 def validate(self):
     """Check that the user really wants to uncommit the given revisions."""
     revision = self._revision_identifier()
     if revision is None:
         log_rqst = log.make_log_request_dict(limit=1)
     else:
         rev_spec = RevisionSpec.from_string(revision)
         revno = rev_spec.in_history(self.branch).revno
         # We need to offset the revno by +1 because we'll be uncommitting
         # *back* to revno, meaning those after it are 'deleted'
         log_rqst = log.make_log_request_dict(start_revision=revno+1)
     log_data = log_as_html(self.branch, log_rqst)
     question = gettext("Do you really want to uncommit these revisions?")
     if self.ask_confirmation(
         '<font color="red">%s</font><br/>%s' % (question, log_data),
         type='warning'):
             return True
     return False
예제 #36
0
파일: bzr.py 프로젝트: RayFerr000/PLTL
 def getheads(self):
     if not self.rev:
         # Set using=True to avoid nested repositories (see issue3254)
         heads = sorted([b.last_revision() for b in self._bzrbranches()])
     else:
         revid = None
         for branch in self._bzrbranches():
             try:
                 r = RevisionSpec.from_string(self.rev)
                 info = r.in_history(branch)
             except errors.BzrError:
                 pass
             revid = info.rev_id
         if revid is None:
             raise util.Abort(_('%s is not a valid revision') % self.rev)
         heads = [revid]
     # Empty repositories return 'null:', which cannot be retrieved
     heads = [h for h in heads if h != 'null:']
     return heads
예제 #37
0
 def getheads(self):
     if not self.rev:
         # Set using=True to avoid nested repositories (see issue3254)
         heads = sorted([b.last_revision() for b in self._bzrbranches()])
     else:
         revid = None
         for branch in self._bzrbranches():
             try:
                 r = RevisionSpec.from_string(self.rev)
                 info = r.in_history(branch)
             except errors.BzrError:
                 pass
             revid = info.rev_id
         if revid is None:
             raise util.Abort(_('%s is not a valid revision') % self.rev)
         heads = [revid]
     # Empty repositories return 'null:', which cannot be retrieved
     heads = [h for h in heads if h != 'null:']
     return heads
예제 #38
0
 def test_merges_nonsupporting_formatter(self):
     """Tests that show_log will raise if the formatter doesn't
     support merge revisions."""
     wt = self.make_branch_and_memory_tree('.')
     wt.lock_write()
     try:
         wt.add('')
         wt.commit('rev-1',
                   rev_id='rev-1',
                   timestamp=1132586655,
                   timezone=36000,
                   committer='Joe Foo <*****@*****.**>')
         wt.commit('rev-merged',
                   rev_id='rev-2a',
                   timestamp=1132586700,
                   timezone=36000,
                   committer='Joe Foo <*****@*****.**>')
         wt.set_parent_ids(['rev-1', 'rev-2a'])
         wt.branch.set_last_revision_info(1, 'rev-1')
         wt.commit('rev-2',
                   rev_id='rev-2b',
                   timestamp=1132586800,
                   timezone=36000,
                   committer='Joe Foo <*****@*****.**>')
         logfile = self.make_utf8_encoded_stringio()
         formatter = ShortLogFormatter(to_file=logfile)
         wtb = wt.branch
         lf = LogCatcher()
         revspec = RevisionSpec.from_string('1.1.1')
         rev = revspec.in_history(wtb)
         self.assertRaises(BzrCommandError,
                           show_log,
                           wtb,
                           lf,
                           start_revision=rev,
                           end_revision=rev)
     finally:
         wt.unlock()
예제 #39
0
 def test_from_string_tag(self):
     spec = RevisionSpec.from_string('tag:bzr-0.14')
     self.assertIsInstance(spec, RevisionSpec_tag)
     self.assertEqual(spec.spec, 'bzr-0.14')
예제 #40
0
파일: bzr.py 프로젝트: socialplanning/sven
    def log(self, uri, rev=None):
        """
        Return the changelog of data stored at or under @param:uri
        as of time @param:rev in JSON-listing format.
        
        @raise:ResourceUnchanged
        etc.
        """

        from bzrlib.log import LogFormatter

        def get_formatter(lst):
            class ListLogFormatter(LogFormatter):

                supports_merge_revisions = True
                preferred_levels = 1
                supports_delta = True
                supports_tags = True
                supports_diff = True

                def __init__(self, *args, **kw):
                    LogFormatter.__init__(self, *args, **kw)
                    self._loglist = lst
                def log_revision(self, revision):
                    revno = int(revision.revno)

                    try:
                        author = revision.rev.get_apparent_authors()[0]
                    except IndexError:
                        author = revision.rev.committer

                    message = revision.rev.message.rstrip('\r\n')
                    timestamp = revision.rev.timestamp

                    id = uri

                    if revision.delta:
                        changed = [i[0] for i in revision.delta.added] \
                            + [i[0] for i in revision.delta.modified]
                        if not len(changed):
                            return
                        id = changed[-1]

                    self._loglist.append(dict(version=revno,
                                              author=author,
                                              message=message,
                                              timestamp=timestamp,
                                              id=id,
                                              revprops=revision.rev.properties))
            return ListLogFormatter

        from bzrlib.builtins import cmd_log
        from bzrlib.revisionspec import RevisionSpec

        log = cmd_log()
        log.outf = None

        foo = []

        absolute_uri = os.path.join(self.checkout_dir, self.normalized(uri))

        try:
            log.run(file_list=[absolute_uri],
                    revision=rev and [RevisionSpec.from_string("1"),
                                      RevisionSpec.from_string(str(rev))] or None,
                    log_format = get_formatter(foo),
                    verbose=True,
                    )
        except BzrCommandError, e:
            raise NoSuchResource(uri)
 def get_as_tree(self, revision_spec, tree=None):
     if tree is None:
         tree = self.tree
     spec = RevisionSpec.from_string(revision_spec)
     return spec.as_tree(tree.branch)
예제 #42
0
 def get_parent_tokens(self, revision):
   rev_spec = RevisionSpec.from_string(revision)
   tree = rev_spec.as_tree(self.branch)
   parents = tree.get_parent_ids()
   return parents
예제 #43
0
 def test_from_string_tag(self):
     spec = RevisionSpec.from_string('tag:bzr-0.14')
     self.assertIsInstance(spec, RevisionSpec_tag)
     self.assertEqual(spec.spec, 'bzr-0.14')
예제 #44
0
                         ' %r != %r'
                         % (revision_spec, exp_revision_id, rev_info.rev_id))

    def assertInvalid(self, revision_spec, extra='',
                      invalid_as_revision_id=True):
        try:
            self.get_in_history(revision_spec)
        except errors.InvalidRevisionSpec, e:
            self.assertEqual(revision_spec, e.spec)
            self.assertEqual(extra, e.extra)
        else:
            self.fail('Expected InvalidRevisionSpec to be raised for'
                      ' %r.in_history' % (revision_spec,))
        if invalid_as_revision_id:
            try:
                spec = RevisionSpec.from_string(revision_spec)
                spec.as_revision_id(self.tree.branch)
            except errors.InvalidRevisionSpec, e:
                self.assertEqual(revision_spec, e.spec)
                self.assertEqual(extra, e.extra)
            else:
                self.fail('Expected InvalidRevisionSpec to be raised for'
                          ' %r.as_revision_id' % (revision_spec,))

    def assertAsRevisionId(self, revision_id, revision_spec):
        """Calling as_revision_id() should return the specified id."""
        spec = RevisionSpec.from_string(revision_spec)
        self.assertEqual(revision_id,
                         spec.as_revision_id(self.tree.branch))

    def get_as_tree(self, revision_spec, tree=None):
예제 #45
0
 def test_non_exact_branch(self):
     # It seems better to require an exact path to the branch
     # Branch.open() rather than using Branch.open_containing()
     spec = RevisionSpec.from_string('revno:2:tree2/a')
     self.assertRaises(errors.NotBranchError,
                       spec.in_history, self.tree.branch)
예제 #46
0
 def assertAsRevisionId(self, revision_id, revision_spec):
     """Calling as_revision_id() should return the specified id."""
     spec = RevisionSpec.from_string(revision_spec)
     self.assertEqual(revision_id,
                      spec.as_revision_id(self.tree.branch))
예제 #47
0
    def assertInvalid(self,
                      revision_spec,
                      extra='',
                      invalid_as_revision_id=True):
        try:
            self.get_in_history(revision_spec)
        except errors.InvalidRevisionSpec, e:
            self.assertEqual(revision_spec, e.spec)
            self.assertEqual(extra, e.extra)
        else:
            self.fail('Expected InvalidRevisionSpec to be raised for'
                      ' %r.in_history' % (revision_spec, ))
        if invalid_as_revision_id:
            try:
                spec = RevisionSpec.from_string(revision_spec)
                spec.as_revision_id(self.tree.branch)
            except errors.InvalidRevisionSpec, e:
                self.assertEqual(revision_spec, e.spec)
                self.assertEqual(extra, e.extra)
            else:
                self.fail('Expected InvalidRevisionSpec to be raised for'
                          ' %r.as_revision_id' % (revision_spec, ))

    def assertAsRevisionId(self, revision_id, revision_spec):
        """Calling as_revision_id() should return the specified id."""
        spec = RevisionSpec.from_string(revision_spec)
        self.assertEqual(revision_id, spec.as_revision_id(self.tree.branch))


class RevisionSpecMatchOnTrap(RevisionSpec):
예제 #48
0
 def test_non_exact_branch(self):
     # It seems better to require an exact path to the branch
     # Branch.open() rather than using Branch.open_containing()
     spec = RevisionSpec.from_string('revno:2:tree2/a')
     self.assertRaises(errors.NotBranchError, spec.in_history,
                       self.tree.branch)
예제 #49
0
    def run(
        self,
        upstream_location=None,
        onto=None,
        revision=None,
        merge_type=None,
        verbose=False,
        dry_run=False,
        always_rebase_merges=False,
        pending_merges=False,
        directory=".",
    ):
        from bzrlib.branch import Branch
        from bzrlib.revisionspec import RevisionSpec
        from bzrlib.workingtree import WorkingTree
        from bzrlib.plugins.rewrite.rebase import (
            generate_simple_plan,
            rebase,
            RebaseState1,
            WorkingTreeRevisionRewriter,
            regenerate_default_revid,
            rebase_todo,
        )

        if revision is not None and pending_merges:
            raise BzrCommandError(gettext("--revision and --pending-merges are mutually exclusive"))

        wt = WorkingTree.open_containing(directory)[0]
        wt.lock_write()
        try:
            state = RebaseState1(wt)
            if upstream_location is None:
                if pending_merges:
                    upstream_location = directory
                else:
                    upstream_location = wt.branch.get_parent()
                    if upstream_location is None:
                        raise BzrCommandError(gettext("No upstream branch specified."))
                    note(gettext("Rebasing on %s"), upstream_location)
            upstream = Branch.open_containing(upstream_location)[0]
            upstream_repository = upstream.repository
            upstream_revision = upstream.last_revision()
            # Abort if there already is a plan file
            if state.has_plan():
                raise BzrCommandError(
                    gettext(
                        "A rebase operation was interrupted. "
                        "Continue using 'bzr rebase-continue' or abort using 'bzr "
                        "rebase-abort'"
                    )
                )

            start_revid = None
            stop_revid = None
            if revision is not None:
                if len(revision) == 1:
                    if revision[0] is not None:
                        stop_revid = revision[0].as_revision_id(wt.branch)
                elif len(revision) == 2:
                    if revision[0] is not None:
                        start_revid = revision[0].as_revision_id(wt.branch)
                    if revision[1] is not None:
                        stop_revid = revision[1].as_revision_id(wt.branch)
                else:
                    raise BzrCommandError(gettext("--revision takes only one or two arguments"))

            if pending_merges:
                wt_parents = wt.get_parent_ids()
                if len(wt_parents) in (0, 1):
                    raise BzrCommandError(gettext("No pending merges present."))
                elif len(wt_parents) > 2:
                    raise BzrCommandError(gettext("Rebasing more than one pending merge not supported"))
                stop_revid = wt_parents[1]
                assert stop_revid is not None, "stop revid invalid"

            # Check for changes in the working tree.
            if not pending_merges and wt.basis_tree().changes_from(wt).has_changed():
                raise UncommittedChanges(wt)

            # Pull required revisions
            wt.branch.repository.fetch(upstream_repository, upstream_revision)
            if onto is None:
                onto = upstream.last_revision()
            else:
                rev_spec = RevisionSpec.from_string(onto)
                onto = rev_spec.as_revision_id(upstream)

            wt.branch.repository.fetch(upstream_repository, onto)

            if stop_revid is None:
                stop_revid = wt.branch.last_revision()
            repo_graph = wt.branch.repository.get_graph()
            our_new, onto_unique = repo_graph.find_difference(stop_revid, onto)

            if start_revid is None:
                if not onto_unique:
                    self.outf.write(gettext("No revisions to rebase.\n"))
                    return
                if not our_new:
                    self.outf.write(gettext("Base branch is descendant of current " "branch. Pulling instead.\n"))
                    if not dry_run:
                        wt.pull(upstream, onto)
                    return
            # else: include extra revisions needed to make start_revid mean
            # something.

            # Create plan
            replace_map = generate_simple_plan(
                our_new,
                start_revid,
                stop_revid,
                onto,
                repo_graph,
                lambda revid, ps: regenerate_default_revid(wt.branch.repository, revid),
                not always_rebase_merges,
            )

            if verbose or dry_run:
                todo = list(rebase_todo(wt.branch.repository, replace_map))
                note(gettext("%d revisions will be rebased:") % len(todo))
                for revid in todo:
                    note("%s" % revid)

            if not dry_run:
                # Write plan file
                state.write_plan(replace_map)

                replayer = WorkingTreeRevisionRewriter(wt, state, merge_type=merge_type)

                finish_rebase(state, wt, replace_map, replayer)
        finally:
            wt.unlock()
예제 #50
0
 def get_parent_tokens(self, revision):
     rev_spec = RevisionSpec.from_string(revision)
     tree = rev_spec.as_tree(self.branch)
     parents = tree.get_parent_ids()
     return parents
예제 #51
0
def spec_in_history(spec, branch):
    """A simple helper to change a revision spec into a branch search"""
    return RevisionSpec.from_string(spec).in_history(branch)
예제 #52
0
def spec_in_history(spec, branch):
    """A simple helper to change a revision spec into a branch search"""
    return RevisionSpec.from_string(spec).in_history(branch)
예제 #53
0
파일: bzr.py 프로젝트: socialplanning/sven
    def log(self, uri, rev=None):
        """
        Return the changelog of data stored at or under @param:uri
        as of time @param:rev in JSON-listing format.
        
        @raise:ResourceUnchanged
        etc.
        """

        from bzrlib.log import LogFormatter

        def get_formatter(lst):
            class ListLogFormatter(LogFormatter):

                supports_merge_revisions = True
                preferred_levels = 1
                supports_delta = True
                supports_tags = True
                supports_diff = True

                def __init__(self, *args, **kw):
                    LogFormatter.__init__(self, *args, **kw)
                    self._loglist = lst

                def log_revision(self, revision):
                    revno = int(revision.revno)

                    try:
                        author = revision.rev.get_apparent_authors()[0]
                    except IndexError:
                        author = revision.rev.committer

                    message = revision.rev.message.rstrip('\r\n')
                    timestamp = revision.rev.timestamp

                    id = uri

                    if revision.delta:
                        changed = [i[0] for i in revision.delta.added] \
                            + [i[0] for i in revision.delta.modified]
                        if not len(changed):
                            return
                        id = changed[-1]

                    self._loglist.append(
                        dict(version=revno,
                             author=author,
                             message=message,
                             timestamp=timestamp,
                             id=id,
                             revprops=revision.rev.properties))

            return ListLogFormatter

        from bzrlib.builtins import cmd_log
        from bzrlib.revisionspec import RevisionSpec

        log = cmd_log()
        log.outf = None

        foo = []

        absolute_uri = os.path.join(self.checkout_dir, self.normalized(uri))

        try:
            log.run(
                file_list=[absolute_uri],
                revision=rev and [
                    RevisionSpec.from_string("1"),
                    RevisionSpec.from_string(str(rev))
                ] or None,
                log_format=get_formatter(foo),
                verbose=True,
            )
        except BzrCommandError, e:
            raise NoSuchResource(uri)
예제 #54
0
 def get_as_tree(self, revision_spec, tree=None):
     if tree is None:
         tree = self.tree
     spec = RevisionSpec.from_string(revision_spec)
     return spec.as_tree(tree.branch)
예제 #55
0
    def test_tree_status_specific_files(self):
        """Tests branch status with given specific files"""
        wt = self.make_branch_and_tree('.')
        b = wt.branch

        self.build_tree(['directory/','directory/hello.c',
                         'bye.c','test.c','dir2/',
                         'missing.c'])
        wt.add('directory')
        wt.add('test.c')
        wt.commit('testing')
        wt.add('missing.c')
        unlink('missing.c')

        self.assertStatus([
                'missing:\n',
                '  missing.c\n',
                'unknown:\n',
                '  bye.c\n',
                '  dir2/\n',
                '  directory/hello.c\n'
                ],
                wt)

        self.assertStatus([
                '?   bye.c\n',
                '?   dir2/\n',
                '+!  missing.c\n',
                '?   directory/hello.c\n'
                ],
                wt, short=True)

        tof = StringIO()
        self.assertRaises(errors.PathsDoNotExist,
                          show_tree_status,
                          wt, specific_files=['bye.c','test.c','absent.c'],
                          to_file=tof)

        tof = StringIO()
        show_tree_status(wt, specific_files=['directory'], to_file=tof)
        tof.seek(0)
        self.assertEquals(tof.readlines(),
                          ['unknown:\n',
                           '  directory/hello.c\n'
                           ])
        tof = StringIO()
        show_tree_status(wt, specific_files=['directory'], to_file=tof,
                         short=True)
        tof.seek(0)
        self.assertEquals(tof.readlines(), ['?   directory/hello.c\n'])

        tof = StringIO()
        show_tree_status(wt, specific_files=['dir2'], to_file=tof)
        tof.seek(0)
        self.assertEquals(tof.readlines(),
                          ['unknown:\n',
                           '  dir2/\n'
                           ])
        tof = StringIO()
        show_tree_status(wt, specific_files=['dir2'], to_file=tof, short=True)
        tof.seek(0)
        self.assertEquals(tof.readlines(), ['?   dir2/\n'])

        tof = StringIO()
        revs = [RevisionSpec.from_string('0'), RevisionSpec.from_string('1')]
        show_tree_status(wt, specific_files=['test.c'], to_file=tof,
                         short=True, revision=revs)
        tof.seek(0)
        self.assertEquals(tof.readlines(), ['+N  test.c\n'])

        tof = StringIO()
        show_tree_status(wt, specific_files=['missing.c'], to_file=tof)
        tof.seek(0)
        self.assertEquals(tof.readlines(),
                          ['missing:\n',
                           '  missing.c\n'])

        tof = StringIO()
        show_tree_status(wt, specific_files=['missing.c'], to_file=tof,
                         short=True)
        tof.seek(0)
        self.assertEquals(tof.readlines(),
                          ['+!  missing.c\n'])
예제 #56
0
def update_openerp(dest_dir, version=_DEFAULT_VERSION, lplogin=None, export=False, revision=None, verbose=False):
    """
        if lplogin == None -> make a branch instead of a checkout
        if export == True -> bzr export 
        if revision is provided, get the branches at this revision
            more information with:
                $> bzr help revisionspec
    """
    def log(msg):
        if verbose:
            print msg

    if version not in _VERSIONS:
        raise Exception('Unknown version')
    dest_dir = dest_dir or '.'

    branch = lplogin is None
    if branch:
        BASEURL = 'lp:'
    else:
        BASEURL = 'bzr+ssh://%[email protected]/' % (lplogin,)

    # map branch URLs according to version
    extraversion = _EXTRA_ADDONS_MAP[version]
    communityversion = 'trunk'
    webversion = version

    bzr_repository = {
        'server': (BASEURL + '~openerp/openobject-server/' + version, True),
        'client': (BASEURL + '~openerp/openobject-client/' + version, True),
        'addons': (BASEURL + '~openerp/openobject-addons/' + version, True),
        'addons-extra': (BASEURL + '~openerp-commiter/openobject-addons/' + extraversion, False),
        'addons-community': (BASEURL + '~openerp-community/openobject-addons/' + communityversion + '-addons-community', False),
        'web': (BASEURL + '~openerp/openobject-client-web/' + webversion, True),
    }

    bzr_links = {
        'addons/*': 'server/bin/addons/',
    }

    if branch:
        cmd = {'new': lambda u, l, r: run_cmd('branch', u, l, revision=r),
               'update': lambda u, l, r: run_cmd('pull', u, directory=l, overwrite=True, revision=r),
        }
    else:
        cmd = {'new': lambda u, l, r: run_cmd('checkout', u, l, lightweight=True, revision=r),
               'update': lambda u, l, r: run_cmd('update', l), # no revision option :(
        }
    cmd['export'] = lambda u, l, r: run_cmd('export', l, u, revision=r)

    msg = "%(status)s %(type)s of %(from)s into %(to)s"

    if not os.path.exists(dest_dir):
        os.makedirs(dest_dir)

    for local, (bzrdir, has_tags) in bzr_repository.items():
        local = os.path.join(dest_dir, local)
        typ = ['checkout', 'branch'][branch]
        if export:
            if os.path.exists(local):
                shutil.rmtree(local)
            status = 'export'
            typ = 'sources'
        else:
            try:
                b = Branch.open(local)
                # FIXME check that the current workingDirectory is a branch or a checkout
                status = 'update'
            except NotBranchError:
                status = 'new'
        
        frm = bzrdir
        rev = None
        if revision and (not revision.startswith('tag:') or has_tags):
            frm = '%s (%s)' % (bzrdir, revision)
            rev = RevisionSpec.from_string(revision)

        log(msg % {'status': status, 'type': typ, 'to': local, 'from': frm})
                
        cmd[status](bzrdir, local, rev and [rev] or None)

    # Doing symlinks
    log('(Re)Computing Symbolic links...')
    for src2,dest2 in bzr_links.items():
        src2 = os.path.join(dest_dir, src2)
        dest2 = os.path.join(dest_dir, dest2)
        for src in glob.glob(src2):
            dest = os.path.join(dest2, os.path.basename(src))
            if not os.path.isdir(dest):
                os.symlink(os.path.realpath(src), dest)

    log('='*79)
    log('Sources of OpenERP have been installed. If you develop new features,')
    log('you can get more information on how to contribute to the project here:')
    log('\thttp://test.openobject.com')
    log('='*79)
예제 #57
0
 def assertAsRevisionId(self, revision_id, revision_spec):
     """Calling as_revision_id() should return the specified id."""
     spec = RevisionSpec.from_string(revision_spec)
     self.assertEqual(revision_id, spec.as_revision_id(self.tree.branch))