repligit 0.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- repligit-0.0.1/.envrc +10 -0
- repligit-0.0.1/.github/ISSUE_TEMPLATE/issue-feature-request.md +13 -0
- repligit-0.0.1/.github/dependabot.yml +23 -0
- repligit-0.0.1/.github/labeler.yml +17 -0
- repligit-0.0.1/.github/workflows/ci.yml +69 -0
- repligit-0.0.1/.github/workflows/label.yml +21 -0
- repligit-0.0.1/.github/workflows/requirements/style.txt +2 -0
- repligit-0.0.1/.github/workflows/requirements/unit-tests.txt +2 -0
- repligit-0.0.1/.github/workflows/style.yml +32 -0
- repligit-0.0.1/.github/workflows/unit-tests.yml +30 -0
- repligit-0.0.1/.gitignore +5 -0
- repligit-0.0.1/LICENSE +217 -0
- repligit-0.0.1/PKG-INFO +114 -0
- repligit-0.0.1/README.md +98 -0
- repligit-0.0.1/examples/git_mirror.py +56 -0
- repligit-0.0.1/examples/git_mirror_async.py +60 -0
- repligit-0.0.1/pyproject.toml +34 -0
- repligit-0.0.1/spack/repo/packages/py-repligit/package.py +24 -0
- repligit-0.0.1/spack/repo/repo.yaml +3 -0
- repligit-0.0.1/spack.yaml +24 -0
- repligit-0.0.1/src/repligit/__init__.py +3 -0
- repligit-0.0.1/src/repligit/asyncio/__init__.py +8 -0
- repligit-0.0.1/src/repligit/asyncio/client.py +91 -0
- repligit-0.0.1/src/repligit/asyncio/parse.py +51 -0
- repligit-0.0.1/src/repligit/client.py +110 -0
- repligit-0.0.1/src/repligit/parse.py +103 -0
- repligit-0.0.1/tests/__init__.py +0 -0
- repligit-0.0.1/tests/test_client.py +63 -0
repligit-0.0.1/.envrc
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#------------------------------------------------------------------------
|
|
2
|
+
# Load Development Spack Environment (If Spack is installed.)
|
|
3
|
+
#
|
|
4
|
+
# Run 'direnv allow' from within the cloned repository to automatically
|
|
5
|
+
# load the spack environment when you enter the directory.
|
|
6
|
+
#------------------------------------------------------------------------
|
|
7
|
+
if type spack &>/dev/null; then
|
|
8
|
+
. $SPACK_ROOT/share/spack/setup-env.sh
|
|
9
|
+
spack env activate -d .
|
|
10
|
+
fi
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
version: 2
|
|
2
|
+
updates:
|
|
3
|
+
- package-ecosystem: "github-actions"
|
|
4
|
+
directory: "/"
|
|
5
|
+
schedule:
|
|
6
|
+
interval: "weekly"
|
|
7
|
+
|
|
8
|
+
- package-ecosystem: "pip"
|
|
9
|
+
directory: "/"
|
|
10
|
+
schedule:
|
|
11
|
+
interval: "monthly"
|
|
12
|
+
ignore:
|
|
13
|
+
# setuptools releases new versions almost daily
|
|
14
|
+
- dependency-name: "setuptools"
|
|
15
|
+
update-types: ["version-update:semver-patch"]
|
|
16
|
+
|
|
17
|
+
- package-ecosystem: "pip"
|
|
18
|
+
directory: "/.github/workflows/requirements"
|
|
19
|
+
schedule:
|
|
20
|
+
interval: "weekly"
|
|
21
|
+
ignore:
|
|
22
|
+
- dependency-name: "setuptools"
|
|
23
|
+
update-types: ["version-update:semver-patch"]
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
ci:
|
|
2
|
+
- changed-files:
|
|
3
|
+
- any-glob-to-any-file:
|
|
4
|
+
- .github/**
|
|
5
|
+
|
|
6
|
+
dependencies:
|
|
7
|
+
- changed-files:
|
|
8
|
+
- any-glob-to-any-file:
|
|
9
|
+
- .github/workflows/requirements/**
|
|
10
|
+
- pyproject.toml
|
|
11
|
+
- spack.yaml
|
|
12
|
+
|
|
13
|
+
docs:
|
|
14
|
+
- changed-files:
|
|
15
|
+
- any-glob-to-any-file:
|
|
16
|
+
- docs/**
|
|
17
|
+
- README.md
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
name: ci
|
|
2
|
+
on:
|
|
3
|
+
push:
|
|
4
|
+
branches:
|
|
5
|
+
- main
|
|
6
|
+
pull_request:
|
|
7
|
+
branches:
|
|
8
|
+
- main
|
|
9
|
+
|
|
10
|
+
concurrency:
|
|
11
|
+
group: ci-${{github.ref}}-${{github.event.pull_request.number || github.run_number}}
|
|
12
|
+
cancel-in-progress: true
|
|
13
|
+
|
|
14
|
+
jobs:
|
|
15
|
+
changes:
|
|
16
|
+
runs-on: ubuntu-latest
|
|
17
|
+
permissions:
|
|
18
|
+
pull-requests: read
|
|
19
|
+
outputs:
|
|
20
|
+
style: ${{ steps.filter.outputs.style }}
|
|
21
|
+
unit-tests: ${{ steps.filter.outputs.unit-tests }}
|
|
22
|
+
container: ${{ steps.filter.outputs.container }}
|
|
23
|
+
steps:
|
|
24
|
+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # @v2
|
|
25
|
+
if: ${{ github.event_name == 'push' }}
|
|
26
|
+
with:
|
|
27
|
+
fetch-depth: 0
|
|
28
|
+
|
|
29
|
+
# For pull requests it's not necessary to checkout the code
|
|
30
|
+
- uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36
|
|
31
|
+
id: filter
|
|
32
|
+
with:
|
|
33
|
+
filters: |
|
|
34
|
+
style:
|
|
35
|
+
- '.github/**/*'
|
|
36
|
+
- 'src/**/*'
|
|
37
|
+
- 'pyproject.toml'
|
|
38
|
+
unit-tests:
|
|
39
|
+
- '.github/**/*'
|
|
40
|
+
- 'src/**/*'
|
|
41
|
+
- 'tests/**/*'
|
|
42
|
+
- 'pyproject.toml'
|
|
43
|
+
|
|
44
|
+
style:
|
|
45
|
+
if: ${{ needs.changes.outputs.style == 'true' }}
|
|
46
|
+
needs: changes
|
|
47
|
+
uses: ./.github/workflows/style.yml
|
|
48
|
+
|
|
49
|
+
unit-tests:
|
|
50
|
+
if: ${{ needs.changes.outputs.unit-tests == 'true' }}
|
|
51
|
+
needs: [changes, style]
|
|
52
|
+
uses: ./.github/workflows/unit-tests.yml
|
|
53
|
+
|
|
54
|
+
all:
|
|
55
|
+
needs:
|
|
56
|
+
- changes
|
|
57
|
+
- style
|
|
58
|
+
- unit-tests
|
|
59
|
+
if: always()
|
|
60
|
+
runs-on: ubuntu-latest
|
|
61
|
+
steps:
|
|
62
|
+
- name: Status summary
|
|
63
|
+
run: |
|
|
64
|
+
if [[ "${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }}" == "true" ]]; then
|
|
65
|
+
echo "One or more required jobs failed or were cancelled"
|
|
66
|
+
exit 1
|
|
67
|
+
else
|
|
68
|
+
echo "All jobs completed successfully"
|
|
69
|
+
fi
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
#-----------------------------------------------------------------------
|
|
2
|
+
# DO NOT modify unless you really know what you are doing.
|
|
3
|
+
#
|
|
4
|
+
# See https://stackoverflow.com/a/74959635 for more info.
|
|
5
|
+
# Talk to @alecbcs if you have questions/are not sure of a change's
|
|
6
|
+
# possible impact to security.
|
|
7
|
+
#-----------------------------------------------------------------------
|
|
8
|
+
name: label
|
|
9
|
+
on:
|
|
10
|
+
pull_request_target:
|
|
11
|
+
branches:
|
|
12
|
+
- main
|
|
13
|
+
|
|
14
|
+
jobs:
|
|
15
|
+
pr:
|
|
16
|
+
runs-on: ubuntu-latest
|
|
17
|
+
permissions:
|
|
18
|
+
contents: read
|
|
19
|
+
pull-requests: write
|
|
20
|
+
steps:
|
|
21
|
+
- uses: actions/labeler@8558fd74291d67161a8a78ce36a881fa63b766a9
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
name: Linting & Style Checks
|
|
2
|
+
on:
|
|
3
|
+
# This Workflow can be triggered manually
|
|
4
|
+
workflow_dispatch:
|
|
5
|
+
workflow_call:
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
lint:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
steps:
|
|
12
|
+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
|
|
13
|
+
|
|
14
|
+
- name: Set up Python 3.11
|
|
15
|
+
uses: actions/setup-python@8d9ed9ac5c53483de85588cdf95a591a75ab9f55
|
|
16
|
+
with:
|
|
17
|
+
python-version: '3.11'
|
|
18
|
+
cache: 'pip'
|
|
19
|
+
cache-dependency-path: '.github/workflows/requirements/style.txt'
|
|
20
|
+
|
|
21
|
+
- name: Install Python dependencies
|
|
22
|
+
run: |
|
|
23
|
+
pip install -r .github/workflows/requirements/style.txt
|
|
24
|
+
|
|
25
|
+
- name: Run Ruff
|
|
26
|
+
run: |
|
|
27
|
+
ruff check --diff
|
|
28
|
+
ruff check --select I --diff
|
|
29
|
+
ruff format --check --diff
|
|
30
|
+
|
|
31
|
+
- name: Run Codespell
|
|
32
|
+
run: codespell
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
name: Unit Tests
|
|
2
|
+
on:
|
|
3
|
+
# This Workflow can be triggered manually
|
|
4
|
+
workflow_dispatch:
|
|
5
|
+
workflow_call:
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
ubuntu:
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
strategy:
|
|
11
|
+
matrix:
|
|
12
|
+
python-version: ['3.13']
|
|
13
|
+
steps:
|
|
14
|
+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
|
|
15
|
+
- uses: actions/setup-python@8d9ed9ac5c53483de85588cdf95a591a75ab9f55
|
|
16
|
+
with:
|
|
17
|
+
python-version: ${{ matrix.python-version }}
|
|
18
|
+
cache: 'pip'
|
|
19
|
+
cache-dependency-path: |
|
|
20
|
+
'requirements.txt'
|
|
21
|
+
'.github/workflows/requirements/unit-tests.txt'
|
|
22
|
+
|
|
23
|
+
- name: Install Python dependencies
|
|
24
|
+
run: |
|
|
25
|
+
pip install .
|
|
26
|
+
pip install -r .github/workflows/requirements/unit-tests.txt
|
|
27
|
+
|
|
28
|
+
- name: Run Unit Tests with Pytest
|
|
29
|
+
run: |
|
|
30
|
+
python -m pytest
|
repligit-0.0.1/LICENSE
ADDED
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
202
|
+
|
|
203
|
+
--- LLVM Exceptions to the Apache 2.0 License ----
|
|
204
|
+
|
|
205
|
+
As an exception, if, as a result of your compiling your source code, portions
|
|
206
|
+
of this Software are embedded into an Object form of such source code, you
|
|
207
|
+
may redistribute such embedded portions in such Object form without complying
|
|
208
|
+
with the conditions of Sections 4(a), 4(b) and 4(d) of the License.
|
|
209
|
+
|
|
210
|
+
In addition, if you combine or link compiled forms of this Software with
|
|
211
|
+
software that is licensed under the GPLv2 ("Combined Software") and if a
|
|
212
|
+
court of competent jurisdiction determines that the patent provision (Section
|
|
213
|
+
3), the indemnity provision (Section 9) or other Section of the License
|
|
214
|
+
conflicts with the conditions of the GPLv2, you may retroactively and
|
|
215
|
+
prospectively choose to deem waived or otherwise exclude such Section(s) of
|
|
216
|
+
the License, but only in their entirety and only with respect to the Combined
|
|
217
|
+
Software.
|
repligit-0.0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: repligit
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: A python library implementing the git http transfer protocol.
|
|
5
|
+
Project-URL: Homepage, https://github.com/llnl/repligit
|
|
6
|
+
Project-URL: Issues, https://github.com/llnl/repligit/issues
|
|
7
|
+
Author-email: Alec Scott <alec@llnl.gov>
|
|
8
|
+
License-Expression: Apache-2.0 WITH LLVM-exception
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Requires-Python: >=3.10
|
|
13
|
+
Provides-Extra: aiohttp
|
|
14
|
+
Requires-Dist: aiohttp; extra == 'aiohttp'
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
|
|
17
|
+
# repligit
|
|
18
|
+
`repligit` is a Python library that implements the Git transfer protocol. It enables users to query remote repositories, mirror repositories between two locations without storing state locally, and incrementally archive repositories to disk. `repligit` is used by [Hubcast](https://github.com/llnl/hubcast) to mirror repositories from GitHub to GitLab for secure CI/CD on local hardware.
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
You can install repligit from PyPI using pip:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
pip install repligit
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Features
|
|
28
|
+
- Query remote Git repositories.
|
|
29
|
+
- Mirror repositories between different Git hosting services.
|
|
30
|
+
- Incrementally archive repositories to disk.
|
|
31
|
+
- Implements Git transfer protocol in pure Python.
|
|
32
|
+
|
|
33
|
+
## Example Usage
|
|
34
|
+
```python
|
|
35
|
+
from repligit import fetch_pack, ls_remote, send_pack
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def main():
|
|
39
|
+
src_remote_url = "https://github.com/spack/spack.git"
|
|
40
|
+
dest_remote_url = "https://gitlab.com/test-org/test-repo.git"
|
|
41
|
+
|
|
42
|
+
branch_name = "main"
|
|
43
|
+
|
|
44
|
+
target_ref = f"refs/heads/{branch_name}"
|
|
45
|
+
|
|
46
|
+
# Authentication credentials
|
|
47
|
+
# Note: Only provide credentials when authentication is required
|
|
48
|
+
# src_username = "<username>" # Uncomment if source repo requires auth
|
|
49
|
+
# src_password = "<token>" # Uncomment if source repo requires auth
|
|
50
|
+
dest_username = "<username>" # For destination repo write access
|
|
51
|
+
dest_password = "<token>" # For destination repo write access
|
|
52
|
+
|
|
53
|
+
# List references from source repository (without authentication)
|
|
54
|
+
gh_refs = ls_remote(src_remote_url)
|
|
55
|
+
|
|
56
|
+
# List references from destination repository (with authentication)
|
|
57
|
+
gl_refs = ls_remote(
|
|
58
|
+
dest_remote_url,
|
|
59
|
+
username=dest_username,
|
|
60
|
+
password=dest_password
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
want_sha = gh_refs[target_ref]
|
|
64
|
+
have_shas = gl_refs.values()
|
|
65
|
+
|
|
66
|
+
from_sha = gl_refs.get(target_ref) or ("0" * 40)
|
|
67
|
+
|
|
68
|
+
if want_sha in have_shas:
|
|
69
|
+
print("Everything is up to date")
|
|
70
|
+
return
|
|
71
|
+
|
|
72
|
+
# Fetch the packfile from source repository
|
|
73
|
+
packfile = fetch_pack(
|
|
74
|
+
src_remote_url,
|
|
75
|
+
want_sha,
|
|
76
|
+
have_shas,
|
|
77
|
+
# username=src_username, # Uncomment if source repo requires auth
|
|
78
|
+
# password=src_password, # Uncomment if source repo requires auth
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
# Upload packfile to destination repository
|
|
82
|
+
send_pack(
|
|
83
|
+
dest_remote_url,
|
|
84
|
+
target_ref,
|
|
85
|
+
from_sha,
|
|
86
|
+
want_sha,
|
|
87
|
+
packfile,
|
|
88
|
+
username=dest_username,
|
|
89
|
+
password=dest_password,
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
if __name__ == "__main__":
|
|
94
|
+
main()
|
|
95
|
+
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## License
|
|
99
|
+
|
|
100
|
+
Licensed under the Apache License, Version 2.0 w/LLVM Exception
|
|
101
|
+
(the "License"); you may not use this file except in compliance
|
|
102
|
+
with the License. You may obtain a copy of the License at
|
|
103
|
+
|
|
104
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
105
|
+
|
|
106
|
+
Unless required by applicable law or agreed to in writing, software
|
|
107
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
108
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
109
|
+
See the License for the specific language governing permissions and
|
|
110
|
+
limitations under the License.
|
|
111
|
+
|
|
112
|
+
SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
113
|
+
|
|
114
|
+
LLNL-CODE-2003682
|
repligit-0.0.1/README.md
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# repligit
|
|
2
|
+
`repligit` is a Python library that implements the Git transfer protocol. It enables users to query remote repositories, mirror repositories between two locations without storing state locally, and incrementally archive repositories to disk. `repligit` is used by [Hubcast](https://github.com/llnl/hubcast) to mirror repositories from GitHub to GitLab for secure CI/CD on local hardware.
|
|
3
|
+
|
|
4
|
+
## Installation
|
|
5
|
+
You can install repligit from PyPI using pip:
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install repligit
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
- Query remote Git repositories.
|
|
13
|
+
- Mirror repositories between different Git hosting services.
|
|
14
|
+
- Incrementally archive repositories to disk.
|
|
15
|
+
- Implements Git transfer protocol in pure Python.
|
|
16
|
+
|
|
17
|
+
## Example Usage
|
|
18
|
+
```python
|
|
19
|
+
from repligit import fetch_pack, ls_remote, send_pack
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def main():
|
|
23
|
+
src_remote_url = "https://github.com/spack/spack.git"
|
|
24
|
+
dest_remote_url = "https://gitlab.com/test-org/test-repo.git"
|
|
25
|
+
|
|
26
|
+
branch_name = "main"
|
|
27
|
+
|
|
28
|
+
target_ref = f"refs/heads/{branch_name}"
|
|
29
|
+
|
|
30
|
+
# Authentication credentials
|
|
31
|
+
# Note: Only provide credentials when authentication is required
|
|
32
|
+
# src_username = "<username>" # Uncomment if source repo requires auth
|
|
33
|
+
# src_password = "<token>" # Uncomment if source repo requires auth
|
|
34
|
+
dest_username = "<username>" # For destination repo write access
|
|
35
|
+
dest_password = "<token>" # For destination repo write access
|
|
36
|
+
|
|
37
|
+
# List references from source repository (without authentication)
|
|
38
|
+
gh_refs = ls_remote(src_remote_url)
|
|
39
|
+
|
|
40
|
+
# List references from destination repository (with authentication)
|
|
41
|
+
gl_refs = ls_remote(
|
|
42
|
+
dest_remote_url,
|
|
43
|
+
username=dest_username,
|
|
44
|
+
password=dest_password
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
want_sha = gh_refs[target_ref]
|
|
48
|
+
have_shas = gl_refs.values()
|
|
49
|
+
|
|
50
|
+
from_sha = gl_refs.get(target_ref) or ("0" * 40)
|
|
51
|
+
|
|
52
|
+
if want_sha in have_shas:
|
|
53
|
+
print("Everything is up to date")
|
|
54
|
+
return
|
|
55
|
+
|
|
56
|
+
# Fetch the packfile from source repository
|
|
57
|
+
packfile = fetch_pack(
|
|
58
|
+
src_remote_url,
|
|
59
|
+
want_sha,
|
|
60
|
+
have_shas,
|
|
61
|
+
# username=src_username, # Uncomment if source repo requires auth
|
|
62
|
+
# password=src_password, # Uncomment if source repo requires auth
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
# Upload packfile to destination repository
|
|
66
|
+
send_pack(
|
|
67
|
+
dest_remote_url,
|
|
68
|
+
target_ref,
|
|
69
|
+
from_sha,
|
|
70
|
+
want_sha,
|
|
71
|
+
packfile,
|
|
72
|
+
username=dest_username,
|
|
73
|
+
password=dest_password,
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
if __name__ == "__main__":
|
|
78
|
+
main()
|
|
79
|
+
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## License
|
|
83
|
+
|
|
84
|
+
Licensed under the Apache License, Version 2.0 w/LLVM Exception
|
|
85
|
+
(the "License"); you may not use this file except in compliance
|
|
86
|
+
with the License. You may obtain a copy of the License at
|
|
87
|
+
|
|
88
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
89
|
+
|
|
90
|
+
Unless required by applicable law or agreed to in writing, software
|
|
91
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
92
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
93
|
+
See the License for the specific language governing permissions and
|
|
94
|
+
limitations under the License.
|
|
95
|
+
|
|
96
|
+
SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
97
|
+
|
|
98
|
+
LLNL-CODE-2003682
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
from repligit import fetch_pack, ls_remote, send_pack
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def main():
|
|
5
|
+
src_remote_url = "https://github.com/spack/spack.git"
|
|
6
|
+
dest_remote_url = "https://gitlab.com/test-org/test-repo.git"
|
|
7
|
+
|
|
8
|
+
branch_name = "main"
|
|
9
|
+
|
|
10
|
+
target_ref = f"refs/heads/{branch_name}"
|
|
11
|
+
|
|
12
|
+
# Authentication credentials
|
|
13
|
+
# Note: Only provide credentials when authentication is required
|
|
14
|
+
# src_username = "<username>" # Uncomment if source repo requires auth
|
|
15
|
+
# src_password = "<token>" # Uncomment if source repo requires auth
|
|
16
|
+
dest_username = "<username>" # For destination repo write access
|
|
17
|
+
dest_password = "<token>" # For destination repo write access
|
|
18
|
+
|
|
19
|
+
# List references from source repository (without authentication)
|
|
20
|
+
gh_refs = ls_remote(src_remote_url)
|
|
21
|
+
|
|
22
|
+
# List references from destination repository (with authentication)
|
|
23
|
+
gl_refs = ls_remote(dest_remote_url, username=dest_username, password=dest_password)
|
|
24
|
+
|
|
25
|
+
want_sha = gh_refs[target_ref]
|
|
26
|
+
have_shas = gl_refs.values()
|
|
27
|
+
|
|
28
|
+
from_sha = gl_refs.get(target_ref) or ("0" * 40)
|
|
29
|
+
|
|
30
|
+
if want_sha in have_shas:
|
|
31
|
+
print("Everything is up to date")
|
|
32
|
+
return
|
|
33
|
+
|
|
34
|
+
# Fetch the packfile from source repository
|
|
35
|
+
packfile = fetch_pack(
|
|
36
|
+
src_remote_url,
|
|
37
|
+
want_sha,
|
|
38
|
+
have_shas,
|
|
39
|
+
# username=src_username, # Uncomment if source repo requires auth
|
|
40
|
+
# password=src_password, # Uncomment if source repo requires auth
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
# Upload packfile to destination repository
|
|
44
|
+
send_pack(
|
|
45
|
+
dest_remote_url,
|
|
46
|
+
target_ref,
|
|
47
|
+
from_sha,
|
|
48
|
+
want_sha,
|
|
49
|
+
packfile,
|
|
50
|
+
username=dest_username,
|
|
51
|
+
password=dest_password,
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
if __name__ == "__main__":
|
|
56
|
+
main()
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
|
|
3
|
+
from repligit.asyncio import fetch_pack, ls_remote, send_pack
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
async def main():
|
|
7
|
+
src_remote_url = "https://github.com/spack/spack.git"
|
|
8
|
+
dest_remote_url = "https://gitlab.com/test-org/test-repo.git"
|
|
9
|
+
|
|
10
|
+
branch_name = "main"
|
|
11
|
+
|
|
12
|
+
target_ref = f"refs/heads/{branch_name}"
|
|
13
|
+
|
|
14
|
+
# Authentication credentials
|
|
15
|
+
# Note: Only provide credentials when authentication is required
|
|
16
|
+
# src_username = "<username>" # Uncomment if source repo requires auth
|
|
17
|
+
# src_password = "<token>" # Uncomment if source repo requires auth
|
|
18
|
+
dest_username = "<username>" # For destination repo write access
|
|
19
|
+
dest_password = "<token>" # For destination repo write access
|
|
20
|
+
|
|
21
|
+
# List references from source repository (without authentication)
|
|
22
|
+
gh_refs = await ls_remote(src_remote_url)
|
|
23
|
+
|
|
24
|
+
# List references from destination repository (with authentication)
|
|
25
|
+
gl_refs = await ls_remote(
|
|
26
|
+
dest_remote_url, username=dest_username, password=dest_password
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
want_sha = gh_refs[target_ref]
|
|
30
|
+
have_shas = gl_refs.values()
|
|
31
|
+
|
|
32
|
+
from_sha = gl_refs.get(target_ref) or ("0" * 40)
|
|
33
|
+
|
|
34
|
+
if want_sha in have_shas:
|
|
35
|
+
print("Everything is up to date")
|
|
36
|
+
return
|
|
37
|
+
|
|
38
|
+
# Fetch the packfile from source repository
|
|
39
|
+
packfile = await fetch_pack(
|
|
40
|
+
src_remote_url,
|
|
41
|
+
want_sha,
|
|
42
|
+
have_shas,
|
|
43
|
+
# username=src_username, # Uncomment if source repo requires auth
|
|
44
|
+
# password=src_password, # Uncomment if source repo requires auth
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
# Upload packfile to destination repository
|
|
48
|
+
await send_pack(
|
|
49
|
+
dest_remote_url,
|
|
50
|
+
target_ref,
|
|
51
|
+
from_sha,
|
|
52
|
+
want_sha,
|
|
53
|
+
packfile,
|
|
54
|
+
username=dest_username,
|
|
55
|
+
password=dest_password,
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
if __name__ == "__main__":
|
|
60
|
+
asyncio.run(main())
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "repligit"
|
|
7
|
+
version = "0.0.1"
|
|
8
|
+
dependencies = []
|
|
9
|
+
authors = [
|
|
10
|
+
{ name="Alec Scott", email="alec@llnl.gov" },
|
|
11
|
+
]
|
|
12
|
+
description = "A python library implementing the git http transfer protocol."
|
|
13
|
+
readme = "README.md"
|
|
14
|
+
requires-python = ">=3.10"
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Programming Language :: Python :: 3",
|
|
17
|
+
"Operating System :: OS Independent",
|
|
18
|
+
]
|
|
19
|
+
license = "Apache-2.0 WITH LLVM-exception"
|
|
20
|
+
|
|
21
|
+
[project.urls]
|
|
22
|
+
Homepage = "https://github.com/llnl/repligit"
|
|
23
|
+
Issues = "https://github.com/llnl/repligit/issues"
|
|
24
|
+
|
|
25
|
+
[project.optional-dependencies]
|
|
26
|
+
aiohttp = ["aiohttp"]
|
|
27
|
+
|
|
28
|
+
[tool.pytest.ini_options]
|
|
29
|
+
pythonpath = [
|
|
30
|
+
"src"
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
[tool.ruff]
|
|
34
|
+
line-length = 88
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Copyright Spack Project Developers. See COPYRIGHT file for details.
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
|
|
4
|
+
|
|
5
|
+
from spack.package import *
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class PyRepligit(PythonPackage):
|
|
9
|
+
"""A Git client for mirroring multiple remotes without storing state."""
|
|
10
|
+
|
|
11
|
+
homepage = "https://github.com/LLNL/repligit"
|
|
12
|
+
git = "https://github.com/LLNL/repligit.git"
|
|
13
|
+
|
|
14
|
+
maintainers("alecbcs", "cmelone")
|
|
15
|
+
|
|
16
|
+
license("Apache-2.0 WITH LLVM-exception")
|
|
17
|
+
|
|
18
|
+
version("main", branch="main")
|
|
19
|
+
|
|
20
|
+
variant("aiohttp", default="False", description="Enable aiohttp support")
|
|
21
|
+
|
|
22
|
+
depends_on("py-hatchling", type="build")
|
|
23
|
+
|
|
24
|
+
depends_on("py-aiohttp", type=("build", "run"), when="+aiohttp")
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# This is a Spack Environment file.
|
|
2
|
+
#
|
|
3
|
+
# It describes a set of packages to be installed, along with
|
|
4
|
+
# configuration settings.
|
|
5
|
+
spack:
|
|
6
|
+
# add package specs to the `specs` list
|
|
7
|
+
repos:
|
|
8
|
+
- $env/spack/repo
|
|
9
|
+
specs:
|
|
10
|
+
- py-codespell
|
|
11
|
+
- py-pytest
|
|
12
|
+
- py-repligit
|
|
13
|
+
- py-ruff
|
|
14
|
+
- py-pip
|
|
15
|
+
- python
|
|
16
|
+
- py-build
|
|
17
|
+
- py-twine
|
|
18
|
+
view: true
|
|
19
|
+
concretizer:
|
|
20
|
+
unify: true
|
|
21
|
+
develop:
|
|
22
|
+
py-repligit:
|
|
23
|
+
spec: py-repligit@=main
|
|
24
|
+
path: $env
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
try:
|
|
2
|
+
import aiohttp # noqa
|
|
3
|
+
except ModuleNotFoundError:
|
|
4
|
+
raise ModuleNotFoundError("aiohttp is required to use the async client") from None
|
|
5
|
+
|
|
6
|
+
from repligit.asyncio.client import fetch_pack, ls_remote, send_pack
|
|
7
|
+
|
|
8
|
+
__all__ = ["ls_remote", "fetch_pack", "send_pack"]
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
from typing import List
|
|
2
|
+
|
|
3
|
+
import aiohttp
|
|
4
|
+
|
|
5
|
+
from repligit.asyncio.parse import decode_lines, iter_lines
|
|
6
|
+
from repligit.parse import generate_fetch_pack_request, generate_send_pack_header
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
async def ls_remote(url: str, username: str = None, password: str = None):
|
|
10
|
+
"""Get commit hash of remote master branch, return SHA-1 hex string or
|
|
11
|
+
None if no remote commits.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
url = f"{url}/info/refs?service=git-upload-pack"
|
|
15
|
+
auth = aiohttp.BasicAuth(username, password) if username or password else None
|
|
16
|
+
async with aiohttp.ClientSession(auth=auth) as session:
|
|
17
|
+
async with session.get(url, raise_for_status=True) as resp:
|
|
18
|
+
lines = decode_lines(iter_lines(resp, encoding="utf-8"))
|
|
19
|
+
service_line = await anext(lines)
|
|
20
|
+
assert service_line == "# service=git-upload-pack"
|
|
21
|
+
|
|
22
|
+
# `async for` inside `dict()` not supported so no dict comprehension
|
|
23
|
+
result = {}
|
|
24
|
+
async for line in lines:
|
|
25
|
+
if not line:
|
|
26
|
+
continue
|
|
27
|
+
sha, ref = line.split()
|
|
28
|
+
result[ref] = sha
|
|
29
|
+
return result
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
async def fetch_pack(
|
|
33
|
+
url: str, want_sha: str, have_shas: List[str], username=None, password=None
|
|
34
|
+
):
|
|
35
|
+
"""Download a packfile from a remote server."""
|
|
36
|
+
url = f"{url}/git-upload-pack"
|
|
37
|
+
auth = aiohttp.BasicAuth(username, password) if username or password else None
|
|
38
|
+
|
|
39
|
+
request = generate_fetch_pack_request(want_sha, have_shas)
|
|
40
|
+
|
|
41
|
+
async with aiohttp.ClientSession(auth=auth) as session:
|
|
42
|
+
async with session.post(
|
|
43
|
+
url,
|
|
44
|
+
headers={
|
|
45
|
+
"Content-type": "application/x-git-upload-pack-request",
|
|
46
|
+
},
|
|
47
|
+
data=request,
|
|
48
|
+
raise_for_status=True,
|
|
49
|
+
timeout=None,
|
|
50
|
+
) as resp:
|
|
51
|
+
length_bytes = await resp.content.readexactly(4)
|
|
52
|
+
line_length = int(length_bytes, 16)
|
|
53
|
+
|
|
54
|
+
line = await resp.content.readexactly(line_length - 4)
|
|
55
|
+
if line[:3] == b"NAK" or line[:3] == b"ACK":
|
|
56
|
+
# this is a difference in API between sync and async
|
|
57
|
+
# has to be read within this context to be used in the caller
|
|
58
|
+
return await resp.content.read()
|
|
59
|
+
else:
|
|
60
|
+
return None
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
async def send_pack(
|
|
64
|
+
url: str,
|
|
65
|
+
ref: str,
|
|
66
|
+
from_sha: str,
|
|
67
|
+
to_sha: str,
|
|
68
|
+
packfile,
|
|
69
|
+
username: str = None,
|
|
70
|
+
password: str = None,
|
|
71
|
+
):
|
|
72
|
+
"""Send a packfile to a remote server."""
|
|
73
|
+
url = f"{url}/git-receive-pack"
|
|
74
|
+
auth = aiohttp.BasicAuth(username, password) if username or password else None
|
|
75
|
+
|
|
76
|
+
header = generate_send_pack_header(ref, from_sha, to_sha)
|
|
77
|
+
# unlike in the sync version the packfile is already read into memory
|
|
78
|
+
receive_pack_request = header + packfile
|
|
79
|
+
|
|
80
|
+
async with aiohttp.ClientSession(auth=auth) as session:
|
|
81
|
+
async with session.post(
|
|
82
|
+
url,
|
|
83
|
+
headers={
|
|
84
|
+
"Content-type": "application/x-git-receive-pack-request",
|
|
85
|
+
},
|
|
86
|
+
data=receive_pack_request,
|
|
87
|
+
raise_for_status=True,
|
|
88
|
+
) as resp:
|
|
89
|
+
lines = decode_lines(iter_lines(resp, encoding="utf-8"))
|
|
90
|
+
assert await anext(lines) == "unpack ok"
|
|
91
|
+
assert await anext(lines) == f"ok {ref}"
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
from typing import AsyncIterable, AsyncIterator
|
|
2
|
+
|
|
3
|
+
import aiohttp
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
async def decode_lines(line_stream: AsyncIterable) -> AsyncIterator:
|
|
7
|
+
"""Decode git server response iterator into individual data lines.
|
|
8
|
+
|
|
9
|
+
This asynchronous function processes a stream of lines from a server response,
|
|
10
|
+
where each line is prefixed with a 4-character hexadecimal length indicator.
|
|
11
|
+
It extracts and yields the actual data portion of each line.
|
|
12
|
+
|
|
13
|
+
Args:
|
|
14
|
+
line_stream: An asynchronous iterable providing the raw server response lines.
|
|
15
|
+
|
|
16
|
+
Yields:
|
|
17
|
+
The decoded data portion of each line, with the length prefix removed.
|
|
18
|
+
"""
|
|
19
|
+
async for line in line_stream:
|
|
20
|
+
line_length = int(line[:4], 16)
|
|
21
|
+
yield line[4:line_length]
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
async def iter_lines(
|
|
25
|
+
resp: aiohttp.ClientResponse, encoding: str = "utf-8", chunk_size: int = 16 * 1024
|
|
26
|
+
):
|
|
27
|
+
"""
|
|
28
|
+
Asynchronously iterate over the lines of an HTTP response.
|
|
29
|
+
|
|
30
|
+
Args:
|
|
31
|
+
resp: The aiohttp ClientResponse object to read from.
|
|
32
|
+
encoding: The character encoding to use for decoding bytes to strings.
|
|
33
|
+
Defaults to "utf-8".
|
|
34
|
+
chunk_size: The number of bytes to read in each chunk.
|
|
35
|
+
Defaults to 16 KiB (16 * 1024 bytes).
|
|
36
|
+
|
|
37
|
+
Yields:
|
|
38
|
+
str: Each line from the response, with trailing carriage returns removed
|
|
39
|
+
and decoded using the specified encoding.
|
|
40
|
+
"""
|
|
41
|
+
incomplete_line = bytearray()
|
|
42
|
+
|
|
43
|
+
async for chunk in resp.content.iter_chunked(chunk_size):
|
|
44
|
+
lines = (incomplete_line + chunk).split(b"\n")
|
|
45
|
+
incomplete_line = lines.pop()
|
|
46
|
+
|
|
47
|
+
for line in lines:
|
|
48
|
+
yield line.rstrip(b"\r").decode(encoding)
|
|
49
|
+
|
|
50
|
+
if incomplete_line:
|
|
51
|
+
yield incomplete_line.rstrip(b"\r").decode(encoding)
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import urllib.request
|
|
2
|
+
from typing import List
|
|
3
|
+
|
|
4
|
+
from repligit.parse import (
|
|
5
|
+
decode_lines,
|
|
6
|
+
generate_fetch_pack_request,
|
|
7
|
+
generate_send_pack_header,
|
|
8
|
+
iter_lines,
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def http_request(url, headers=None, username=None, password=None, data=None):
|
|
13
|
+
"""
|
|
14
|
+
Constructs and executes an HTTP request using urllib. (GET by default,
|
|
15
|
+
POST if "data" is not None).
|
|
16
|
+
|
|
17
|
+
Args:
|
|
18
|
+
url (str): The URL to send the request to
|
|
19
|
+
headers (dict, optional): HTTP headers to include in the request
|
|
20
|
+
username (str, optional): Username for basic authentication
|
|
21
|
+
password (str, optional): Password for basic authentication
|
|
22
|
+
data (bytes, optional): Data to send in the request body
|
|
23
|
+
|
|
24
|
+
Returns:
|
|
25
|
+
file-like object: The response file handler from the request
|
|
26
|
+
"""
|
|
27
|
+
password_manager = urllib.request.HTTPPasswordMgrWithDefaultRealm()
|
|
28
|
+
password_manager.add_password(None, url, username, password)
|
|
29
|
+
|
|
30
|
+
auth_handler = urllib.request.HTTPBasicAuthHandler(password_manager)
|
|
31
|
+
opener = urllib.request.build_opener(auth_handler)
|
|
32
|
+
|
|
33
|
+
request = urllib.request.Request(url, data=data)
|
|
34
|
+
|
|
35
|
+
if headers:
|
|
36
|
+
for header, value in headers.items():
|
|
37
|
+
request.add_header(header, value)
|
|
38
|
+
|
|
39
|
+
return opener.open(request)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def ls_remote(url: str, username: str = None, password: str = None):
|
|
43
|
+
"""Get commit hash of remote master branch, return SHA-1 hex string or
|
|
44
|
+
None if no remote commits.
|
|
45
|
+
"""
|
|
46
|
+
url = f"{url}/info/refs?service=git-upload-pack"
|
|
47
|
+
|
|
48
|
+
resp = http_request(url, username=username, password=password)
|
|
49
|
+
|
|
50
|
+
lines = decode_lines(iter_lines(resp))
|
|
51
|
+
service_line = next(lines)
|
|
52
|
+
assert service_line == "# service=git-upload-pack"
|
|
53
|
+
|
|
54
|
+
return dict(reversed(line.split()) for line in lines if line)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def fetch_pack(
|
|
58
|
+
url: str, want_sha: str, have_shas: List[str], username=None, password=None
|
|
59
|
+
):
|
|
60
|
+
"""Download a packfile from a remote server."""
|
|
61
|
+
url = f"{url}/git-upload-pack"
|
|
62
|
+
request = generate_fetch_pack_request(want_sha, have_shas)
|
|
63
|
+
|
|
64
|
+
resp = http_request(
|
|
65
|
+
url,
|
|
66
|
+
headers={
|
|
67
|
+
"Content-type": "application/x-git-upload-pack-request",
|
|
68
|
+
},
|
|
69
|
+
username=username,
|
|
70
|
+
password=password,
|
|
71
|
+
data=request,
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
line_length = int(resp.read(4), 16)
|
|
75
|
+
line = resp.read(line_length - 4)
|
|
76
|
+
|
|
77
|
+
if line[:3] == b"NAK" or line[:3] == b"ACK":
|
|
78
|
+
return resp
|
|
79
|
+
else:
|
|
80
|
+
return None
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def send_pack(
|
|
84
|
+
url: str,
|
|
85
|
+
ref: str,
|
|
86
|
+
from_sha: str,
|
|
87
|
+
to_sha: str,
|
|
88
|
+
packfile,
|
|
89
|
+
username: str = None,
|
|
90
|
+
password: str = None,
|
|
91
|
+
):
|
|
92
|
+
"""Send a packfile to a remote server."""
|
|
93
|
+
url = f"{url}/git-receive-pack"
|
|
94
|
+
|
|
95
|
+
header = generate_send_pack_header(ref, from_sha, to_sha)
|
|
96
|
+
receive_pack_request = header + packfile.read()
|
|
97
|
+
|
|
98
|
+
resp = http_request(
|
|
99
|
+
url,
|
|
100
|
+
headers={
|
|
101
|
+
"Content-type": "application/x-git-receive-pack-request",
|
|
102
|
+
},
|
|
103
|
+
username=username,
|
|
104
|
+
password=password,
|
|
105
|
+
data=receive_pack_request,
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
lines = decode_lines(iter_lines(resp))
|
|
109
|
+
assert next(lines) == "unpack ok"
|
|
110
|
+
assert next(lines) == f"ok {ref}"
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
from typing import IO, Generator, List, Union
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def iter_lines(
|
|
5
|
+
data: IO, encoding: str = "utf-8", chunk_size: int = 16 * 1024
|
|
6
|
+
) -> Generator[str]:
|
|
7
|
+
"""
|
|
8
|
+
Iterate over the lines of a file-like object, yielding one line at a time.
|
|
9
|
+
|
|
10
|
+
Args:
|
|
11
|
+
data: A file-like object with a read() method that returns bytes
|
|
12
|
+
encoding (str, optional): Character encoding to use for decoding bytes to strings.
|
|
13
|
+
Defaults to "utf-8".
|
|
14
|
+
chunk_size (int, optional): Number of bytes to read in each chunk.
|
|
15
|
+
Defaults to 16 KiB.
|
|
16
|
+
|
|
17
|
+
Yields:
|
|
18
|
+
str: Each line from the input data, with line endings removed.
|
|
19
|
+
"""
|
|
20
|
+
incomplete_line = bytearray()
|
|
21
|
+
|
|
22
|
+
for chunk in iter(lambda: data.read(chunk_size), b""):
|
|
23
|
+
lines = (incomplete_line + chunk).split(b"\n")
|
|
24
|
+
incomplete_line = lines.pop()
|
|
25
|
+
|
|
26
|
+
for line in lines:
|
|
27
|
+
yield line.rstrip(b"\r").decode(encoding)
|
|
28
|
+
|
|
29
|
+
if incomplete_line:
|
|
30
|
+
yield incomplete_line.rstrip(b"\r").decode(encoding)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def decode_lines(lines: Generator[str]) -> Generator[str]:
|
|
34
|
+
"""
|
|
35
|
+
Decode lines from the git transfer protocol into usable lines.
|
|
36
|
+
|
|
37
|
+
This asynchronous function processes a stream of lines from a server response,
|
|
38
|
+
where each line is prefixed with a 4-character hexadecimal length indicator.
|
|
39
|
+
It extracts and yields the actual data portion of each line.
|
|
40
|
+
|
|
41
|
+
Args:
|
|
42
|
+
lines: A generator yielding strings from a git server response.
|
|
43
|
+
|
|
44
|
+
Yields:
|
|
45
|
+
str: Decoded content from each line with the length prefix removed.
|
|
46
|
+
"""
|
|
47
|
+
for line in lines:
|
|
48
|
+
line_length = int(line[:4], 16)
|
|
49
|
+
yield line[4:line_length]
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def encode_lines(lines: List[Union[bytes, str]]) -> bytes:
|
|
53
|
+
"""
|
|
54
|
+
Encode a list of lines into a byte string format for git transmission.
|
|
55
|
+
|
|
56
|
+
Args:
|
|
57
|
+
lines: A list of strings or byte objects to be encoded.
|
|
58
|
+
|
|
59
|
+
Returns:
|
|
60
|
+
bytes: A single byte string containing all encoded lines.
|
|
61
|
+
"""
|
|
62
|
+
result = []
|
|
63
|
+
for line in lines:
|
|
64
|
+
if type(line) is str:
|
|
65
|
+
line = line.encode("utf-8")
|
|
66
|
+
|
|
67
|
+
result.append(f"{len(line) + 5:04x}".encode())
|
|
68
|
+
result.append(line)
|
|
69
|
+
result.append(b"\n")
|
|
70
|
+
|
|
71
|
+
return b"".join(result)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def generate_send_pack_header(ref: str, from_sha: str, to_sha: str) -> bytes:
|
|
75
|
+
"""
|
|
76
|
+
Generate a Git send-pack header for updating references.
|
|
77
|
+
|
|
78
|
+
Args:
|
|
79
|
+
ref (str): The full reference name (e.g., 'refs/heads/main')
|
|
80
|
+
from_sha (str): The source SHA-1 object ID (40 hex characters)
|
|
81
|
+
to_sha (str): The target SHA-1 object ID (40 hex characters)
|
|
82
|
+
|
|
83
|
+
Returns:
|
|
84
|
+
bytes: Encoded pack header with the format "<from_sha> <to_sha> <ref>\0 report-status"
|
|
85
|
+
followed by the "0000" flush packet
|
|
86
|
+
"""
|
|
87
|
+
return encode_lines([f"{from_sha} {to_sha} {ref}\x00 report-status"]) + b"0000"
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def generate_fetch_pack_request(want: str, haves: List[str]) -> bytes:
|
|
91
|
+
"""Generate a git-upload packfile request.
|
|
92
|
+
|
|
93
|
+
Args:
|
|
94
|
+
want (str): The SHA-1 hash of the commit that is wanted.
|
|
95
|
+
haves (List[str]): A list of SHA-1 hashes of commits that the client already has.
|
|
96
|
+
|
|
97
|
+
Returns:
|
|
98
|
+
bytes: The formatted git-upload-pack request as bytes.
|
|
99
|
+
"""
|
|
100
|
+
want_cmds = encode_lines([f"want {want}".encode()])
|
|
101
|
+
have_cmds = encode_lines([f"have {sha}".encode() for sha in haves])
|
|
102
|
+
|
|
103
|
+
return want_cmds + b"0000" + have_cmds + encode_lines([b"done"])
|
|
File without changes
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
from repligit.parse import decode_lines, encode_lines, generate_send_pack_header
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def test_decode_lines():
|
|
5
|
+
raw_lines = [
|
|
6
|
+
b"003fbef547a59eec448284136f03984dce0f2f8239a9 refs/pull/95/head",
|
|
7
|
+
b"003f358aa046cd57dbca306e80d4c3fbb86edc5b36af refs/pull/96/head",
|
|
8
|
+
b"0000",
|
|
9
|
+
]
|
|
10
|
+
|
|
11
|
+
decoded_lines = [
|
|
12
|
+
b"bef547a59eec448284136f03984dce0f2f8239a9 refs/pull/95/head",
|
|
13
|
+
b"358aa046cd57dbca306e80d4c3fbb86edc5b36af refs/pull/96/head",
|
|
14
|
+
b"",
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
lines = list(decode_lines(raw_lines))
|
|
18
|
+
assert decoded_lines == lines
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def test_encode_lines_from_bytes():
|
|
22
|
+
input_lines = [
|
|
23
|
+
b"bef547a59eec448284136f03984dce0f2f8239a9 refs/pull/95/head",
|
|
24
|
+
b"358aa046cd57dbca306e80d4c3fbb86edc5b36af refs/pull/96/head",
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
encoded_lines = (
|
|
28
|
+
b"003fbef547a59eec448284136f03984dce0f2f8239a9 refs/pull/95/head\n"
|
|
29
|
+
b"003f358aa046cd57dbca306e80d4c3fbb86edc5b36af refs/pull/96/head\n"
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
output_lines = encode_lines(input_lines)
|
|
33
|
+
assert encoded_lines == output_lines
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def test_encode_lines_from_str():
|
|
37
|
+
input_lines = [
|
|
38
|
+
"bef547a59eec448284136f03984dce0f2f8239a9 refs/pull/95/head",
|
|
39
|
+
"358aa046cd57dbca306e80d4c3fbb86edc5b36af refs/pull/96/head",
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
encoded_lines = (
|
|
43
|
+
b"003fbef547a59eec448284136f03984dce0f2f8239a9 refs/pull/95/head\n"
|
|
44
|
+
b"003f358aa046cd57dbca306e80d4c3fbb86edc5b36af refs/pull/96/head\n"
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
output_lines = encode_lines(input_lines)
|
|
48
|
+
assert encoded_lines == output_lines
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def test_generate_send_pack_header():
|
|
52
|
+
expected_header = (
|
|
53
|
+
b"0075aed5561af12f75f0b6b6ca34082610eaba109db7"
|
|
54
|
+
b" b03ab96b18ed6633c877221318db41d36b15e3d7"
|
|
55
|
+
b" refs/heads/main\x00 report-status\n0000"
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
from_sha = "aed5561af12f75f0b6b6ca34082610eaba109db7"
|
|
59
|
+
to_sha = "b03ab96b18ed6633c877221318db41d36b15e3d7"
|
|
60
|
+
ref = "refs/heads/main"
|
|
61
|
+
|
|
62
|
+
output_header = generate_send_pack_header(ref, from_sha, to_sha)
|
|
63
|
+
assert expected_header == output_header
|