Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add initial support for Git protocol v2 #1244

Merged
merged 12 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add initial support for Git protocol v2
Implement Git protocol version negotiation and use Git protocol v2 for
fetches if supported. For now, the observable behaviour of Dulwich is
equivalent regardless of protocol version, except that two new features
may be used if the server supports Git protocol v2.

The first feature is a reference prefix list which may be used to filter
refs server-side. This can be used to reduce the size of the initial
reference listing announced by the server. Reducing the size of this
announcement was a major design goal for protocol v2 to avoid sending of
very large announcements when a repository contains a lot of references.
This feature is intended as an optimization which servers are free to
ignore depending on available server-side resources. Therefore, users of
Dulwich should still be prepared to filter redundant refs manually (this
limitation also applies to Git itself).
A new --refspec porcelain option is provided in order to test this
feature on the command line.

The second feature is an object filter specification, which corresponds
to the --filter option of 'git clone'. This can be used to omit objects
while cloning repositories. For instance, the following command will
clone a given repsitory without fetching any blob objects:

   dulwich clone --filter blob:none --bare REPO_URL

(In this example the --bare option is used because creation of a work
tree would fail without any blobs present.)

The test suite now enables protocol v2 and keeps passing for me.
  • Loading branch information
stspdotname committed Jun 25, 2024
commit 2b975ec7e49caf98c1c4d0b1eea848d0dd86ae77
33 changes: 26 additions & 7 deletions dulwich/cli.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,19 @@ def run(self, args):
type=str,
help=("Check out branch instead of branch pointed to by remote " "HEAD"),
)
parser.add_option(
"--refspec",
dest="refspec",
type=str,
help="References to fetch",
action="append",
)
parser.add_option(
"--filter",
dest="filter_spec",
type=str,
help="git-rev-list-style object filter",
)
options, args = parser.parse_args(args)

if args == []:
Expand All @@ -282,6 +295,8 @@ def run(self, args):
bare=options.bare,
depth=options.depth,
branch=options.branch,
refspec=options.refspec,
filter_spec=options.filter_spec,
)
except GitProtocolError as e:
print(f"{e}")
Expand Down Expand Up @@ -586,13 +601,17 @@ def run(self, args):

class cmd_pull(Command):
def run(self, args):
parser = optparse.OptionParser()
options, args = parser.parse_args(args)
try:
from_location = args[0]
except IndexError:
from_location = None
porcelain.pull(".", from_location)
parser = argparse.ArgumentParser()
parser.add_argument("--from_location", type=str)
parser.add_argument("--refspec", type=str, nargs="*")
parser.add_argument("--filter", type=str, nargs=1)
args = parser.parse_args(args)
porcelain.pull(
".",
args.from_location or None,
args.refspec or None,
filter_spec=args.filter,
)


class cmd_push(Command):
Expand Down
Loading