Anonymous avatar Anonymous committed 8726ea0

hgshelve: fix issue where shelved hunk not removed from working files

The issue:
% mkdir hg-issue
% cd hg-issue
% hg init
% cat > a <<EOF
1
2
3
4
EOF
% hg add a
% hg commit -m 'one'
% rm a
% cat > a <<EOF
a
1
2
3
4
b
EOF
% hg shelve
y
n
y
% cat a
a
1
2
3
4
b
% hg unshelve -i
... exists with line +b in patch...

The solution:
The 'in' operator was missing the chunk as the chunk is modified in
filterpatch(). Since the toline attribute is the only thing changed,
override the __cmp__() method and ignore the toline attribute in cmp().

Comments (0)

Files changed (1)

         self.hunk = hunk
         self.added, self.removed = countchanges(self.hunk)
 
+    def __cmp__(self,rhs):
+        # since the hunk().toline needs to be adjusted when hunks are
+        # removed/added, we can't take it into account when we cmp
+        attrs = ['header','fromline','proc','hunk','added','removed']
+        for attr in attrs:
+            selfattr = getattr(self,attr,None)
+            rhsattr = getattr(rhs,attr,None)
+
+            if selfattr is None or rhsattr is None:
+                raise Exception("non-existant attribute %s" % attr)
+
+            rv = cmp(selfattr,rhsattr)
+            if rv != 0:
+                return rv
+        return rv
+
+
     def write(self, fp):
         delta = len(self.before) + len(self.after)
         fromlen = delta + self.removed
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.