Mercurial > hg-git-serve
annotate src/hgext3rd/hggit_serve/_export.py @ 12:f630d9904ea7
Reorganize project into multiple files.
| author | Paul Fisher <paul@pfish.zone> |
|---|---|
| date | Wed, 18 Feb 2026 16:17:05 -0500 |
| parents | src/hgext3rd/hggit_serve.py@ce204bcc4e04 |
| children | 00bdfac5416c |
| 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 |
|
12
f630d9904ea7
Reorganize project into multiple files.
Paul Fisher <paul@pfish.zone>
parents:
11
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 |
|
12
f630d9904ea7
Reorganize project into multiple files.
Paul Fisher <paul@pfish.zone>
parents:
11
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 |
|
12
f630d9904ea7
Reorganize project into multiple files.
Paul Fisher <paul@pfish.zone>
parents:
11
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 |
|
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
71 # |
|
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
72 # Export handling. |
|
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
73 # |
|
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
74 |
|
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
75 |
|
12
f630d9904ea7
Reorganize project into multiple files.
Paul Fisher <paul@pfish.zone>
parents:
11
diff
changeset
|
76 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
|
77 """Removes all refs from the Git repository.""" |
|
1
a39dd69b8972
Create a more-or-less real package and make it work (?)
Paul Fisher <paul@pfish.zone>
parents:
0
diff
changeset
|
78 |
|
a39dd69b8972
Create a more-or-less real package and make it work (?)
Paul Fisher <paul@pfish.zone>
parents:
0
diff
changeset
|
79 |
|
12
f630d9904ea7
Reorganize project into multiple files.
Paul Fisher <paul@pfish.zone>
parents:
11
diff
changeset
|
80 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
|
81 """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
|
82 # 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
|
83 current = b'@' |
|
a39dd69b8972
Create a more-or-less real package and make it work (?)
Paul Fisher <paul@pfish.zone>
parents:
0
diff
changeset
|
84 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
|
85 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
|
86 |
|
a39dd69b8972
Create a more-or-less real package and make it work (?)
Paul Fisher <paul@pfish.zone>
parents:
0
diff
changeset
|
87 # 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
|
88 git_current = current |
|
a39dd69b8972
Create a more-or-less real package and make it work (?)
Paul Fisher <paul@pfish.zone>
parents:
0
diff
changeset
|
89 if current == b'@': |
|
a39dd69b8972
Create a more-or-less real package and make it work (?)
Paul Fisher <paul@pfish.zone>
parents:
0
diff
changeset
|
90 # @ 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
|
91 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
|
92 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
|
93 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
|
94 # 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
|
95 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
|
96 return |
|
7113e0ac3662
fix refs on git-export; clean up how gitserve export works.
Paul Fisher <paul@pfish.zone>
parents:
5
diff
changeset
|
97 try: |
|
7113e0ac3662
fix refs on git-export; clean up how gitserve export works.
Paul Fisher <paul@pfish.zone>
parents:
5
diff
changeset
|
98 # Maybe this is a real bookmark? |
|
8
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
99 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
|
100 except KeyError: |
|
7113e0ac3662
fix refs on git-export; clean up how gitserve export works.
Paul Fisher <paul@pfish.zone>
parents:
5
diff
changeset
|
101 # 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
|
102 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
|
103 try: |
|
8
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
104 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
|
105 except hgerr.RepoLookupError: |
|
7113e0ac3662
fix refs on git-export; clean up how gitserve export works.
Paul Fisher <paul@pfish.zone>
parents:
5
diff
changeset
|
106 # This branch somehow doesn't exist??? |
|
8
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
107 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
|
108 return |
|
8
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
109 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
|
110 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
|
111 if not gitsha: |
|
7113e0ac3662
fix refs on git-export; clean up how gitserve export works.
Paul Fisher <paul@pfish.zone>
parents:
5
diff
changeset
|
112 # 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
|
113 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
|
114 return |
|
a39dd69b8972
Create a more-or-less real package and make it work (?)
Paul Fisher <paul@pfish.zone>
parents:
0
diff
changeset
|
115 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
|
116 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
|
117 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
|
118 |
|
a39dd69b8972
Create a more-or-less real package and make it work (?)
Paul Fisher <paul@pfish.zone>
parents:
0
diff
changeset
|
119 |
|
12
f630d9904ea7
Reorganize project into multiple files.
Paul Fisher <paul@pfish.zone>
parents:
11
diff
changeset
|
120 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
|
121 """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
|
122 |
|
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
123 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
|
124 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
|
125 """ |
|
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
126 refs = repo.githandler.git.refs |
|
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
127 # dump to allkeys so we explicitly are iterating over a snapshot |
|
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
128 # and not over something while we mutate |
|
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
129 for ref in refs.allkeys(): |
|
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
130 refs.remove_if_equals(ref, None) |
|
6
7113e0ac3662
fix refs on git-export; clean up how gitserve export works.
Paul Fisher <paul@pfish.zone>
parents:
5
diff
changeset
|
131 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
|
132 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
|
133 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
|
134 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
|
135 ) |
|
12
f630d9904ea7
Reorganize project into multiple files.
Paul Fisher <paul@pfish.zone>
parents:
11
diff
changeset
|
136 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
|
137 |
|
7113e0ac3662
fix refs on git-export; clean up how gitserve export works.
Paul Fisher <paul@pfish.zone>
parents:
5
diff
changeset
|
138 |
|
12
f630d9904ea7
Reorganize project into multiple files.
Paul Fisher <paul@pfish.zone>
parents:
11
diff
changeset
|
139 # |
|
f630d9904ea7
Reorganize project into multiple files.
Paul Fisher <paul@pfish.zone>
parents:
11
diff
changeset
|
140 # Hooks |
|
f630d9904ea7
Reorganize project into multiple files.
Paul Fisher <paul@pfish.zone>
parents:
11
diff
changeset
|
141 # |
|
f630d9904ea7
Reorganize project into multiple files.
Paul Fisher <paul@pfish.zone>
parents:
11
diff
changeset
|
142 |
|
f630d9904ea7
Reorganize project into multiple files.
Paul Fisher <paul@pfish.zone>
parents:
11
diff
changeset
|
143 |
|
f630d9904ea7
Reorganize project into multiple files.
Paul Fisher <paul@pfish.zone>
parents:
11
diff
changeset
|
144 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
|
145 """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
|
146 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
|
147 return |
|
7113e0ac3662
fix refs on git-export; clean up how gitserve export works.
Paul Fisher <paul@pfish.zone>
parents:
5
diff
changeset
|
148 auto_export = ui.config(b'hggit-serve', b'auto-export') |
|
7113e0ac3662
fix refs on git-export; clean up how gitserve export works.
Paul Fisher <paul@pfish.zone>
parents:
5
diff
changeset
|
149 if auto_export == b'never': |
|
7113e0ac3662
fix refs on git-export; clean up how gitserve export works.
Paul Fisher <paul@pfish.zone>
parents:
5
diff
changeset
|
150 return |
|
8
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
151 if auto_export == b'always' or git_handler.has_gitrepo(repo): |
|
12
f630d9904ea7
Reorganize project into multiple files.
Paul Fisher <paul@pfish.zone>
parents:
11
diff
changeset
|
152 if is_importing(repo): |
|
8
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
153 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
|
154 return |
|
6
7113e0ac3662
fix refs on git-export; clean up how gitserve export works.
Paul Fisher <paul@pfish.zone>
parents:
5
diff
changeset
|
155 repo.githandler.export_commits() |
|
12
f630d9904ea7
Reorganize project into multiple files.
Paul Fisher <paul@pfish.zone>
parents:
11
diff
changeset
|
156 fix_refs(ui, repo) |
|
f630d9904ea7
Reorganize project into multiple files.
Paul Fisher <paul@pfish.zone>
parents:
11
diff
changeset
|
157 |
|
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 _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
|
160 """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
|
161 if not is_gitty(repo): |
|
f630d9904ea7
Reorganize project into multiple files.
Paul Fisher <paul@pfish.zone>
parents:
11
diff
changeset
|
162 return |
|
f630d9904ea7
Reorganize project into multiple files.
Paul Fisher <paul@pfish.zone>
parents:
11
diff
changeset
|
163 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
|
164 |
|
a39dd69b8972
Create a more-or-less real package and make it work (?)
Paul Fisher <paul@pfish.zone>
parents:
0
diff
changeset
|
165 |
|
8
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
166 # |
|
1
a39dd69b8972
Create a more-or-less real package and make it work (?)
Paul Fisher <paul@pfish.zone>
parents:
0
diff
changeset
|
167 # Interfacing with Mercurial |
|
8
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
168 # |
|
1
a39dd69b8972
Create a more-or-less real package and make it work (?)
Paul Fisher <paul@pfish.zone>
parents:
0
diff
changeset
|
169 |
|
a39dd69b8972
Create a more-or-less real package and make it work (?)
Paul Fisher <paul@pfish.zone>
parents:
0
diff
changeset
|
170 |
|
6
7113e0ac3662
fix refs on git-export; clean up how gitserve export works.
Paul Fisher <paul@pfish.zone>
parents:
5
diff
changeset
|
171 def uipopulate(ui: hgui.ui) -> None: |
|
8
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
172 # 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
|
173 ui.setconfig( |
|
12
f630d9904ea7
Reorganize project into multiple files.
Paul Fisher <paul@pfish.zone>
parents:
11
diff
changeset
|
174 b'hooks', b'post-git-export.__gitserve_add_tag__', _fix_refs_hook |
|
6
7113e0ac3662
fix refs on git-export; clean up how gitserve export works.
Paul Fisher <paul@pfish.zone>
parents:
5
diff
changeset
|
175 ) |
|
8
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
176 # Whenever we get new revisions, export them to the Git repository. |
|
12
f630d9904ea7
Reorganize project into multiple files.
Paul Fisher <paul@pfish.zone>
parents:
11
diff
changeset
|
177 ui.setconfig(b'hooks', b'txnclose.__gitserve_export__', _export_hook) |
|
8
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
178 # 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
|
179 ui.setconfig( |
|
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
180 b'hooks', |
|
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
181 b'pre-git-import.__gitserve_suppress_export__', |
|
12
f630d9904ea7
Reorganize project into multiple files.
Paul Fisher <paul@pfish.zone>
parents:
11
diff
changeset
|
182 lambda _, repo, **__: importing_enter(repo), |
|
8
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
183 ) |
|
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
184 ui.setconfig( |
|
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
185 b'hooks', |
|
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
186 b'post-git-import.__gitserve_suppress_export__', |
|
12
f630d9904ea7
Reorganize project into multiple files.
Paul Fisher <paul@pfish.zone>
parents:
11
diff
changeset
|
187 lambda _, repo, **__: importing_exit(repo), |
|
8
fe3c9fae4d4d
Add support for pushes, and improve authentication.
Paul Fisher <paul@pfish.zone>
parents:
7
diff
changeset
|
188 ) |
