OLD | NEW |
1 # Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2006-2009 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 os | 7 import os |
8 import re | 8 import re |
9 import subprocess | 9 import subprocess |
10 import sys | 10 import sys |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 status = GIT.Capture(command).rstrip() | 63 status = GIT.Capture(command).rstrip() |
64 results = [] | 64 results = [] |
65 if status: | 65 if status: |
66 for statusline in status.split('\n'): | 66 for statusline in status.split('\n'): |
67 m = re.match('^(\w)\t(.+)$', statusline) | 67 m = re.match('^(\w)\t(.+)$', statusline) |
68 if not m: | 68 if not m: |
69 raise Exception("status currently unsupported: %s" % statusline) | 69 raise Exception("status currently unsupported: %s" % statusline) |
70 results.append(('%s ' % m.group(1), m.group(2))) | 70 results.append(('%s ' % m.group(1), m.group(2))) |
71 return results | 71 return results |
72 | 72 |
| 73 @staticmethod |
| 74 def GetEmail(repo_root): |
| 75 """Retrieves the user email address if known.""" |
| 76 # We could want to look at the svn cred when it has a svn remote but it |
| 77 # should be fine for now, users should simply configure their git settings. |
| 78 return GIT.Capture(['config', 'user.email'], repo_root).strip() |
| 79 |
73 | 80 |
74 class SVN(object): | 81 class SVN(object): |
75 COMMAND = "svn" | 82 COMMAND = "svn" |
76 | 83 |
77 @staticmethod | 84 @staticmethod |
78 def Run(args, in_directory): | 85 def Run(args, in_directory): |
79 """Runs svn, sending output to stdout. | 86 """Runs svn, sending output to stdout. |
80 | 87 |
81 Args: | 88 Args: |
82 args: A sequence of command line parameters to be passed to svn. | 89 args: A sequence of command line parameters to be passed to svn. |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 filename = filename.replace('\\', '/') | 413 filename = filename.replace('\\', '/') |
407 data = "Index: %s\n" % filename | 414 data = "Index: %s\n" % filename |
408 data += ("=============================================================" | 415 data += ("=============================================================" |
409 "======\n") | 416 "======\n") |
410 # Note: Should we use /dev/null instead? | 417 # Note: Should we use /dev/null instead? |
411 data += "--- %s\n" % filename | 418 data += "--- %s\n" % filename |
412 data += "+++ %s\n" % filename | 419 data += "+++ %s\n" % filename |
413 data += "@@ -0,0 +1,%d @@\n" % nb_lines | 420 data += "@@ -0,0 +1,%d @@\n" % nb_lines |
414 data += ''.join(file_content) | 421 data += ''.join(file_content) |
415 return data | 422 return data |
| 423 |
| 424 @staticmethod |
| 425 def GetEmail(repo_root): |
| 426 """Retrieves the svn account which we assume is an email address.""" |
| 427 infos = SVN.CaptureInfo(repo_root) |
| 428 uuid = infos.get('UUID') |
| 429 root = infos.get('Repository Root') |
| 430 if not root: |
| 431 return None |
| 432 |
| 433 # Should check for uuid but it is incorrectly saved for https creds. |
| 434 realm = root.rsplit('/', 1)[0] |
| 435 if root.startswith('https') or not uuid: |
| 436 regexp = re.compile(r'<%s:\d+>.*' % realm) |
| 437 else: |
| 438 regexp = re.compile(r'<%s:\d+> %s' % (realm, uuid)) |
| 439 if regexp is None: |
| 440 return None |
| 441 if sys.platform.startswith('win'): |
| 442 if not 'APPDATA' in os.environ: |
| 443 return None |
| 444 auth_dir = os.path.join(os.environ['APPDATA'], 'auth', 'svn.simple') |
| 445 else: |
| 446 if not 'HOME' in os.environ: |
| 447 return None |
| 448 auth_dir = os.path.join(os.environ['HOME'], '.subversion', 'auth', |
| 449 'svn.simple') |
| 450 for credfile in os.listdir(auth_dir): |
| 451 cred_info = SVN.ReadSimpleAuth(os.path.join(auth_dir, credfile)) |
| 452 if regexp.match(cred_info.get('svn:realmstring')): |
| 453 return cred_info.get('username') |
| 454 |
| 455 @staticmethod |
| 456 def ReadSimpleAuth(filename): |
| 457 f = open(filename, 'r') |
| 458 values = {} |
| 459 def ReadOneItem(type): |
| 460 m = re.match(r'%s (\d+)' % type, f.readline()) |
| 461 if not m: |
| 462 return None |
| 463 data = f.read(int(m.group(1))) |
| 464 if f.read(1) != '\n': |
| 465 return None |
| 466 return data |
| 467 |
| 468 while True: |
| 469 key = ReadOneItem('K') |
| 470 if not key: |
| 471 break |
| 472 value = ReadOneItem('V') |
| 473 if not value: |
| 474 break |
| 475 values[key] = value |
| 476 return values |
OLD | NEW |