Mercurial > public > mercurial-scm > hg
comparison mercurial/patch.py @ 24416:f07047a506d1
patch.trydiff: add support for stripping a relative root
This assumes that if relroot is not None, all the files in modified, added and
removed start with it. In upcoming patches we'll follow that.
author | Siddharth Agarwal <sid0@fb.com> |
---|---|
date | Tue, 17 Mar 2015 12:59:41 -0700 |
parents | 72d7d390ef5d |
children | f2e1e097cda1 |
comparison
equal
deleted
inserted
replaced
24415:1cfded2fa1a9 | 24416:f07047a506d1 |
---|---|
2120 if opts.git or opts.upgrade: | 2120 if opts.git or opts.upgrade: |
2121 copy = copies.pathcopies(ctx1, ctx2) | 2121 copy = copies.pathcopies(ctx1, ctx2) |
2122 | 2122 |
2123 def difffn(opts, losedata): | 2123 def difffn(opts, losedata): |
2124 return trydiff(repo, revs, ctx1, ctx2, modified, added, removed, | 2124 return trydiff(repo, revs, ctx1, ctx2, modified, added, removed, |
2125 copy, getfilectx, opts, losedata, prefix) | 2125 copy, getfilectx, opts, losedata, prefix, '') |
2126 if opts.upgrade and not opts.git: | 2126 if opts.upgrade and not opts.git: |
2127 try: | 2127 try: |
2128 def losedata(fn): | 2128 def losedata(fn): |
2129 if not losedatafn or not losedatafn(fn=fn): | 2129 if not losedatafn or not losedatafn(fn=fn): |
2130 raise GitDiffRequired | 2130 raise GitDiffRequired |
2228 and copy[copyto[f]] == f): | 2228 and copy[copyto[f]] == f): |
2229 continue | 2229 continue |
2230 yield f1, f2, copyop | 2230 yield f1, f2, copyop |
2231 | 2231 |
2232 def trydiff(repo, revs, ctx1, ctx2, modified, added, removed, | 2232 def trydiff(repo, revs, ctx1, ctx2, modified, added, removed, |
2233 copy, getfilectx, opts, losedatafn, prefix): | 2233 copy, getfilectx, opts, losedatafn, prefix, relroot): |
2234 '''given input data, generate a diff and yield it in blocks | 2234 '''given input data, generate a diff and yield it in blocks |
2235 | 2235 |
2236 If generating a diff would lose data like flags or binary data and | 2236 If generating a diff would lose data like flags or binary data and |
2237 losedatafn is not None, it will be called. | 2237 losedatafn is not None, it will be called. |
2238 | 2238 |
2239 prefix is added to every path in the diff output.''' | 2239 relroot is removed and prefix is added to every path in the diff output. |
2240 | |
2241 If relroot is not empty, this function expects every path in modified, | |
2242 added, removed and copy to start with it.''' | |
2240 | 2243 |
2241 def gitindex(text): | 2244 def gitindex(text): |
2242 if not text: | 2245 if not text: |
2243 text = "" | 2246 text = "" |
2244 l = len(text) | 2247 l = len(text) |
2258 | 2261 |
2259 date1 = util.datestr(ctx1.date()) | 2262 date1 = util.datestr(ctx1.date()) |
2260 date2 = util.datestr(ctx2.date()) | 2263 date2 = util.datestr(ctx2.date()) |
2261 | 2264 |
2262 gitmode = {'l': '120000', 'x': '100755', '': '100644'} | 2265 gitmode = {'l': '120000', 'x': '100755', '': '100644'} |
2266 | |
2267 if relroot != '' and (repo.ui.configbool('devel', 'all') | |
2268 or repo.ui.configbool('devel', 'check-relroot')): | |
2269 for f in modified + added + removed + copy.keys() + copy.values(): | |
2270 if f is not None and not f.startswith(relroot): | |
2271 raise AssertionError( | |
2272 "file %s doesn't start with relroot %s" % (f, relroot)) | |
2263 | 2273 |
2264 for f1, f2, copyop in _filepairs( | 2274 for f1, f2, copyop in _filepairs( |
2265 ctx1, modified, added, removed, copy, opts): | 2275 ctx1, modified, added, removed, copy, opts): |
2266 content1 = None | 2276 content1 = None |
2267 content2 = None | 2277 content2 = None |
2291 (not f1 and flag2) or | 2301 (not f1 and flag2) or |
2292 # change flags | 2302 # change flags |
2293 (f1 and f2 and flag1 != flag2)): | 2303 (f1 and f2 and flag1 != flag2)): |
2294 losedatafn(f2 or f1) | 2304 losedatafn(f2 or f1) |
2295 | 2305 |
2296 path1 = posixpath.join(prefix, f1 or f2) | 2306 path1 = f1 or f2 |
2297 path2 = posixpath.join(prefix, f2 or f1) | 2307 path2 = f2 or f1 |
2308 path1 = posixpath.join(prefix, path1[len(relroot):]) | |
2309 path2 = posixpath.join(prefix, path2[len(relroot):]) | |
2298 header = [] | 2310 header = [] |
2299 if opts.git: | 2311 if opts.git: |
2300 header.append('diff --git %s%s %s%s' % | 2312 header.append('diff --git %s%s %s%s' % |
2301 (aprefix, path1, bprefix, path2)) | 2313 (aprefix, path1, bprefix, path2)) |
2302 if not f1: # added | 2314 if not f1: # added |