Per discussion with nbjoerg in IRC.
Details
Details
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Branch
- default
- Lint
No Linters Available - Unit
No Unit Test Coverage
Per discussion with nbjoerg in IRC.
| No Linters Available |
| No Unit Test Coverage |
| Path | Packages | |||
|---|---|---|---|---|
| M | mercurial/utils/rewriteutil.py (12 lines) |
| Commit | Parents | Author | Summary | Date |
|---|---|---|---|---|
| 0d1ec038eae3 | 340959e96059 | Matt Harbison | Aug 25 2020, 11:18 PM |
| Status | Author | Revision | |
|---|---|---|---|
| Closed | mharbison72 | ||
| Closed | mharbison72 | ||
| Closed | mharbison72 | ||
| Closed | mharbison72 | ||
| Closed | mharbison72 |
| from typing import ( | from typing import ( | ||||
| Dict, | Dict, | ||||
| List, | List, | ||||
| Optional, | Optional, | ||||
| ) | ) | ||||
| assert any((Dict, List, Optional,)) | assert any((Dict, List, Optional,)) | ||||
| sha1re = re.compile(br'\b[0-9a-f]{6,40}\b') | NODE_RE = re.compile(br'\b[0-9a-f]{6,64}\b') | ||||
| def update_hash_refs(repo, commitmsg, pending=None): | def update_hash_refs(repo, commitmsg, pending=None): | ||||
| # type: (localrepo.localrepository, bytes, Optional[Dict[bytes, List[bytes]]]) -> bytes | # type: (localrepo.localrepository, bytes, Optional[Dict[bytes, List[bytes]]]) -> bytes | ||||
| """Replace all obsolete commit hashes in the message with the current hash. | """Replace all obsolete commit hashes in the message with the current hash. | ||||
| If the obsolete commit was split or is divergent, the hash is not replaced | If the obsolete commit was split or is divergent, the hash is not replaced | ||||
| as there's no way to know which successor to choose. | as there's no way to know which successor to choose. | ||||
| """ | """ | ||||
| if not pending: | if not pending: | ||||
| pending = {} | pending = {} | ||||
| cache = {} | cache = {} | ||||
| sha1s = re.findall(sha1re, commitmsg) | hashes = re.findall(NODE_RE, commitmsg) | ||||
| unfi = repo.unfiltered() | unfi = repo.unfiltered() | ||||
| for sha1 in sha1s: | for h in hashes: | ||||
| fullnode = scmutil.resolvehexnodeidprefix(unfi, sha1) | fullnode = scmutil.resolvehexnodeidprefix(unfi, h) | ||||
| if fullnode is None: | if fullnode is None: | ||||
| continue | continue | ||||
| ctx = unfi[fullnode] | ctx = unfi[fullnode] | ||||
| if not ctx.obsolete(): | if not ctx.obsolete(): | ||||
| successors = pending.get(fullnode, None) | successors = pending.get(fullnode, None) | ||||
| if successors is None: | if successors is None: | ||||
| continue | continue | ||||
| # obsutil.successorssets() returns a list of list of nodes | # obsutil.successorssets() returns a list of list of nodes | ||||
| successors = [successors] | successors = [successors] | ||||
| else: | else: | ||||
| successors = obsutil.successorssets(repo, ctx.node(), cache=cache) | successors = obsutil.successorssets(repo, ctx.node(), cache=cache) | ||||
| # We can't make any assumptions about how to update the hash if the | # We can't make any assumptions about how to update the hash if the | ||||
| # cset in question was split or diverged. | # cset in question was split or diverged. | ||||
| if len(successors) == 1 and len(successors[0]) == 1: | if len(successors) == 1 and len(successors[0]) == 1: | ||||
| newsha1 = nodemod.hex(successors[0][0]) | newsha1 = nodemod.hex(successors[0][0]) | ||||
| commitmsg = commitmsg.replace(sha1, newsha1[: len(sha1)]) | commitmsg = commitmsg.replace(h, newsha1[: len(h)]) | ||||
| else: | else: | ||||
| repo.ui.note( | repo.ui.note( | ||||
| _( | _( | ||||
| b'The stale commit message reference to %s could ' | b'The stale commit message reference to %s could ' | ||||
| b'not be updated\n' | b'not be updated\n' | ||||
| ) | ) | ||||
| % sha1 | % h | ||||
| ) | ) | ||||
| return commitmsg | return commitmsg | ||||