Show More
@@ -1,5 +1,6 b'' | |||
|
1 | 1 | # common code for the convert extension |
|
2 | 2 | import base64, errno |
|
3 | import os | |
|
3 | 4 | import cPickle as pickle |
|
4 | 5 | from mercurial import util |
|
5 | 6 | from mercurial.i18n import _ |
@@ -212,7 +213,7 b' class commandline(object):' | |||
|
212 | 213 | def postrun(self): |
|
213 | 214 | pass |
|
214 | 215 | |
|
215 |
def _ |
|
|
216 | def _cmdline(self, cmd, *args, **kwargs): | |
|
216 | 217 | cmdline = [self.command, cmd] + list(args) |
|
217 | 218 | for k, v in kwargs.iteritems(): |
|
218 | 219 | if len(k) == 1: |
@@ -230,7 +231,10 b' class commandline(object):' | |||
|
230 | 231 | cmdline += ['<', util.nulldev] |
|
231 | 232 | cmdline = ' '.join(cmdline) |
|
232 | 233 | self.ui.debug(cmdline, '\n') |
|
234 | return cmdline | |
|
233 | 235 | |
|
236 | def _run(self, cmd, *args, **kwargs): | |
|
237 | cmdline = self._cmdline(cmd, *args, **kwargs) | |
|
234 | 238 | self.prerun() |
|
235 | 239 | try: |
|
236 | 240 | return util.popen(cmdline) |
@@ -256,6 +260,47 b' class commandline(object):' | |||
|
256 | 260 | self.checkexit(status, output) |
|
257 | 261 | return output |
|
258 | 262 | |
|
263 | def getargmax(self): | |
|
264 | if '_argmax' in self.__dict__: | |
|
265 | return self._argmax | |
|
266 | ||
|
267 | # POSIX requires at least 4096 bytes for ARG_MAX | |
|
268 | self._argmax = 4096 | |
|
269 | try: | |
|
270 | self._argmax = os.sysconf("SC_ARG_MAX") | |
|
271 | except: | |
|
272 | pass | |
|
273 | ||
|
274 | # Windows shells impose their own limits on command line length, | |
|
275 | # down to 2047 bytes for cmd.exe under Windows NT/2k and 2500 bytes | |
|
276 | # for older 4nt.exe. See http://support.microsoft.com/kb/830473 for | |
|
277 | # details about cmd.exe limitations. | |
|
278 | ||
|
279 | # Since ARG_MAX is for command line _and_ environment, lower our limit | |
|
280 | # (and make happy Windows shells while doing this). | |
|
281 | ||
|
282 | self._argmax = self._argmax/2 - 1 | |
|
283 | return self._argmax | |
|
284 | ||
|
285 | def limit_arglist(self, arglist, cmd, *args, **kwargs): | |
|
286 | limit = self.getargmax() - len(self._cmdline(cmd, *args, **kwargs)) | |
|
287 | bytes = 0 | |
|
288 | fl = [] | |
|
289 | for fn in arglist: | |
|
290 | b = len(fn) + 3 | |
|
291 | if bytes + b < limit or len(fl) == 0: | |
|
292 | fl.append(fn) | |
|
293 | bytes += b | |
|
294 | else: | |
|
295 | yield fl | |
|
296 | fl = [fn] | |
|
297 | bytes = b | |
|
298 | if fl: | |
|
299 | yield fl | |
|
300 | ||
|
301 | def xargs(self, arglist, cmd, *args, **kwargs): | |
|
302 | for l in self.limit_arglist(arglist, cmd, *args, **kwargs): | |
|
303 | self.run0(cmd, *(list(args) + l), **kwargs) | |
|
259 | 304 | |
|
260 | 305 | class mapfile(dict): |
|
261 | 306 | def __init__(self, ui, path): |
@@ -707,27 +707,6 b' exit 1' | |||
|
707 | 707 | class svn_sink(converter_sink, commandline): |
|
708 | 708 | commit_re = re.compile(r'Committed revision (\d+).', re.M) |
|
709 | 709 | |
|
710 | # iterates sublist of given list for concatenated length is within limit | |
|
711 | def limit_arglist(self, files): | |
|
712 | if os.name != 'nt': | |
|
713 | yield files | |
|
714 | return | |
|
715 | # When I tested on WinXP, limit = 2500 is NG, 2400 is OK | |
|
716 | limit = 2000 | |
|
717 | bytes = 0 | |
|
718 | fl = [] | |
|
719 | for fn in files: | |
|
720 | b = len(fn) + 1 | |
|
721 | if bytes + b < limit: | |
|
722 | fl.append(fn) | |
|
723 | bytes += b | |
|
724 | else: | |
|
725 | yield fl | |
|
726 | fl = [fn] | |
|
727 | bytes = b | |
|
728 | if fl: | |
|
729 | yield fl | |
|
730 | ||
|
731 | 710 | def prerun(self): |
|
732 | 711 | if self.wc: |
|
733 | 712 | os.chdir(self.wc) |
@@ -866,14 +845,12 b' class svn_sink(converter_sink, commandli' | |||
|
866 | 845 | if not os.path.exists(self.wjoin(d, '.svn', 'entries'))] |
|
867 | 846 | if add_dirs: |
|
868 | 847 | add_dirs.sort() |
|
869 | for fl in self.limit_arglist(add_dirs): | |
|
870 | self.run('add', non_recursive=True, quiet=True, *fl) | |
|
848 | self.xargs(add_dirs, 'add', non_recursive=True, quiet=True) | |
|
871 | 849 | return add_dirs |
|
872 | 850 | |
|
873 | 851 | def add_files(self, files): |
|
874 | 852 | if files: |
|
875 | for fl in self.limit_arglist(files): | |
|
876 | self.run('add', quiet=True, *fl) | |
|
853 | self.xargs(files, 'add', quiet=True) | |
|
877 | 854 | return files |
|
878 | 855 | |
|
879 | 856 | def tidy_dirs(self, names): |
@@ -907,18 +884,15 b' class svn_sink(converter_sink, commandli' | |||
|
907 | 884 | self._copyfile(s, d) |
|
908 | 885 | self.copies = [] |
|
909 | 886 | if self.delete: |
|
910 |
|
|
|
911 | self.run0('delete', *fl) | |
|
887 | self.xargs(self.delete, 'delete') | |
|
912 | 888 | self.delete = [] |
|
913 | 889 | entries.update(self.add_files(files.difference(entries))) |
|
914 | 890 | entries.update(self.tidy_dirs(entries)) |
|
915 | 891 | if self.delexec: |
|
916 | for fl in self.limit_arglist(self.delexec): | |
|
917 | self.run0('propdel', 'svn:executable', *fl) | |
|
892 | self.xargs(self.delexec, 'propdel', 'svn:executable') | |
|
918 | 893 | self.delexec = [] |
|
919 | 894 | if self.setexec: |
|
920 | for fl in self.limit_arglist(self.setexec): | |
|
921 | self.run0('propset', 'svn:executable', '*', *fl) | |
|
895 | self.xargs(self.setexec, 'propset', 'svn:executable', '*') | |
|
922 | 896 | self.setexec = [] |
|
923 | 897 | |
|
924 | 898 | fd, messagefile = tempfile.mkstemp(prefix='hg-convert-') |
General Comments 0
You need to be logged in to leave comments.
Login now