| 1 | # -*- coding: utf-8 -*- |
|---|
| 2 | # |
|---|
| 3 | # Copyright (C) 2010 Itamar Ostricher <itamarost@gmail.com> |
|---|
| 4 | # Copyright (C) 2016 Cinc |
|---|
| 5 | # |
|---|
| 6 | # All rights reserved. |
|---|
| 7 | # |
|---|
| 8 | # This software is licensed as described in the file COPYING, which |
|---|
| 9 | # you should have received as part of this distribution. The terms |
|---|
| 10 | # are also available at http://trac.edgewall.org/wiki/TracLicense. |
|---|
| 11 | # |
|---|
| 12 | # This software consists of voluntary contributions made by many |
|---|
| 13 | # individuals. For the exact contribution history, see the revision |
|---|
| 14 | # history and logs, available at http://trac.edgewall.org/log/. |
|---|
| 15 | # |
|---|
| 16 | # Author: Itamar Ostricher <itamarost@gmail.com> |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | def parse_externals(prop_str): |
|---|
| 20 | """Parse svn:externals property string and generate external references dictionaries from the valid lines |
|---|
| 21 | (skip invalid). |
|---|
| 22 | """ |
|---|
| 23 | for prop_line in prop_str.splitlines(): |
|---|
| 24 | prop_line = prop_line.strip().replace('\\', '/') |
|---|
| 25 | if not prop_line or prop_line.startswith('#'): |
|---|
| 26 | continue |
|---|
| 27 | elements = prop_line.split() |
|---|
| 28 | if len(elements) < 2: |
|---|
| 29 | continue |
|---|
| 30 | |
|---|
| 31 | ext_dict = {} |
|---|
| 32 | ext_dict['rev'] = rev_str = None |
|---|
| 33 | if '://' in elements[-1]: |
|---|
| 34 | # Old-style syntax |
|---|
| 35 | ext_dict['dir'] = elements[0] |
|---|
| 36 | ext_dict['url'] = elements[-1] |
|---|
| 37 | if len(elements) >= 3: |
|---|
| 38 | rev_str = ''.join(elements[1:(len(elements) == 4 and 3 or 2)]) |
|---|
| 39 | else: |
|---|
| 40 | # New-style syntax svn >= 1.5 |
|---|
| 41 | ext_dict['dir'] = elements[-1] |
|---|
| 42 | ext_dict['url'] = elements[-2] |
|---|
| 43 | if len(elements) >= 3: |
|---|
| 44 | rev_str = ''.join(elements[0:(len(elements) == 4 and 2 or 1)]) |
|---|
| 45 | elif '@' in ext_dict['url']: |
|---|
| 46 | ext_dict['url'], rev_str = ext_dict['url'].split('@') |
|---|
| 47 | rev_str = '-r%s' % (rev_str) |
|---|
| 48 | if rev_str: |
|---|
| 49 | if not rev_str.startswith('-r'): |
|---|
| 50 | continue |
|---|
| 51 | if not rev_str[2:].isdigit(): |
|---|
| 52 | continue |
|---|
| 53 | ext_dict['rev'] = int(rev_str[2:]) |
|---|
| 54 | if ext_dict: |
|---|
| 55 | yield ext_dict |
|---|