Mercurial > hg-git-serve
annotate src/hgext3rd/hggit_serve/_export.py @ 16:78ea1ec94be5
Fix error message for auto-export setting.
| author | Paul Fisher <paul@pfish.zone> |
|---|---|
| date | Fri, 20 Feb 2026 21:08:54 -0500 |
| parents | 959ef686193f |
| children |
| rev | line source |
|---|---|
|
1
a39dd69b8972
Create a more-or-less real package and make it work (?)
Paul Fisher <paul@pfish.zone>
parents:
0
diff
changeset
|
1 from __future__ import annotations |
|
a39dd69b8972
Create a more-or-less real package and make it work (?)
Paul Fisher <paul@pfish.zone>
parents:
0
diff
changeset
|
2 |
|
a39dd69b8972
Create a more-or-less real package and make it work (?)
Paul Fisher <paul@pfish.zone>
parents:
0
diff
changeset
|
3 import binascii |
|
0
c1dc9d21fa57
First cut at serving hg repos with git.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
4 import typing as t |
|
c1dc9d21fa57
First cut at serving hg repos with git.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
5 |
|
1
a39dd69b8972
Create a more-or-less real package and make it work (?)
Paul Fisher <paul@pfish.zone>
parents:
0
diff
changeset
|
6 import dulwich.refs |
|
a39dd69b8972
Create a more-or-less real package and make it work (?)
Paul Fisher <paul@pfish.zone>
parents:
0
diff
changeset
|
7 import mercurial.error as hgerr |
|
8
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
8 from hggit import git_handler |
|
0
c1dc9d21fa57
First cut at serving hg repos with git.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
9 |
|
1
a39dd69b8972
Create a more-or-less real package and make it work (?)
Paul Fisher <paul@pfish.zone>
parents:
0
diff
changeset
|
10 if t.TYPE_CHECKING: |
|
a39dd69b8972
Create a more-or-less real package and make it work (?)
Paul Fisher <paul@pfish.zone>
parents:
0
diff
changeset
|
11 import mercurial.interfaces.repository as hgrepo |
|
a39dd69b8972
Create a more-or-less real package and make it work (?)
Paul Fisher <paul@pfish.zone>
parents:
0
diff
changeset
|
12 import mercurial.ui as hgui |
|
a39dd69b8972
Create a more-or-less real package and make it work (?)
Paul Fisher <paul@pfish.zone>
parents:
0
diff
changeset
|
13 |
|
a39dd69b8972
Create a more-or-less real package and make it work (?)
Paul Fisher <paul@pfish.zone>
parents:
0
diff
changeset
|
14 class GittyRepo(hgrepo.IRepo, t.Protocol): |
|
8
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
15 githandler: git_handler.GitHandler |
|
1
a39dd69b8972
Create a more-or-less real package and make it work (?)
Paul Fisher <paul@pfish.zone>
parents:
0
diff
changeset
|
16 |
|
0
c1dc9d21fa57
First cut at serving hg repos with git.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
17 |
|
12
f630d9904ea7
Reorganize project into multiple files.
Paul Fisher <paul@pfish.zone>
parents:
11
diff
changeset
|
18 def is_gitty(repo: hgrepo.IRepo) -> t.TypeGuard[GittyRepo]: |
|
4
5ad58438318a
Fix issue where sometimes reads would be cut off.
Paul Fisher <paul@pfish.zone>
parents:
3
diff
changeset
|
19 """Ensures that we have hg-git installed and active.""" |
|
5ad58438318a
Fix issue where sometimes reads would be cut off.
Paul Fisher <paul@pfish.zone>
parents:
3
diff
changeset
|
20 return hasattr(repo, 'githandler') |
|
5ad58438318a
Fix issue where sometimes reads would be cut off.
Paul Fisher <paul@pfish.zone>
parents:
3
diff
changeset
|
21 |
|
5ad58438318a
Fix issue where sometimes reads would be cut off.
Paul Fisher <paul@pfish.zone>
parents:
3
diff
changeset
|
22 |
|
12
f630d9904ea7
Reorganize project into multiple files.
Paul Fisher <paul@pfish.zone>
parents:
11
diff
changeset
|
23 PULL = b'pull' |
|
f630d9904ea7
Reorganize project into multiple files.
Paul Fisher <paul@pfish.zone>
parents:
11
diff
changeset
|
24 PUSH = b'push' |
|
0
c1dc9d21fa57
First cut at serving hg repos with git.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
25 |
|
12
f630d9904ea7
Reorganize project into multiple files.
Paul Fisher <paul@pfish.zone>
parents:
11
diff
changeset
|
26 SERVICE_PERMISSIONS = { |
|
f630d9904ea7
Reorganize project into multiple files.
Paul Fisher <paul@pfish.zone>
parents:
11
diff
changeset
|
27 b'git-upload-pack': PULL, |
|
f630d9904ea7
Reorganize project into multiple files.
Paul Fisher <paul@pfish.zone>
parents:
11
diff
changeset
|
28 b'git-receive-pack': PUSH, |
|
8
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
29 } |
|
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
30 """The Mercurial permission corresponding to each Git action. |
|
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
31 |
|
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
32 These seem backwards because the direction of up/download is relative to |
|
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
33 the server, so when the client pulls, the server is *uploading*, |
|
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
34 and when the client pushes, the server is *downloading*. |
|
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
35 """ |
|
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
36 |
|
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
37 |
|
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
38 # |
|
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
39 # Stuff so that we don't try to export revisions while we're importing. |
|
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
40 # |
|
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
41 |
|
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
42 _ILEVEL_ATTR = '@hggit_import_level' |
|
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
43 """An attribute that tracks how many "levels deep" we are into importing. |
|
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
44 |
|
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
45 We set this on the repository object when we're importing and remove it |
|
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
46 when we're done. It's not just a bool in case somebody sets up some crazy |
|
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
47 recursive hook situation where we start importing inside another import. |
|
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
48 """ |
|
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
49 |
|
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
50 |
|
13
00bdfac5416c
Create Git SSH commands and add some documentation. Also cleanup.
Paul Fisher <paul@pfish.zone>
parents:
12
diff
changeset
|
51 def _importing_enter(repo: hgrepo.IRepo) -> None: |
|
8
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
52 """Call this before you start importing from Git.""" |
|
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
53 level = getattr(repo, _ILEVEL_ATTR, 0) + 1 |
|
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
54 setattr(repo, _ILEVEL_ATTR, level) |
|
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
55 |
|
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
56 |
|
13
00bdfac5416c
Create Git SSH commands and add some documentation. Also cleanup.
Paul Fisher <paul@pfish.zone>
parents:
12
diff
changeset
|
57 def _is_importing(repo: hgrepo.IRepo) -> bool: |
|
8
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
58 """Call this to check if you're currently importing.""" |
|
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
59 return hasattr(repo, _ILEVEL_ATTR) |
|
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
60 |
|
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
61 |
|
13
00bdfac5416c
Create Git SSH commands and add some documentation. Also cleanup.
Paul Fisher <paul@pfish.zone>
parents:
12
diff
changeset
|
62 def _importing_exit(repo: hgrepo.IRepo) -> None: |
|
8
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
63 """Call this after you finish importing from Git.""" |
|
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
64 level = getattr(repo, _ILEVEL_ATTR) - 1 |
|
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
65 if level: |
|
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
66 setattr(repo, _ILEVEL_ATTR, level) |
|
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
67 else: |
|
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
68 delattr(repo, _ILEVEL_ATTR) |
|
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
69 |
|
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
70 |
|
13
00bdfac5416c
Create Git SSH commands and add some documentation. Also cleanup.
Paul Fisher <paul@pfish.zone>
parents:
12
diff
changeset
|
71 def import_all(repo: GittyRepo, command: bytes = b'(unknown)') -> None: |
|
00bdfac5416c
Create Git SSH commands and add some documentation. Also cleanup.
Paul Fisher <paul@pfish.zone>
parents:
12
diff
changeset
|
72 _importing_enter(repo) |
|
00bdfac5416c
Create Git SSH commands and add some documentation. Also cleanup.
Paul Fisher <paul@pfish.zone>
parents:
12
diff
changeset
|
73 try: |
|
00bdfac5416c
Create Git SSH commands and add some documentation. Also cleanup.
Paul Fisher <paul@pfish.zone>
parents:
12
diff
changeset
|
74 gh = repo.githandler |
|
00bdfac5416c
Create Git SSH commands and add some documentation. Also cleanup.
Paul Fisher <paul@pfish.zone>
parents:
12
diff
changeset
|
75 gh.import_git_objects( |
|
00bdfac5416c
Create Git SSH commands and add some documentation. Also cleanup.
Paul Fisher <paul@pfish.zone>
parents:
12
diff
changeset
|
76 command, remote_names=(), refs=gh.git.refs.as_dict() |
|
00bdfac5416c
Create Git SSH commands and add some documentation. Also cleanup.
Paul Fisher <paul@pfish.zone>
parents:
12
diff
changeset
|
77 ) |
|
00bdfac5416c
Create Git SSH commands and add some documentation. Also cleanup.
Paul Fisher <paul@pfish.zone>
parents:
12
diff
changeset
|
78 finally: |
|
00bdfac5416c
Create Git SSH commands and add some documentation. Also cleanup.
Paul Fisher <paul@pfish.zone>
parents:
12
diff
changeset
|
79 _importing_exit(repo) |
|
00bdfac5416c
Create Git SSH commands and add some documentation. Also cleanup.
Paul Fisher <paul@pfish.zone>
parents:
12
diff
changeset
|
80 |
|
00bdfac5416c
Create Git SSH commands and add some documentation. Also cleanup.
Paul Fisher <paul@pfish.zone>
parents:
12
diff
changeset
|
81 |
|
8
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
82 # |
|
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
83 # Export handling. |
|
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
84 # |
|
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
85 |
|
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
86 |
|
13
00bdfac5416c
Create Git SSH commands and add some documentation. Also cleanup.
Paul Fisher <paul@pfish.zone>
parents:
12
diff
changeset
|
87 def _clean_all_refs(refs: dulwich.refs.RefsContainer) -> None: |
|
4
5ad58438318a
Fix issue where sometimes reads would be cut off.
Paul Fisher <paul@pfish.zone>
parents:
3
diff
changeset
|
88 """Removes all refs from the Git repository.""" |
|
13
00bdfac5416c
Create Git SSH commands and add some documentation. Also cleanup.
Paul Fisher <paul@pfish.zone>
parents:
12
diff
changeset
|
89 # dump to allkeys so we explicitly are iterating over a snapshot |
|
00bdfac5416c
Create Git SSH commands and add some documentation. Also cleanup.
Paul Fisher <paul@pfish.zone>
parents:
12
diff
changeset
|
90 # and not over something while we mutate |
|
00bdfac5416c
Create Git SSH commands and add some documentation. Also cleanup.
Paul Fisher <paul@pfish.zone>
parents:
12
diff
changeset
|
91 for ref in refs.allkeys(): |
|
00bdfac5416c
Create Git SSH commands and add some documentation. Also cleanup.
Paul Fisher <paul@pfish.zone>
parents:
12
diff
changeset
|
92 refs.remove_if_equals(ref, None) |
|
1
a39dd69b8972
Create a more-or-less real package and make it work (?)
Paul Fisher <paul@pfish.zone>
parents:
0
diff
changeset
|
93 |
|
a39dd69b8972
Create a more-or-less real package and make it work (?)
Paul Fisher <paul@pfish.zone>
parents:
0
diff
changeset
|
94 |
|
13
00bdfac5416c
Create Git SSH commands and add some documentation. Also cleanup.
Paul Fisher <paul@pfish.zone>
parents:
12
diff
changeset
|
95 def _set_head(ui: hgui.ui, repo: GittyRepo, at_name: bytes) -> None: |
|
1
a39dd69b8972
Create a more-or-less real package and make it work (?)
Paul Fisher <paul@pfish.zone>
parents:
0
diff
changeset
|
96 """Creates a HEAD reference in Git referring to the current HEAD.""" |
|
a39dd69b8972
Create a more-or-less real package and make it work (?)
Paul Fisher <paul@pfish.zone>
parents:
0
diff
changeset
|
97 # By default, we use '@', since that's what will be auto checked out. |
|
a39dd69b8972
Create a more-or-less real package and make it work (?)
Paul Fisher <paul@pfish.zone>
parents:
0
diff
changeset
|
98 current = b'@' |
|
a39dd69b8972
Create a more-or-less real package and make it work (?)
Paul Fisher <paul@pfish.zone>
parents:
0
diff
changeset
|
99 if current not in repo._bookmarks: |
|
a39dd69b8972
Create a more-or-less real package and make it work (?)
Paul Fisher <paul@pfish.zone>
parents:
0
diff
changeset
|
100 current = repo._bookmarks.active or current |
|
a39dd69b8972
Create a more-or-less real package and make it work (?)
Paul Fisher <paul@pfish.zone>
parents:
0
diff
changeset
|
101 |
|
a39dd69b8972
Create a more-or-less real package and make it work (?)
Paul Fisher <paul@pfish.zone>
parents:
0
diff
changeset
|
102 # We'll be moving this (possibly fake) bookmark into Git. |
|
a39dd69b8972
Create a more-or-less real package and make it work (?)
Paul Fisher <paul@pfish.zone>
parents:
0
diff
changeset
|
103 git_current = current |
|
a39dd69b8972
Create a more-or-less real package and make it work (?)
Paul Fisher <paul@pfish.zone>
parents:
0
diff
changeset
|
104 if current == b'@': |
|
a39dd69b8972
Create a more-or-less real package and make it work (?)
Paul Fisher <paul@pfish.zone>
parents:
0
diff
changeset
|
105 # @ is a special keyword in Git, so we can't use it as a bookmark. |
|
6
7113e0ac3662
fix refs on git-export; clean up how gitserve export works.
Paul Fisher <paul@pfish.zone>
parents:
5
diff
changeset
|
106 git_current = at_name |
|
1
a39dd69b8972
Create a more-or-less real package and make it work (?)
Paul Fisher <paul@pfish.zone>
parents:
0
diff
changeset
|
107 git_branch = dulwich.refs.LOCAL_BRANCH_PREFIX + git_current |
|
a39dd69b8972
Create a more-or-less real package and make it work (?)
Paul Fisher <paul@pfish.zone>
parents:
0
diff
changeset
|
108 if not dulwich.refs.check_ref_format(git_branch): |
|
a39dd69b8972
Create a more-or-less real package and make it work (?)
Paul Fisher <paul@pfish.zone>
parents:
0
diff
changeset
|
109 # We can't export this ref to Git. Give up. |
|
6
7113e0ac3662
fix refs on git-export; clean up how gitserve export works.
Paul Fisher <paul@pfish.zone>
parents:
5
diff
changeset
|
110 ui.warn(f'{git_branch!r} is not a valid branch name for Git.'.encode()) |
|
7113e0ac3662
fix refs on git-export; clean up how gitserve export works.
Paul Fisher <paul@pfish.zone>
parents:
5
diff
changeset
|
111 return |
|
7113e0ac3662
fix refs on git-export; clean up how gitserve export works.
Paul Fisher <paul@pfish.zone>
parents:
5
diff
changeset
|
112 try: |
|
7113e0ac3662
fix refs on git-export; clean up how gitserve export works.
Paul Fisher <paul@pfish.zone>
parents:
5
diff
changeset
|
113 # Maybe this is a real bookmark? |
|
8
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
114 hgnode = repo._bookmarks[current] |
|
6
7113e0ac3662
fix refs on git-export; clean up how gitserve export works.
Paul Fisher <paul@pfish.zone>
parents:
5
diff
changeset
|
115 except KeyError: |
|
7113e0ac3662
fix refs on git-export; clean up how gitserve export works.
Paul Fisher <paul@pfish.zone>
parents:
5
diff
changeset
|
116 # Not a real bookmark. Assume we want the tip of the current branch. |
|
7113e0ac3662
fix refs on git-export; clean up how gitserve export works.
Paul Fisher <paul@pfish.zone>
parents:
5
diff
changeset
|
117 branch = repo.dirstate.branch() |
|
7113e0ac3662
fix refs on git-export; clean up how gitserve export works.
Paul Fisher <paul@pfish.zone>
parents:
5
diff
changeset
|
118 try: |
|
8
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
119 hgnode = repo.branchtip(branch) |
|
6
7113e0ac3662
fix refs on git-export; clean up how gitserve export works.
Paul Fisher <paul@pfish.zone>
parents:
5
diff
changeset
|
120 except hgerr.RepoLookupError: |
|
7113e0ac3662
fix refs on git-export; clean up how gitserve export works.
Paul Fisher <paul@pfish.zone>
parents:
5
diff
changeset
|
121 # This branch somehow doesn't exist??? |
|
8
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
122 ui.warn(f"{branch!r} doesn't seem to exist?".encode()) |
|
6
7113e0ac3662
fix refs on git-export; clean up how gitserve export works.
Paul Fisher <paul@pfish.zone>
parents:
5
diff
changeset
|
123 return |
|
8
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
124 hgsha = binascii.hexlify(hgnode) |
|
6
7113e0ac3662
fix refs on git-export; clean up how gitserve export works.
Paul Fisher <paul@pfish.zone>
parents:
5
diff
changeset
|
125 gitsha = repo.githandler.map_git_get(hgsha) |
|
7113e0ac3662
fix refs on git-export; clean up how gitserve export works.
Paul Fisher <paul@pfish.zone>
parents:
5
diff
changeset
|
126 if not gitsha: |
|
7113e0ac3662
fix refs on git-export; clean up how gitserve export works.
Paul Fisher <paul@pfish.zone>
parents:
5
diff
changeset
|
127 # No Git SHA to match this Hg sha. Give up. |
|
8
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
128 ui.warn(f'revision {hgsha!r} was not exported to Git'.encode()) |
|
1
a39dd69b8972
Create a more-or-less real package and make it work (?)
Paul Fisher <paul@pfish.zone>
parents:
0
diff
changeset
|
129 return |
|
a39dd69b8972
Create a more-or-less real package and make it work (?)
Paul Fisher <paul@pfish.zone>
parents:
0
diff
changeset
|
130 refs = repo.githandler.git.refs |
|
6
7113e0ac3662
fix refs on git-export; clean up how gitserve export works.
Paul Fisher <paul@pfish.zone>
parents:
5
diff
changeset
|
131 refs.add_packed_refs({git_branch: gitsha}) |
|
1
a39dd69b8972
Create a more-or-less real package and make it work (?)
Paul Fisher <paul@pfish.zone>
parents:
0
diff
changeset
|
132 refs.set_symbolic_ref(b'HEAD', git_branch) |
|
a39dd69b8972
Create a more-or-less real package and make it work (?)
Paul Fisher <paul@pfish.zone>
parents:
0
diff
changeset
|
133 |
|
a39dd69b8972
Create a more-or-less real package and make it work (?)
Paul Fisher <paul@pfish.zone>
parents:
0
diff
changeset
|
134 |
|
13
00bdfac5416c
Create Git SSH commands and add some documentation. Also cleanup.
Paul Fisher <paul@pfish.zone>
parents:
12
diff
changeset
|
135 def _fix_refs(ui: hgui.ui, repo: GittyRepo) -> None: |
|
8
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
136 """After a git export, fix up the refs. |
|
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
137 |
|
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
138 This ensures that there are no leftover refs from older, removed bookmarks |
|
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
139 and that there is a proper HEAD set so that cloning works. |
|
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
140 """ |
|
13
00bdfac5416c
Create Git SSH commands and add some documentation. Also cleanup.
Paul Fisher <paul@pfish.zone>
parents:
12
diff
changeset
|
141 _clean_all_refs(repo.githandler.git.refs) |
|
6
7113e0ac3662
fix refs on git-export; clean up how gitserve export works.
Paul Fisher <paul@pfish.zone>
parents:
5
diff
changeset
|
142 repo.githandler.export_hg_tags() |
|
7113e0ac3662
fix refs on git-export; clean up how gitserve export works.
Paul Fisher <paul@pfish.zone>
parents:
5
diff
changeset
|
143 repo.githandler.update_references() |
|
7113e0ac3662
fix refs on git-export; clean up how gitserve export works.
Paul Fisher <paul@pfish.zone>
parents:
5
diff
changeset
|
144 default_branch_name = ui.config( |
|
7113e0ac3662
fix refs on git-export; clean up how gitserve export works.
Paul Fisher <paul@pfish.zone>
parents:
5
diff
changeset
|
145 b'hggit-serve', b'default-branch', b'default' |
|
7113e0ac3662
fix refs on git-export; clean up how gitserve export works.
Paul Fisher <paul@pfish.zone>
parents:
5
diff
changeset
|
146 ) |
|
13
00bdfac5416c
Create Git SSH commands and add some documentation. Also cleanup.
Paul Fisher <paul@pfish.zone>
parents:
12
diff
changeset
|
147 _set_head(ui, repo, default_branch_name) |
|
6
7113e0ac3662
fix refs on git-export; clean up how gitserve export works.
Paul Fisher <paul@pfish.zone>
parents:
5
diff
changeset
|
148 |
|
7113e0ac3662
fix refs on git-export; clean up how gitserve export works.
Paul Fisher <paul@pfish.zone>
parents:
5
diff
changeset
|
149 |
|
12
f630d9904ea7
Reorganize project into multiple files.
Paul Fisher <paul@pfish.zone>
parents:
11
diff
changeset
|
150 # |
|
f630d9904ea7
Reorganize project into multiple files.
Paul Fisher <paul@pfish.zone>
parents:
11
diff
changeset
|
151 # Hooks |
|
f630d9904ea7
Reorganize project into multiple files.
Paul Fisher <paul@pfish.zone>
parents:
11
diff
changeset
|
152 # |
|
f630d9904ea7
Reorganize project into multiple files.
Paul Fisher <paul@pfish.zone>
parents:
11
diff
changeset
|
153 |
|
14
959ef686193f
Add user-facing documentation.
Paul Fisher <paul@pfish.zone>
parents:
13
diff
changeset
|
154 _AX_ALWAYS = b'always' |
|
959ef686193f
Add user-facing documentation.
Paul Fisher <paul@pfish.zone>
parents:
13
diff
changeset
|
155 _AX_DEFAULT = b'default' |
|
959ef686193f
Add user-facing documentation.
Paul Fisher <paul@pfish.zone>
parents:
13
diff
changeset
|
156 _AX_NEVER = b'never' |
|
959ef686193f
Add user-facing documentation.
Paul Fisher <paul@pfish.zone>
parents:
13
diff
changeset
|
157 |
|
12
f630d9904ea7
Reorganize project into multiple files.
Paul Fisher <paul@pfish.zone>
parents:
11
diff
changeset
|
158 |
|
f630d9904ea7
Reorganize project into multiple files.
Paul Fisher <paul@pfish.zone>
parents:
11
diff
changeset
|
159 def _export_hook(ui: hgui.ui, repo: hgrepo.IRepo, **__: object) -> None: |
|
8
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
160 """Maybe exports the repository to get after we get new revs.""" |
|
12
f630d9904ea7
Reorganize project into multiple files.
Paul Fisher <paul@pfish.zone>
parents:
11
diff
changeset
|
161 if not is_gitty(repo): |
|
6
7113e0ac3662
fix refs on git-export; clean up how gitserve export works.
Paul Fisher <paul@pfish.zone>
parents:
5
diff
changeset
|
162 return |
|
7113e0ac3662
fix refs on git-export; clean up how gitserve export works.
Paul Fisher <paul@pfish.zone>
parents:
5
diff
changeset
|
163 auto_export = ui.config(b'hggit-serve', b'auto-export') |
|
14
959ef686193f
Add user-facing documentation.
Paul Fisher <paul@pfish.zone>
parents:
13
diff
changeset
|
164 if auto_export == _AX_NEVER: |
|
6
7113e0ac3662
fix refs on git-export; clean up how gitserve export works.
Paul Fisher <paul@pfish.zone>
parents:
5
diff
changeset
|
165 return |
|
14
959ef686193f
Add user-facing documentation.
Paul Fisher <paul@pfish.zone>
parents:
13
diff
changeset
|
166 if auto_export == _AX_ALWAYS or git_handler.has_gitrepo(repo): |
|
959ef686193f
Add user-facing documentation.
Paul Fisher <paul@pfish.zone>
parents:
13
diff
changeset
|
167 if auto_export not in (None, _AX_ALWAYS, _AX_DEFAULT): |
|
959ef686193f
Add user-facing documentation.
Paul Fisher <paul@pfish.zone>
parents:
13
diff
changeset
|
168 ui.warn( |
|
16
78ea1ec94be5
Fix error message for auto-export setting.
Paul Fisher <paul@pfish.zone>
parents:
14
diff
changeset
|
169 b'unrecognized auto-export setting "' |
|
78ea1ec94be5
Fix error message for auto-export setting.
Paul Fisher <paul@pfish.zone>
parents:
14
diff
changeset
|
170 + auto_export |
|
78ea1ec94be5
Fix error message for auto-export setting.
Paul Fisher <paul@pfish.zone>
parents:
14
diff
changeset
|
171 + b'"; using "' |
|
78ea1ec94be5
Fix error message for auto-export setting.
Paul Fisher <paul@pfish.zone>
parents:
14
diff
changeset
|
172 + _AX_DEFAULT |
|
78ea1ec94be5
Fix error message for auto-export setting.
Paul Fisher <paul@pfish.zone>
parents:
14
diff
changeset
|
173 + b'"\n' |
|
14
959ef686193f
Add user-facing documentation.
Paul Fisher <paul@pfish.zone>
parents:
13
diff
changeset
|
174 ) |
|
13
00bdfac5416c
Create Git SSH commands and add some documentation. Also cleanup.
Paul Fisher <paul@pfish.zone>
parents:
12
diff
changeset
|
175 if _is_importing(repo): |
|
8
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
176 ui.note(b'currently importing revs from git; not exporting\n') |
|
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
177 return |
|
6
7113e0ac3662
fix refs on git-export; clean up how gitserve export works.
Paul Fisher <paul@pfish.zone>
parents:
5
diff
changeset
|
178 repo.githandler.export_commits() |
|
13
00bdfac5416c
Create Git SSH commands and add some documentation. Also cleanup.
Paul Fisher <paul@pfish.zone>
parents:
12
diff
changeset
|
179 _fix_refs(ui, repo) |
|
12
f630d9904ea7
Reorganize project into multiple files.
Paul Fisher <paul@pfish.zone>
parents:
11
diff
changeset
|
180 |
|
f630d9904ea7
Reorganize project into multiple files.
Paul Fisher <paul@pfish.zone>
parents:
11
diff
changeset
|
181 |
|
f630d9904ea7
Reorganize project into multiple files.
Paul Fisher <paul@pfish.zone>
parents:
11
diff
changeset
|
182 def _fix_refs_hook(ui: hgui.ui, repo: hgrepo.IRepo, **__: object) -> None: |
|
f630d9904ea7
Reorganize project into multiple files.
Paul Fisher <paul@pfish.zone>
parents:
11
diff
changeset
|
183 """Exports to Git and sets up for serving. See ``_fix_refs``.""" |
|
f630d9904ea7
Reorganize project into multiple files.
Paul Fisher <paul@pfish.zone>
parents:
11
diff
changeset
|
184 if not is_gitty(repo): |
|
f630d9904ea7
Reorganize project into multiple files.
Paul Fisher <paul@pfish.zone>
parents:
11
diff
changeset
|
185 return |
|
13
00bdfac5416c
Create Git SSH commands and add some documentation. Also cleanup.
Paul Fisher <paul@pfish.zone>
parents:
12
diff
changeset
|
186 _fix_refs(ui, repo) |
|
1
a39dd69b8972
Create a more-or-less real package and make it work (?)
Paul Fisher <paul@pfish.zone>
parents:
0
diff
changeset
|
187 |
|
a39dd69b8972
Create a more-or-less real package and make it work (?)
Paul Fisher <paul@pfish.zone>
parents:
0
diff
changeset
|
188 |
|
8
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
189 # |
|
1
a39dd69b8972
Create a more-or-less real package and make it work (?)
Paul Fisher <paul@pfish.zone>
parents:
0
diff
changeset
|
190 # Interfacing with Mercurial |
|
8
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
191 # |
|
1
a39dd69b8972
Create a more-or-less real package and make it work (?)
Paul Fisher <paul@pfish.zone>
parents:
0
diff
changeset
|
192 |
|
a39dd69b8972
Create a more-or-less real package and make it work (?)
Paul Fisher <paul@pfish.zone>
parents:
0
diff
changeset
|
193 |
|
6
7113e0ac3662
fix refs on git-export; clean up how gitserve export works.
Paul Fisher <paul@pfish.zone>
parents:
5
diff
changeset
|
194 def uipopulate(ui: hgui.ui) -> None: |
|
8
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
195 # Fix up our tags after a Git export. |
|
6
7113e0ac3662
fix refs on git-export; clean up how gitserve export works.
Paul Fisher <paul@pfish.zone>
parents:
5
diff
changeset
|
196 ui.setconfig( |
|
13
00bdfac5416c
Create Git SSH commands and add some documentation. Also cleanup.
Paul Fisher <paul@pfish.zone>
parents:
12
diff
changeset
|
197 b'hooks', |
|
00bdfac5416c
Create Git SSH commands and add some documentation. Also cleanup.
Paul Fisher <paul@pfish.zone>
parents:
12
diff
changeset
|
198 b'post-git-export.__gitserve_add_tag__', |
|
00bdfac5416c
Create Git SSH commands and add some documentation. Also cleanup.
Paul Fisher <paul@pfish.zone>
parents:
12
diff
changeset
|
199 _fix_refs_hook, |
|
00bdfac5416c
Create Git SSH commands and add some documentation. Also cleanup.
Paul Fisher <paul@pfish.zone>
parents:
12
diff
changeset
|
200 source=b'hggit_serve', |
|
6
7113e0ac3662
fix refs on git-export; clean up how gitserve export works.
Paul Fisher <paul@pfish.zone>
parents:
5
diff
changeset
|
201 ) |
|
8
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
202 # Whenever we get new revisions, export them to the Git repository. |
|
13
00bdfac5416c
Create Git SSH commands and add some documentation. Also cleanup.
Paul Fisher <paul@pfish.zone>
parents:
12
diff
changeset
|
203 ui.setconfig( |
|
00bdfac5416c
Create Git SSH commands and add some documentation. Also cleanup.
Paul Fisher <paul@pfish.zone>
parents:
12
diff
changeset
|
204 b'hooks', |
|
00bdfac5416c
Create Git SSH commands and add some documentation. Also cleanup.
Paul Fisher <paul@pfish.zone>
parents:
12
diff
changeset
|
205 b'txnclose.__gitserve_export__', |
|
00bdfac5416c
Create Git SSH commands and add some documentation. Also cleanup.
Paul Fisher <paul@pfish.zone>
parents:
12
diff
changeset
|
206 _export_hook, |
|
00bdfac5416c
Create Git SSH commands and add some documentation. Also cleanup.
Paul Fisher <paul@pfish.zone>
parents:
12
diff
changeset
|
207 source=b'hggit_serve', |
|
00bdfac5416c
Create Git SSH commands and add some documentation. Also cleanup.
Paul Fisher <paul@pfish.zone>
parents:
12
diff
changeset
|
208 ) |
|
8
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
209 # Don't step on ourselves when importing data from Git. |
|
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
210 ui.setconfig( |
|
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
211 b'hooks', |
|
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
212 b'pre-git-import.__gitserve_suppress_export__', |
|
13
00bdfac5416c
Create Git SSH commands and add some documentation. Also cleanup.
Paul Fisher <paul@pfish.zone>
parents:
12
diff
changeset
|
213 lambda _, repo, **__: _importing_enter(repo), |
|
00bdfac5416c
Create Git SSH commands and add some documentation. Also cleanup.
Paul Fisher <paul@pfish.zone>
parents:
12
diff
changeset
|
214 source=b'hggit_serve', |
|
8
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
215 ) |
|
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
216 ui.setconfig( |
|
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
217 b'hooks', |
|
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
218 b'post-git-import.__gitserve_suppress_export__', |
|
13
00bdfac5416c
Create Git SSH commands and add some documentation. Also cleanup.
Paul Fisher <paul@pfish.zone>
parents:
12
diff
changeset
|
219 lambda _, repo, **__: _importing_exit(repo), |
|
00bdfac5416c
Create Git SSH commands and add some documentation. Also cleanup.
Paul Fisher <paul@pfish.zone>
parents:
12
diff
changeset
|
220 source=b'hggit-serve', |
|
8
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
221 ) |
