Patchwork [4,of,6] scmutil.addremove: factor out code to mark added/removed/renames

login
register
mail settings
Submitter Siddharth Agarwal
Date May 7, 2013, 12:12 a.m.
Message ID <3f123b5d113d0b2626c7.1367885550@sid0x220>
Download mbox | patch
Permalink /patch/1574/
State Accepted, archived
Commit 9a4e219bda89b940b094948b3d278b35d9c61db5
Delegated to: Augie Fackler
Headers show

Comments

Siddharth Agarwal - May 7, 2013, 12:12 a.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@fb.com>
# Date 1365029639 25200
#      Wed Apr 03 15:53:59 2013 -0700
# Node ID 3f123b5d113d0b2626c74678aa0b6fe994a8883d
# Parent  bc4a797e7206ac8180f20cebf6a3c0ea927e127d
scmutil.addremove: factor out code to mark added/removed/renames

An upcoming patch will reuse this code in another function.

Patch

diff -r bc4a797e7206 -r 3f123b5d113d mercurial/scmutil.py
--- a/mercurial/scmutil.py	Wed Apr 03 16:32:41 2013 -0700
+++ b/mercurial/scmutil.py	Wed Apr 03 15:53:59 2013 -0700
@@ -707,15 +707,7 @@  def addremove(repo, pats=[], opts={}, dr
                            similarity)
 
     if not dry_run:
-        wctx = repo[None]
-        wlock = repo.wlock()
-        try:
-            wctx.forget(deleted)
-            wctx.add(unknown)
-            for new, old in renames.iteritems():
-                wctx.copy(old, new)
-        finally:
-            wlock.release()
+        _markchanges(repo, unknown, deleted, renames)
 
     for f in rejected:
         if f in m.files():
@@ -763,6 +755,19 @@  def _findrenames(repo, matcher, added, r
             renames[new] = old
     return renames
 
+def _markchanges(repo, unknown, deleted, renames):
+    '''Marks the files in unknown as added, the files in deleted as removed,
+    and the files in renames as copied.'''
+    wctx = repo[None]
+    wlock = repo.wlock()
+    try:
+        wctx.forget(deleted)
+        wctx.add(unknown)
+        for new, old in renames.iteritems():
+            wctx.copy(old, new)
+    finally:
+        wlock.release()
+
 def dirstatecopy(ui, repo, wctx, src, dst, dryrun=False, cwd=None):
     """Update the dirstate to reflect the intent of copying src to dst. For
     different reasons it might not end with dst being marked as copied from src.