Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Side by Side Diff: patch.py

Issue 10915240: Fix the patch application sorting. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « checkout.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # coding=utf8 1 # coding=utf8
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 """Utility functions to handle patches.""" 5 """Utility functions to handle patches."""
6 6
7 import posixpath 7 import posixpath
8 import os 8 import os
9 import re 9 import re
10 10
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 def __init__(self, patches): 496 def __init__(self, patches):
497 for p in patches: 497 for p in patches:
498 assert isinstance(p, FilePatchBase) 498 assert isinstance(p, FilePatchBase)
499 499
500 def key(p): 500 def key(p):
501 """Sort by ordering of application. 501 """Sort by ordering of application.
502 502
503 File move are first. 503 File move are first.
504 Deletes are last. 504 Deletes are last.
505 """ 505 """
506 if p.source_filename: 506 # The bool is necessary because None < 'string' but the reverse is needed.
507 return (p.is_delete, p.source_filename_utf8, p.filename_utf8) 507 return (
508 else: 508 p.is_delete,
509 # tuple are always greater than string, abuse that fact. 509 # False is before True, so files *with* a source file will be first.
510 return (p.is_delete, (p.filename_utf8,), p.filename_utf8) 510 not bool(p.source_filename),
511 p.source_filename_utf8,
512 p.filename_utf8)
511 513
512 self.patches = sorted(patches, key=key) 514 self.patches = sorted(patches, key=key)
513 515
514 def set_relpath(self, relpath): 516 def set_relpath(self, relpath):
515 """Used to offset the patch into a subdirectory.""" 517 """Used to offset the patch into a subdirectory."""
516 for patch in self.patches: 518 for patch in self.patches:
517 patch.set_relpath(relpath) 519 patch.set_relpath(relpath)
518 520
519 def __iter__(self): 521 def __iter__(self):
520 for patch in self.patches: 522 for patch in self.patches:
521 yield patch 523 yield patch
522 524
523 def __getitem__(self, key): 525 def __getitem__(self, key):
524 return self.patches[key] 526 return self.patches[key]
525 527
526 @property 528 @property
527 def filenames(self): 529 def filenames(self):
528 return [p.filename for p in self.patches] 530 return [p.filename for p in self.patches]
OLDNEW
« no previous file with comments | « checkout.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698