[MERGE REVIEW] Numbered backups

Martin Pool mbp at sourcefrog.net
Mon Apr 10 01:38:56 BST 2006


On 10/04/2006, at 6:19 AM, Aaron Bentley wrote:
>
> Once more with patches!
>

> +
> +def get_backup_name(entry, by_parent, parent_trans_id, tt):
> +    """Produce a backup-style name that appears to be available"""
> +    def name_gen():
> +        yield entry.name+"~"
> +        counter = 1
> +        while True:
> +            yield "%s~%d~" % (entry.name, counter)
> +            counter += 1
> +    for name in name_gen():
> +        if not tt.has_named_child(by_parent, parent_trans_id, name):
> +            return name

It would be nice to make this a bit more like the behaviour of GNU  
tools.  The full rules are pretty complex (http://www.gnu.org/ 
software/emacs/manual/html_node/Backup-Names.html) but there are two  
things that should be easily:

Numbered backups are

   file.~1~
   file.~2~

i.e. '%s.~%d~'

Secondly, the plain file~ backup is not stage 0 of numbered backups,  
but rather an alternative.  So we should just start at ~1~ and go on  
from there.

Possibly it would be better for get_backup_name to take a callback  
that checks the names rather than mixing it in here?  Up to you.

+1 with the numbering change, and a very welcome improvement.

-- 
Martin







More information about the bazaar mailing list