# HG changeset patch # User Augie Fackler # Date 1318254948 18000 # Node ID d4b3b8370b3c9ef8292cab174a6fcb5e419594a8 # Parent 5061640fe5bc920dcec8d3348d9f43affacdb238# Parent 4244f8f37484b48aa7ee28979c9662e28a0cfd95 Merge queued patches. Hg: -- diff --git a/.hgignore b/.hgignore --- a/.hgignore +++ b/.hgignore @@ -13,3 +13,7 @@ dist *.egg-info hgsubversion/__version__.py nbproject +.project +.pydevproject +.settings +*.orig diff --git a/hgsubversion/maps.py b/hgsubversion/maps.py --- a/hgsubversion/maps.py +++ b/hgsubversion/maps.py @@ -5,6 +5,7 @@ from mercurial import util as hgutil from mercurial import node import svncommands +import util class AuthorMap(dict): '''A mapping from Subversion-style authors to Mercurial-style @@ -136,14 +137,14 @@ class Tags(dict): print 'tagmap too new -- please upgrade' raise NotImplementedError for l in f: - hash, revision, tag = l.split(' ', 2) + ha, revision, tag = l.split(' ', 2) revision = int(revision) tag = tag[:-1] if self.endrev is not None and revision > self.endrev: break if not tag: continue - dict.__setitem__(self, tag, node.bin(hash)) + dict.__setitem__(self, tag, node.bin(ha)) f.close() def _write(self): @@ -168,11 +169,11 @@ class Tags(dict): def __setitem__(self, tag, info): if not tag: raise hgutil.Abort('tag cannot be empty') - hash, revision = info + ha, revision = info f = open(self.path, 'a') - f.write('%s %s %s\n' % (node.hex(hash), revision, tag)) + f.write('%s %s %s\n' % (node.hex(ha), revision, tag)) f.close() - dict.__setitem__(self, tag, hash) + dict.__setitem__(self, tag, ha) class RevMap(dict): @@ -185,11 +186,10 @@ class RevMap(dict): self.ypath = os.path.join(repo.path, 'svn', 'lastpulled') # TODO(durin42): Consider moving management of the youngest # file to svnmeta itself rather than leaving it here. - self._youngest = 0 # must load youngest file first, or else self._load() can # clobber the info - if os.path.isfile(self.ypath): - self._youngest = int(open(self.ypath).read().strip()) + _yonngest_str = util.load_string(self.ypath, '0') + self._youngest = int(_yonngest_str.strip()) self.oldest = 0 if os.path.isfile(self.path): self._load() @@ -198,9 +198,7 @@ class RevMap(dict): def _set_youngest(self, rev): self._youngest = max(self._youngest, rev) - fp = open(self.ypath, 'wb') - fp.write(str(self._youngest) + '\n') - fp.close() + util.save_string(self.ypath, str(self._youngest) + '\n') def _get_youngest(self): return self._youngest @@ -221,7 +219,7 @@ class RevMap(dict): print 'revmap too new -- please upgrade' raise NotImplementedError for l in f: - revnum, hash, branch = l.split(' ', 2) + revnum, ha, branch = l.split(' ', 2) if branch == '\n': branch = None else: @@ -231,7 +229,7 @@ class RevMap(dict): self.youngest = revnum if revnum < self.oldest or not self.oldest: self.oldest = revnum - dict.__setitem__(self, (revnum, branch), node.bin(hash)) + dict.__setitem__(self, (revnum, branch), node.bin(ha)) f.close() def _write(self): @@ -239,17 +237,17 @@ class RevMap(dict): f.write('%s\n' % self.VERSION) f.close() - def __setitem__(self, key, hash): + def __setitem__(self, key, ha): revnum, branch = key f = open(self.path, 'a') b = branch or '' - f.write(str(revnum) + ' ' + node.hex(hash) + ' ' + b + '\n') + f.write(str(revnum) + ' ' + node.hex(ha) + ' ' + b + '\n') f.close() if revnum > self.youngest or not self.youngest: self.youngest = revnum if revnum < self.oldest or not self.oldest: self.oldest = revnum - dict.__setitem__(self, (revnum, branch), hash) + dict.__setitem__(self, (revnum, branch), ha) class FileMap(object): @@ -269,12 +267,12 @@ class FileMap(object): yield name[:e], name[e+1:] e = name.rfind('/', 0, e) - def check(self, map, path): - map = getattr(self, map) - for pre, suf in self._rpairs(path): - if pre not in map: + def check(self, m, path): + m = getattr(self, m) + for pre, _suf in self._rpairs(path): + if pre not in m: continue - return map[pre] + return m[pre] return None def __contains__(self, path): @@ -294,13 +292,13 @@ class FileMap(object): def __len__(self): return len(self.include) + len(self.exclude) - def add(self, fn, map, path): - mapping = getattr(self, map) + def add(self, fn, m, path): + mapping = getattr(self, m) if path in mapping: msg = 'duplicate %s entry in %s: "%s"\n' - self.ui.status(msg % (map, fn, path)) + self.ui.status(msg % (m, fn, path)) return - bits = map.strip('e'), path + bits = m.strip('e'), path self.ui.debug('%sing %s\n' % bits) mapping[path] = path diff --git a/hgsubversion/svnexternals.py b/hgsubversion/svnexternals.py --- a/hgsubversion/svnexternals.py +++ b/hgsubversion/svnexternals.py @@ -17,7 +17,7 @@ try: canonpath = hgutil.canonpath except (ImportError, AttributeError): from mercurial import scmutil - canonpath = scmutil.canonpath + canonpath = scmutil.canonpath passpegrev = False import util @@ -59,7 +59,6 @@ class externalsfile(dict): def read(self, data): self.clear() fp = cStringIO.StringIO(data) - dirs = {} target = None for line in fp.readlines(): if not line.strip(): @@ -232,7 +231,7 @@ class externalsupdater: if rev: revspec = ['-r', rev] if os.path.isdir(path): - exturl, extroot, extrev = getsvninfo(path) + exturl, _extroot, extrev = getsvninfo(path) # Comparing the source paths is not enough, but I don't # know how to compare path+pegrev. The following update # might fail if the path was replaced by another unrelated @@ -347,7 +346,7 @@ def getchanges(ui, repo, parentctx, exts if exts: defs = parsedefinitions(ui, repo, '', exts) hgsub, hgsubstate = [], [] - for path, rev, source, pegrev, norevline, base in sorted(defs): + for path, rev, _source, _pegrev, norevline, base in sorted(defs): hgsub.append('%s = [hgsubversion] %s:%s\n' % (path, base, norevline)) if rev is None: diff --git a/hgsubversion/util.py b/hgsubversion/util.py --- a/hgsubversion/util.py +++ b/hgsubversion/util.py @@ -99,6 +99,29 @@ def normalize_url(url): url = '%s#%s' % (url, checkout) return url + +def load_string(file_path, default=None, limit=1024): + if not os.path.exists(file_path): + return default + try: + f = open(file_path, 'r') + ret = f.read(limit) + f.close() + except: + return default + if ret == '': + return default + return ret + + +def save_string(file_path, string): + if string is None: + string = "" + f = open(file_path, 'wb') + f.write(str(string)) + f.close() + + # TODO remove when we drop 1.3 support def progress(ui, *args, **kwargs): if getattr(ui, 'progress', False): diff --git a/setup.py b/setup.py --- a/setup.py +++ b/setup.py @@ -72,7 +72,7 @@ elif os.path.exists('.hg_archival.txt'): kw = dict([t.strip() for t in l.split(':', 1)] for l in open('.hg_archival.txt')) if 'tag' in kw: - version = kw['tag'] + version = kw['tag'] elif 'latesttag' in kw: version = '%(latesttag)s+%(latesttagdistance)s-%(node).12s' % kw else: @@ -107,22 +107,22 @@ except ImportError: requires.append('subvertpy>=0.7.4') setup( - name = 'hgsubversion', - version = version, - url = 'http://bitbucket.org/durin42/hgsubversion', - license = 'GNU GPL', - author = 'Augie Fackler, others', - author_email = 'durin42@gmail.com', - description = ('hgsubversion is a Mercurial extension for working with ' + name='hgsubversion', + version=version, + url='http://bitbucket.org/durin42/hgsubversion', + license='GNU GPL', + author='Augie Fackler, others', + author_email='durin42@gmail.com', + description=('hgsubversion is a Mercurial extension for working with ' 'Subversion repositories.'), - long_description = open(os.path.join(os.path.dirname(__file__), + long_description=open(os.path.join(os.path.dirname(__file__), 'README')).read(), - keywords = 'mercurial', - packages = ('hgsubversion', 'hgsubversion.svnwrap'), - package_data = { 'hgsubversion': ['help/subversion.rst'] }, - platforms = 'any', + keywords='mercurial', + packages=('hgsubversion', 'hgsubversion.svnwrap'), + package_data={ 'hgsubversion': ['help/subversion.rst'] }, + platforms='any', install_requires=requires, - classifiers = [ + classifiers=[ 'License :: OSI Approved :: GNU General Public License (GPL)', 'Intended Audience :: Developers', 'Topic :: Software Development :: Version Control', @@ -130,5 +130,5 @@ setup( 'Programming Language :: Python', 'Operating System :: OS Independent', ], - cmdclass = {'build_py': build_py}, + cmdclass={'build_py': build_py}, )