comparison mercurial/context.py @ 7077:ccbd39cad3c3

context: improve memctx documentation
author Patrick Mezard <pmezard@gmail.com>
date Sat, 11 Oct 2008 13:07:29 +0200
parents 8fee8ff13d37
children 9fe97eea5510
comparison
equal deleted inserted replaced
7076:c29d3f4ed967 7077:ccbd39cad3c3
684 return (t, tz) 684 return (t, tz)
685 685
686 def cmp(self, text): return self._repo.wread(self._path) == text 686 def cmp(self, text): return self._repo.wread(self._path) == text
687 687
688 class memctx(object): 688 class memctx(object):
689 """A memctx is a subset of changectx supposed to be built on memory 689 """Use memctx to perform in-memory commits via localrepo.commitctx().
690 and passed to commit functions. 690
691 691 Revision information is supplied at initialization time while
692 NOTE: this interface and the related memfilectx are experimental and 692 related files data and is made available through a callback
693 may change without notice. 693 mechanism. 'repo' is the current localrepo, 'parents' is a
694 694 sequence of two parent revisions identifiers (pass None for every
695 parents - a pair of parent nodeids. 695 missing parent), 'text' is the commit message and 'files' lists
696 filectxfn - a callable taking (repo, memctx, path) arguments and 696 names of files touched by the revision (normalized and relative to
697 returning a memctx object. 697 repository root).
698 date - any valid date string or (unixtime, offset), or None. 698
699 user - username string, or None. 699 filectxfn(repo, memctx, path) is a callable receiving the
700 extra - a dictionary of extra values, or None. 700 repository, the current memctx object and the normalized path of
701 requested file, relative to repository root. It is fired by the
702 commit function for every file in 'files', but calls order is
703 undefined. If the file is available in the revision being
704 committed (updated or added), filectxfn returns a memfilectx
705 object. If the file was removed, filectxfn raises an
706 IOError. Moved files are represented by marking the source file
707 removed and the new file added with copy information (see
708 memfilectx).
709
710 user receives the committer name and defaults to current
711 repository username, date is the commit date in any format
712 supported by util.parsedate() and defaults to current date, extra
713 is a dictionary of metadata or is left empty.
701 """ 714 """
702 def __init__(self, repo, parents, text, files, filectxfn, user=None, 715 def __init__(self, repo, parents, text, files, filectxfn, user=None,
703 date=None, extra=None): 716 date=None, extra=None):
704 self._repo = repo 717 self._repo = repo
705 self._rev = None 718 self._rev = None
750 def filectx(self, path, filelog=None): 763 def filectx(self, path, filelog=None):
751 """get a file context from the working directory""" 764 """get a file context from the working directory"""
752 return self._filectxfn(self._repo, self, path) 765 return self._filectxfn(self._repo, self, path)
753 766
754 class memfilectx(object): 767 class memfilectx(object):
755 """A memfilectx is a subset of filectx supposed to be built by client 768 """memfilectx represents an in-memory file to commit.
756 code and passed to commit functions. 769
770 See memctx for more details.
757 """ 771 """
758 def __init__(self, path, data, islink, isexec, copied): 772 def __init__(self, path, data, islink, isexec, copied):
759 """copied is the source file path, or None.""" 773 """
774 path is the normalized file path relative to repository root.
775 data is the file content as a string.
776 islink is True if the file is a symbolic link.
777 isexec is True if the file is executable.
778 copied is the source file path if current file was copied in the
779 revision being committed, or None."""
760 self._path = path 780 self._path = path
761 self._data = data 781 self._data = data
762 self._flags = (islink and 'l' or '') + (isexec and 'x' or '') 782 self._flags = (islink and 'l' or '') + (isexec and 'x' or '')
763 self._copied = None 783 self._copied = None
764 if copied: 784 if copied: