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

Fetch default branch 'main' instead of 'master' #279

Merged
merged 3 commits into from
Jan 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
17 changes: 13 additions & 4 deletions src/fetch_git.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
This file is part of Restraint.

Restraint is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -30,6 +30,8 @@
#include "fetch.h"
#include "fetch_git.h"

static const gchar *g_git_branches[] = {GIT_BRANCHES};

static gint
packet_length(const gchar *linelen)
{
Expand Down Expand Up @@ -230,9 +232,16 @@ myopen(FetchData *fetch_data, GError **error)
"While writing to %s: ", fetch_data->url->host);
goto error;
}
write_succeeded = packet_write(fetch_data->ostream, &tmp_error, "argument %s:%s\0",
fetch_data->url->query == NULL ? GIT_BRANCH : fetch_data->url->query,
fetch_data->url->fragment == NULL ? "" : fetch_data->url->fragment + fragment_offset);

// traverse git branches one by one
for (gint i = 0; i < sizeof (g_git_branches) / sizeof (const gchar *); i++) {
gchar *branch = (gchar *)(g_git_branches[i]);
write_succeeded = packet_write(fetch_data->ostream, &tmp_error, "argument %s:%s\0",
fetch_data->url->query == NULL ? branch: fetch_data->url->query,
fetch_data->url->fragment == NULL ? "" : fetch_data->url->fragment + fragment_offset);
if (write_succeeded)
break;
}
if (!write_succeeded) {
g_propagate_prefixed_error(error, tmp_error,
"While writing to %s: ", fetch_data->url->host);
Expand Down
7 changes: 6 additions & 1 deletion src/fetch_git.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@
#ifndef _RESTRAINT_FETCH_GIT_H
#define _RESTRAINT_FETCH_GIT_H

/*
* The main branch ("main") is fetched by default, but we also support to
* fetch the legacy one (i.e. "master") because it is required by some old
* repositories.
*/
#define GIT_BRANCHES "main", "master"
#define GIT_PORT 9418
#define GIT_BRANCH "master"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can still have a define here..

#define GIT_BRANCHES "main", "master"

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestion! GIT_BRANCHES is added to file src/fetch_git.h.

#define HDR_LEN_SIZE 4

#include <libsoup/soup.h>
Expand Down