| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 # Monkeypatch IMapIterator so that Ctrl-C can kill everything properly. | 5 # Monkeypatch IMapIterator so that Ctrl-C can kill everything properly. |
| 6 # Derived from https://gist.github.com/aljungberg/626518 | 6 # Derived from https://gist.github.com/aljungberg/626518 |
| 7 import multiprocessing.pool | 7 import multiprocessing.pool |
| 8 from multiprocessing.pool import IMapIterator | 8 from multiprocessing.pool import IMapIterator |
| 9 def wrapper(func): | 9 def wrapper(func): |
| 10 def wrap(self, timeout=None): | 10 def wrap(self, timeout=None): |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 | 345 |
| 346 return skipped, branch_tree | 346 return skipped, branch_tree |
| 347 | 347 |
| 348 | 348 |
| 349 def get_or_create_merge_base(branch, parent=None): | 349 def get_or_create_merge_base(branch, parent=None): |
| 350 """Finds the configured merge base for branch. | 350 """Finds the configured merge base for branch. |
| 351 | 351 |
| 352 If parent is supplied, it's used instead of calling upstream(branch). | 352 If parent is supplied, it's used instead of calling upstream(branch). |
| 353 """ | 353 """ |
| 354 base = branch_config(branch, 'base') | 354 base = branch_config(branch, 'base') |
| 355 base_upstream = branch_config(branch, 'base-upstream') |
| 355 parent = parent or upstream(branch) | 356 parent = parent or upstream(branch) |
| 357 if not parent: |
| 358 return None |
| 356 actual_merge_base = run('merge-base', parent, branch) | 359 actual_merge_base = run('merge-base', parent, branch) |
| 357 | 360 |
| 361 if base_upstream != parent: |
| 362 base = None |
| 363 base_upstream = None |
| 364 |
| 358 def is_ancestor(a, b): | 365 def is_ancestor(a, b): |
| 359 return run_with_retcode('merge-base', '--is-ancestor', a, b) == 0 | 366 return run_with_retcode('merge-base', '--is-ancestor', a, b) == 0 |
| 360 | 367 |
| 361 if base: | 368 if base: |
| 362 if not is_ancestor(base, branch): | 369 if not is_ancestor(base, branch): |
| 363 logging.debug('Found WRONG pre-set merge-base for %s: %s', branch, base) | 370 logging.debug('Found WRONG pre-set merge-base for %s: %s', branch, base) |
| 364 base = None | 371 base = None |
| 365 elif is_ancestor(base, actual_merge_base): | 372 elif is_ancestor(base, actual_merge_base): |
| 366 logging.debug('Found OLD pre-set merge-base for %s: %s', branch, base) | 373 logging.debug('Found OLD pre-set merge-base for %s: %s', branch, base) |
| 367 base = None | 374 base = None |
| 368 else: | 375 else: |
| 369 logging.debug('Found pre-set merge-base for %s: %s', branch, base) | 376 logging.debug('Found pre-set merge-base for %s: %s', branch, base) |
| 370 | 377 |
| 371 if not base: | 378 if not base: |
| 372 base = actual_merge_base | 379 base = actual_merge_base |
| 373 manual_merge_base(branch, base) | 380 manual_merge_base(branch, base, parent) |
| 374 | 381 |
| 375 return base | 382 return base |
| 376 | 383 |
| 377 | 384 |
| 378 def hash_multi(*reflike): | 385 def hash_multi(*reflike): |
| 379 return run('rev-parse', *reflike).splitlines() | 386 return run('rev-parse', *reflike).splitlines() |
| 380 | 387 |
| 381 | 388 |
| 382 def hash_one(reflike): | 389 def hash_one(reflike): |
| 383 return run('rev-parse', reflike) | 390 return run('rev-parse', reflike) |
| (...skipping 18 matching lines...) Expand all Loading... |
| 402 ret = run('hash-object', '-t', kind, '-w', '--stdin', stdin=f) | 409 ret = run('hash-object', '-t', kind, '-w', '--stdin', stdin=f) |
| 403 f.close() | 410 f.close() |
| 404 return ret | 411 return ret |
| 405 | 412 |
| 406 | 413 |
| 407 def is_dormant(branch): | 414 def is_dormant(branch): |
| 408 # TODO(iannucci): Do an oldness check? | 415 # TODO(iannucci): Do an oldness check? |
| 409 return branch_config(branch, 'dormant', 'false') != 'false' | 416 return branch_config(branch, 'dormant', 'false') != 'false' |
| 410 | 417 |
| 411 | 418 |
| 412 def manual_merge_base(branch, base): | 419 def manual_merge_base(branch, base, parent): |
| 413 set_branch_config(branch, 'base', base) | 420 set_branch_config(branch, 'base', base) |
| 421 set_branch_config(branch, 'base-upstream', parent) |
| 414 | 422 |
| 415 | 423 |
| 416 def mktree(treedict): | 424 def mktree(treedict): |
| 417 """Makes a git tree object and returns its hash. | 425 """Makes a git tree object and returns its hash. |
| 418 | 426 |
| 419 See |tree()| for the values of mode, type, and ref. | 427 See |tree()| for the values of mode, type, and ref. |
| 420 | 428 |
| 421 Args: | 429 Args: |
| 422 treedict - { name: (mode, type, ref) } | 430 treedict - { name: (mode, type, ref) } |
| 423 """ | 431 """ |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 run('rebase', *args) | 476 run('rebase', *args) |
| 469 return RebaseRet(True, '') | 477 return RebaseRet(True, '') |
| 470 except subprocess2.CalledProcessError as cpe: | 478 except subprocess2.CalledProcessError as cpe: |
| 471 if abort: | 479 if abort: |
| 472 run('rebase', '--abort') | 480 run('rebase', '--abort') |
| 473 return RebaseRet(False, cpe.stdout) | 481 return RebaseRet(False, cpe.stdout) |
| 474 | 482 |
| 475 | 483 |
| 476 def remove_merge_base(branch): | 484 def remove_merge_base(branch): |
| 477 del_branch_config(branch, 'base') | 485 del_branch_config(branch, 'base') |
| 486 del_branch_config(branch, 'base-upstream') |
| 478 | 487 |
| 479 | 488 |
| 480 def root(): | 489 def root(): |
| 481 return config('depot-tools.upstream', 'origin/master') | 490 return config('depot-tools.upstream', 'origin/master') |
| 482 | 491 |
| 483 | 492 |
| 484 def run(*cmd, **kwargs): | 493 def run(*cmd, **kwargs): |
| 485 """The same as run_with_stderr, except it only returns stdout.""" | 494 """The same as run_with_stderr, except it only returns stdout.""" |
| 486 return run_with_stderr(*cmd, **kwargs)[0] | 495 return run_with_stderr(*cmd, **kwargs)[0] |
| 487 | 496 |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 650 return None | 659 return None |
| 651 return ret | 660 return ret |
| 652 | 661 |
| 653 | 662 |
| 654 def upstream(branch): | 663 def upstream(branch): |
| 655 try: | 664 try: |
| 656 return run('rev-parse', '--abbrev-ref', '--symbolic-full-name', | 665 return run('rev-parse', '--abbrev-ref', '--symbolic-full-name', |
| 657 branch+'@{upstream}') | 666 branch+'@{upstream}') |
| 658 except subprocess2.CalledProcessError: | 667 except subprocess2.CalledProcessError: |
| 659 return None | 668 return None |
| OLD | NEW |