Patchwork [5,of,6] scmutil: add a function to mark that files have been operated on

login
register
mail settings
Submitter Siddharth Agarwal
Date May 7, 2013, 12:12 a.m.
Message ID <486f0b01206477869f6a.1367885551@sid0x220>
Download mbox | patch
Permalink /patch/1577/
State Superseded, archived
Commit 0c7cf411b3902f41e76d923f972c9cccf70d9f8c
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 1365107908 25200
#      Thu Apr 04 13:38:28 2013 -0700
# Node ID 486f0b01206477869f6a6946961fea0b2e776b12
# 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.
Augie Fackler - May 7, 2013, 5:25 p.m.
On Mon, May 06, 2013 at 05:12:31PM -0700, Siddharth Agarwal wrote:
> # HG changeset patch
> # User Siddharth Agarwal <sid0@fb.com>
> # Date 1365107908 25200
> #      Thu Apr 04 13:38:28 2013 -0700
> # Node ID 486f0b01206477869f6a6946961fea0b2e776b12
> # 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.
>
> diff -r 3f123b5d113d -r 486f0b012064 mercurial/scmutil.py
> --- a/mercurial/scmutil.py	Wed Apr 03 15:53:59 2013 -0700
> +++ b/mercurial/scmutil.py	Thu Apr 04 13:38:28 2013 -0700
> @@ -714,6 +714,36 @@ def addremove(repo, pats=[], opts={}, dr
>              return 1
>      return 0
>
> +def touch(repo, files, similarity=0.0):

markhandled?
markchecked?

touch confuses me, as it sounds to me like we're trying to dirty the
file, when in fact it's the opposite.

> +    '''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.
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel

Patch

diff -r 3f123b5d113d -r 486f0b012064 mercurial/scmutil.py
--- a/mercurial/scmutil.py	Wed Apr 03 15:53:59 2013 -0700
+++ b/mercurial/scmutil.py	Thu Apr 04 13:38:28 2013 -0700
@@ -714,6 +714,36 @@  def addremove(repo, pats=[], opts={}, dr
             return 1
     return 0
 
+def touch(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.