83 lines · 1.5 KB · C
RawDownload
#include <u.h>#include <libc.h>#include <libsec.h>#include <thread.h>#include "pkg.h"#include "src.h" typedef struct Exec Exec; struct Exec {	char *file;	char **argv;	Channel *pidch;}; voidpexec(void *args){	Exec *e = args;	procexec(e->pidch, e->file, e->argv);} static intfetchgit(char *url, char *rev, char *dir){	Exec e;	char *argv[] = {"rc", "-c", smprint("git/clone %s %s", url, dir), nil};	Channel *c = threadwaitchan();	Waitmsg *w;	int pid, rpid; 	e.argv = argv;	e.file = "/bin/rc";	e.pidch = chancreate(sizeof(int), 0); 	if(rev != nil){		free(argv[2]);		fprint(2, "FIXME git/clone %s rev %s\n", url, dir);		return -1;	} 	procrfork(pexec, &e, 0x2000, RFFDG);	recv(e.pidch, &pid);	chanfree(e.pidch);	if(pid < 0){		fprint(2, "failed to spawn process\n");		return -1;	}	w = recvp(c);	free(argv[2]);	if(w == nil){		fprint(2, "Receiving pid failed\n");		return -1;	}	rpid = w->pid;	free(w);	return rpid == pid;} intfetchsrc(Src *src){	char *url, dir[12] = "XXXXXXXXXXX";	int d; 	mktemp(dir);	d = -1;	if(strncmp(src->url, "github://", 9) == 0){		url = smprint("git://github.com/%s", src->url + 9);		d = fetchgit(url, src->rev, dir);		free(url);	}else if(strncmp(src->url, "sourcehut://", 12) == 0){		url = smprint("https://git.sr.ht/%s", src->url + 12);		d = fetchgit(url, src->rev, dir);		free(url);	}else if(strncmp(src->url, "git://", 6) == 0){		d = fetchgit(src->url, src->rev, dir);	}else{		werrstr("unknown scheme");	} 	return d;}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t