Kiln » Kiln Extensions
Clone URL:  
Pushed to 2 repositories · View In Graph Contained in tip

Kiln 2.8 extensions

Changeset 0b1d58ee5c34

Parent 67d19149537f

by Profile picture of User 276Kevin Gessner <kevin@fogcreek.com>

Changes to 3 files · Browse files at 0b1d58ee5c34 Showing diff from parent 67d19149537f Diff from another changeset...

 
1155
1156
1157
 
1158
1159
1160
1161
1162
 
1163
1164
 
1165
1166
1167
 
1155
1156
1157
1158
1159
1160
1161
1162
 
1163
1164
 
1165
1166
1167
1168
@@ -1155,13 +1155,14 @@
  f = bfutil.splitstandin(f)     def getdatafn(): + fd = None   try:   fd = open(path, 'rb')   return fd.read()   finally: - fd.close() + if fd: fd.close()   - getdata = getdatafn + if path: getdata = getdatafn   write(f, 'x' in ff and 0755 or 0644, 'l' in ff, getdata)     if subrepos:
Change 1 of 1 Show Changes Only big-push.py Stacked
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
 
 
 
 
 
 
 
 
 
 
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
 
39
 
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
 # Copyright (C) 2009-2011 Fog Creek Software. All rights reserved.  #  # This program is free software; you can redistribute it and/or modify  # it under the terms of the GNU General Public License as published by  # the Free Software Foundation; either version 2 of the License, or  # (at your option) any later version.  #  # This program is distributed in the hope that it will be useful,  # but WITHOUT ANY WARRANTY; without even the implied warranty of  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the  # GNU General Public License for more details.  #  # You should have received a copy of the GNU General Public License  # along with this program; if not, write to the Free Software  # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.    '''automatically push large repositories in chunks'''    from mercurial import cmdutil, commands, hg, extensions  from mercurial.i18n import _    max_push_size = 1000    def findoutgoing(repo, other):   try:   # Mercurial 1.6 through 1.8   from mercurial import discovery   return discovery.findoutgoing(repo, other, force=False)   except AttributeError:   # Mercurial 1.9 and higher   common, _anyinc, _heads = discovery.findcommonincoming(repo, other, force=False)   return repo.changelog.findmissing(common)   except ImportError:   # Mercurial 1.5 and lower   return repo.findoutgoing(other, force=False)    def prepush(repo, other, force, revs):   try: - # Mercurial 1.6 and higher   from mercurial import discovery - return discovery.prepush(repo, other, force, revs, False) + try: + # Mercurial 1.6 through 2.0 + return discovery.prepush(repo, other, force, revs, False) + except AttributeError: + # Mercurial 2.1 and higher + fci = discovery.findcommonincoming(repo, other, force=force) + outgoing = discovery.findcommonoutgoing(repo, other, onlyheads=revs, commoninc=fci, force=force) + if not force: + discovery.checkheads(repo, other, outgoing, fci[2], False) + return [True]   except ImportError:   # Mercurial 1.5 and lower   return repo.prepush(other, False, revs)    def remoteui(repo, opts):   if hasattr(cmdutil, 'remoteui'):   # Mercurial 1.5 and lower   return cmdutil.remoteui(repo, opts)   else:   # Mercurial 1.6 and higher   return hg.remoteui(repo, opts)    def bigpush(push_fn, ui, repo, dest=None, *files, **opts):   '''Pushes this repository to a target repository.     If this repository is small, behaves as the native push command.   For large, remote repositories, the repository is pushed in chunks   of size optimized for performance on the network.'''   if not opts.get('chunked'):   return push_fn(ui, repo, dest, **opts)     source, revs = parseurl(ui.expandpath(dest or 'default-push', dest or 'default'))   other = hg.repository(remoteui(repo, opts), source)   if hasattr(hg, 'addbranchrevs'):   revs = hg.addbranchrevs(repo, other, revs, opts.get('rev'))[0]   if revs:   revs = [repo.lookup(rev) for rev in revs]   if other.local():   return push_fn(ui, repo, dest, **opts)     ui.status(_('pushing to %s\n') % other.path)     outgoing = findoutgoing(repo, other)   if outgoing:   outgoing = repo.changelog.nodesbetween(outgoing, revs)[0]     # if the push will create multiple heads and isn't forced, fail now   # (prepush prints an error message, so we can just exit)   if not opts.get('force') and not opts.get('new_branch') and None == prepush(repo, other, False, revs)[0]:   return   try:   push_size = 1   while len(outgoing) > 0:   ui.debug('start: %d to push\n' % len(outgoing))   current_push_size = min(push_size, len(outgoing))   ui.debug('pushing: %d\n' % current_push_size)   # force the push, because we checked above that by the time the whole push is done, we'll have merged back to one head   remote_heads = repo.push(other, force=True, revs=outgoing[:current_push_size])   if remote_heads: # push succeeded   outgoing = outgoing[current_push_size:]   ui.debug('pushed %d ok\n' % current_push_size)   if push_size < max_push_size:   push_size *= 2   else: # push failed; try again with a smaller size   push_size /= 2   ui.debug('failed, trying %d\n' % current_push_size)   if push_size == 0:   raise UnpushableChangesetError   except UnpushableChangesetError:   ui.status(_('unable to push changeset %s\n') % outgoing[0])   ui.debug('done\n')    def parseurl(source):   '''wrap hg.parseurl to work on 1.3 -> 1.5'''   return hg.parseurl(source, None)[:2]    def uisetup(ui):   push_cmd = extensions.wrapcommand(commands.table, 'push', bigpush)   push_cmd[1].extend([('', 'chunked', None, 'push large repository in chunks')])    class UnpushableChangesetError(Exception):   pass
