~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to baz2bzr

  • Committer: Aaron Bentley
  • Date: 2005-06-08 15:57:57 UTC
  • Revision ID: abentley@panoramicfeedback.com-20050608155757-a2ea60ffcdfed681
got dry run and continued import under test

Show diffs side-by-side

added added

removed removed

Lines of Context:
155
155
    add_file("ofile", "this is another file", "ofile by aaron")
156
156
    commit(tree, "altered mainfile")
157
157
 
 
158
 
 
159
def commit_more_test_revisions():
 
160
    """
 
161
    >>> q = test_environ()
 
162
    >>> commit_test_revisions()
 
163
    >>> commit_more_test_revisions()
 
164
    >>> a = pybaz.Archive("test@example.com")
 
165
    >>> revisions = list(a.iter_revisions("test--test--0"))
 
166
    >>> len(revisions)
 
167
    4
 
168
    >>> str(revisions[0])
 
169
    'test@example.com/test--test--0--patch-3'
 
170
    >>> teardown_environ(q)
 
171
    """
 
172
    tree = pybaz.tree_root(".")
 
173
    add_file("trainfile", "void train(void){}", "trainfile by aaron")
 
174
    commit(tree, "altered trainfile")
 
175
 
158
176
def version_ancestry(version):
159
177
    """
160
178
    >>> q = test_environ()
219
237
    >>> result_path = os.path.join(q, "result")
220
238
    >>> commit_test_revisions()
221
239
    >>> version = pybaz.Version("test@example.com/test--test--0")
 
240
    >>> import_version(result_path, version, fancy=False, dry_run=True)
 
241
    not fancy
 
242
    ....
 
243
    Dry run, not modifying output_dir
 
244
    Cleaning up
222
245
    >>> import_version(result_path, version, fancy=False)
223
246
    not fancy
224
247
    ....
225
248
    Cleaning up
226
249
    Import complete.
 
250
    >>> import_version(result_path, version, fancy=False)
 
251
    Tree is up-to-date with test@example.com/test--test--0--patch-2
227
252
    >>> teardown_environ(q)
228
253
    """
229
254
    ancestors, old_revno = get_remaining_revisions(output_dir, version)
230
255
    if len(ancestors) == 0:
231
256
        last_revision = get_last_revision(bzrlib.Branch(output_dir))
232
 
        print '* Tree is up-to-date with %s' % last_revision
233
 
        return 0
 
257
        print 'Tree is up-to-date with %s' % last_revision
 
258
        return
234
259
 
235
260
    progress_bar = ProgressBar()
236
261
    tempdir = tempfile.mkdtemp(prefix="baz2bzr-",
238
263
    try:
239
264
        if not fancy:
240
265
            print "not fancy"
241
 
        for result in iter_import_version(output_dir, ancestors, tempdir,
242
 
                fast=fast, verbose=verbose, dry_run=dry_run, 
243
 
                max_count=max_count, skip_symlinks=skip_symlinks):
 
266
        try:
 
267
            for result in iter_import_version(output_dir, ancestors, tempdir,
 
268
                    fast=fast, verbose=verbose, dry_run=dry_run, 
 
269
                    max_count=max_count, skip_symlinks=skip_symlinks):
 
270
                if fancy:
 
271
                    progress_bar(result)
 
272
                else:
 
273
                    sys.stdout.write('.')
 
274
        finally:
244
275
            if fancy:
245
 
                progress_bar(result)
 
276
                clear_progress_bar()
246
277
            else:
247
 
                sys.stdout.write('.')
 
278
                sys.stdout.write('\n')
248
279
 
249
280
        if dry_run:
250
 
            print '**Dry run, not modifying output_dir'
251
 
            return 0
 
281
            print 'Dry run, not modifying output_dir'
 
282
            return
252
283
        if os.path.exists(output_dir):
253
284
            # Move the bzr control directory back, and update the working tree
254
285
            tmp_bzr_dir = os.path.join(tempdir, '.bzr')
259
290
            os.rename(bzr_dir, tmp_bzr_dir) # Move the original bzr out of the way
260
291
            os.rename(new_bzr_dir, bzr_dir)
261
292
            try:
262
 
                # bzrlib.merge that exists in mainline does not have a this_dir component,
263
 
                # so we have to work in the local directory
264
293
                bzrlib.merge.merge(('.', -1), ('.', old_revno), 
265
294
                                   check_clean=False, this_dir=output_dir, 
266
295
                                   ignore_zero=True)
274
303
            os.rename(revdir, output_dir)
275
304
 
276
305
    finally:
277
 
        if fancy:
278
 
            clear_progress_bar()
279
 
        else:
280
 
            sys.stdout.write('\n')
281
306
        print 'Cleaning up'
282
307
        shutil.rmtree(tempdir)
283
308
    print "Import complete."