githelper.git / githelper.pike

version» Context lines:

githelper.git/githelper.pike:182:      class GitAttributes   {    enum {    ATTR_TRUE = 1,    ATTR_FALSE = 2,    ATTR_UNSET = 3    };       class AttrState(string attr, string|int setto) { -  static string _sprintf(int type) { +  protected string _sprintf(int type) {    return type=='O' && sprintf("AttrState(%O, %O)\n", attr, setto);    }    };       class MatchAttr(string name, int is_macro, array(AttrState) states) { -  static string _sprintf(int type) { +  protected string _sprintf(int type) {    return type=='O' && sprintf("MatchAttr(%O, %d, %O)\n",    name, is_macro, states);    }    };    -  static array(MatchAttr) attrs = ({}); -  static mapping(string:MatchAttr) macros = ([]); +  protected array(MatchAttr) attrs = ({}); +  protected mapping(string:MatchAttr) macros = ([]);    -  static int invalid_attr_name(string name) +  protected int invalid_attr_name(string name)    {    int n;    if(name == "" || name[0] == '-')    return 1;    sscanf(name, "%*[-._0-9a-zA-Z]%n", n);    return n != sizeof(name);    }    -  static AttrState parse_attr(string src) +  protected AttrState parse_attr(string src)    {    string equals = 0;    string|int setto;    sscanf(src, "%s=%s", src, equals);    if(src[0] == '-' || src[0] == '!') {    setto = (src[0]=='-'? ATTR_FALSE : ATTR_UNSET);    src = src[1..];    } else    setto = equals || ATTR_TRUE;    if(invalid_attr_name(src))    fail("%s is not a valid attribute name\n", src);    return AttrState(src, setto);    }    -  static MatchAttr parse_attr_line(string line, int macro_ok) +  protected MatchAttr parse_attr_line(string line, int macro_ok)    {    int is_macro=0;    string name;    line = String.trim_whites(replace(line, ({"\t","\r","\n"}),    ({" ", " ", " "})));    if(!sizeof(line) || line[0] == '#')    return 0;    if(has_prefix(line, "[attr]")) {    if(!macro_ok)    fail("%s not allowed\n", name);    is_macro=1;    sscanf(line, "[attr]%*[ ]%s%*[ ]%s", name, line);    } else {    sscanf(line, "%s%*[ ]%s", name, line);    }    return MatchAttr(name, is_macro, reverse(map(line/" "-({""}), parse_attr)));    }    -  static void handle_attr_line(string line, int macro_ok) +  protected void handle_attr_line(string line, int macro_ok)    {    MatchAttr a = parse_attr_line(line, macro_ok);    if(a) attrs += ({ a });    }    -  static void create(string data) +  protected void create(string data)    {    foreach(data/"\n", string line)    handle_attr_line(line, 1);    attrs = reverse(attrs);    foreach(attrs, MatchAttr a)    if(a->is_macro)    macros[a->name] = a;    attrs = filter(attrs, lambda(MatchAttr a) { return !a->is_macro; });    }    -  static int path_matches(string path, string pattern) +  protected int path_matches(string path, string pattern)    {    if(search(pattern, "/")<0)    return glob(pattern, (path/"/")[-1]);    if(has_prefix(pattern, "/"))    pattern = pattern[1..];    return glob(pattern, path);    }    -  static void macroexpand_one(string attrname, array(MatchAttr) attrs, +  protected void macroexpand_one(string attrname, array(MatchAttr) attrs,    mapping(string:string|int) all_attr)    {    if(all_attr[attrname] != ATTR_TRUE)    return;    MatchAttr ma = macros[attrname];    if(ma) fill_one(ma, attrs, all_attr);    }    -  static void fill_one(MatchAttr attr, array(MatchAttr) attrs, +  protected void fill_one(MatchAttr attr, array(MatchAttr) attrs,    mapping(string:string|int) all_attr)    {    foreach(attr->states, AttrState s) {    if(!all_attr[s->attr]) {    all_attr[s->attr] = s->setto;    macroexpand_one(s->attr, attrs, all_attr);    }    }    }    -  static void fill(string path, array(MatchAttr) attrs, +  protected void fill(string path, array(MatchAttr) attrs,    mapping(string:string|int) all_attr)    {    foreach(attrs, MatchAttr a)    if(/*!a->is_macro &&*/ path_matches(path, a->name))    fill_one(a, attrs, all_attr);    }       mapping(string:string|int) checkattr(string path)    {    mapping(string:string|int) all_attr = ([]);
githelper.git/githelper.pike:317:    if(state->attr == attrname && state->setto == ATTR_TRUE) {    z = 1;    break;    }    if (z)    r += ({ attr->name });    }    return r;    }    -  static string _sprintf(int type) { +  protected string _sprintf(int type) {    return type=='O' && sprintf("GitAttributes(%O)\n", attrs);    }   }            /* Hooks */      class CommitHookUtils   { -  static array(string) files_to_commit; +  protected array(string) files_to_commit;    GitAttributes attrs;       private string git_dir;       string get_git_dir()    {    return git_dir ||    (git_dir = String.trim_all_whites(run_git("rev-parse", "--git-dir")));    }   
githelper.git/githelper.pike:453:    }    }    return err;    }   }      class CommitHookUtilsRepo   {    inherit CommitHookUtils;    -  static string sha; +  protected string sha;       string get_file(string filename, int|void allow_empty)    {    return get_committed_file(sha, filename, allow_empty);    }       string get_old_file(string filename, int|void allow_empty)    {    return get_committed_file(sha+"^", filename, allow_empty);    }
githelper.git/githelper.pike:549:   class PreReceiveHook   {    inherit CommitHookUtilsRepo;       enum AccessLevel {    ACCESS_NONE = 0,    ACCESS_BASIC = 1,    ACCESS_FULL = 2, // rebase/delete branch, move/delete tag, etc.    };    -  static mapping(string:AccessLevel) groups = ([ +  protected mapping(string:AccessLevel) groups = ([    "scratch": ACCESS_FULL,    ]);    -  static array(string) commits_to_check = ({}); +  protected array(string) commits_to_check = ({});    -  static void parse_groups(string user) +  protected void parse_groups(string user)    {    string git_dir = get_git_dir();       groups[user] = ACCESS_FULL;       string group_data = Stdio.read_bytes(combine_path(git_dir, "info/group"));       if (!group_data) return;       foreach(replace(group_data, "\r", "\n")/"\n", string line) {
githelper.git/githelper.pike:778:    return 0;    }   }      /* Filters */      /* A sample filter, not really useful... */      class NiceIdentFilter   { -  static string replace_id(string f, function(string:string) replace) { +  protected string replace_id(string f, function(string:string) replace) {    int p=0;    while((p=search(f, DOLLAR"Id", p)) >= 0) {    int p2 = search(f, DOLLAR, p+3), p3 = search(f, "\n", p+3);    if (p2 > p && (p3 < 0 || p2 < p3)) {    string r = replace(f[p..p2]);    if (r) {    // werror("Replacing %O with %O\n", f[p..p2], r);    f = f[..p-1]+r+f[p2+1..];    p += sizeof(r);    } else {    // werror("Not replacing %O\n", f[p..p2]);    p = p2+1;    }    } else p += 3;    }    return f;    }    -  static string clean_ident(string i) +  protected string clean_ident(string i)    {    if(has_prefix(i, DOLLAR"Id:") && sizeof(i/" ")==13)    return unexpanded_id;    }    -  static string smudge_ident(string i) +  protected string smudge_ident(string i)    {    return DOLLAR"Id: some nice ident perhaps, but based on what? "DOLLAR;    }       int clean()    {    write(replace_id(Stdio.stdin->read(), clean_ident));    return 0;    }