annotate extensions/revinfo.py @ 125:fb7e1e4e4d2c

Provide some SCCS markers also to be able to search with "what(1)" also
author Franz Glasner <hg@dom66.de>
date Fri, 17 Aug 2018 09:07:02 +0200
parents a51822141ccf
children 5e502e9dd5e5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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$
104
65789e3e8e3d Provide a "HGnodeid" per file keyword that expands to the NodeID of the artifact.
Franz Glasner <hg@dom66.de>
parents: 102
diff changeset
3 # $HGnodeid$
34
7c4addd60935 Put keyword into the extensions itself
Franz Glasner <hg@dom66.de>
parents: 27
diff changeset
4 #
1
a80645763196 revinfo: a module to write .hg_archival.txt like repository metadata
Franz Glasner <hg@dom66.de>
parents:
diff changeset
5 """write a revision summary similar to .hg_archival.txt
a80645763196 revinfo: a module to write .hg_archival.txt like repository metadata
Franz Glasner <hg@dom66.de>
parents:
diff changeset
6 """
a80645763196 revinfo: a module to write .hg_archival.txt like repository metadata
Franz Glasner <hg@dom66.de>
parents:
diff changeset
7
42
b46ab29aefd8 Remove the "__version__" variable: use "__revision__" only instead
Franz Glasner <hg@dom66.de>
parents: 40
diff changeset
8 __revision__ = "$Revision$"
1
a80645763196 revinfo: a module to write .hg_archival.txt like repository metadata
Franz Glasner <hg@dom66.de>
parents:
diff changeset
9
a80645763196 revinfo: a module to write .hg_archival.txt like repository metadata
Franz Glasner <hg@dom66.de>
parents:
diff changeset
10 __author__ = "Franz Glasner"
a80645763196 revinfo: a module to write .hg_archival.txt like repository metadata
Franz Glasner <hg@dom66.de>
parents:
diff changeset
11
a80645763196 revinfo: a module to write .hg_archival.txt like repository metadata
Franz Glasner <hg@dom66.de>
parents:
diff changeset
12
a80645763196 revinfo: a module to write .hg_archival.txt like repository metadata
Franz Glasner <hg@dom66.de>
parents:
diff changeset
13 from mercurial.i18n import _
112
1744b36c39b7 Don't import mercurial.commands because it's not used
Franz Glasner <hg@dom66.de>
parents: 105
diff changeset
14 from mercurial import cmdutil, scmutil, util, error, archival
1
a80645763196 revinfo: a module to write .hg_archival.txt like repository metadata
Franz Glasner <hg@dom66.de>
parents:
diff changeset
15
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 cmdtable = {}
a80645763196 revinfo: a module to write .hg_archival.txt like repository metadata
Franz Glasner <hg@dom66.de>
parents:
diff changeset
18
a80645763196 revinfo: a module to write .hg_archival.txt like repository metadata
Franz Glasner <hg@dom66.de>
parents:
diff changeset
19 command = cmdutil.command(cmdtable)
a80645763196 revinfo: a module to write .hg_archival.txt like repository metadata
Franz Glasner <hg@dom66.de>
parents:
diff changeset
20
105
f142bdb90c8d Testify that "revinfo" and "kwarchive" work with Mercurial v4.6.1 now
Franz Glasner <hg@dom66.de>
parents: 104
diff changeset
21 testedwith = "3.5 3.5.1 3.5.2 4.3.1 4.3.2 4.4.1 4.4.2 4.5.2 4.6.1"
3
133dab95fb84 Added the recommended "testedwith" module attribute
Franz Glasner <hg@dom66.de>
parents: 1
diff changeset
22
1
a80645763196 revinfo: a module to write .hg_archival.txt like repository metadata
Franz Glasner <hg@dom66.de>
parents:
diff changeset
23
114
a51822141ccf Style: handled some more flake8 warnings: consistent command declaration list formatting
Franz Glasner <hg@dom66.de>
parents: 113
diff changeset
24 @command(
a51822141ccf Style: handled some more flake8 warnings: consistent command declaration list formatting
Franz Glasner <hg@dom66.de>
parents: 113
diff changeset
25 "revinfo",
a51822141ccf Style: handled some more flake8 warnings: consistent command declaration list formatting
Franz Glasner <hg@dom66.de>
parents: 113
diff changeset
26 [
a51822141ccf Style: handled some more flake8 warnings: consistent command declaration list formatting
Franz Glasner <hg@dom66.de>
parents: 113
diff changeset
27 ("r", "rev", "", _('revision to handle'), _('REV')),
a51822141ccf Style: handled some more flake8 warnings: consistent command declaration list formatting
Franz Glasner <hg@dom66.de>
parents: 113
diff changeset
28 ("", "amend", None, _('amend a given file with path information')),
a51822141ccf Style: handled some more flake8 warnings: consistent command declaration list formatting
Franz Glasner <hg@dom66.de>
parents: 113
diff changeset
29 ("p", "path", [], _('the configured default path'), _('SOURCE')),
a51822141ccf Style: handled some more flake8 warnings: consistent command declaration list formatting
Franz Glasner <hg@dom66.de>
parents: 113
diff changeset
30 ("d", "data", [], _("add an extra `KEY: VALUE' pair into the file"), _('KEY=VALUE')),
a51822141ccf Style: handled some more flake8 warnings: consistent command declaration list formatting
Franz Glasner <hg@dom66.de>
parents: 113
diff changeset
31 ],
a51822141ccf Style: handled some more flake8 warnings: consistent command declaration list formatting
Franz Glasner <hg@dom66.de>
parents: 113
diff changeset
32 _("hg revinfo [OPTION]... [DEST]"))
1
a80645763196 revinfo: a module to write .hg_archival.txt like repository metadata
Franz Glasner <hg@dom66.de>
parents:
diff changeset
33 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
34 """write a revision summary
a80645763196 revinfo: a module to write .hg_archival.txt like repository metadata
Franz Glasner <hg@dom66.de>
parents:
diff changeset
35
a80645763196 revinfo: a module to write .hg_archival.txt like repository metadata
Franz Glasner <hg@dom66.de>
parents:
diff changeset
36 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
37 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
38
a80645763196 revinfo: a module to write .hg_archival.txt like repository metadata
Franz Glasner <hg@dom66.de>
parents:
diff changeset
39 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
40 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
41
40
fe48ca312f92 Use "." if the current repository root is to be assumed as path information
Franz Glasner <hg@dom66.de>
parents: 34
diff changeset
42 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
43 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
44 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
45 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
46 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
47
13
c78608f802d4 Implemented "--amend" for revinfo to put extra "path" items into existing files
Franz Glasner <hg@dom66.de>
parents: 12
diff changeset
48 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
49 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
50
1
a80645763196 revinfo: a module to write .hg_archival.txt like repository metadata
Franz Glasner <hg@dom66.de>
parents:
diff changeset
51 The printed information is the same as the :hg:`archive` command
13
c78608f802d4 Implemented "--amend" for revinfo to put extra "path" items into existing files
Franz Glasner <hg@dom66.de>
parents: 12
diff changeset
52 writes into ".hg_archival.txt". The "path" info is an extra item.
40
fe48ca312f92 Use "." if the current repository root is to be assumed as path information
Franz Glasner <hg@dom66.de>
parents: 34
diff changeset
53
1
a80645763196 revinfo: a module to write .hg_archival.txt like repository metadata
Franz Glasner <hg@dom66.de>
parents:
diff changeset
54 """
13
c78608f802d4 Implemented "--amend" for revinfo to put extra "path" items into existing files
Franz Glasner <hg@dom66.de>
parents: 12
diff changeset
55 if opts.get("amend") and opts.get("rev"):
102
702d473b6d85 FIX: The "mercurial.util.Abort" alias is gone: use the mercurial.error.Abort instead.
Franz Glasner <hg@dom66.de>
parents: 99
diff changeset
56 raise error.Abort(_("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
57
13
c78608f802d4 Implemented "--amend" for revinfo to put extra "path" items into existing files
Franz Glasner <hg@dom66.de>
parents: 12
diff changeset
58 if opts.get("amend"):
c78608f802d4 Implemented "--amend" for revinfo to put extra "path" items into existing files
Franz Glasner <hg@dom66.de>
parents: 12
diff changeset
59 if not dest:
102
702d473b6d85 FIX: The "mercurial.util.Abort" alias is gone: use the mercurial.error.Abort instead.
Franz Glasner <hg@dom66.de>
parents: 99
diff changeset
60 raise error.Abort(_('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
61 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
62 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
63 else:
c78608f802d4 Implemented "--amend" for revinfo to put extra "path" items into existing files
Franz Glasner <hg@dom66.de>
parents: 12
diff changeset
64 ctx = scmutil.revsingle(repo, opts.get("rev"))
c78608f802d4 Implemented "--amend" for revinfo to put extra "path" items into existing files
Franz Glasner <hg@dom66.de>
parents: 12
diff changeset
65 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
66 raise error.Abort(
a51822141ccf Style: handled some more flake8 warnings: consistent command declaration list formatting
Franz Glasner <hg@dom66.de>
parents: 113
diff changeset
67 _("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
68
c78608f802d4 Implemented "--amend" for revinfo to put extra "path" items into existing files
Franz Glasner <hg@dom66.de>
parents: 12
diff changeset
69 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
70
c91a5c0f1be3 Add a "-d/--data" option that adds additional "KEY: VALUE" pairs into the revinfo.
Franz Glasner <hg@dom66.de>
parents: 22
diff changeset
71 for kv in opts.get("data"):
113
b3170649d7ab Style (flake8)
Franz Glasner <hg@dom66.de>
parents: 112
diff changeset
72 kvparts = [i.strip() for i in kv.split("=", 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
73 if len(kvparts) == 2:
c91a5c0f1be3 Add a "-d/--data" option that adds additional "KEY: VALUE" pairs into the revinfo.
Franz Glasner <hg@dom66.de>
parents: 22
diff changeset
74 msg += "%s: %s\n" % tuple(kvparts)
c91a5c0f1be3 Add a "-d/--data" option that adds additional "KEY: VALUE" pairs into the revinfo.
Franz Glasner <hg@dom66.de>
parents: 22
diff changeset
75 else:
114
a51822141ccf Style: handled some more flake8 warnings: consistent command declaration list formatting
Franz Glasner <hg@dom66.de>
parents: 113
diff changeset
76 raise error.Abort(
a51822141ccf Style: handled some more flake8 warnings: consistent command declaration list formatting
Franz Glasner <hg@dom66.de>
parents: 113
diff changeset
77 _("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
78
20
8ca89d70b44c Make the "-p/--path" option an option that can be repeated.
Franz Glasner <hg@dom66.de>
parents: 18
diff changeset
79 paths = opts.get("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
80 #
c91a5c0f1be3 Add a "-d/--data" option that adds additional "KEY: VALUE" pairs into the revinfo.
Franz Glasner <hg@dom66.de>
parents: 22
diff changeset
81 # 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
82 # "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
83 #
c91a5c0f1be3 Add a "-d/--data" option that adds additional "KEY: VALUE" pairs into the revinfo.
Franz Glasner <hg@dom66.de>
parents: 22
diff changeset
84 if not opts.get("amend"):
c91a5c0f1be3 Add a "-d/--data" option that adds additional "KEY: VALUE" pairs into the revinfo.
Franz Glasner <hg@dom66.de>
parents: 22
diff changeset
85 if not paths:
c91a5c0f1be3 Add a "-d/--data" option that adds additional "KEY: VALUE" pairs into the revinfo.
Franz Glasner <hg@dom66.de>
parents: 22
diff changeset
86 paths = ["default"]
20
8ca89d70b44c Make the "-p/--path" option an option that can be repeated.
Franz Glasner <hg@dom66.de>
parents: 18
diff changeset
87 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
88 if canonicalpath:
40
fe48ca312f92 Use "." if the current repository root is to be assumed as path information
Franz Glasner <hg@dom66.de>
parents: 34
diff changeset
89 if canonicalpath == ".":
fe48ca312f92 Use "." if the current repository root is to be assumed as path information
Franz Glasner <hg@dom66.de>
parents: 34
diff changeset
90 msg += "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
91 else:
40
fe48ca312f92 Use "." if the current repository root is to be assumed as path information
Franz Glasner <hg@dom66.de>
parents: 34
diff changeset
92 for name, path in sorted(ui.paths.iteritems()):
fe48ca312f92 Use "." if the current repository root is to be assumed as path information
Franz Glasner <hg@dom66.de>
parents: 34
diff changeset
93 if name == canonicalpath:
fe48ca312f92 Use "." if the current repository root is to be assumed as path information
Franz Glasner <hg@dom66.de>
parents: 34
diff changeset
94 msg += "path: %s\n" % util.hidepassword(path.loc)
fe48ca312f92 Use "." if the current repository root is to be assumed as path information
Franz Glasner <hg@dom66.de>
parents: 34
diff changeset
95 break
fe48ca312f92 Use "." if the current repository root is to be assumed as path information
Franz Glasner <hg@dom66.de>
parents: 34
diff changeset
96 else:
fe48ca312f92 Use "." if the current repository root is to be assumed as path information
Franz Glasner <hg@dom66.de>
parents: 34
diff changeset
97 msg += "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
98 if dest:
a80645763196 revinfo: a module to write .hg_archival.txt like repository metadata
Franz Glasner <hg@dom66.de>
parents:
diff changeset
99 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
100 rfile.write(msg)
a80645763196 revinfo: a module to write .hg_archival.txt like repository metadata
Franz Glasner <hg@dom66.de>
parents:
diff changeset
101 else:
a80645763196 revinfo: a module to write .hg_archival.txt like repository metadata
Franz Glasner <hg@dom66.de>
parents:
diff changeset
102 ui.write(msg)