comparison mercurial/patch.py @ 24243:daee2039dd11

patch.pathtransform: add doctests In upcoming patches we're going to make this function more complex, so add some unit tests for it.
author Siddharth Agarwal <sid0@fb.com>
date Fri, 06 Mar 2015 21:48:40 -0800
parents 3acb83c6c0f1
children 5918bb365c72
comparison
equal deleted inserted replaced
24242:3acb83c6c0f1 24243:daee2039dd11
1086 if i < 0: 1086 if i < 0:
1087 return s 1087 return s
1088 return s[:i] 1088 return s[:i]
1089 1089
1090 def pathtransform(path, strip): 1090 def pathtransform(path, strip):
1091 '''turn a path from a patch into a path suitable for the repository
1092
1093 Returns (stripped components, path in repository).
1094
1095 >>> pathtransform('a/b/c', 0)
1096 ('', 'a/b/c')
1097 >>> pathtransform(' a/b/c ', 0)
1098 ('', ' a/b/c')
1099 >>> pathtransform(' a/b/c ', 2)
1100 ('a/b/', 'c')
1101 >>> pathtransform(' a//b/c ', 2)
1102 ('a//b/', 'c')
1103 >>> pathtransform('a/b/c', 3)
1104 Traceback (most recent call last):
1105 PatchError: unable to strip away 1 of 3 dirs from a/b/c
1106 '''
1091 pathlen = len(path) 1107 pathlen = len(path)
1092 i = 0 1108 i = 0
1093 if strip == 0: 1109 if strip == 0:
1094 return '', path.rstrip() 1110 return '', path.rstrip()
1095 count = strip 1111 count = strip