Patchwork [1,of,2,V3] scmutil: add a function to mark that files have been operated on

login
register
mail settings
Submitter Siddharth Agarwal
Date May 8, 2013, 10:18 p.m.
Message ID <80ac5083bbebdc64b816.1368051515@dev1091.prn1.facebook.com>
Download mbox | patch
Permalink /patch/1594/
State Accepted, archived
Headers show

Comments

Siddharth Agarwal - May 8, 2013, 10:18 p.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@fb.com>
# Date 1365107908 25200
#      Thu Apr 04 13:38:28 2013 -0700
# Node ID 80ac5083bbebdc64b81656510278dbc830cf0e13
# Parent  3f123b5d113d0b2626c74678aa0b6fe994a8883d
scmutil: add a function to mark that files have been operated on

Several places use scmutil.addremove as a means to declare that certain files
have been operated on. This is ugly because:
- addremove takes patterns relative to the cwd, not paths relative to the root,
  which means extra contortions for callers.
- addremove doesn't make clear what happens to files whose status hasn't
  changed.

This new method accepts filenames relative to the repo root, and has a much
clearer contract. It also allows future modifications that do more with files
whose status hasn't changed.

Patch

diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -714,6 +714,36 @@ 
             return 1
     return 0
 
+def marktouched(repo, files, similarity=0.0):
+    '''Assert that files have somehow been operated upon. files are relative to
+    the repo root.'''
+    m = matchfiles(repo, files)
+    rejected = []
+    m.bad = lambda x, y: rejected.append(x)
+
+    added, unknown, deleted, removed = _interestingfiles(repo, m)
+
+    if repo.ui.verbose:
+        unknownset = set(unknown)
+        toprint = unknownset.copy()
+        toprint.update(deleted)
+        for abs in sorted(toprint):
+            if abs in unknownset:
+                status = _('adding %s\n') % abs
+            else:
+                status = _('removing %s\n') % abs
+            repo.ui.status(status)
+
+    renames = _findrenames(repo, m, added + unknown, removed + deleted,
+                           similarity)
+
+    _markchanges(repo, unknown, deleted, renames)
+
+    for f in rejected:
+        if f in m.files():
+            return 1
+    return 0
+
 def _interestingfiles(repo, matcher):
     '''Walk dirstate with matcher, looking for files that addremove would care
     about.