mercurial/localrepo.py
changeset 8412 2bf4f380f6ab
parent 8411 4d5916358abd
child 8414 2348ce25849b
equal deleted inserted replaced
8411:4d5916358abd 8412:2bf4f380f6ab
   824         Revision information is passed via the context argument.
   824         Revision information is passed via the context argument.
   825         If editor is supplied, it is called to get a commit message.
   825         If editor is supplied, it is called to get a commit message.
   826         If working is set, the working directory is affected.
   826         If working is set, the working directory is affected.
   827         """
   827         """
   828 
   828 
   829         tr = None
   829         tr = lock = None
   830         valid = 0 # don't save the dirstate if this isn't set
   830         valid = 0 # don't save the dirstate if this isn't set
   831         lock = None
       
   832         commit = sorted(ctx.modified() + ctx.added())
       
   833         remove = ctx.removed()
   831         remove = ctx.removed()
   834         extra = ctx.extra().copy()
       
   835         branchname = extra['branch']
       
   836         user = ctx.user()
       
   837         text = ctx.description()
       
   838 
   832 
   839         p1, p2 = [p.node() for p in ctx.parents()]
   833         p1, p2 = [p.node() for p in ctx.parents()]
   840         c1 = self.changelog.read(p1)
   834         c1 = self.changelog.read(p1)
   841         c2 = self.changelog.read(p2)
   835         c2 = self.changelog.read(p2)
   842         m1 = self.manifest.read(c1[0]).copy()
   836         m1 = self.manifest.read(c1[0]).copy()
   843         m2 = self.manifest.read(c2[0])
   837         m2 = self.manifest.read(c2[0])
   844 
   838         user = ctx.user()
   845         xp1 = hex(p1)
   839 
   846         if p2 == nullid: xp2 = ''
   840         xp1, xp2 = hex(p1), hex(p2)
   847         else: xp2 = hex(p2)
   841         if p2 == nullid:
       
   842             xp2 = ''
   848         self.hook("precommit", throw=True, parent1=xp1, parent2=xp2)
   843         self.hook("precommit", throw=True, parent1=xp1, parent2=xp2)
   849 
   844 
   850         lock = self.lock()
   845         lock = self.lock()
   851         try:
   846         try:
   852             tr = self.transaction()
   847             tr = self.transaction()
   854 
   849 
   855             # check in files
   850             # check in files
   856             new = {}
   851             new = {}
   857             changed = []
   852             changed = []
   858             linkrev = len(self)
   853             linkrev = len(self)
   859             for f in commit:
   854             for f in sorted(ctx.modified() + ctx.added()):
   860                 self.ui.note(f + "\n")
   855                 self.ui.note(f + "\n")
   861                 try:
   856                 try:
   862                     fctx = ctx[f]
   857                     fctx = ctx[f]
   863                     new[f] = self._filecommit(fctx, m1, m2, linkrev, trp,
   858                     new[f] = self._filecommit(fctx, m1, m2, linkrev, trp,
   864                                               changed)
   859                                               changed)
   890                     del m1[f]
   885                     del m1[f]
   891                     removed1.append(f)
   886                     removed1.append(f)
   892             mn = self.manifest.add(m1, trp, linkrev, c1[0], c2[0],
   887             mn = self.manifest.add(m1, trp, linkrev, c1[0], c2[0],
   893                                    (new, removed1))
   888                                    (new, removed1))
   894 
   889 
       
   890             text = ctx.description()
   895             if editor:
   891             if editor:
   896                 text = editor(self, ctx, added, updated, removed)
   892                 text = editor(self, ctx, added, updated, removed)
   897 
   893 
   898             lines = [line.rstrip() for line in text.rstrip().splitlines()]
   894             lines = [line.rstrip() for line in text.rstrip().splitlines()]
   899             while lines and not lines[0]:
   895             while lines and not lines[0]:
   900                 del lines[0]
   896                 del lines[0]
   901             text = '\n'.join(lines)
   897             text = '\n'.join(lines)
   902 
   898 
   903             self.changelog.delayupdate()
   899             self.changelog.delayupdate()
   904             n = self.changelog.add(mn, changed + removed, text, trp, p1, p2,
   900             n = self.changelog.add(mn, changed + removed, text, trp, p1, p2,
   905                                    user, ctx.date(), extra)
   901                                    user, ctx.date(), ctx.extra().copy())
   906             p = lambda: self.changelog.writepending() and self.root or ""
   902             p = lambda: self.changelog.writepending() and self.root or ""
   907             self.hook('pretxncommit', throw=True, node=hex(n), parent1=xp1,
   903             self.hook('pretxncommit', throw=True, node=hex(n), parent1=xp1,
   908                       parent2=xp2, pending=p)
   904                       parent2=xp2, pending=p)
   909             self.changelog.finalize(trp)
   905             self.changelog.finalize(trp)
   910             tr.close()
   906             tr.close()