mirror of
https://github.com/git/git.git
synced 2025-12-12 20:36:24 +01:00
Move ref path matching to connect.c library
It's a generic thing for matching refs from the other side.
This commit is contained in:
1
cache.h
1
cache.h
@@ -261,6 +261,7 @@ struct pack_entry {
|
|||||||
|
|
||||||
extern int git_connect(int fd[2], char *url, const char *prog);
|
extern int git_connect(int fd[2], char *url, const char *prog);
|
||||||
extern int finish_connect(pid_t pid);
|
extern int finish_connect(pid_t pid);
|
||||||
|
extern int path_match(const char *path, int nr, char **match);
|
||||||
|
|
||||||
extern void prepare_packed_git(void);
|
extern void prepare_packed_git(void);
|
||||||
extern int use_packed_git(struct packed_git *);
|
extern int use_packed_git(struct packed_git *);
|
||||||
|
|||||||
21
connect.c
21
connect.c
@@ -1,6 +1,27 @@
|
|||||||
#include "cache.h"
|
#include "cache.h"
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
|
|
||||||
|
int path_match(const char *path, int nr, char **match)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int pathlen = strlen(path);
|
||||||
|
|
||||||
|
for (i = 0; i < nr; i++) {
|
||||||
|
char *s = match[i];
|
||||||
|
int len = strlen(s);
|
||||||
|
|
||||||
|
if (!len || len > pathlen)
|
||||||
|
continue;
|
||||||
|
if (memcmp(path + pathlen - len, s, len))
|
||||||
|
continue;
|
||||||
|
if (pathlen > len && path[pathlen - len - 1] != '/')
|
||||||
|
continue;
|
||||||
|
*s = 0;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* First, make it shell-safe. We do this by just disallowing any
|
* First, make it shell-safe. We do this by just disallowing any
|
||||||
* special characters. Somebody who cares can do escaping and let
|
* special characters. Somebody who cares can do escaping and let
|
||||||
|
|||||||
21
send-pack.c
21
send-pack.c
@@ -4,27 +4,6 @@
|
|||||||
static const char send_pack_usage[] = "git-send-pack [--exec=other] destination [heads]*";
|
static const char send_pack_usage[] = "git-send-pack [--exec=other] destination [heads]*";
|
||||||
static const char *exec = "git-receive-pack";
|
static const char *exec = "git-receive-pack";
|
||||||
|
|
||||||
static int path_match(const char *path, int nr, char **match)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int pathlen = strlen(path);
|
|
||||||
|
|
||||||
for (i = 0; i < nr; i++) {
|
|
||||||
char *s = match[i];
|
|
||||||
int len = strlen(s);
|
|
||||||
|
|
||||||
if (!len || len > pathlen)
|
|
||||||
continue;
|
|
||||||
if (memcmp(path + pathlen - len, s, len))
|
|
||||||
continue;
|
|
||||||
if (pathlen > len && path[pathlen - len - 1] != '/')
|
|
||||||
continue;
|
|
||||||
*s = 0;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct ref {
|
struct ref {
|
||||||
struct ref *next;
|
struct ref *next;
|
||||||
unsigned char old_sha1[20];
|
unsigned char old_sha1[20];
|
||||||
|
|||||||
Reference in New Issue
Block a user