Mercurial > hgrepos > DevTools > mercurial-extensions
annotate extensions/revinfo.py @ 437:11bbdd7fd7b0
Provide "-T/--timestamp" and "-D/--date" options for revinfo.
To print full commit timestamps or just the date.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Sat, 30 May 2026 13:13:01 +0200 |
| parents | 111aa1d44ffd |
| children |
| rev | line source |
|---|---|
|
1
a80645763196
revinfo: a module to write .hg_archival.txt like repository metadata
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
1 # -*- coding: utf-8 -*- |
|
125
fb7e1e4e4d2c
Provide some SCCS markers also to be able to search with "what(1)" also
Franz Glasner <hg@dom66.de>
parents:
114
diff
changeset
|
2 # @(#) $HGheader$ |
|
315
e9ded6c1db41
Add a copyright and license note to the revinfo and kwarchive modules and to the README also.
Franz Glasner <fzglas.hg@dom66.de>
parents:
314
diff
changeset
|
3 # $HGnodeid$ |
|
336
eb1e0f129963
More compliance with the private style guide for Mercurial extensions for the metadata of the extensions
Franz Glasner <fzglas.hg@dom66.de>
parents:
329
diff
changeset
|
4 # :- |
|
436
111aa1d44ffd
Put the copyright symbol © into the copyright message instead of (C)
Franz Glasner <fzglas.hg@dom66.de>
parents:
432
diff
changeset
|
5 # :Copyright: © 2015-2026 Franz Glasner <fzglas.hg@dom66.de> |
|
315
e9ded6c1db41
Add a copyright and license note to the revinfo and kwarchive modules and to the README also.
Franz Glasner <fzglas.hg@dom66.de>
parents:
314
diff
changeset
|
6 # :License: This software may be used and distributed according to the |
|
e9ded6c1db41
Add a copyright and license note to the revinfo and kwarchive modules and to the README also.
Franz Glasner <fzglas.hg@dom66.de>
parents:
314
diff
changeset
|
7 # terms of the GNU General Public License version 2 or any |
|
e9ded6c1db41
Add a copyright and license note to the revinfo and kwarchive modules and to the README also.
Franz Glasner <fzglas.hg@dom66.de>
parents:
314
diff
changeset
|
8 # later version. |
|
e9ded6c1db41
Add a copyright and license note to the revinfo and kwarchive modules and to the README also.
Franz Glasner <fzglas.hg@dom66.de>
parents:
314
diff
changeset
|
9 # The license is incorporated herein by reference. |
|
336
eb1e0f129963
More compliance with the private style guide for Mercurial extensions for the metadata of the extensions
Franz Glasner <fzglas.hg@dom66.de>
parents:
329
diff
changeset
|
10 # :- |
|
34
7c4addd60935
Put keyword into the extensions itself
Franz Glasner <hg@dom66.de>
parents:
27
diff
changeset
|
11 # |
|
1
a80645763196
revinfo: a module to write .hg_archival.txt like repository metadata
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
12 """write a revision summary similar to .hg_archival.txt |
|
137
5e502e9dd5e5
As an example: put the |VCSRevision| into the extensions also and print it with the help output
Franz Glasner <hg@dom66.de>
parents:
125
diff
changeset
|
13 |
|
5e502e9dd5e5
As an example: put the |VCSRevision| into the extensions also and print it with the help output
Franz Glasner <hg@dom66.de>
parents:
125
diff
changeset
|
14 (rev |VCSRevision|) |
|
5e502e9dd5e5
As an example: put the |VCSRevision| into the extensions also and print it with the help output
Franz Glasner <hg@dom66.de>
parents:
125
diff
changeset
|
15 |
|
1
a80645763196
revinfo: a module to write .hg_archival.txt like repository metadata
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
16 """ |
|
a80645763196
revinfo: a module to write .hg_archival.txt like repository metadata
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
17 |
|
336
eb1e0f129963
More compliance with the private style guide for Mercurial extensions for the metadata of the extensions
Franz Glasner <fzglas.hg@dom66.de>
parents:
329
diff
changeset
|
18 __revision__ = "|VCSRevision|" |
|
eb1e0f129963
More compliance with the private style guide for Mercurial extensions for the metadata of the extensions
Franz Glasner <fzglas.hg@dom66.de>
parents:
329
diff
changeset
|
19 __date__ = "|VCSJustDate|" |
|
1
a80645763196
revinfo: a module to write .hg_archival.txt like repository metadata
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
20 __author__ = "Franz Glasner" |
|
a80645763196
revinfo: a module to write .hg_archival.txt like repository metadata
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
21 |
|
a80645763196
revinfo: a module to write .hg_archival.txt like repository metadata
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
22 |
|
a80645763196
revinfo: a module to write .hg_archival.txt like repository metadata
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
23 from mercurial.i18n import _ |
|
425
2a062f87f75d
Make "revinfo" and "kwarchive" work on Mercurial 6.
Franz Glasner <fzglas.hg@dom66.de>
parents:
424
diff
changeset
|
24 from mercurial import (cmdutil, scmutil, error, archival, pycompat, util, |
|
437
11bbdd7fd7b0
Provide "-T/--timestamp" and "-D/--date" options for revinfo.
Franz Glasner <fzglas.hg@dom66.de>
parents:
436
diff
changeset
|
25 templatefilters, demandimport) |
|
326
26e617693ae8
FIX: kwarchive and revinfo do not run on versions prior to Mercurial 4.3 after testing this with unit-tests
Franz Glasner <fzglas.hg@dom66.de>
parents:
315
diff
changeset
|
26 with demandimport.deactivated(): |
|
26e617693ae8
FIX: kwarchive and revinfo do not run on versions prior to Mercurial 4.3 after testing this with unit-tests
Franz Glasner <fzglas.hg@dom66.de>
parents:
315
diff
changeset
|
27 try: |
|
26e617693ae8
FIX: kwarchive and revinfo do not run on versions prior to Mercurial 4.3 after testing this with unit-tests
Franz Glasner <fzglas.hg@dom66.de>
parents:
315
diff
changeset
|
28 from mercurial import registrar |
|
26e617693ae8
FIX: kwarchive and revinfo do not run on versions prior to Mercurial 4.3 after testing this with unit-tests
Franz Glasner <fzglas.hg@dom66.de>
parents:
315
diff
changeset
|
29 except ImportError: |
|
26e617693ae8
FIX: kwarchive and revinfo do not run on versions prior to Mercurial 4.3 after testing this with unit-tests
Franz Glasner <fzglas.hg@dom66.de>
parents:
315
diff
changeset
|
30 registrar = None |
|
1
a80645763196
revinfo: a module to write .hg_archival.txt like repository metadata
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
31 |
|
425
2a062f87f75d
Make "revinfo" and "kwarchive" work on Mercurial 6.
Franz Glasner <fzglas.hg@dom66.de>
parents:
424
diff
changeset
|
32 # some URL specific util functions moved to new mercurial.utils.urlutil |
|
2a062f87f75d
Make "revinfo" and "kwarchive" work on Mercurial 6.
Franz Glasner <fzglas.hg@dom66.de>
parents:
424
diff
changeset
|
33 try: |
|
2a062f87f75d
Make "revinfo" and "kwarchive" work on Mercurial 6.
Franz Glasner <fzglas.hg@dom66.de>
parents:
424
diff
changeset
|
34 from mercurial.utils import urlutil as _urlutil |
|
2a062f87f75d
Make "revinfo" and "kwarchive" work on Mercurial 6.
Franz Glasner <fzglas.hg@dom66.de>
parents:
424
diff
changeset
|
35 except ImportError: |
|
2a062f87f75d
Make "revinfo" and "kwarchive" work on Mercurial 6.
Franz Glasner <fzglas.hg@dom66.de>
parents:
424
diff
changeset
|
36 _urlutil = util |
|
1
a80645763196
revinfo: a module to write .hg_archival.txt like repository metadata
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
37 |
|
425
2a062f87f75d
Make "revinfo" and "kwarchive" work on Mercurial 6.
Franz Glasner <fzglas.hg@dom66.de>
parents:
424
diff
changeset
|
38 |
|
432
e036013a4003
Note that the extensions work with Mercurkal 6.9.5
Franz Glasner <fzglas.hg@dom66.de>
parents:
425
diff
changeset
|
39 testedwith = b"4.3.1 4.3.2 4.4.1 4.4.2 4.5.2 4.6.1 4.8.1 4.9 5.0.1 5.1.2 5.2.1 5.5 5.6 5.9.1 6.1.4 6.9.5" |
|
337
cd42b8578901
Place "testedwith" at the begin of global variables
Franz Glasner <fzglas.hg@dom66.de>
parents:
336
diff
changeset
|
40 |
|
1
a80645763196
revinfo: a module to write .hg_archival.txt like repository metadata
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
41 cmdtable = {} |
|
a80645763196
revinfo: a module to write .hg_archival.txt like repository metadata
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
42 |
|
326
26e617693ae8
FIX: kwarchive and revinfo do not run on versions prior to Mercurial 4.3 after testing this with unit-tests
Franz Glasner <fzglas.hg@dom66.de>
parents:
315
diff
changeset
|
43 if registrar and hasattr(registrar, "command"): |
|
248
436b2db75a34
cmdutil.command is deprecated: use registrar.command instead; also need always a repository for the commands: inferrepo=True
Franz Glasner <hg@dom66.de>
parents:
151
diff
changeset
|
44 command = registrar.command(cmdtable) |
|
436b2db75a34
cmdutil.command is deprecated: use registrar.command instead; also need always a repository for the commands: inferrepo=True
Franz Glasner <hg@dom66.de>
parents:
151
diff
changeset
|
45 else: |
|
436b2db75a34
cmdutil.command is deprecated: use registrar.command instead; also need always a repository for the commands: inferrepo=True
Franz Glasner <hg@dom66.de>
parents:
151
diff
changeset
|
46 command = cmdutil.command(cmdtable) |
|
436b2db75a34
cmdutil.command is deprecated: use registrar.command instead; also need always a repository for the commands: inferrepo=True
Franz Glasner <hg@dom66.de>
parents:
151
diff
changeset
|
47 |
|
1
a80645763196
revinfo: a module to write .hg_archival.txt like repository metadata
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
48 |
|
150
f195b4704726
For each extension: provide a "getversion()" function that will be called by Mercurial to get the module version.
Franz Glasner <hg@dom66.de>
parents:
137
diff
changeset
|
49 def getversion(): |
|
f195b4704726
For each extension: provide a "getversion()" function that will be called by Mercurial to get the module version.
Franz Glasner <hg@dom66.de>
parents:
137
diff
changeset
|
50 """Provide the version information for verbose :hg:`version` output. |
|
f195b4704726
For each extension: provide a "getversion()" function that will be called by Mercurial to get the module version.
Franz Glasner <hg@dom66.de>
parents:
137
diff
changeset
|
51 |
|
f195b4704726
For each extension: provide a "getversion()" function that will be called by Mercurial to get the module version.
Franz Glasner <hg@dom66.de>
parents:
137
diff
changeset
|
52 Read the :file:`VERSION` from the parent of the :file:`extensions` |
|
f195b4704726
For each extension: provide a "getversion()" function that will be called by Mercurial to get the module version.
Franz Glasner <hg@dom66.de>
parents:
137
diff
changeset
|
53 directory. |
|
f195b4704726
For each extension: provide a "getversion()" function that will be called by Mercurial to get the module version.
Franz Glasner <hg@dom66.de>
parents:
137
diff
changeset
|
54 |
|
f195b4704726
For each extension: provide a "getversion()" function that will be called by Mercurial to get the module version.
Franz Glasner <hg@dom66.de>
parents:
137
diff
changeset
|
55 """ |
|
f195b4704726
For each extension: provide a "getversion()" function that will be called by Mercurial to get the module version.
Franz Glasner <hg@dom66.de>
parents:
137
diff
changeset
|
56 import re |
|
f195b4704726
For each extension: provide a "getversion()" function that will be called by Mercurial to get the module version.
Franz Glasner <hg@dom66.de>
parents:
137
diff
changeset
|
57 import os |
|
f195b4704726
For each extension: provide a "getversion()" function that will be called by Mercurial to get the module version.
Franz Glasner <hg@dom66.de>
parents:
137
diff
changeset
|
58 try: |
|
f195b4704726
For each extension: provide a "getversion()" function that will be called by Mercurial to get the module version.
Franz Glasner <hg@dom66.de>
parents:
137
diff
changeset
|
59 fn = __file__ |
|
f195b4704726
For each extension: provide a "getversion()" function that will be called by Mercurial to get the module version.
Franz Glasner <hg@dom66.de>
parents:
137
diff
changeset
|
60 except NameError: |
|
329
39674f294709
Ported the revinfo extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents:
328
diff
changeset
|
61 return b"<unknown>" |
|
150
f195b4704726
For each extension: provide a "getversion()" function that will be called by Mercurial to get the module version.
Franz Glasner <hg@dom66.de>
parents:
137
diff
changeset
|
62 else: |
|
f195b4704726
For each extension: provide a "getversion()" function that will be called by Mercurial to get the module version.
Franz Glasner <hg@dom66.de>
parents:
137
diff
changeset
|
63 try: |
|
f195b4704726
For each extension: provide a "getversion()" function that will be called by Mercurial to get the module version.
Franz Glasner <hg@dom66.de>
parents:
137
diff
changeset
|
64 verdata = open(os.path.join(os.path.dirname(fn), |
|
f195b4704726
For each extension: provide a "getversion()" function that will be called by Mercurial to get the module version.
Franz Glasner <hg@dom66.de>
parents:
137
diff
changeset
|
65 "../VERSION"), |
|
329
39674f294709
Ported the revinfo extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents:
328
diff
changeset
|
66 "rb").read() |
|
39674f294709
Ported the revinfo extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents:
328
diff
changeset
|
67 return re.search(b"^(.*)", verdata,).group(1) |
|
150
f195b4704726
For each extension: provide a "getversion()" function that will be called by Mercurial to get the module version.
Franz Glasner <hg@dom66.de>
parents:
137
diff
changeset
|
68 except OSError: |
|
329
39674f294709
Ported the revinfo extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents:
328
diff
changeset
|
69 return b"<not found>" |
|
150
f195b4704726
For each extension: provide a "getversion()" function that will be called by Mercurial to get the module version.
Franz Glasner <hg@dom66.de>
parents:
137
diff
changeset
|
70 |
|
f195b4704726
For each extension: provide a "getversion()" function that will be called by Mercurial to get the module version.
Franz Glasner <hg@dom66.de>
parents:
137
diff
changeset
|
71 |
|
114
a51822141ccf
Style: handled some more flake8 warnings: consistent command declaration list formatting
Franz Glasner <hg@dom66.de>
parents:
113
diff
changeset
|
72 @command( |
|
329
39674f294709
Ported the revinfo extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents:
328
diff
changeset
|
73 b"revinfo", |
|
114
a51822141ccf
Style: handled some more flake8 warnings: consistent command declaration list formatting
Franz Glasner <hg@dom66.de>
parents:
113
diff
changeset
|
74 [ |
|
329
39674f294709
Ported the revinfo extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents:
328
diff
changeset
|
75 (b'r', b"rev", b'', _(b"revision to handle"), _(b"REV")), |
|
39674f294709
Ported the revinfo extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents:
328
diff
changeset
|
76 (b'', b"amend", None, _(b"amend a given file with path information")), |
|
437
11bbdd7fd7b0
Provide "-T/--timestamp" and "-D/--date" options for revinfo.
Franz Glasner <fzglas.hg@dom66.de>
parents:
436
diff
changeset
|
77 (b'T', b'timestamp', None, _(b"put also the commit timestamp into the file")), |
|
11bbdd7fd7b0
Provide "-T/--timestamp" and "-D/--date" options for revinfo.
Franz Glasner <fzglas.hg@dom66.de>
parents:
436
diff
changeset
|
78 (b'D', b'date', None, _(b"put also the the commit date into the file")), |
|
329
39674f294709
Ported the revinfo extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents:
328
diff
changeset
|
79 (b'p', b"path", [], _(b"the configured default path"), _(b"SOURCE")), |
|
39674f294709
Ported the revinfo extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents:
328
diff
changeset
|
80 (b'd', b"data", [], _(b"add an extra `KEY: VALUE' pair into the file"), _(b"KEY=VALUE")), |
|
114
a51822141ccf
Style: handled some more flake8 warnings: consistent command declaration list formatting
Franz Glasner <hg@dom66.de>
parents:
113
diff
changeset
|
81 ], |
|
329
39674f294709
Ported the revinfo extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents:
328
diff
changeset
|
82 _(b"hg revinfo [OPTION]... [DEST]"), |
|
248
436b2db75a34
cmdutil.command is deprecated: use registrar.command instead; also need always a repository for the commands: inferrepo=True
Franz Glasner <hg@dom66.de>
parents:
151
diff
changeset
|
83 inferrepo=True) |
|
1
a80645763196
revinfo: a module to write .hg_archival.txt like repository metadata
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
84 def revinfo(ui, repo, dest=None, **opts): |
|
a80645763196
revinfo: a module to write .hg_archival.txt like repository metadata
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
85 """write a revision summary |
|
a80645763196
revinfo: a module to write .hg_archival.txt like repository metadata
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
86 |
|
a80645763196
revinfo: a module to write .hg_archival.txt like repository metadata
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
87 If DEST is given the info is written into the file DEST. Otherwise |
|
a80645763196
revinfo: a module to write .hg_archival.txt like repository metadata
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
88 it is written to stdout. |
|
a80645763196
revinfo: a module to write .hg_archival.txt like repository metadata
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
89 |
|
a80645763196
revinfo: a module to write .hg_archival.txt like repository metadata
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
90 By default, the revision used is the parent of the working |
|
a80645763196
revinfo: a module to write .hg_archival.txt like repository metadata
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
91 directory; use -r/--rev to specify a different revision. |
|
a80645763196
revinfo: a module to write .hg_archival.txt like repository metadata
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
92 |
|
40
fe48ca312f92
Use "." if the current repository root is to be assumed as path information
Franz Glasner <hg@dom66.de>
parents:
34
diff
changeset
|
93 Use -p/--path to specify named path information from :hg:`paths` |
|
fe48ca312f92
Use "." if the current repository root is to be assumed as path information
Franz Glasner <hg@dom66.de>
parents:
34
diff
changeset
|
94 as the canonical repository location. It will be printed as "path" |
|
fe48ca312f92
Use "." if the current repository root is to be assumed as path information
Franz Glasner <hg@dom66.de>
parents:
34
diff
changeset
|
95 item to the output. If no path is given then "default" is |
|
fe48ca312f92
Use "." if the current repository root is to be assumed as path information
Franz Glasner <hg@dom66.de>
parents:
34
diff
changeset
|
96 assumed. Use "." to use the current workspace root. |
|
fe48ca312f92
Use "." if the current repository root is to be assumed as path information
Franz Glasner <hg@dom66.de>
parents:
34
diff
changeset
|
97 Disable this by providing an empty SOURCE. |
|
9
33899e714b14
Added a new option "-n/--name" for revinfo to print the canonical repository path
Franz Glasner <hg@dom66.de>
parents:
4
diff
changeset
|
98 |
|
13
c78608f802d4
Implemented "--amend" for revinfo to put extra "path" items into existing files
Franz Glasner <hg@dom66.de>
parents:
12
diff
changeset
|
99 Use --amend to extend a given file with a "path" item. |
|
c78608f802d4
Implemented "--amend" for revinfo to put extra "path" items into existing files
Franz Glasner <hg@dom66.de>
parents:
12
diff
changeset
|
100 Can also be used to put more than one path item into the file. |
|
c78608f802d4
Implemented "--amend" for revinfo to put extra "path" items into existing files
Franz Glasner <hg@dom66.de>
parents:
12
diff
changeset
|
101 |
|
437
11bbdd7fd7b0
Provide "-T/--timestamp" and "-D/--date" options for revinfo.
Franz Glasner <fzglas.hg@dom66.de>
parents:
436
diff
changeset
|
102 Use -T/--timestamp to put also the complete commit timestamp in ISO |
|
11bbdd7fd7b0
Provide "-T/--timestamp" and "-D/--date" options for revinfo.
Franz Glasner <fzglas.hg@dom66.de>
parents:
436
diff
changeset
|
103 format into the output. It will be printed as "timestamp" item. |
|
11bbdd7fd7b0
Provide "-T/--timestamp" and "-D/--date" options for revinfo.
Franz Glasner <fzglas.hg@dom66.de>
parents:
436
diff
changeset
|
104 |
|
11bbdd7fd7b0
Provide "-T/--timestamp" and "-D/--date" options for revinfo.
Franz Glasner <fzglas.hg@dom66.de>
parents:
436
diff
changeset
|
105 Use -D/--date to put the commit date in ISO format (YYYY-MM-DD) into |
|
11bbdd7fd7b0
Provide "-T/--timestamp" and "-D/--date" options for revinfo.
Franz Glasner <fzglas.hg@dom66.de>
parents:
436
diff
changeset
|
106 the output. It will be printed as "date" item. |
|
11bbdd7fd7b0
Provide "-T/--timestamp" and "-D/--date" options for revinfo.
Franz Glasner <fzglas.hg@dom66.de>
parents:
436
diff
changeset
|
107 |
|
1
a80645763196
revinfo: a module to write .hg_archival.txt like repository metadata
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
108 The printed information is the same as the :hg:`archive` command |
|
437
11bbdd7fd7b0
Provide "-T/--timestamp" and "-D/--date" options for revinfo.
Franz Glasner <fzglas.hg@dom66.de>
parents:
436
diff
changeset
|
109 writes into ".hg_archival.txt". The "path", "timestamp" and "date" infos |
|
11bbdd7fd7b0
Provide "-T/--timestamp" and "-D/--date" options for revinfo.
Franz Glasner <fzglas.hg@dom66.de>
parents:
436
diff
changeset
|
110 are extra items. |
|
40
fe48ca312f92
Use "." if the current repository root is to be assumed as path information
Franz Glasner <hg@dom66.de>
parents:
34
diff
changeset
|
111 |
|
1
a80645763196
revinfo: a module to write .hg_archival.txt like repository metadata
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
112 """ |
|
151
11b39af77153
Process opts through pycompat.byteskwargs as all other current extensions do
Franz Glasner <hg@dom66.de>
parents:
150
diff
changeset
|
113 opts = pycompat.byteskwargs(opts) |
|
329
39674f294709
Ported the revinfo extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents:
328
diff
changeset
|
114 if opts.get(b"amend") and opts.get(b"rev"): |
|
39674f294709
Ported the revinfo extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents:
328
diff
changeset
|
115 raise error.Abort(_(b"cannot use -r/--rev together with --amend")) |
|
1
a80645763196
revinfo: a module to write .hg_archival.txt like repository metadata
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
116 |
|
437
11bbdd7fd7b0
Provide "-T/--timestamp" and "-D/--date" options for revinfo.
Franz Glasner <fzglas.hg@dom66.de>
parents:
436
diff
changeset
|
117 if opts.get(b"amend") and opts.get(b"timestamp"): |
|
11bbdd7fd7b0
Provide "-T/--timestamp" and "-D/--date" options for revinfo.
Franz Glasner <fzglas.hg@dom66.de>
parents:
436
diff
changeset
|
118 raise error.Abort(_(b"cannot use -T/--timestamp together with --amend")) |
|
11bbdd7fd7b0
Provide "-T/--timestamp" and "-D/--date" options for revinfo.
Franz Glasner <fzglas.hg@dom66.de>
parents:
436
diff
changeset
|
119 |
|
11bbdd7fd7b0
Provide "-T/--timestamp" and "-D/--date" options for revinfo.
Franz Glasner <fzglas.hg@dom66.de>
parents:
436
diff
changeset
|
120 if opts.get(b"amend") and opts.get(b"date"): |
|
11bbdd7fd7b0
Provide "-T/--timestamp" and "-D/--date" options for revinfo.
Franz Glasner <fzglas.hg@dom66.de>
parents:
436
diff
changeset
|
121 raise error.Abort(_(b"cannot use -D/--date together with --amend")) |
|
11bbdd7fd7b0
Provide "-T/--timestamp" and "-D/--date" options for revinfo.
Franz Glasner <fzglas.hg@dom66.de>
parents:
436
diff
changeset
|
122 |
|
329
39674f294709
Ported the revinfo extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents:
328
diff
changeset
|
123 if opts.get(b"amend"): |
|
13
c78608f802d4
Implemented "--amend" for revinfo to put extra "path" items into existing files
Franz Glasner <hg@dom66.de>
parents:
12
diff
changeset
|
124 if not dest: |
|
329
39674f294709
Ported the revinfo extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents:
328
diff
changeset
|
125 raise error.Abort(_(b"need a destination file with --amend")) |
|
13
c78608f802d4
Implemented "--amend" for revinfo to put extra "path" items into existing files
Franz Glasner <hg@dom66.de>
parents:
12
diff
changeset
|
126 with open(dest, "rb") as rfile: |
|
c78608f802d4
Implemented "--amend" for revinfo to put extra "path" items into existing files
Franz Glasner <hg@dom66.de>
parents:
12
diff
changeset
|
127 msg = rfile.read() |
|
c78608f802d4
Implemented "--amend" for revinfo to put extra "path" items into existing files
Franz Glasner <hg@dom66.de>
parents:
12
diff
changeset
|
128 else: |
|
329
39674f294709
Ported the revinfo extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents:
328
diff
changeset
|
129 ctx = scmutil.revsingle(repo, opts.get(b"rev")) |
|
13
c78608f802d4
Implemented "--amend" for revinfo to put extra "path" items into existing files
Franz Glasner <hg@dom66.de>
parents:
12
diff
changeset
|
130 if not ctx: |
|
114
a51822141ccf
Style: handled some more flake8 warnings: consistent command declaration list formatting
Franz Glasner <hg@dom66.de>
parents:
113
diff
changeset
|
131 raise error.Abort( |
|
329
39674f294709
Ported the revinfo extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents:
328
diff
changeset
|
132 _(b"no working directory: please specify a revision")) |
|
13
c78608f802d4
Implemented "--amend" for revinfo to put extra "path" items into existing files
Franz Glasner <hg@dom66.de>
parents:
12
diff
changeset
|
133 |
|
c78608f802d4
Implemented "--amend" for revinfo to put extra "path" items into existing files
Franz Glasner <hg@dom66.de>
parents:
12
diff
changeset
|
134 msg = archival.buildmetadata(ctx) |
|
24
c91a5c0f1be3
Add a "-d/--data" option that adds additional "KEY: VALUE" pairs into the revinfo.
Franz Glasner <hg@dom66.de>
parents:
22
diff
changeset
|
135 |
|
437
11bbdd7fd7b0
Provide "-T/--timestamp" and "-D/--date" options for revinfo.
Franz Glasner <fzglas.hg@dom66.de>
parents:
436
diff
changeset
|
136 if opts.get(b"timestamp"): |
|
11bbdd7fd7b0
Provide "-T/--timestamp" and "-D/--date" options for revinfo.
Franz Glasner <fzglas.hg@dom66.de>
parents:
436
diff
changeset
|
137 msg += b"timestamp: %s\n" % templatefilters.isodatesec(ctx.date()) |
|
11bbdd7fd7b0
Provide "-T/--timestamp" and "-D/--date" options for revinfo.
Franz Glasner <fzglas.hg@dom66.de>
parents:
436
diff
changeset
|
138 |
|
11bbdd7fd7b0
Provide "-T/--timestamp" and "-D/--date" options for revinfo.
Franz Glasner <fzglas.hg@dom66.de>
parents:
436
diff
changeset
|
139 if opts.get(b"date"): |
|
11bbdd7fd7b0
Provide "-T/--timestamp" and "-D/--date" options for revinfo.
Franz Glasner <fzglas.hg@dom66.de>
parents:
436
diff
changeset
|
140 msg += b"date: %s\n" % templatefilters.shortdate(ctx.date()) |
|
11bbdd7fd7b0
Provide "-T/--timestamp" and "-D/--date" options for revinfo.
Franz Glasner <fzglas.hg@dom66.de>
parents:
436
diff
changeset
|
141 |
|
11bbdd7fd7b0
Provide "-T/--timestamp" and "-D/--date" options for revinfo.
Franz Glasner <fzglas.hg@dom66.de>
parents:
436
diff
changeset
|
142 |
|
329
39674f294709
Ported the revinfo extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents:
328
diff
changeset
|
143 for kv in opts.get(b"data"): |
|
39674f294709
Ported the revinfo extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents:
328
diff
changeset
|
144 kvparts = [i.strip() for i in kv.split(b'=', 1)] |
|
24
c91a5c0f1be3
Add a "-d/--data" option that adds additional "KEY: VALUE" pairs into the revinfo.
Franz Glasner <hg@dom66.de>
parents:
22
diff
changeset
|
145 if len(kvparts) == 2: |
|
329
39674f294709
Ported the revinfo extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents:
328
diff
changeset
|
146 msg += b"%s: %s\n" % tuple(kvparts) |
|
24
c91a5c0f1be3
Add a "-d/--data" option that adds additional "KEY: VALUE" pairs into the revinfo.
Franz Glasner <hg@dom66.de>
parents:
22
diff
changeset
|
147 else: |
|
114
a51822141ccf
Style: handled some more flake8 warnings: consistent command declaration list formatting
Franz Glasner <hg@dom66.de>
parents:
113
diff
changeset
|
148 raise error.Abort( |
|
329
39674f294709
Ported the revinfo extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents:
328
diff
changeset
|
149 _(b"given data `%s' is not a KEY=VALUE pair") % (kv, )) |
|
24
c91a5c0f1be3
Add a "-d/--data" option that adds additional "KEY: VALUE" pairs into the revinfo.
Franz Glasner <hg@dom66.de>
parents:
22
diff
changeset
|
150 |
|
329
39674f294709
Ported the revinfo extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents:
328
diff
changeset
|
151 paths = opts.get(b"path") |
|
24
c91a5c0f1be3
Add a "-d/--data" option that adds additional "KEY: VALUE" pairs into the revinfo.
Franz Glasner <hg@dom66.de>
parents:
22
diff
changeset
|
152 # |
|
c91a5c0f1be3
Add a "-d/--data" option that adds additional "KEY: VALUE" pairs into the revinfo.
Franz Glasner <hg@dom66.de>
parents:
22
diff
changeset
|
153 # When not amending and no path options is given print the |
|
c91a5c0f1be3
Add a "-d/--data" option that adds additional "KEY: VALUE" pairs into the revinfo.
Franz Glasner <hg@dom66.de>
parents:
22
diff
changeset
|
154 # "default" path |
|
c91a5c0f1be3
Add a "-d/--data" option that adds additional "KEY: VALUE" pairs into the revinfo.
Franz Glasner <hg@dom66.de>
parents:
22
diff
changeset
|
155 # |
|
329
39674f294709
Ported the revinfo extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents:
328
diff
changeset
|
156 if not opts.get(b"amend"): |
|
24
c91a5c0f1be3
Add a "-d/--data" option that adds additional "KEY: VALUE" pairs into the revinfo.
Franz Glasner <hg@dom66.de>
parents:
22
diff
changeset
|
157 if not paths: |
|
329
39674f294709
Ported the revinfo extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents:
328
diff
changeset
|
158 paths = [b"default"] |
|
20
8ca89d70b44c
Make the "-p/--path" option an option that can be repeated.
Franz Glasner <hg@dom66.de>
parents:
18
diff
changeset
|
159 for canonicalpath in paths: |
|
8ca89d70b44c
Make the "-p/--path" option an option that can be repeated.
Franz Glasner <hg@dom66.de>
parents:
18
diff
changeset
|
160 if canonicalpath: |
|
329
39674f294709
Ported the revinfo extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents:
328
diff
changeset
|
161 if canonicalpath == b'.': |
|
39674f294709
Ported the revinfo extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents:
328
diff
changeset
|
162 msg += b"path: %s\n" % repo.root |
|
20
8ca89d70b44c
Make the "-p/--path" option an option that can be repeated.
Franz Glasner <hg@dom66.de>
parents:
18
diff
changeset
|
163 else: |
|
420
43fd36a465cc
Make revinfo and kwarchive compatible to Mercurial 5.8: ui.paths yields now a list of location objects
Franz Glasner <fzglas.hg@dom66.de>
parents:
357
diff
changeset
|
164 # |
|
43fd36a465cc
Make revinfo and kwarchive compatible to Mercurial 5.8: ui.paths yields now a list of location objects
Franz Glasner <fzglas.hg@dom66.de>
parents:
357
diff
changeset
|
165 # Since Mercurial 5.8 ui.paths[n] yields a list of |
|
43fd36a465cc
Make revinfo and kwarchive compatible to Mercurial 5.8: ui.paths yields now a list of location objects
Franz Glasner <fzglas.hg@dom66.de>
parents:
357
diff
changeset
|
166 # locations |
|
43fd36a465cc
Make revinfo and kwarchive compatible to Mercurial 5.8: ui.paths yields now a list of location objects
Franz Glasner <fzglas.hg@dom66.de>
parents:
357
diff
changeset
|
167 # |
|
43fd36a465cc
Make revinfo and kwarchive compatible to Mercurial 5.8: ui.paths yields now a list of location objects
Franz Glasner <fzglas.hg@dom66.de>
parents:
357
diff
changeset
|
168 for name, paths in sorted(ui.paths.items()): |
|
43fd36a465cc
Make revinfo and kwarchive compatible to Mercurial 5.8: ui.paths yields now a list of location objects
Franz Glasner <fzglas.hg@dom66.de>
parents:
357
diff
changeset
|
169 if not isinstance(paths, list): |
|
43fd36a465cc
Make revinfo and kwarchive compatible to Mercurial 5.8: ui.paths yields now a list of location objects
Franz Glasner <fzglas.hg@dom66.de>
parents:
357
diff
changeset
|
170 paths = [paths] |
|
43fd36a465cc
Make revinfo and kwarchive compatible to Mercurial 5.8: ui.paths yields now a list of location objects
Franz Glasner <fzglas.hg@dom66.de>
parents:
357
diff
changeset
|
171 # for now a quick check of assumptions |
|
43fd36a465cc
Make revinfo and kwarchive compatible to Mercurial 5.8: ui.paths yields now a list of location objects
Franz Glasner <fzglas.hg@dom66.de>
parents:
357
diff
changeset
|
172 assert len(paths) == 1 |
|
40
fe48ca312f92
Use "." if the current repository root is to be assumed as path information
Franz Glasner <hg@dom66.de>
parents:
34
diff
changeset
|
173 if name == canonicalpath: |
|
425
2a062f87f75d
Make "revinfo" and "kwarchive" work on Mercurial 6.
Franz Glasner <fzglas.hg@dom66.de>
parents:
424
diff
changeset
|
174 msg += b"path: %s\n" % _urlutil.hidepassword(paths[0].loc) |
|
40
fe48ca312f92
Use "." if the current repository root is to be assumed as path information
Franz Glasner <hg@dom66.de>
parents:
34
diff
changeset
|
175 break |
|
fe48ca312f92
Use "." if the current repository root is to be assumed as path information
Franz Glasner <hg@dom66.de>
parents:
34
diff
changeset
|
176 else: |
|
329
39674f294709
Ported the revinfo extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents:
328
diff
changeset
|
177 msg += b"path: %s\n" % canonicalpath |
|
1
a80645763196
revinfo: a module to write .hg_archival.txt like repository metadata
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
178 if dest: |
|
a80645763196
revinfo: a module to write .hg_archival.txt like repository metadata
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
179 with open(dest, "wb") as rfile: |
|
a80645763196
revinfo: a module to write .hg_archival.txt like repository metadata
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
180 rfile.write(msg) |
|
a80645763196
revinfo: a module to write .hg_archival.txt like repository metadata
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
181 else: |
|
a80645763196
revinfo: a module to write .hg_archival.txt like repository metadata
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
182 ui.write(msg) |
