#pike __REAL_VERSION__ |
|
|
|
protected Stdio.File export_fd; |
|
protected Process.Process fast_importer; |
|
protected int verbosity; |
|
protected mapping(string:string|int) requested_features = ([]); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected void create(Stdio.File|string|void fd_or_gitdir, |
int|void verbosity) |
{ |
global::verbosity = verbosity; |
if (!stringp(fd_or_gitdir)) { |
export_fd = fd_or_gitdir || Stdio.stdout; |
} else { |
if (!Stdio.is_dir(fd_or_gitdir)) { |
if (verbosity) werror("Creating %s\n", fd_or_gitdir); |
Git.git(fd_or_gitdir, "init", "--bare"); |
} |
if (verbosity) |
werror("Starting a fast importer for git-dir %O...\n", fd_or_gitdir); |
export_fd = Stdio.File(); |
fast_importer = Git.low_git(([ "stdin":export_fd->pipe() ]), |
fd_or_gitdir, "fast-import"); |
} |
} |
|
|
void command(sprintf_format cmd, sprintf_args ... args) |
{ |
export_fd->write(cmd, @args); |
} |
|
|
int done() |
{ |
if (requested_features["done"]) { |
command("done\n"); |
} |
if (export_fd) { |
export_fd->close(); |
export_fd = UNDEFINED; |
} |
int ret; |
if (fast_importer) { |
ret = fast_importer->wait(); |
fast_importer = UNDEFINED; |
} |
return ret; |
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
void reset(string ref, string|void committish) |
{ |
command("reset %s\n", ref); |
if (committish) { |
command("from %s\n", committish); |
} |
} |
|
void mark(string marker) |
{ |
command("mark %s\n", marker); |
} |
|
void data(string data) |
{ |
command("data %d\n" |
"%s\n", sizeof(data), data); |
} |
|
|
|
|
|
|
|
|
void blob(string blob, string|void marker) |
{ |
command("blob\n"); |
if (marker) mark(marker); |
data(blob); |
} |
|
|
void checkpoint() |
{ |
command("checkpoint\n"); |
} |
|
|
|
|
|
|
|
|
|
void progress(string message) |
{ |
foreach(message/"\n", string line) { |
command("progress %s\n", line); |
} |
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void feature(string feature, string|void arg) |
{ |
if (arg) { |
command("feature %s=%s\n", feature, arg); |
} else { |
command("feature %s\n", feature); |
} |
requested_features[feature] = arg || 1; |
} |
|
|
void option(string option) |
{ |
command("option %s\n", option); |
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void tag(string name, string committish, string tagger_info, string message) |
{ |
command("tag %s\n" |
"from %s\n" |
"tagger %s\n", |
name, committish, tagger_info); |
data(message); |
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void commit(string ref, string|void commit_marker, |
string|void author_info, string committer_info, |
string message, string|void ... parents) |
{ |
command("commit %s\n", ref); |
if (commit_marker) { |
mark(commit_marker); |
} |
if (author_info) { |
command("author %s\n", author_info); |
} |
command("committer %s\n", committer_info); |
data(message); |
if (sizeof(parents)) { |
command("from %s\n" |
"%{merge %s\n%}", |
parents[0], parents[1..]); |
} |
} |
|
|
|
|
void filedeleteall() |
{ |
command("deleteall\n"); |
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void filemodify(int mode, string path, string|void dataref) |
{ |
path = combine_path_unix("/", path)[1..]; |
if (path == "") { |
error("Invalid path.\n"); |
} |
command("M %06o %s %q\n", |
mode, dataref || "inline", path); |
} |
|
|
void filedelete(string path) |
{ |
path = combine_path_unix("/", path)[1..]; |
if (path == "") { |
error("Invalid path.\n"); |
} |
command("D %q\n", path); |
} |
|
|
void filecopy(string from, string to) |
{ |
from = combine_path_unix("/", from)[1..]; |
to = combine_path_unix("/", to)[1..]; |
if ((from == "") || (to == "")) { |
error("Invalid path.\n"); |
} |
command("C %q %q\n", from, to); |
} |
|
|
void filerename(string from, string to) |
{ |
from = combine_path_unix("/", from)[1..]; |
to = combine_path_unix("/", to)[1..]; |
if ((from == "") || (to == "")) { |
error("Invalid path.\n"); |
} |
command("C %q %q\n", from, to); |
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void notemodify(string commit, string|void dataref) |
{ |
if (!requested_features["notes"]) { |
error("The notes feature has not been requested.\n"); |
} |
command("N %s %s\n", dataref || "inline", commit); |
} |
|
|
|
|
|
void cat_blob(string dataref) |
{ |
command("cat-blob %s\n", dataref); |
} |
|
|
|
|
|
|
|
|
|
void ls(string path, string|void dataref) |
{ |
if (dataref) { |
command("ls %s %s\n", dataref, path); |
} else { |
command("ls %q\n", path); |
} |
} |
|
|
|
|
|
|
|
|
|
void export(string file_name, string|void git_name) |
{ |
int mode = file_stat(file_name)->mode; |
if (mode & Git.MODE_DIR) { |
mode = Git.MODE_DIR; |
} else if (mode & 0111) { |
mode = Git.MODE_EXE; |
} else if (mode & 0666) { |
mode = Git.MODE_FILE; |
} else { |
error("Unsupported filesystem mode for %O: %03o\n", file_name, mode); |
} |
if (mode == Git.MODE_DIR) { |
foreach(get_dir(file_name), string fn) { |
export(combine_path(file_name, fn), |
combine_path(git_name || file_name, fn)); |
} |
} else { |
filemodify(mode, git_name); |
data(Stdio.read_bytes(file_name)); |
} |
} |
|