##// END OF EJS Templates
context: add memctx for memory commits
Patrick Mezard -
r6715:a3c41abf default
parent child Browse files
Show More
@@ -673,3 +673,89 b' class workingfilectx(filectx):'
673 return (t, tz)
673 return (t, tz)
674
674
675 def cmp(self, text): return self._repo.wread(self._path) == text
675 def cmp(self, text): return self._repo.wread(self._path) == text
676
677 class memctx(object):
678 """A memctx is a subset of changectx supposed to be built on memory
679 and passed to commit functions.
680
681 NOTE: this interface and the related memfilectx are experimental and
682 may change without notice.
683
684 parents - a pair of parent nodeids.
685 filectxfn - a callable taking (repo, memctx, path) arguments and
686 returning a memctx object.
687 date - any valid date string or (unixtime, offset), or None.
688 user - username string, or None.
689 extra - a dictionary of extra values, or None.
690 """
691 def __init__(self, repo, parents, text, files, filectxfn, user=None,
692 date=None, extra=None):
693 self._repo = repo
694 self._rev = None
695 self._node = None
696 self._text = text
697 self._date = date and util.parsedate(date) or util.makedate()
698 self._user = user or self._repo.ui.username()
699 parents = [(p or nullid) for p in parents]
700 p1, p2 = parents
701 self._parents = [self._repo.changectx(p) for p in (p1, p2)]
702 files = list(files)
703 files.sort()
704 self._status = [files, [], [], [], []]
705 self._filectxfn = filectxfn
706
707 self._extra = extra and extra.copy() or {}
708 if 'branch' not in self._extra:
709 self._extra['branch'] = 'default'
710 elif self._extra.get('branch') == '':
711 self._extra['branch'] = 'default'
712
713 def __str__(self):
714 return str(self._parents[0]) + "+"
715
716 def __nonzero__(self):
717 return True
718
719 def user(self): return self._user
720 def date(self): return self._date
721 def description(self): return self._text
722 def files(self): return self.modified()
723 def modified(self): return self._status[0]
724 def added(self): return self._status[1]
725 def removed(self): return self._status[2]
726 def deleted(self): return self._status[3]
727 def unknown(self): return self._status[4]
728 def clean(self): return self._status[5]
729 def branch(self): return self._extra['branch']
730 def extra(self): return self._extra
731
732 def parents(self):
733 """return contexts for each parent changeset"""
734 return self._parents
735
736 def filectx(self, path, filelog=None):
737 """get a file context from the working directory"""
738 return self._filectxfn(self._repo, self, path)
739
740 class memfilectx(object):
741 """A memfilectx is a subset of filectx supposed to be built by client
742 code and passed to commit functions.
743 """
744 def __init__(self, path, data, islink, isexec, copied):
745 """copied is the source file path, or None."""
746 self._path = path
747 self._data = data
748 self._flags = (islink and 'l' or '') + (isexec and 'x' or '')
749 self._copied = None
750 if copied:
751 self._copied = (copied, nullid)
752
753 def __nonzero__(self): return True
754 def __str__(self): return "%s@%s" % (self.path(), self._changectx)
755 def path(self): return self._path
756 def data(self): return self._data
757 def fileflags(self): return self._flags
758 def isexec(self): return 'x' in self._flags
759 def islink(self): return 'l' in self._flags
760 def renamed(self): return self._copied
761
@@ -798,6 +798,17 b' class localrepository(repo.repository):'
798 finally:
798 finally:
799 del lock, wlock
799 del lock, wlock
800
800
801 def commitctx(self, ctx):
802 wlock = lock = None
803 try:
804 wlock = self.wlock()
805 lock = self.lock()
806 return self._commitctx(ctx, force=True, force_editor=False,
807 empty_ok=True, use_dirstate=False,
808 update_dirstate=False)
809 finally:
810 del lock, wlock
811
801 def _commitctx(self, wctx, force=False, force_editor=False, empty_ok=False,
812 def _commitctx(self, wctx, force=False, force_editor=False, empty_ok=False,
802 use_dirstate=True, update_dirstate=True):
813 use_dirstate=True, update_dirstate=True):
803 tr = None
814 tr = None
General Comments 0
You need to be logged in to leave comments. Login now