githelper.git
/
githelper.pike
version
»
Context lines:
10
20
40
80
file
none
3
githelper.git/githelper.pike:72:
// because that could mean the committed stuff ends up with different // attributes than they have right now... if (sizeof(run_git("diff", "--name-only", ".gitattributes"))) { write("You have unstaged changes to .gitattributes.\n" "Please add or stash them before commit.\n"); return 1; } }
-
int
check
_ident(string
filename
)
+
int
find
_
expanded_
ident(string
data
)
{
-
string data = get_staged_file(filename);
+
int p=0; while ((p = search(data, "$Id", p))>=0) {
-
if (data[p..p+3] != "$Id$") {
+
if (data[p..p+3] != "$Id$")
+
return 1;
+
p += 4;
+
}
+
return 0;
+
}
+
+
int find_expanded_ident_in_staged_file(string filename)
+
{
+
return find_expanded_ident(get_staged_file(filename));
+
}
+
+
int check_ident(string filename)
+
{
+
if (find_expanded_ident_in_staged_file(filename)) {
write("File %s contains an expanded ident.\n" "Try 'git reset %s; git add %s', " "or remove the ident manually.\n", @({filename})*3); return 1; }
-
p += 4;
-
}
+
return 0; } int check_blocker_attributes(array(string) files_to_commit) { constant attrs_to_check = ({ "foreign_ident", "block_commit", "ident" }); foreach(run_git("check-attr", @attrs_to_check, "--", @files_to_commit) / "\n" - ({""}), string line) { array(string) parts = line / ": ";
githelper.git/githelper.pike:120:
break; if (check_ident(filename)) return 1; break; } } } return 0; }
+
int check_gitattributes_files(array(string) files_to_commit)
+
{
+
foreach(files_to_commit, string filename)
+
if(filename == ".gitattributes" ||
+
has_suffix(filename, "/.gitattributes"))
+
{
+
string dir=filename[..sizeof(filename)-15];
+
string diff = run_git("diff", "-p", "-Sforeign_ident", "--cached",
+
"--", filename);
+
if (sizeof(diff)) {
+
int pos = search(diff, "\n@@");
+
if (pos >= 0)
+
diff = diff[pos+1..];
+
foreach(diff/"\n", string line)
+
if(sizeof(line) &&
+
(line[0]=='+' || line[0]=='-')) {
+
int code, len;
+
string fn;
+
if(sscanf(line, "%c/%s foreign_ident%n", code, fn, len) != 3 ||
+
len != sizeof(line)) {
+
write("Unsupported change of foreign_ident in %s\n",
+
filename);
+
return 1;
+
}
+
fn = dir+fn;
+
if (code=='-' && search(files_to_commit, fn)<0) {
+
write("Removed foreign_ident from unstaged file %s\n", fn);
+
return 1;
+
}
+
}
+
}
+
}
+
return 0;
+
}
+
int hook() { array(string) files_to_commit = split_z(run_git("diff", "--staged", "--name-only", "-z")); return check_attributes_staged() ||
-
check_blocker_attributes(files_to_commit);
+
check_blocker_attributes(files_to_commit)
||
+
check_gitattributes_files(files_to_commit)
;
} } /* Filters */ /* A sample filter, not really useful... */ class NiceIdentFilter { static string replace_id(string f, function(string:string) replace) {