Show More
@@ -82,6 +82,7 b' from mercurial import (' | |||||
82 | cmdutil, |
|
82 | cmdutil, | |
83 | error, |
|
83 | error, | |
84 | filemerge, |
|
84 | filemerge, | |
|
85 | formatter, | |||
85 | pycompat, |
|
86 | pycompat, | |
86 | registrar, |
|
87 | registrar, | |
87 | scmutil, |
|
88 | scmutil, | |
@@ -267,9 +268,11 b' def dodiff(ui, repo, cmdline, pats, opts' | |||||
267 | label2 = common_file + rev2 |
|
268 | label2 = common_file + rev2 | |
268 | else: |
|
269 | else: | |
269 | template = 'hg-%h.patch' |
|
270 | template = 'hg-%h.patch' | |
270 | cmdutil.export(repo, [repo[node1a].rev(), repo[node2].rev()], |
|
271 | with formatter.nullformatter(ui, 'extdiff', {}) as fm: | |
271 | fntemplate=repo.vfs.reljoin(tmproot, template), |
|
272 | cmdutil.export(repo, [repo[node1a].rev(), repo[node2].rev()], | |
272 |
|
|
273 | fm, | |
|
274 | fntemplate=repo.vfs.reljoin(tmproot, template), | |||
|
275 | match=matcher) | |||
273 | label1a = cmdutil.makefilename(repo[node1a], template) |
|
276 | label1a = cmdutil.makefilename(repo[node1a], template) | |
274 | label2 = cmdutil.makefilename(repo[node2], template) |
|
277 | label2 = cmdutil.makefilename(repo[node2], template) | |
275 | dir1a = repo.vfs.reljoin(tmproot, label1a) |
|
278 | dir1a = repo.vfs.reljoin(tmproot, label1a) |
@@ -1565,24 +1565,17 b' def _exportsingle(repo, ctx, fm, match, ' | |||||
1565 | # TODO: make it structured? |
|
1565 | # TODO: make it structured? | |
1566 | fm.data(diff=b''.join(chunkiter)) |
|
1566 | fm.data(diff=b''.join(chunkiter)) | |
1567 |
|
1567 | |||
1568 |
def _exportfile(repo, revs, f |
|
1568 | def _exportfile(repo, revs, fm, dest, switch_parent, diffopts, match): | |
1569 | """Export changesets to stdout or a single file""" |
|
1569 | """Export changesets to stdout or a single file""" | |
1570 | dest = '<unnamed>' |
|
|||
1571 | if fp: |
|
|||
1572 | dest = getattr(fp, 'name', dest) |
|
|||
1573 | fm = formatter.formatter(repo.ui, fp, 'export', {}) |
|
|||
1574 | else: |
|
|||
1575 | fm = repo.ui.formatter('export', {}) |
|
|||
1576 |
|
||||
1577 | for seqno, rev in enumerate(revs, 1): |
|
1570 | for seqno, rev in enumerate(revs, 1): | |
1578 | ctx = repo[rev] |
|
1571 | ctx = repo[rev] | |
1579 | if not dest.startswith('<'): |
|
1572 | if not dest.startswith('<'): | |
1580 | repo.ui.note("%s\n" % dest) |
|
1573 | repo.ui.note("%s\n" % dest) | |
1581 | fm.startitem() |
|
1574 | fm.startitem() | |
1582 | _exportsingle(repo, ctx, fm, match, switch_parent, seqno, diffopts) |
|
1575 | _exportsingle(repo, ctx, fm, match, switch_parent, seqno, diffopts) | |
1583 | fm.end() |
|
1576 | ||
1584 |
|
1577 | def _exportfntemplate(repo, revs, basefm, fntemplate, switch_parent, diffopts, | ||
1585 | def _exportfntemplate(repo, revs, fntemplate, switch_parent, diffopts, match): |
|
1578 | match): | |
1586 | """Export changesets to possibly multiple files""" |
|
1579 | """Export changesets to possibly multiple files""" | |
1587 | total = len(revs) |
|
1580 | total = len(revs) | |
1588 | revwidth = max(len(str(rev)) for rev in revs) |
|
1581 | revwidth = max(len(str(rev)) for rev in revs) | |
@@ -1595,7 +1588,7 b' def _exportfntemplate(repo, revs, fntemp' | |||||
1595 | filemap.setdefault(dest, []).append((seqno, rev)) |
|
1588 | filemap.setdefault(dest, []).append((seqno, rev)) | |
1596 |
|
1589 | |||
1597 | for dest in filemap: |
|
1590 | for dest in filemap: | |
1598 |
with formatter. |
|
1591 | with formatter.maybereopen(basefm, dest) as fm: | |
1599 | repo.ui.note("%s\n" % dest) |
|
1592 | repo.ui.note("%s\n" % dest) | |
1600 | for seqno, rev in filemap[dest]: |
|
1593 | for seqno, rev in filemap[dest]: | |
1601 | fm.startitem() |
|
1594 | fm.startitem() | |
@@ -1603,13 +1596,14 b' def _exportfntemplate(repo, revs, fntemp' | |||||
1603 | _exportsingle(repo, ctx, fm, match, switch_parent, seqno, |
|
1596 | _exportsingle(repo, ctx, fm, match, switch_parent, seqno, | |
1604 | diffopts) |
|
1597 | diffopts) | |
1605 |
|
1598 | |||
1606 | def export(repo, revs, fntemplate='hg-%h.patch', switch_parent=False, |
|
1599 | def export(repo, revs, basefm, fntemplate='hg-%h.patch', switch_parent=False, | |
1607 | opts=None, match=None): |
|
1600 | opts=None, match=None): | |
1608 | '''export changesets as hg patches |
|
1601 | '''export changesets as hg patches | |
1609 |
|
1602 | |||
1610 | Args: |
|
1603 | Args: | |
1611 | repo: The repository from which we're exporting revisions. |
|
1604 | repo: The repository from which we're exporting revisions. | |
1612 | revs: A list of revisions to export as revision numbers. |
|
1605 | revs: A list of revisions to export as revision numbers. | |
|
1606 | basefm: A formatter to which patches should be written. | |||
1613 | fntemplate: An optional string to use for generating patch file names. |
|
1607 | fntemplate: An optional string to use for generating patch file names. | |
1614 | switch_parent: If True, show diffs against second parent when not nullid. |
|
1608 | switch_parent: If True, show diffs against second parent when not nullid. | |
1615 | Default is false, which always shows diff against p1. |
|
1609 | Default is false, which always shows diff against p1. | |
@@ -1624,16 +1618,19 b" def export(repo, revs, fntemplate='hg-%h" | |||||
1624 | destinations: |
|
1618 | destinations: | |
1625 | fntemplate specified: Each rev is written to a unique file named using |
|
1619 | fntemplate specified: Each rev is written to a unique file named using | |
1626 | the given template. |
|
1620 | the given template. | |
1627 |
Otherwise: All revs written to |
|
1621 | Otherwise: All revs will be written to basefm. | |
1628 | ''' |
|
1622 | ''' | |
1629 | if not fntemplate: |
|
1623 | if not fntemplate: | |
1630 |
_exportfile(repo, revs, |
|
1624 | _exportfile(repo, revs, basefm, '<unnamed>', switch_parent, opts, match) | |
1631 | else: |
|
1625 | else: | |
1632 |
_exportfntemplate(repo, revs, fntemplate, switch_parent, opts, |
|
1626 | _exportfntemplate(repo, revs, basefm, fntemplate, switch_parent, opts, | |
|
1627 | match) | |||
1633 |
|
1628 | |||
1634 | def exportfile(repo, revs, fp, switch_parent=False, opts=None, match=None): |
|
1629 | def exportfile(repo, revs, fp, switch_parent=False, opts=None, match=None): | |
1635 | """Export changesets to the given file stream""" |
|
1630 | """Export changesets to the given file stream""" | |
1636 | _exportfile(repo, revs, fp, switch_parent, opts, match) |
|
1631 | dest = getattr(fp, 'name', '<unnamed>') | |
|
1632 | with formatter.formatter(repo.ui, fp, 'export', {}) as fm: | |||
|
1633 | _exportfile(repo, revs, fm, dest, switch_parent, opts, match) | |||
1637 |
|
1634 | |||
1638 | def showmarker(fm, marker, index=None): |
|
1635 | def showmarker(fm, marker, index=None): | |
1639 | """utility function to display obsolescence marker in a readable way |
|
1636 | """utility function to display obsolescence marker in a readable way |
@@ -1894,7 +1894,7 b' def diff(ui, repo, *pats, **opts):' | |||||
1894 | _('print output to file with formatted name'), _('FORMAT')), |
|
1894 | _('print output to file with formatted name'), _('FORMAT')), | |
1895 | ('', 'switch-parent', None, _('diff against the second parent')), |
|
1895 | ('', 'switch-parent', None, _('diff against the second parent')), | |
1896 | ('r', 'rev', [], _('revisions to export'), _('REV')), |
|
1896 | ('r', 'rev', [], _('revisions to export'), _('REV')), | |
1897 | ] + diffopts, |
|
1897 | ] + diffopts + formatteropts, | |
1898 | _('[OPTION]... [-o OUTFILESPEC] [-r] [REV]...'), cmdtype=readonly) |
|
1898 | _('[OPTION]... [-o OUTFILESPEC] [-r] [REV]...'), cmdtype=readonly) | |
1899 | def export(ui, repo, *changesets, **opts): |
|
1899 | def export(ui, repo, *changesets, **opts): | |
1900 | """dump the header and diffs for one or more changesets |
|
1900 | """dump the header and diffs for one or more changesets | |
@@ -1976,11 +1976,15 b' def export(ui, repo, *changesets, **opts' | |||||
1976 | if cmdutil.isstdiofilename(fntemplate): |
|
1976 | if cmdutil.isstdiofilename(fntemplate): | |
1977 | fntemplate = '' |
|
1977 | fntemplate = '' | |
1978 |
|
1978 | |||
1979 |
if |
|
1979 | if fntemplate: | |
|
1980 | fm = formatter.nullformatter(ui, 'export', opts) | |||
|
1981 | else: | |||
1980 | ui.pager('export') |
|
1982 | ui.pager('export') | |
1981 | cmdutil.export(repo, revs, fntemplate=fntemplate, |
|
1983 | fm = ui.formatter('export', opts) | |
1982 | switch_parent=opts.get('switch_parent'), |
|
1984 | with fm: | |
1983 | opts=patch.diffallopts(ui, opts)) |
|
1985 | cmdutil.export(repo, revs, fm, fntemplate=fntemplate, | |
|
1986 | switch_parent=opts.get('switch_parent'), | |||
|
1987 | opts=patch.diffallopts(ui, opts)) | |||
1984 |
|
1988 | |||
1985 | @command('files', |
|
1989 | @command('files', | |
1986 | [('r', 'rev', '', _('search the repository as it is in REV'), _('REV')), |
|
1990 | [('r', 'rev', '', _('search the repository as it is in REV'), _('REV')), |
@@ -231,7 +231,7 b' Show all commands + options' | |||||
231 | clone: noupdate, updaterev, rev, branch, pull, uncompressed, stream, ssh, remotecmd, insecure |
|
231 | clone: noupdate, updaterev, rev, branch, pull, uncompressed, stream, ssh, remotecmd, insecure | |
232 | commit: addremove, close-branch, amend, secret, edit, interactive, include, exclude, message, logfile, date, user, subrepos |
|
232 | commit: addremove, close-branch, amend, secret, edit, interactive, include, exclude, message, logfile, date, user, subrepos | |
233 | diff: rev, change, text, git, binary, nodates, noprefix, show-function, reverse, ignore-all-space, ignore-space-change, ignore-blank-lines, ignore-space-at-eol, unified, stat, root, include, exclude, subrepos |
|
233 | diff: rev, change, text, git, binary, nodates, noprefix, show-function, reverse, ignore-all-space, ignore-space-change, ignore-blank-lines, ignore-space-at-eol, unified, stat, root, include, exclude, subrepos | |
234 | export: output, switch-parent, rev, text, git, binary, nodates |
|
234 | export: output, switch-parent, rev, text, git, binary, nodates, template | |
235 | forget: include, exclude, dry-run |
|
235 | forget: include, exclude, dry-run | |
236 | init: ssh, remotecmd, insecure |
|
236 | init: ssh, remotecmd, insecure | |
237 | log: follow, follow-first, date, copies, keyword, rev, line-range, removed, only-merges, user, only-branch, branch, prune, patch, git, limit, no-merges, stat, graph, style, template, include, exclude |
|
237 | log: follow, follow-first, date, copies, keyword, rev, line-range, removed, only-merges, user, only-branch, branch, prune, patch, git, limit, no-merges, stat, graph, style, template, include, exclude |
@@ -159,6 +159,85 b' Exporting wdir revision:' | |||||
159 | +foo-wdir |
|
159 | +foo-wdir | |
160 | $ hg revert -q foo |
|
160 | $ hg revert -q foo | |
161 |
|
161 | |||
|
162 | Templated output to stdout: | |||
|
163 | ||||
|
164 | $ hg export -Tjson 0 | |||
|
165 | [ | |||
|
166 | { | |||
|
167 | "branch": "default", | |||
|
168 | "date": [0.0, 0], | |||
|
169 | "desc": "foo-0", | |||
|
170 | "diff": "diff -r 000000000000 -r 871558de6af2 foo\n--- /dev/null\tThu Jan 01 00:00:00 1970 +0000\n+++ b/foo\tThu Jan 01 00:00:00 1970 +0000\n@@ -0,0 +1,1 @@\n+foo-0\n", | |||
|
171 | "node": "871558de6af2e8c244222f8eea69b782c94ce3df", | |||
|
172 | "parents": [], | |||
|
173 | "user": "test" | |||
|
174 | } | |||
|
175 | ] | |||
|
176 | ||||
|
177 | Templated output to single file: | |||
|
178 | ||||
|
179 | $ hg export -Tjson 0:1 -o out.json | |||
|
180 | $ cat out.json | |||
|
181 | [ | |||
|
182 | { | |||
|
183 | "branch": "default", | |||
|
184 | "date": [0.0, 0], | |||
|
185 | "desc": "foo-0", | |||
|
186 | "diff": "diff -r 000000000000 -r 871558de6af2 foo\n--- /dev/null\tThu Jan 01 00:00:00 1970 +0000\n+++ b/foo\tThu Jan 01 00:00:00 1970 +0000\n@@ -0,0 +1,1 @@\n+foo-0\n", | |||
|
187 | "node": "871558de6af2e8c244222f8eea69b782c94ce3df", | |||
|
188 | "parents": [], | |||
|
189 | "user": "test" | |||
|
190 | }, | |||
|
191 | { | |||
|
192 | "branch": "default", | |||
|
193 | "date": [0.0, 0], | |||
|
194 | "desc": "foo-1", | |||
|
195 | "diff": "diff -r 871558de6af2 -r d1c9656e973c foo\n--- a/foo\tThu Jan 01 00:00:00 1970 +0000\n+++ b/foo\tThu Jan 01 00:00:00 1970 +0000\n@@ -1,1 +1,2 @@\n foo-0\n+foo-1\n", | |||
|
196 | "node": "d1c9656e973cfb5aebd5499bbd2cb350e3b12266", | |||
|
197 | "parents": ["871558de6af2e8c244222f8eea69b782c94ce3df"], | |||
|
198 | "user": "test" | |||
|
199 | } | |||
|
200 | ] | |||
|
201 | ||||
|
202 | Templated output to multiple files: | |||
|
203 | ||||
|
204 | $ hg export -Tjson 0:1 -o 'out-{rev}.json' | |||
|
205 | $ cat out-0.json | |||
|
206 | [ | |||
|
207 | { | |||
|
208 | "branch": "default", | |||
|
209 | "date": [0.0, 0], | |||
|
210 | "desc": "foo-0", | |||
|
211 | "diff": "diff -r 000000000000 -r 871558de6af2 foo\n--- /dev/null\tThu Jan 01 00:00:00 1970 +0000\n+++ b/foo\tThu Jan 01 00:00:00 1970 +0000\n@@ -0,0 +1,1 @@\n+foo-0\n", | |||
|
212 | "node": "871558de6af2e8c244222f8eea69b782c94ce3df", | |||
|
213 | "parents": [], | |||
|
214 | "user": "test" | |||
|
215 | } | |||
|
216 | ] | |||
|
217 | $ cat out-1.json | |||
|
218 | [ | |||
|
219 | { | |||
|
220 | "branch": "default", | |||
|
221 | "date": [0.0, 0], | |||
|
222 | "desc": "foo-1", | |||
|
223 | "diff": "diff -r 871558de6af2 -r d1c9656e973c foo\n--- a/foo\tThu Jan 01 00:00:00 1970 +0000\n+++ b/foo\tThu Jan 01 00:00:00 1970 +0000\n@@ -1,1 +1,2 @@\n foo-0\n+foo-1\n", | |||
|
224 | "node": "d1c9656e973cfb5aebd5499bbd2cb350e3b12266", | |||
|
225 | "parents": ["871558de6af2e8c244222f8eea69b782c94ce3df"], | |||
|
226 | "user": "test" | |||
|
227 | } | |||
|
228 | ] | |||
|
229 | ||||
|
230 | Template keywrods: | |||
|
231 | ||||
|
232 | $ hg export 0 -T '# {node|shortest}\n\n{diff}' | |||
|
233 | # 8715 | |||
|
234 | ||||
|
235 | diff -r 000000000000 -r 871558de6af2 foo | |||
|
236 | --- /dev/null Thu Jan 01 00:00:00 1970 +0000 | |||
|
237 | +++ b/foo Thu Jan 01 00:00:00 1970 +0000 | |||
|
238 | @@ -0,0 +1,1 @@ | |||
|
239 | +foo-0 | |||
|
240 | ||||
162 |
|
|
241 | No filename should be printed if stdout is specified explicitly: | |
163 |
|
242 | |||
164 |
|
|
243 | $ hg export -v 1 -o - |
General Comments 0
You need to be logged in to leave comments.
Login now