~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to baz_import.py

  • Committer: Aaron Bentley
  • Date: 2005-11-11 17:43:12 UTC
  • Revision ID: aaron.bentley@utoronto.ca-20051111174312-1c627d82a07bf8fd
Added patch for tab-in-patch-filename support

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
import os.path
28
28
import shutil
29
29
import bzrlib
30
 
from bzrlib.errors import BzrError
 
30
from bzrlib.errors import BzrError, NotBranchError, BzrCommandError
31
31
import bzrlib.trace
32
32
import bzrlib.merge
33
33
import bzrlib.inventory
206
206
    return ancestors
207
207
 
208
208
def get_last_revision(branch):
209
 
    last_patch = branch.last_patch()
 
209
    last_patch = branch.last_revision()
210
210
    try:
211
211
        return arch_revision(last_patch)
212
212
    except NotArchRevision:
223
223
        # the current version is
224
224
        branch = find_branch(output_dir)
225
225
        last_patch = get_last_revision(branch)
 
226
        if last_patch is None:
 
227
            raise NotPreviousImport(branch.base)
226
228
        if version is None:
227
229
            version = last_patch.version
228
230
    elif version is None:
230
232
 
231
233
    try:
232
234
        ancestors = version_ancestry(version)
 
235
        if len(ancestors) > 0 and not ancestors[0].archive.is_registered():
 
236
            ancestors = ancestors[1:]
233
237
    except NoSuchVersion, e:
234
238
        raise UserError(e)
235
239
 
285
289
    try:
286
290
        ancestors, old_revno = get_remaining_revisions(output_dir, version)
287
291
    except NotInABranch, e:
288
 
        raise UserError("%s exists, but is not a bzr branch." % e.path)
 
292
        raise NotPreviousImport(e.path)
289
293
    if len(ancestors) == 0:
290
294
        last_revision = get_last_revision(find_branch(output_dir))
291
295
        print 'Tree is up-to-date with %s' % last_revision
341
345
        shutil.rmtree(tempdir)
342
346
    print "Import complete."
343
347
            
344
 
class UserError(Exception):
 
348
class UserError(BzrCommandError):
345
349
    def __init__(self, message):
346
350
        """Exception to throw when a user makes an impossible request
347
351
        :param message: The message to emit when printing this exception
348
352
        :type message: string
349
353
        """
350
 
        Exception.__init__(self, message)
 
354
        BzrCommandError.__init__(self, message)
 
355
 
 
356
class NotPreviousImport(UserError):
 
357
    def __init__(self, path):
 
358
        UserError.__init__(self, "%s is not the location of a previous import."
 
359
                           % path)
 
360
 
351
361
 
352
362
def revision_id(arch_revision):
353
363
    """
437
447
                # next revision of the baz tree
438
448
                branch = find_branch(revdir)
439
449
            else:
440
 
                branch = Branch(revdir, init=True)
 
450
                branch = Branch.initialize(revdir)
441
451
        else:
442
452
            old = os.path.join(revdir, ".bzr")
443
453
            new = os.path.join(tempdir, ".bzr")
450
460
        rev_id = revision_id(revision)
451
461
        branch.lock_write()
452
462
        try:
453
 
            branch.set_inventory(baz_inv)
 
463
            branch.working_tree().set_inventory(baz_inv)
454
464
            bzrlib.trace.silent = True
455
465
            branch.commit(log.summary, verbose=False, committer=log.creator,
456
466
                          timestamp=timestamp, timezone=0, rev_id=rev_id)
544
554
    True
545
555
    """
546
556
    try:
547
 
        return Branch(path)
548
 
    except BzrError, e:
549
 
        if e.args[0].endswith("' is not in a branch"):
550
 
            raise NotInABranch(path)
 
557
        return Branch.open(path)
 
558
    except NotBranchError, e:
 
559
        raise NotInABranch(path)
551
560
 
552
561
class cmd_baz_import(Command):
553
562
    """Import an Arch or Baz branch into a bzr branch"""