Show More
@@ -16,6 +16,7 from .node import ( | |||||
16 | from .thirdparty import attr |
|
16 | from .thirdparty import attr | |
17 |
|
17 | |||
18 | from . import ( |
|
18 | from . import ( | |
|
19 | copies, | |||
19 | encoding, |
|
20 | encoding, | |
20 | error, |
|
21 | error, | |
21 | pycompat, |
|
22 | pycompat, | |
@@ -89,61 +90,6 def encodeextra(d): | |||||
89 | return b"\0".join(items) |
|
90 | return b"\0".join(items) | |
90 |
|
91 | |||
91 |
|
92 | |||
92 | def encodecopies(files, copies): |
|
|||
93 | items = [] |
|
|||
94 | for i, dst in enumerate(files): |
|
|||
95 | if dst in copies: |
|
|||
96 | items.append(b'%d\0%s' % (i, copies[dst])) |
|
|||
97 | if len(items) != len(copies): |
|
|||
98 | raise error.ProgrammingError( |
|
|||
99 | b'some copy targets missing from file list' |
|
|||
100 | ) |
|
|||
101 | return b"\n".join(items) |
|
|||
102 |
|
||||
103 |
|
||||
104 | def decodecopies(files, data): |
|
|||
105 | try: |
|
|||
106 | copies = {} |
|
|||
107 | if not data: |
|
|||
108 | return copies |
|
|||
109 | for l in data.split(b'\n'): |
|
|||
110 | strindex, src = l.split(b'\0') |
|
|||
111 | i = int(strindex) |
|
|||
112 | dst = files[i] |
|
|||
113 | copies[dst] = src |
|
|||
114 | return copies |
|
|||
115 | except (ValueError, IndexError): |
|
|||
116 | # Perhaps someone had chosen the same key name (e.g. "p1copies") and |
|
|||
117 | # used different syntax for the value. |
|
|||
118 | return None |
|
|||
119 |
|
||||
120 |
|
||||
121 | def encodefileindices(files, subset): |
|
|||
122 | subset = set(subset) |
|
|||
123 | indices = [] |
|
|||
124 | for i, f in enumerate(files): |
|
|||
125 | if f in subset: |
|
|||
126 | indices.append(b'%d' % i) |
|
|||
127 | return b'\n'.join(indices) |
|
|||
128 |
|
||||
129 |
|
||||
130 | def decodefileindices(files, data): |
|
|||
131 | try: |
|
|||
132 | subset = [] |
|
|||
133 | if not data: |
|
|||
134 | return subset |
|
|||
135 | for strindex in data.split(b'\n'): |
|
|||
136 | i = int(strindex) |
|
|||
137 | if i < 0 or i >= len(files): |
|
|||
138 | return None |
|
|||
139 | subset.append(files[i]) |
|
|||
140 | return subset |
|
|||
141 | except (ValueError, IndexError): |
|
|||
142 | # Perhaps someone had chosen the same key name (e.g. "added") and |
|
|||
143 | # used different syntax for the value. |
|
|||
144 | return None |
|
|||
145 |
|
||||
146 |
|
||||
147 | def stripdesc(desc): |
|
93 | def stripdesc(desc): | |
148 | """strip trailing whitespace and leading and trailing empty lines""" |
|
94 | """strip trailing whitespace and leading and trailing empty lines""" | |
149 | return b'\n'.join([l.rstrip() for l in desc.splitlines()]).strip(b'\n') |
|
95 | return b'\n'.join([l.rstrip() for l in desc.splitlines()]).strip(b'\n') | |
@@ -368,7 +314,7 class changelogrevision(object): | |||||
368 | rawindices = self.extra.get(b'filesadded') |
|
314 | rawindices = self.extra.get(b'filesadded') | |
369 | if rawindices is None: |
|
315 | if rawindices is None: | |
370 | return None |
|
316 | return None | |
371 | return decodefileindices(self.files, rawindices) |
|
317 | return copies.decodefileindices(self.files, rawindices) | |
372 |
|
318 | |||
373 | @property |
|
319 | @property | |
374 | def filesremoved(self): |
|
320 | def filesremoved(self): | |
@@ -378,7 +324,7 class changelogrevision(object): | |||||
378 | rawindices = self.extra.get(b'filesremoved') |
|
324 | rawindices = self.extra.get(b'filesremoved') | |
379 | if rawindices is None: |
|
325 | if rawindices is None: | |
380 | return None |
|
326 | return None | |
381 | return decodefileindices(self.files, rawindices) |
|
327 | return copies.decodefileindices(self.files, rawindices) | |
382 |
|
328 | |||
383 | @property |
|
329 | @property | |
384 | def p1copies(self): |
|
330 | def p1copies(self): | |
@@ -388,7 +334,7 class changelogrevision(object): | |||||
388 | rawcopies = self.extra.get(b'p1copies') |
|
334 | rawcopies = self.extra.get(b'p1copies') | |
389 | if rawcopies is None: |
|
335 | if rawcopies is None: | |
390 | return None |
|
336 | return None | |
391 | return decodecopies(self.files, rawcopies) |
|
337 | return copies.decodecopies(self.files, rawcopies) | |
392 |
|
338 | |||
393 | @property |
|
339 | @property | |
394 | def p2copies(self): |
|
340 | def p2copies(self): | |
@@ -398,7 +344,7 class changelogrevision(object): | |||||
398 | rawcopies = self.extra.get(b'p2copies') |
|
344 | rawcopies = self.extra.get(b'p2copies') | |
399 | if rawcopies is None: |
|
345 | if rawcopies is None: | |
400 | return None |
|
346 | return None | |
401 | return decodecopies(self.files, rawcopies) |
|
347 | return copies.decodecopies(self.files, rawcopies) | |
402 |
|
348 | |||
403 | @property |
|
349 | @property | |
404 | def description(self): |
|
350 | def description(self): | |
@@ -711,13 +657,13 class changelog(revlog.revlog): | |||||
711 | ): |
|
657 | ): | |
712 | extra.pop(name, None) |
|
658 | extra.pop(name, None) | |
713 | if p1copies is not None: |
|
659 | if p1copies is not None: | |
714 | p1copies = encodecopies(sortedfiles, p1copies) |
|
660 | p1copies = copies.encodecopies(sortedfiles, p1copies) | |
715 | if p2copies is not None: |
|
661 | if p2copies is not None: | |
716 | p2copies = encodecopies(sortedfiles, p2copies) |
|
662 | p2copies = copies.encodecopies(sortedfiles, p2copies) | |
717 | if filesadded is not None: |
|
663 | if filesadded is not None: | |
718 | filesadded = encodefileindices(sortedfiles, filesadded) |
|
664 | filesadded = copies.encodefileindices(sortedfiles, filesadded) | |
719 | if filesremoved is not None: |
|
665 | if filesremoved is not None: | |
720 | filesremoved = encodefileindices(sortedfiles, filesremoved) |
|
666 | filesremoved = copies.encodefileindices(sortedfiles, filesremoved) | |
721 | if self._copiesstorage == b'extra': |
|
667 | if self._copiesstorage == b'extra': | |
722 | extrasentries = p1copies, p2copies, filesadded, filesremoved |
|
668 | extrasentries = p1copies, p2copies, filesadded, filesremoved | |
723 | if extra is None and any(x is not None for x in extrasentries): |
|
669 | if extra is None and any(x is not None for x in extrasentries): |
@@ -546,7 +546,7 class changectx(basectx): | |||||
546 | filesadded = None |
|
546 | filesadded = None | |
547 | if filesadded is None: |
|
547 | if filesadded is None: | |
548 | if compute_on_none: |
|
548 | if compute_on_none: | |
549 |
filesadded = |
|
549 | filesadded = copies.computechangesetfilesadded(self) | |
550 | else: |
|
550 | else: | |
551 | filesadded = [] |
|
551 | filesadded = [] | |
552 | return filesadded |
|
552 | return filesadded | |
@@ -565,7 +565,7 class changectx(basectx): | |||||
565 | filesremoved = None |
|
565 | filesremoved = None | |
566 | if filesremoved is None: |
|
566 | if filesremoved is None: | |
567 | if compute_on_none: |
|
567 | if compute_on_none: | |
568 |
filesremoved = |
|
568 | filesremoved = copies.computechangesetfilesremoved(self) | |
569 | else: |
|
569 | else: | |
570 | filesremoved = [] |
|
570 | filesremoved = [] | |
571 | return filesremoved |
|
571 | return filesremoved |
@@ -14,6 +14,7 import os | |||||
14 | from .i18n import _ |
|
14 | from .i18n import _ | |
15 |
|
15 | |||
16 | from . import ( |
|
16 | from . import ( | |
|
17 | error, | |||
17 | match as matchmod, |
|
18 | match as matchmod, | |
18 | node, |
|
19 | node, | |
19 | pathutil, |
|
20 | pathutil, | |
@@ -855,6 +856,26 def duplicatecopies(repo, wctx, rev, fro | |||||
855 | wctx[dst].markcopied(src) |
|
856 | wctx[dst].markcopied(src) | |
856 |
|
857 | |||
857 |
|
858 | |||
|
859 | def computechangesetfilesadded(ctx): | |||
|
860 | """return the list of files added in a changeset | |||
|
861 | """ | |||
|
862 | added = [] | |||
|
863 | for f in ctx.files(): | |||
|
864 | if not any(f in p for p in ctx.parents()): | |||
|
865 | added.append(f) | |||
|
866 | return added | |||
|
867 | ||||
|
868 | ||||
|
869 | def computechangesetfilesremoved(ctx): | |||
|
870 | """return the list of files removed in a changeset | |||
|
871 | """ | |||
|
872 | removed = [] | |||
|
873 | for f in ctx.files(): | |||
|
874 | if f not in ctx: | |||
|
875 | removed.append(f) | |||
|
876 | return removed | |||
|
877 | ||||
|
878 | ||||
858 | def computechangesetcopies(ctx): |
|
879 | def computechangesetcopies(ctx): | |
859 | """return the copies data for a changeset |
|
880 | """return the copies data for a changeset | |
860 |
|
881 | |||
@@ -879,3 +900,58 def computechangesetcopies(ctx): | |||||
879 | elif src in p2 and p2[src].filenode() == srcnode: |
|
900 | elif src in p2 and p2[src].filenode() == srcnode: | |
880 | p2copies[dst] = src |
|
901 | p2copies[dst] = src | |
881 | return p1copies, p2copies |
|
902 | return p1copies, p2copies | |
|
903 | ||||
|
904 | ||||
|
905 | def encodecopies(files, copies): | |||
|
906 | items = [] | |||
|
907 | for i, dst in enumerate(files): | |||
|
908 | if dst in copies: | |||
|
909 | items.append(b'%d\0%s' % (i, copies[dst])) | |||
|
910 | if len(items) != len(copies): | |||
|
911 | raise error.ProgrammingError( | |||
|
912 | b'some copy targets missing from file list' | |||
|
913 | ) | |||
|
914 | return b"\n".join(items) | |||
|
915 | ||||
|
916 | ||||
|
917 | def decodecopies(files, data): | |||
|
918 | try: | |||
|
919 | copies = {} | |||
|
920 | if not data: | |||
|
921 | return copies | |||
|
922 | for l in data.split(b'\n'): | |||
|
923 | strindex, src = l.split(b'\0') | |||
|
924 | i = int(strindex) | |||
|
925 | dst = files[i] | |||
|
926 | copies[dst] = src | |||
|
927 | return copies | |||
|
928 | except (ValueError, IndexError): | |||
|
929 | # Perhaps someone had chosen the same key name (e.g. "p1copies") and | |||
|
930 | # used different syntax for the value. | |||
|
931 | return None | |||
|
932 | ||||
|
933 | ||||
|
934 | def encodefileindices(files, subset): | |||
|
935 | subset = set(subset) | |||
|
936 | indices = [] | |||
|
937 | for i, f in enumerate(files): | |||
|
938 | if f in subset: | |||
|
939 | indices.append(b'%d' % i) | |||
|
940 | return b'\n'.join(indices) | |||
|
941 | ||||
|
942 | ||||
|
943 | def decodefileindices(files, data): | |||
|
944 | try: | |||
|
945 | subset = [] | |||
|
946 | if not data: | |||
|
947 | return subset | |||
|
948 | for strindex in data.split(b'\n'): | |||
|
949 | i = int(strindex) | |||
|
950 | if i < 0 or i >= len(files): | |||
|
951 | return None | |||
|
952 | subset.append(files[i]) | |||
|
953 | return subset | |||
|
954 | except (ValueError, IndexError): | |||
|
955 | # Perhaps someone had chosen the same key name (e.g. "added") and | |||
|
956 | # used different syntax for the value. | |||
|
957 | return None |
@@ -2219,23 +2219,3 def bookmarkrevs(repo, mark): | |||||
2219 | mark, |
|
2219 | mark, | |
2220 | mark, |
|
2220 | mark, | |
2221 | ) |
|
2221 | ) | |
2222 |
|
||||
2223 |
|
||||
2224 | def computechangesetfilesadded(ctx): |
|
|||
2225 | """return the list of files added in a changeset |
|
|||
2226 | """ |
|
|||
2227 | added = [] |
|
|||
2228 | for f in ctx.files(): |
|
|||
2229 | if not any(f in p for p in ctx.parents()): |
|
|||
2230 | added.append(f) |
|
|||
2231 | return added |
|
|||
2232 |
|
||||
2233 |
|
||||
2234 | def computechangesetfilesremoved(ctx): |
|
|||
2235 | """return the list of files removed in a changeset |
|
|||
2236 | """ |
|
|||
2237 | removed = [] |
|
|||
2238 | for f in ctx.files(): |
|
|||
2239 | if f not in ctx: |
|
|||
2240 | removed.append(f) |
|
|||
2241 | return removed |
|
General Comments 0
You need to be logged in to leave comments.
Login now