# HG changeset patch # User David Schleimer # Date 1369179246 25200 # Node ID 2bf860f327e22276e54721373aa68c99819fa80a # Parent 8feff33e387d64c0c0ad87b812edefbaa4c3b616 util: move pickle_atomic from svnmeta to util diff --git a/hgsubversion/svnmeta.py b/hgsubversion/svnmeta.py --- a/hgsubversion/svnmeta.py +++ b/hgsubversion/svnmeta.py @@ -14,22 +14,6 @@ import layouts import editor -def pickle_atomic(data, file_path): - """pickle some data to a path atomically. - - This is present because I kept corrupting my revmap by managing to hit ^C - during the pickle of that file. - """ - f = hgutil.atomictempfile(file_path, 'w+b', 0644) - pickle.dump(data, f) - # Older versions of hg have .rename() instead of .close on - # atomictempfile. - if getattr(hgutil.atomictempfile, 'rename', False): - f.rename() - else: - f.close() - - class SVNMeta(object): def __init__(self, repo, uuid=None, subdir=None): @@ -73,7 +57,7 @@ class SVNMeta(object): self._layout = layouts.detect.layout_from_file(self.meta_data_dir, ui=self.repo.ui) self._layoutobj = None - pickle_atomic(self.tag_locations, self.tag_locations_file) + util.pickle_atomic(self.tag_locations, self.tag_locations_file) # ensure nested paths are handled properly self.tag_locations.sort() self.tag_locations.reverse() @@ -217,7 +201,7 @@ class SVNMeta(object): '''Save the Subversion metadata. This should really be called after every revision is created. ''' - pickle_atomic(self.branches, self.branch_info_file) + util.pickle_atomic(self.branches, self.branch_info_file) def localname(self, path): """Compute the local name for a branch located at path. diff --git a/hgsubversion/util.py b/hgsubversion/util.py --- a/hgsubversion/util.py +++ b/hgsubversion/util.py @@ -1,3 +1,4 @@ +import cPickle as pickle import errno import re import os @@ -128,6 +129,20 @@ def save_string(file_path, string): f.write(str(string)) f.close() +def pickle_atomic(data, file_path): + """pickle some data to a path atomically. + + This is present because I kept corrupting my revmap by managing to hit ^C + during the pickle of that file. + """ + f = hgutil.atomictempfile(file_path, 'w+b', 0644) + pickle.dump(data, f) + # Older versions of hg have .rename() instead of .close on + # atomictempfile. + if getattr(hgutil.atomictempfile, 'rename', False): + f.rename() + else: + f.close() # TODO remove when we drop 1.3 support def progress(ui, *args, **kwargs):