Mercurial > public > mercurial-scm > hg
comparison mercurial/patch.py @ 24253:26fa5ff9e660
patch.patchbackend: accept a prefix parameter
author | Siddharth Agarwal <sid0@fb.com> |
---|---|
date | Fri, 06 Mar 2015 22:27:41 -0800 |
parents | 6e19516094a3 |
children | 60c279ab7bd3 |
comparison
equal
deleted
inserted
replaced
24252:f962692853c0 | 24253:26fa5ff9e660 |
---|---|
1492 if code: | 1492 if code: |
1493 raise PatchError(_("patch command failed: %s") % | 1493 raise PatchError(_("patch command failed: %s") % |
1494 util.explainexit(code)[0]) | 1494 util.explainexit(code)[0]) |
1495 return fuzz | 1495 return fuzz |
1496 | 1496 |
1497 def patchbackend(ui, backend, patchobj, strip, files=None, eolmode='strict'): | 1497 def patchbackend(ui, backend, patchobj, strip, prefix, files=None, |
1498 eolmode='strict'): | |
1498 if files is None: | 1499 if files is None: |
1499 files = set() | 1500 files = set() |
1500 if eolmode is None: | 1501 if eolmode is None: |
1501 eolmode = ui.config('patch', 'eol', 'strict') | 1502 eolmode = ui.config('patch', 'eol', 'strict') |
1502 if eolmode.lower() not in eolmodes: | 1503 if eolmode.lower() not in eolmodes: |
1507 try: | 1508 try: |
1508 fp = open(patchobj, 'rb') | 1509 fp = open(patchobj, 'rb') |
1509 except TypeError: | 1510 except TypeError: |
1510 fp = patchobj | 1511 fp = patchobj |
1511 try: | 1512 try: |
1512 ret = applydiff(ui, fp, backend, store, strip=strip, | 1513 ret = applydiff(ui, fp, backend, store, strip=strip, prefix=prefix, |
1513 eolmode=eolmode) | 1514 eolmode=eolmode) |
1514 finally: | 1515 finally: |
1515 if fp != patchobj: | 1516 if fp != patchobj: |
1516 fp.close() | 1517 fp.close() |
1517 files.update(backend.close()) | 1518 files.update(backend.close()) |
1523 def internalpatch(ui, repo, patchobj, strip, files=None, eolmode='strict', | 1524 def internalpatch(ui, repo, patchobj, strip, files=None, eolmode='strict', |
1524 similarity=0): | 1525 similarity=0): |
1525 """use builtin patch to apply <patchobj> to the working directory. | 1526 """use builtin patch to apply <patchobj> to the working directory. |
1526 returns whether patch was applied with fuzz factor.""" | 1527 returns whether patch was applied with fuzz factor.""" |
1527 backend = workingbackend(ui, repo, similarity) | 1528 backend = workingbackend(ui, repo, similarity) |
1528 return patchbackend(ui, backend, patchobj, strip, files, eolmode) | 1529 return patchbackend(ui, backend, patchobj, strip, '', files, eolmode) |
1529 | 1530 |
1530 def patchrepo(ui, repo, ctx, store, patchobj, strip, files=None, | 1531 def patchrepo(ui, repo, ctx, store, patchobj, strip, files=None, |
1531 eolmode='strict'): | 1532 eolmode='strict'): |
1532 backend = repobackend(ui, repo, ctx, store) | 1533 backend = repobackend(ui, repo, ctx, store) |
1533 return patchbackend(ui, backend, patchobj, strip, files, eolmode) | 1534 return patchbackend(ui, backend, patchobj, strip, '', files, eolmode) |
1534 | 1535 |
1535 def patch(ui, repo, patchname, strip=1, files=None, eolmode='strict', | 1536 def patch(ui, repo, patchname, strip=1, files=None, eolmode='strict', |
1536 similarity=0): | 1537 similarity=0): |
1537 """Apply <patchname> to the working directory. | 1538 """Apply <patchname> to the working directory. |
1538 | 1539 |