Patchwork D6367: context: add modified(), added(), removed() to changectx too

login
register
mail settings
Submitter phabricator
Date May 11, 2019, 7:18 a.m.
Message ID <differential-rev-PHID-DREV-wgyjpmzxwckxcq3vcvek-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/40009/
State New
Headers show

Comments

phabricator - May 11, 2019, 7:18 a.m.
martinvonz created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  committablectx already has these, so it seems reasonable for changectx
  to also have them. I have considered storing these sets in the
  changeset extras in order to speed up copy tracing (to unmark a copy
  when it's been removed). If we do that, then these functions would be
  changed to get the information from the changeset extras. But I think
  this patch makes sense whether or not we eventually do that.
  
  Note that these are different from than {file_mods}, {file_adds}, and
  {file_dels} on merge commits. I think those template keywords always
  compare to p1. See https://bz.mercurial-scm.org/show_bug.cgi?id=4292
  for some discussion.
  
  Not optimized because they're not meant to be used generally used.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D6367

AFFECTED FILES
  mercurial/context.py

CHANGE DETAILS




To: martinvonz, #hg-reviewers
Cc: mercurial-devel
Yuya Nishihara - May 12, 2019, 2:59 a.m.
> +    def modified(self):
> +        modified = set(self.files())
> +        modified.difference_update(self.added())
> +        modified.difference_update(self.removed())
> +        return sorted(modified)
> +    def added(self):
> +        added = []
> +        for f in self.files():
> +            if not any(f in p for p in self.parents()):
> +                added.append(f)
> +        return added
> +    def removed(self):
> +        removed = []
> +        for f in self.files():
> +            if f not in self:
> +                removed.append(f)
> +        return removed

Do these definitions agree with the committablectx ones?
I think the committablectx calculates them based on the status from p1.
phabricator - May 12, 2019, 3:07 a.m.
yuja added a comment.


  > +    def modified(self):
  >  +        modified = set(self.files())
  >  +        modified.difference_update(self.added())
  >  +        modified.difference_update(self.removed())
  >  +        return sorted(modified)
  >  +    def added(self):
  >  +        added = []
  >  +        for f in self.files():
  >  +            if not any(f in p for p in self.parents()):
  >  +                added.append(f)
  >  +        return added
  >  +    def removed(self):
  >  +        removed = []
  >  +        for f in self.files():
  >  +            if f not in self:
  >  +                removed.append(f)
  >  +        return removed
  
  Do these definitions agree with the committablectx ones?
  I think the committablectx calculates them based on the status from p1.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D6367

To: martinvonz, #hg-reviewers
Cc: yuja, mercurial-devel
via Mercurial-devel - May 12, 2019, 5:06 p.m.
*From: *yuja (Yuya Nishihara) <phabricator@mercurial-scm.org>
*Date: *Sat, May 11, 2019, 20:12
*To: * <mercurial-devel@mercurial-scm.org>

yuja added a comment.
>
>
>   > +    def modified(self):
>   >  +        modified = set(self.files())
>   >  +        modified.difference_update(self.added())
>   >  +        modified.difference_update(self.removed())
>   >  +        return sorted(modified)
>   >  +    def added(self):
>   >  +        added = []
>   >  +        for f in self.files():
>   >  +            if not any(f in p for p in self.parents()):
>   >  +                added.append(f)
>   >  +        return added
>   >  +    def removed(self):
>   >  +        removed = []
>   >  +        for f in self.files():
>   >  +            if f not in self:
>   >  +                removed.append(f)
>   >  +        return removed
>
>   Do these definitions agree with the committablectx ones?
>   I think the committablectx calculates them based on the status from p1.
>

Oh, good point. I suppose I should rename these to something like
files{modified,added,removed} since they're slightly different.


> REPOSITORY
>   rHG Mercurial
>
> REVISION DETAIL
>   https://phab.mercurial-scm.org/D6367
>
> To: martinvonz, #hg-reviewers
> Cc: yuja, mercurial-devel
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
>

Patch

diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -439,6 +439,24 @@ 
         return self._changeset.date
     def files(self):
         return self._changeset.files
+    def modified(self):
+        modified = set(self.files())
+        modified.difference_update(self.added())
+        modified.difference_update(self.removed())
+        return sorted(modified)
+    def added(self):
+        added = []
+        for f in self.files():
+            if not any(f in p for p in self.parents()):
+                added.append(f)
+        return added
+    def removed(self):
+        removed = []
+        for f in self.files():
+            if f not in self:
+                removed.append(f)
+        return removed
+
     @propertycache
     def _copies(self):
         source = self._repo.ui.config('experimental', 'copies.read-from')