OLD | NEW |
---|---|
1 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2010 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 """SCM-specific utility classes.""" | 5 """SCM-specific utility classes.""" |
6 | 6 |
7 import cStringIO | 7 import cStringIO |
8 import glob | 8 import glob |
9 import logging | 9 import logging |
10 import os | 10 import os |
(...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
652 | 652 |
653 @staticmethod | 653 @staticmethod |
654 def GenerateDiff(filenames, root=None, full_move=False, revision=None): | 654 def GenerateDiff(filenames, root=None, full_move=False, revision=None): |
655 """Returns a string containing the diff for the given file list. | 655 """Returns a string containing the diff for the given file list. |
656 | 656 |
657 The files in the list should either be absolute paths or relative to the | 657 The files in the list should either be absolute paths or relative to the |
658 given root. If no root directory is provided, the repository root will be | 658 given root. If no root directory is provided, the repository root will be |
659 used. | 659 used. |
660 The diff will always use relative paths. | 660 The diff will always use relative paths. |
661 """ | 661 """ |
662 assert isinstance(filenames, (list, tuple)) | |
662 previous_cwd = os.getcwd() | 663 previous_cwd = os.getcwd() |
663 root = root or SVN.GetCheckoutRoot(previous_cwd) | 664 root = root or SVN.GetCheckoutRoot(previous_cwd) |
664 root = os.path.normcase(os.path.join(root, '')) | 665 root = os.path.normcase(os.path.join(root, '')) |
665 def RelativePath(path, root): | 666 def RelativePath(path, root): |
666 """We must use relative paths.""" | 667 """We must use relative paths.""" |
667 if os.path.normcase(path).startswith(root): | 668 if os.path.normcase(path).startswith(root): |
668 return path[len(root):] | 669 return path[len(root):] |
669 return path | 670 return path |
670 # If the user specified a custom diff command in their svn config file, | 671 # If the user specified a custom diff command in their svn config file, |
671 # then it'll be used when we do svn diff, which we don't want to happen | 672 # then it'll be used when we do svn diff, which we don't want to happen |
(...skipping 24 matching lines...) Expand all Loading... | |
696 metaheaders = [] | 697 metaheaders = [] |
697 for (filename, info) in data.iteritems(): | 698 for (filename, info) in data.iteritems(): |
698 if SVN.IsMovedInfo(info): | 699 if SVN.IsMovedInfo(info): |
699 # for now, the most common case is a head copy, | 700 # for now, the most common case is a head copy, |
700 # so let's just encode that as a straight up cp. | 701 # so let's just encode that as a straight up cp. |
701 srcurl = info.get('Copied From URL') | 702 srcurl = info.get('Copied From URL') |
702 root = info.get('Repository Root') | 703 root = info.get('Repository Root') |
703 rev = int(info.get('Copied From Rev')) | 704 rev = int(info.get('Copied From Rev')) |
704 assert srcurl.startswith(root) | 705 assert srcurl.startswith(root) |
705 src = srcurl[len(root)+1:] | 706 src = srcurl[len(root)+1:] |
706 srcinfo = SVN.CaptureInfo(srcurl) | 707 try: |
708 srcinfo = SVN.CaptureInfo(srcurl) | |
709 except gclient_utils.CheckCallError, e: | |
710 if not 'Not a valid URL' in e.stderr: | |
711 raise | |
712 # Assume the file was deleted. No idea how to figure out at which | |
713 # revision the file was deleted. | |
nsylvain
2011/02/23 22:08:35
The new file most likely has a mergeinfo property
M-A Ruel
2011/02/24 01:37:58
The idea is to not use the svn:mergeinfo metadata
| |
714 srcinfo = {'Revision': rev} | |
707 if (srcinfo.get('Revision') != rev and | 715 if (srcinfo.get('Revision') != rev and |
708 SVN.Capture(['diff', '-r', '%d:head' % rev, srcurl])): | 716 SVN.Capture(['diff', '-r', '%d:head' % rev, srcurl])): |
709 metaheaders.append("#$ svn cp -r %d %s %s " | 717 metaheaders.append("#$ svn cp -r %d %s %s " |
710 "### WARNING: note non-trunk copy\n" % | 718 "### WARNING: note non-trunk copy\n" % |
711 (rev, src, filename)) | 719 (rev, src, filename)) |
712 else: | 720 else: |
713 metaheaders.append("#$ cp %s %s\n" % (src, | 721 metaheaders.append("#$ cp %s %s\n" % (src, |
714 filename)) | 722 filename)) |
715 | 723 |
716 if metaheaders: | 724 if metaheaders: |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
867 elif os.path.isfile(file_path) or os.path.islink(file_path): | 875 elif os.path.isfile(file_path) or os.path.islink(file_path): |
868 logging.info('os.remove(%s)' % file_path) | 876 logging.info('os.remove(%s)' % file_path) |
869 os.remove(file_path) | 877 os.remove(file_path) |
870 elif os.path.isdir(file_path): | 878 elif os.path.isdir(file_path): |
871 logging.info('gclient_utils.RemoveDirectory(%s)' % file_path) | 879 logging.info('gclient_utils.RemoveDirectory(%s)' % file_path) |
872 gclient_utils.RemoveDirectory(file_path) | 880 gclient_utils.RemoveDirectory(file_path) |
873 else: | 881 else: |
874 logging.critical( | 882 logging.critical( |
875 ('No idea what is %s.\nYou just found a bug in gclient' | 883 ('No idea what is %s.\nYou just found a bug in gclient' |
876 ', please ping maruel@chromium.org ASAP!') % file_path) | 884 ', please ping maruel@chromium.org ASAP!') % file_path) |
OLD | NEW |