Mercurial > hg > openjdk > trees
changeset 17:4287704dd0bf
config: write .hg/trees only when it has changed
Also delete .hg/trees instead of writing an empty file.
author | jcoomes |
---|---|
date | Tue, 25 Feb 2014 06:42:56 -0800 |
parents | a6ed24673925 |
children | 6df509277779 |
files | trees.py |
diffstat | 1 files changed, 22 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/trees.py Mon Feb 03 10:14:38 2014 -0800 +++ b/trees.py Tue Feb 25 06:42:56 2014 -0800 @@ -308,13 +308,30 @@ l += [dirpath] return sorted(l) -def _writeconfig(repo, namespace, subtrees, append = False): - f = open(repo.join(namespace or 'trees'), append and 'a' or 'w') +def _readfile(path): + f = None try: - if subtrees: - f.write('\n'.join(subtrees) + '\n') - finally: + f = open(path, 'r') + s = f.read() f.close() + return s + except: + if f: + f.close() + return None + +def _writeconfig(repo, namespace, subtrees, append = False): + confpath = repo.join(namespace or 'trees') + if subtrees: + newconfig = '\n'.join(subtrees) + '\n' + if append or newconfig != _readfile(confpath): + f = open(confpath, append and 'a' or 'w') + try: + f.write(newconfig) + finally: + f.close() + elif os.path.exists(confpath): + os.remove(confpath) return 0 # ---------------- commands and associated recursion helpers -------------------