Mercurial > public > mercurial-scm > hg
comparison mercurial/scmutil.py @ 44544:13da36d77a3f
scmutil: add option to register summary callbacks as transaction validators
We have a list of summary callbacks which are run after the transaction is
closed to show what has changed and what not. This patch makes it possible to
register those callbacks as transaction validators so that we can show summary
before committing the transaction and prompt user to accept the changes.
The goal of this is to implement `pull --confirm`.
Differential Revision: https://phab.mercurial-scm.org/D8199
author | Pulkit Goyal <7895pulkit@gmail.com> |
---|---|
date | Sat, 29 Feb 2020 12:58:13 +0530 |
parents | 9d2b2df2c2ba |
children | fdc802f29b2c |
comparison
equal
deleted
inserted
replaced
44543:36f08ae87ef6 | 44544:13da36d77a3f |
---|---|
1898 | 1898 |
1899 # A marker that tells the evolve extension to suppress its own reporting | 1899 # A marker that tells the evolve extension to suppress its own reporting |
1900 _reportstroubledchangesets = True | 1900 _reportstroubledchangesets = True |
1901 | 1901 |
1902 | 1902 |
1903 def registersummarycallback(repo, otr, txnname=b''): | 1903 def registersummarycallback(repo, otr, txnname=b'', as_validator=False): |
1904 """register a callback to issue a summary after the transaction is closed | 1904 """register a callback to issue a summary after the transaction is closed |
1905 | |
1906 If as_validator is true, then the callbacks are registered as transaction | |
1907 validators instead | |
1905 """ | 1908 """ |
1906 | 1909 |
1907 def txmatch(sources): | 1910 def txmatch(sources): |
1908 return any(txnname.startswith(source) for source in sources) | 1911 return any(txnname.startswith(source) for source in sources) |
1909 | 1912 |
1925 assert repo is not None # help pytype | 1928 assert repo is not None # help pytype |
1926 repo = repo.filtered(filtername) | 1929 repo = repo.filtered(filtername) |
1927 func(repo, tr) | 1930 func(repo, tr) |
1928 | 1931 |
1929 newcat = b'%02i-txnreport' % len(categories) | 1932 newcat = b'%02i-txnreport' % len(categories) |
1930 otr.addpostclose(newcat, wrapped) | 1933 if as_validator: |
1934 otr.addvalidator(newcat, wrapped) | |
1935 else: | |
1936 otr.addpostclose(newcat, wrapped) | |
1931 categories.append(newcat) | 1937 categories.append(newcat) |
1932 return wrapped | 1938 return wrapped |
1933 | 1939 |
1934 @reportsummary | 1940 @reportsummary |
1935 def reportchangegroup(repo, tr): | 1941 def reportchangegroup(repo, tr): |
1940 if cgchangesets or cgrevisions or cgfiles: | 1946 if cgchangesets or cgrevisions or cgfiles: |
1941 htext = b"" | 1947 htext = b"" |
1942 if cgheads: | 1948 if cgheads: |
1943 htext = _(b" (%+d heads)") % cgheads | 1949 htext = _(b" (%+d heads)") % cgheads |
1944 msg = _(b"added %d changesets with %d changes to %d files%s\n") | 1950 msg = _(b"added %d changesets with %d changes to %d files%s\n") |
1951 if as_validator: | |
1952 msg = _(b"adding %d changesets with %d changes to %d files%s\n") | |
1945 assert repo is not None # help pytype | 1953 assert repo is not None # help pytype |
1946 repo.ui.status(msg % (cgchangesets, cgrevisions, cgfiles, htext)) | 1954 repo.ui.status(msg % (cgchangesets, cgrevisions, cgfiles, htext)) |
1947 | 1955 |
1948 if txmatch(_reportobsoletedsource): | 1956 if txmatch(_reportobsoletedsource): |
1949 | 1957 |
1952 obsoleted = obsutil.getobsoleted(repo, tr) | 1960 obsoleted = obsutil.getobsoleted(repo, tr) |
1953 newmarkers = len(tr.changes.get(b'obsmarkers', ())) | 1961 newmarkers = len(tr.changes.get(b'obsmarkers', ())) |
1954 if newmarkers: | 1962 if newmarkers: |
1955 repo.ui.status(_(b'%i new obsolescence markers\n') % newmarkers) | 1963 repo.ui.status(_(b'%i new obsolescence markers\n') % newmarkers) |
1956 if obsoleted: | 1964 if obsoleted: |
1957 repo.ui.status(_(b'obsoleted %i changesets\n') % len(obsoleted)) | 1965 msg = _(b'obsoleted %i changesets\n') |
1966 if as_validator: | |
1967 msg = _(b'obsoleting %i changesets\n') | |
1968 repo.ui.status(msg % len(obsoleted)) | |
1958 | 1969 |
1959 if obsolete.isenabled( | 1970 if obsolete.isenabled( |
1960 repo, obsolete.createmarkersopt | 1971 repo, obsolete.createmarkersopt |
1961 ) and repo.ui.configbool( | 1972 ) and repo.ui.configbool( |
1962 b'experimental', b'evolution.report-instabilities' | 1973 b'experimental', b'evolution.report-instabilities' |
2055 for rev, (old, new) in pycompat.iteritems(phasetracking) | 2066 for rev, (old, new) in pycompat.iteritems(phasetracking) |
2056 if new == phases.public and rev < origrepolen | 2067 if new == phases.public and rev < origrepolen |
2057 ] | 2068 ] |
2058 if not published: | 2069 if not published: |
2059 return | 2070 return |
2060 repo.ui.status( | 2071 msg = _(b'%d local changesets published\n') |
2061 _(b'%d local changesets published\n') % len(published) | 2072 if as_validator: |
2062 ) | 2073 msg = _(b'%d local changesets will be published\n') |
2074 repo.ui.status(msg % len(published)) | |
2063 | 2075 |
2064 | 2076 |
2065 def getinstabilitymessage(delta, instability): | 2077 def getinstabilitymessage(delta, instability): |
2066 """function to return the message to show warning about new instabilities | 2078 """function to return the message to show warning about new instabilities |
2067 | 2079 |