Change 1 of 8 Show Entire File kiln.py Stacked
 
6
7
8
 
9
10
11
 
31
32
33
34
 
 
35
 
 
 
 
36
37
38
39
40
 
45
46
47
48
 
49
50
51
 
84
85
86
87
88
89
90
 
91
92
93
 
94
95
96
 
332
333
334
335
 
336
337
338
 
372
373
374
375
 
376
377
378
 
536
537
538
539
540
 
 
541
542
543
 
566
567
568
569
570
 
 
 
 
 
 
 
 
571
572
573
 
6
7
8
9
10
11
12
 
32
33
34
 
35
36
37
38
39
40
41
42
 
43
44
45
 
50
51
52
 
53
54
55
56
 
89
90
91
 
 
 
 
92
93
94
 
95
96
97
98
 
334
335
336
 
337
338
339
340
 
374
375
376
 
377
378
379
380
 
538
539
540
 
 
541
542
543
544
545
 
568
569
570
 
 
571
572
573
574
575
576
577
578
579
580
581
@@ -6,6 +6,7 @@
 #  # For help on the usage of "hg kiln" use:  # hg help kiln +# hg help -e kiln  #  # This program is free software; you can redistribute it and/or modify  # it under the terms of the GNU General Public License as published by @@ -31,10 +32,14 @@
 This extension will also notify you when a Kiln server you access has an  updated version of the Kiln Client and Tools available.  To disable the check for a version 'X.Y.Z' and all lower versions, add the -following line in the [kiln] section of your hgrc: +following line in the [kiln] section of your hgrc:: +   ignoreversion = X.Y.Z + +This extension also lets you create or add changesets to a code review when +pushing to Kiln. See :hg:`help push` and +http://kiln.stackexchange.com/questions/4679/ for more information.  ''' -import httplib  import os  import re  import unicodedata @@ -45,7 +50,7 @@
   from cookielib import MozillaCookieJar  from hashlib import md5 -from mercurial import commands, cmdutil, demandimport, error, extensions, hg, \ +from mercurial import commands, cmdutil, demandimport, extensions, hg, \   httprepo, localrepo, match, util  from mercurial import ui as hgui  from mercurial import url as hgurl @@ -84,13 +89,10 @@
    Inspect self.errors to see the API errors thrown.   ''' - self.errors = [] - for error in obj['errors']: - data = error['codeError'], error['sError'] - self.errors.append('%s: %s' % data) + self.errors = dict((e['codeError'], e['sError']) for e in obj['errors'])     def __str__(self): - return '\n'.join(self.errors) + return '\n'.join('%s: %s' % (k, v) for k, v in self.errors.items())    def urljoin(*components):   url = components[0] @@ -332,7 +334,7 @@
  if not os.path.exists(cookiepath):   return ''   cj = MozillaCookieJar(cookiepath) - except IOError, e: + except IOError:   return ''     domain = get_domain(url) @@ -372,7 +374,7 @@
  # Mercurial assumes Unix newlines by default and so do we.   fp.write('\n[paths]\n%s = %s\n' % (path, value))   fp.close() - except IOError, e: + except IOError:   return    def unremember_path(ui, repo): @@ -536,8 +538,8 @@
  url = fd.headers.getheaders('location')[0]   elif 'uri' in fd.headers:   url = fd.headers.getheaders('uri')[0] - except HTTPError as e: - raise util.Abort(_('Invalid URL: %s' % url)) + except urllib2.HTTPError: + raise util.Abort(_('Invalid URL: %s') % url)     def find_slug(slug, l, attr=None):   if not l: @@ -566,8 +568,14 @@
  'fCentral': False,   'sDefaultPermission': 'inherit',   'token': token} - repo.ui.write('branching from %s' % url) - return call_api(repo.ui, baseurl, 'Api/1.0/Repo/Create', params, post=True) + repo.ui.write(_('branching from %s\n') % url) + try: + return call_api(repo.ui, baseurl, 'Api/1.0/Repo/Create', params, post=True) + except APIError, e: + if 'RepoNameAlreadyUsed' in e.errors: + repo.ui.write_err(_('error: a repo with this name already exists: %s\n') % name) + return + raise    def normalize_user(s):   '''Takes a Unicode string and returns an ASCII string.'''