From patchwork Fri Aug 29 08:59:25 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [8, of, 9, PoC] mq2: write new node to patch file when qpushing and orphan old node From: Mads Kiilerich X-Patchwork-Id: 5613 Message-Id: <5f5f3c1fe8196842ce41.1409302765@localhost.localdomain> To: mercurial-devel@selenic.com Date: Fri, 29 Aug 2014 10:59:25 +0200 # HG changeset patch # User Mads Kiilerich # Date 1409301991 -7200 # Fri Aug 29 10:46:31 2014 +0200 # Node ID 5f5f3c1fe8196842ce4198ad1f6c11a83ce9f80e # Parent a192c511d96e84fa9c018fb99b6737e899b926ac mq2: write new node to patch file when qpushing and orphan old node diff --git a/hgext/mq.py b/hgext/mq.py --- a/hgext/mq.py +++ b/hgext/mq.py @@ -810,6 +810,7 @@ class queue(object): message.append("\nimported patch %s" % patchname) message = '\n'.join(message) + repo = repo.unfiltered() if ph.nodeid and ph.nodeid in repo: orgctx = repo[ph.nodeid] current = repo['.'] @@ -844,6 +845,30 @@ class queue(object): date=ph.date, force=True)#, extra=extra, editor=editor) self.ui.debug(_("grafted %s as %s\n") % (orgctx, short(n))) + diffopts = self.patchopts(self.diffopts(), patchname) + + patchf = self.opener(patchname, "w", atomictemp=True) + + ph.setnodeid(hex(n)) + ph.setparent(hex(current.node())) + comments = str(ph) + if comments: + patchf.write(comments) + chunks = patchmod.diff(repo.unfiltered(), current.node(), + opts=diffopts) + for chunk in chunks: + patchf.write(chunk) + + patchf.close() + + self.ui.debug('obsoleting org %s by %s\n' % (short(orgctx.node()), short(n))) + tr = repo.transaction('qrefresh-old-obsolete') + try: + repo.obsstore.create(tr, orgctx.node(), [n]) + tr.close() + finally: + tr.release() + if update_status: self.applied.append(statusentry(n, patchname)) diff --git a/tests/test-mq-guards.t b/tests/test-mq-guards.t --- a/tests/test-mq-guards.t +++ b/tests/test-mq-guards.t @@ -128,7 +128,6 @@ should display b.patch should push c.patch $ hg qpush -a - (working directory not at a head) applying c.patch now at: c.patch @@ -165,7 +164,6 @@ should push a.patch, not b.patch applying a.patch now at: a.patch $ hg qpush - (working directory not at a head) applying c.patch now at: c.patch $ hg qpop -a @@ -182,7 +180,6 @@ should push b.patch applying b.patch now at: b.patch $ hg qpush -a - (working directory not at a head) applying c.patch now at: c.patch $ hg qprev @@ -208,7 +205,6 @@ should push a.patch, b.patch applying a.patch now at: a.patch $ hg qpush - (working directory not at a head) applying b.patch now at: b.patch $ hg qpop -a @@ -271,7 +267,6 @@ should push b.patch now at: b.patch $ hg qpush -a - (working directory not at a head) applying c.patch now at: c.patch $ hg qselect -n --reapply diff --git a/tests/test-mq2.t b/tests/test-mq2.t --- a/tests/test-mq2.t +++ b/tests/test-mq2.t @@ -123,8 +123,8 @@ now at: b $ cat .hg/patches/b # HG changeset patch - # Node ID 3506c28d72aa3a31f8ce50ca4cfcb812af131450 - # Parent cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b + # Node ID c27d00b1f47f75fd7d1a0582d905310adfac707c + # Parent dfa6dafa9c6c9006134bb31aa2ec52a3c17baccc # Date 47 0 b @@ -146,10 +146,6 @@ | o 4 dfa6dafa9c6c draft yada | - | o 3 757e6e08e7eb draft a2 - | | - | o 2 3506c28d72aa draft b - |/ o 0 cb9a9f314b8b draft a @@ -170,9 +166,5 @@ | @ 4 dfa6dafa9c6c draft yada | - | o 3 757e6e08e7eb draft a2 - | | - | o 2 3506c28d72aa draft b - |/ o 0 cb9a9f314b8b draft a