Browse Source
* master: (40 commits) Clean up sha1 file writing Builtin git-cat-file builtin format-patch: squelch content-type for 7-bit ASCII CMIT_FMT_EMAIL: Q-encode Subject: and display-name part of From: fields. add more informative error messages to git-mktag remove the artificial restriction tagsize < 8kb git-rebase: use canonical A..B syntax to format-patch git-format-patch: now built-in. fmt-patch: Support --attach fmt-patch: understand old <his> notation Teach fmt-patch about --keep-subject Teach fmt-patch about --numbered fmt-patch: implement -o <dir> fmt-patch: output file names to stdout Teach fmt-patch to write individual files. Use RFC2822 dates from "git fmt-patch". git-fmt-patch: thinkofix to show [PATCH] properly. rename internal format-patch wip Minor tweak on subject line in --pretty=email Tentative built-in format-patch. ...maint
Junio C Hamano
19 years ago
41 changed files with 1698 additions and 1065 deletions
@ -0,0 +1,187 @@
@@ -0,0 +1,187 @@
|
||||
/* |
||||
* "git add" builtin command |
||||
* |
||||
* Copyright (C) 2006 Linus Torvalds |
||||
*/ |
||||
#include <fnmatch.h> |
||||
|
||||
#include "cache.h" |
||||
#include "builtin.h" |
||||
#include "dir.h" |
||||
|
||||
static const char builtin_add_usage[] = |
||||
"git-add [-n] [-v] <filepattern>..."; |
||||
|
||||
static void prune_directory(struct dir_struct *dir, const char **pathspec, int prefix) |
||||
{ |
||||
char *seen; |
||||
int i, specs; |
||||
struct dir_entry **src, **dst; |
||||
|
||||
for (specs = 0; pathspec[specs]; specs++) |
||||
/* nothing */; |
||||
seen = xmalloc(specs); |
||||
memset(seen, 0, specs); |
||||
|
||||
src = dst = dir->entries; |
||||
i = dir->nr; |
||||
while (--i >= 0) { |
||||
struct dir_entry *entry = *src++; |
||||
if (!match_pathspec(pathspec, entry->name, entry->len, prefix, seen)) { |
||||
free(entry); |
||||
continue; |
||||
} |
||||
*dst++ = entry; |
||||
} |
||||
dir->nr = dst - dir->entries; |
||||
|
||||
for (i = 0; i < specs; i++) { |
||||
struct stat st; |
||||
const char *match; |
||||
if (seen[i]) |
||||
continue; |
||||
|
||||
/* Existing file? We must have ignored it */ |
||||
match = pathspec[i]; |
||||
if (!match[0] || !lstat(match, &st)) |
||||
continue; |
||||
die("pathspec '%s' did not match any files", match); |
||||
} |
||||
} |
||||
|
||||
static void fill_directory(struct dir_struct *dir, const char **pathspec) |
||||
{ |
||||
const char *path, *base; |
||||
int baselen; |
||||
|
||||
/* Set up the default git porcelain excludes */ |
||||
memset(dir, 0, sizeof(*dir)); |
||||
dir->exclude_per_dir = ".gitignore"; |
||||
path = git_path("info/exclude"); |
||||
if (!access(path, R_OK)) |
||||
add_excludes_from_file(dir, path); |
||||
|
||||
/* |
||||
* Calculate common prefix for the pathspec, and |
||||
* use that to optimize the directory walk |
||||
*/ |
||||
baselen = common_prefix(pathspec); |
||||
path = "."; |
||||
base = ""; |
||||
if (baselen) { |
||||
char *common = xmalloc(baselen + 1); |
||||
common = xmalloc(baselen + 1); |
||||
memcpy(common, *pathspec, baselen); |
||||
common[baselen] = 0; |
||||
path = base = common; |
||||
} |
||||
|
||||
/* Read the directory and prune it */ |
||||
read_directory(dir, path, base, baselen); |
||||
if (pathspec) |
||||
prune_directory(dir, pathspec, baselen); |
||||
} |
||||
|
||||
static int add_file_to_index(const char *path, int verbose) |
||||
{ |
||||
int size, namelen; |
||||
struct stat st; |
||||
struct cache_entry *ce; |
||||
|
||||
if (lstat(path, &st)) |
||||
die("%s: unable to stat (%s)", path, strerror(errno)); |
||||
|
||||
if (!S_ISREG(st.st_mode) && !S_ISLNK(st.st_mode)) |
||||
die("%s: can only add regular files or symbolic links", path); |
||||
|
||||
namelen = strlen(path); |
||||
size = cache_entry_size(namelen); |
||||
ce = xcalloc(1, size); |
||||
memcpy(ce->name, path, namelen); |
||||
ce->ce_flags = htons(namelen); |
||||
fill_stat_cache_info(ce, &st); |
||||
|
||||
ce->ce_mode = create_ce_mode(st.st_mode); |
||||
if (!trust_executable_bit) { |
||||
/* If there is an existing entry, pick the mode bits |
||||
* from it. |
||||
*/ |
||||
int pos = cache_name_pos(path, namelen); |
||||
if (pos >= 0) |
||||
ce->ce_mode = active_cache[pos]->ce_mode; |
||||
} |
||||
|
||||
if (index_path(ce->sha1, path, &st, 1)) |
||||
die("unable to index file %s", path); |
||||
if (add_cache_entry(ce, ADD_CACHE_OK_TO_ADD)) |
||||
die("unable to add %s to index",path); |
||||
if (verbose) |
||||
printf("add '%s'\n", path); |
||||
return 0; |
||||
} |
||||
|
||||
static struct cache_file cache_file; |
||||
|
||||
int cmd_add(int argc, const char **argv, char **envp) |
||||
{ |
||||
int i, newfd; |
||||
int verbose = 0, show_only = 0; |
||||
const char *prefix = setup_git_directory(); |
||||
const char **pathspec; |
||||
struct dir_struct dir; |
||||
|
||||
git_config(git_default_config); |
||||
|
||||
newfd = hold_index_file_for_update(&cache_file, get_index_file()); |
||||
if (newfd < 0) |
||||
die("unable to create new cachefile"); |
||||
|
||||
if (read_cache() < 0) |
||||
die("index file corrupt"); |
||||
|
||||
for (i = 1; i < argc; i++) { |
||||
const char *arg = argv[i]; |
||||
|
||||
if (arg[0] != '-') |
||||
break; |
||||
if (!strcmp(arg, "--")) { |
||||
i++; |
||||
break; |
||||
} |
||||
if (!strcmp(arg, "-n")) { |
||||
show_only = 1; |
||||
continue; |
||||
} |
||||
if (!strcmp(arg, "-v")) { |
||||
verbose = 1; |
||||
continue; |
||||
} |
||||
die(builtin_add_usage); |
||||
} |
||||
git_config(git_default_config); |
||||
pathspec = get_pathspec(prefix, argv + i); |
||||
|
||||
fill_directory(&dir, pathspec); |
||||
|
||||
if (show_only) { |
||||
const char *sep = "", *eof = ""; |
||||
for (i = 0; i < dir.nr; i++) { |
||||
printf("%s%s", sep, dir.entries[i]->name); |
||||
sep = " "; |
||||
eof = "\n"; |
||||
} |
||||
fputs(eof, stdout); |
||||
return 0; |
||||
} |
||||
|
||||
for (i = 0; i < dir.nr; i++) |
||||
add_file_to_index(dir.entries[i]->name, verbose); |
||||
|
||||
if (active_cache_changed) { |
||||
if (write_cache(newfd, active_cache, active_nr) || |
||||
commit_index_file(&cache_file)) |
||||
die("Unable to write new index file"); |
||||
} |
||||
|
||||
return 0; |
||||
} |
@ -0,0 +1,150 @@
@@ -0,0 +1,150 @@
|
||||
/* |
||||
* "git rm" builtin command |
||||
* |
||||
* Copyright (C) Linus Torvalds 2006 |
||||
*/ |
||||
#include "cache.h" |
||||
#include "builtin.h" |
||||
#include "dir.h" |
||||
|
||||
static const char builtin_rm_usage[] = |
||||
"git-rm [-n] [-v] [-f] <filepattern>..."; |
||||
|
||||
static struct { |
||||
int nr, alloc; |
||||
const char **name; |
||||
} list; |
||||
|
||||
static void add_list(const char *name) |
||||
{ |
||||
if (list.nr >= list.alloc) { |
||||
list.alloc = alloc_nr(list.alloc); |
||||
list.name = xrealloc(list.name, list.alloc * sizeof(const char *)); |
||||
} |
||||
list.name[list.nr++] = name; |
||||
} |
||||
|
||||
static int remove_file(const char *name) |
||||
{ |
||||
int ret; |
||||
char *slash; |
||||
|
||||
ret = unlink(name); |
||||
if (!ret && (slash = strrchr(name, '/'))) { |
||||
char *n = strdup(name); |
||||
do { |
||||
n[slash - name] = 0; |
||||
name = n; |
||||
} while (!rmdir(name) && (slash = strrchr(name, '/'))); |
||||
} |
||||
return ret; |
||||
} |
||||
|
||||
static struct cache_file cache_file; |
||||
|
||||
int cmd_rm(int argc, const char **argv, char **envp) |
||||
{ |
||||
int i, newfd; |
||||
int verbose = 0, show_only = 0, force = 0; |
||||
const char *prefix = setup_git_directory(); |
||||
const char **pathspec; |
||||
char *seen; |
||||
|
||||
git_config(git_default_config); |
||||
|
||||
newfd = hold_index_file_for_update(&cache_file, get_index_file()); |
||||
if (newfd < 0) |
||||
die("unable to create new index file"); |
||||
|
||||
if (read_cache() < 0) |
||||
die("index file corrupt"); |
||||
|
||||
for (i = 1 ; i < argc ; i++) { |
||||
const char *arg = argv[i]; |
||||
|
||||
if (*arg != '-') |
||||
break; |
||||
if (!strcmp(arg, "--")) { |
||||
i++; |
||||
break; |
||||
} |
||||
if (!strcmp(arg, "-n")) { |
||||
show_only = 1; |
||||
continue; |
||||
} |
||||
if (!strcmp(arg, "-v")) { |
||||
verbose = 1; |
||||
continue; |
||||
} |
||||
if (!strcmp(arg, "-f")) { |
||||
force = 1; |
||||
continue; |
||||
} |
||||
die(builtin_rm_usage); |
||||
} |
||||
pathspec = get_pathspec(prefix, argv + i); |
||||
|
||||
seen = NULL; |
||||
if (pathspec) { |
||||
for (i = 0; pathspec[i] ; i++) |
||||
/* nothing */; |
||||
seen = xmalloc(i); |
||||
memset(seen, 0, i); |
||||
} |
||||
|
||||
for (i = 0; i < active_nr; i++) { |
||||
struct cache_entry *ce = active_cache[i]; |
||||
if (!match_pathspec(pathspec, ce->name, ce_namelen(ce), 0, seen)) |
||||
continue; |
||||
add_list(ce->name); |
||||
} |
||||
|
||||
if (pathspec) { |
||||
const char *match; |
||||
for (i = 0; (match = pathspec[i]) != NULL ; i++) { |
||||
if (*match && !seen[i]) |
||||
die("pathspec '%s' did not match any files", match); |
||||
} |
||||
} |
||||
|
||||
/* |
||||
* First remove the names from the index: we won't commit |
||||
* the index unless all of them succeed |
||||
*/ |
||||
for (i = 0; i < list.nr; i++) { |
||||
const char *path = list.name[i]; |
||||
printf("rm '%s'\n", path); |
||||
|
||||
if (remove_file_from_cache(path)) |
||||
die("git rm: unable to remove %s", path); |
||||
} |
||||
|
||||
/* |
||||
* Then, if we used "-f", remove the filenames from the |
||||
* workspace. If we fail to remove the first one, we |
||||
* abort the "git rm" (but once we've successfully removed |
||||
* any file at all, we'll go ahead and commit to it all: |
||||
* by then we've already committed ourself and can't fail |
||||
* in the middle) |
||||
*/ |
||||
if (force) { |
||||
int removed = 0; |
||||
for (i = 0; i < list.nr; i++) { |
||||
const char *path = list.name[i]; |
||||
if (!remove_file(path)) { |
||||
removed = 1; |
||||
continue; |
||||
} |
||||
if (!removed) |
||||
die("git rm: %s: %s", path, strerror(errno)); |
||||
} |
||||
} |
||||
|
||||
if (active_cache_changed) { |
||||
if (write_cache(newfd, active_cache, active_nr) || |
||||
commit_index_file(&cache_file)) |
||||
die("Unable to write new index file"); |
||||
} |
||||
|
||||
return 0; |
||||
} |
@ -0,0 +1,74 @@
@@ -0,0 +1,74 @@
|
||||
/* |
||||
* Copyright (c) 2006 Junio C Hamano |
||||
*/ |
||||
#include "cache.h" |
||||
#include "pkt-line.h" |
||||
#include "exec_cmd.h" |
||||
#include "builtin.h" |
||||
|
||||
static const char upload_tar_usage[] = "git-upload-tar <repo>"; |
||||
|
||||
static int nak(const char *reason) |
||||
{ |
||||
packet_write(1, "NACK %s\n", reason); |
||||
packet_flush(1); |
||||
return 1; |
||||
} |
||||
|
||||
int cmd_upload_tar(int argc, const char **argv, char **envp) |
||||
{ |
||||
int len; |
||||
const char *dir = argv[1]; |
||||
char buf[8192]; |
||||
unsigned char sha1[20]; |
||||
char *base = NULL; |
||||
char hex[41]; |
||||
int ac; |
||||
const char *av[4]; |
||||
|
||||
if (argc != 2) |
||||
usage(upload_tar_usage); |
||||
if (strlen(dir) < sizeof(buf)-1) |
||||
strcpy(buf, dir); /* enter-repo smudges its argument */ |
||||
else |
||||
packet_write(1, "NACK insanely long repository name %s\n", dir); |
||||
if (!enter_repo(buf, 0)) { |
||||
packet_write(1, "NACK not a git archive %s\n", dir); |
||||
packet_flush(1); |
||||
return 1; |
||||
} |
||||
|
||||
len = packet_read_line(0, buf, sizeof(buf)); |
||||
if (len < 5 || strncmp("want ", buf, 5)) |
||||
return nak("expected want"); |
||||
if (buf[len-1] == '\n') |
||||
buf[--len] = 0; |
||||
if (get_sha1(buf + 5, sha1)) |
||||
return nak("expected sha1"); |
||||
strcpy(hex, sha1_to_hex(sha1)); |
||||
|
||||
len = packet_read_line(0, buf, sizeof(buf)); |
||||
if (len) { |
||||
if (len < 5 || strncmp("base ", buf, 5)) |
||||
return nak("expected (optional) base"); |
||||
if (buf[len-1] == '\n') |
||||
buf[--len] = 0; |
||||
base = strdup(buf + 5); |
||||
len = packet_read_line(0, buf, sizeof(buf)); |
||||
} |
||||
if (len) |
||||
return nak("expected flush"); |
||||
|
||||
packet_write(1, "ACK\n"); |
||||
packet_flush(1); |
||||
|
||||
ac = 0; |
||||
av[ac++] = "tar-tree"; |
||||
av[ac++] = hex; |
||||
if (base) |
||||
av[ac++] = base; |
||||
av[ac++] = NULL; |
||||
execv_git_cmd(av); |
||||
/* should it return that is an error */ |
||||
return 1; |
||||
} |
@ -0,0 +1,401 @@
@@ -0,0 +1,401 @@
|
||||
/* |
||||
* This handles recursive filename detection with exclude |
||||
* files, index knowledge etc.. |
||||
* |
||||
* Copyright (C) Linus Torvalds, 2005-2006 |
||||
* Junio Hamano, 2005-2006 |
||||
*/ |
||||
#include <dirent.h> |
||||
#include <fnmatch.h> |
||||
|
||||
#include "cache.h" |
||||
#include "dir.h" |
||||
|
||||
int common_prefix(const char **pathspec) |
||||
{ |
||||
const char *path, *slash, *next; |
||||
int prefix; |
||||
|
||||
if (!pathspec) |
||||
return 0; |
||||
|
||||
path = *pathspec; |
||||
slash = strrchr(path, '/'); |
||||
if (!slash) |
||||
return 0; |
||||
|
||||
prefix = slash - path + 1; |
||||
while ((next = *++pathspec) != NULL) { |
||||
int len = strlen(next); |
||||
if (len >= prefix && !memcmp(path, next, len)) |
||||
continue; |
||||
for (;;) { |
||||
if (!len) |
||||
return 0; |
||||
if (next[--len] != '/') |
||||
continue; |
||||
if (memcmp(path, next, len+1)) |
||||
continue; |
||||
prefix = len + 1; |
||||
break; |
||||
} |
||||
} |
||||
return prefix; |
||||
} |
||||
|
||||
static int match_one(const char *match, const char *name, int namelen) |
||||
{ |
||||
int matchlen; |
||||
|
||||
/* If the match was just the prefix, we matched */ |
||||
matchlen = strlen(match); |
||||
if (!matchlen) |
||||
return 1; |
||||
|
||||
/* |
||||
* If we don't match the matchstring exactly, |
||||
* we need to match by fnmatch |
||||
*/ |
||||
if (strncmp(match, name, matchlen)) |
||||
return !fnmatch(match, name, 0); |
||||
|
||||
/* |
||||
* If we did match the string exactly, we still |
||||
* need to make sure that it happened on a path |
||||
* component boundary (ie either the last character |
||||
* of the match was '/', or the next character of |
||||
* the name was '/' or the terminating NUL. |
||||
*/ |
||||
return match[matchlen-1] == '/' || |
||||
name[matchlen] == '/' || |
||||
!name[matchlen]; |
||||
} |
||||
|
||||
int match_pathspec(const char **pathspec, const char *name, int namelen, int prefix, char *seen) |
||||
{ |
||||
int retval; |
||||
const char *match; |
||||
|
||||
name += prefix; |
||||
namelen -= prefix; |
||||
|
||||
for (retval = 0; (match = *pathspec++) != NULL; seen++) { |
||||
if (retval & *seen) |
||||
continue; |
||||
match += prefix; |
||||
if (match_one(match, name, namelen)) { |
||||
retval = 1; |
||||
*seen = 1; |
||||
} |
||||
} |
||||
return retval; |
||||
} |
||||
|
||||
void add_exclude(const char *string, const char *base, |
||||
int baselen, struct exclude_list *which) |
||||
{ |
||||
struct exclude *x = xmalloc(sizeof (*x)); |
||||
|
||||
x->pattern = string; |
||||
x->base = base; |
||||
x->baselen = baselen; |
||||
if (which->nr == which->alloc) { |
||||
which->alloc = alloc_nr(which->alloc); |
||||
which->excludes = realloc(which->excludes, |
||||
which->alloc * sizeof(x)); |
||||
} |
||||
which->excludes[which->nr++] = x; |
||||
} |
||||
|
||||
static int add_excludes_from_file_1(const char *fname, |
||||
const char *base, |
||||
int baselen, |
||||
struct exclude_list *which) |
||||
{ |
||||
int fd, i; |
||||
long size; |
||||
char *buf, *entry; |
||||
|
||||
fd = open(fname, O_RDONLY); |
||||
if (fd < 0) |
||||
goto err; |
||||
size = lseek(fd, 0, SEEK_END); |
||||
if (size < 0) |
||||
goto err; |
||||
lseek(fd, 0, SEEK_SET); |
||||
if (size == 0) { |
||||
close(fd); |
||||
return 0; |
||||
} |
||||
buf = xmalloc(size+1); |
||||
if (read(fd, buf, size) != size) |
||||
goto err; |
||||
close(fd); |
||||
|
||||
buf[size++] = '\n'; |
||||
entry = buf; |
||||
for (i = 0; i < size; i++) { |
||||
if (buf[i] == '\n') { |
||||
if (entry != buf + i && entry[0] != '#') { |
||||
buf[i - (i && buf[i-1] == '\r')] = 0; |
||||
add_exclude(entry, base, baselen, which); |
||||
} |
||||
entry = buf + i + 1; |
||||
} |
||||
} |
||||
return 0; |
||||
|
||||
err: |
||||
if (0 <= fd) |
||||
close(fd); |
||||
return -1; |
||||
} |
||||
|
||||
void add_excludes_from_file(struct dir_struct *dir, const char *fname) |
||||
{ |
||||
if (add_excludes_from_file_1(fname, "", 0, |
||||
&dir->exclude_list[EXC_FILE]) < 0) |
||||
die("cannot use %s as an exclude file", fname); |
||||
} |
||||
|
||||
static int push_exclude_per_directory(struct dir_struct *dir, const char *base, int baselen) |
||||
{ |
||||
char exclude_file[PATH_MAX]; |
||||
struct exclude_list *el = &dir->exclude_list[EXC_DIRS]; |
||||
int current_nr = el->nr; |
||||
|
||||
if (dir->exclude_per_dir) { |
||||
memcpy(exclude_file, base, baselen); |
||||
strcpy(exclude_file + baselen, dir->exclude_per_dir); |
||||
add_excludes_from_file_1(exclude_file, base, baselen, el); |
||||
} |
||||
return current_nr; |
||||
} |
||||
|
||||
static void pop_exclude_per_directory(struct dir_struct *dir, int stk) |
||||
{ |
||||
struct exclude_list *el = &dir->exclude_list[EXC_DIRS]; |
||||
|
||||
while (stk < el->nr) |
||||
free(el->excludes[--el->nr]); |
||||
} |
||||
|
||||
/* Scan the list and let the last match determines the fate. |
||||
* Return 1 for exclude, 0 for include and -1 for undecided. |
||||
*/ |
||||
static int excluded_1(const char *pathname, |
||||
int pathlen, |
||||
struct exclude_list *el) |
||||
{ |
||||
int i; |
||||
|
||||
if (el->nr) { |
||||
for (i = el->nr - 1; 0 <= i; i--) { |
||||
struct exclude *x = el->excludes[i]; |
||||
const char *exclude = x->pattern; |
||||
int to_exclude = 1; |
||||
|
||||
if (*exclude == '!') { |
||||
to_exclude = 0; |
||||
exclude++; |
||||
} |
||||
|
||||
if (!strchr(exclude, '/')) { |
||||
/* match basename */ |
||||
const char *basename = strrchr(pathname, '/'); |
||||
basename = (basename) ? basename+1 : pathname; |
||||
if (fnmatch(exclude, basename, 0) == 0) |
||||
return to_exclude; |
||||
} |
||||
else { |
||||
/* match with FNM_PATHNAME: |
||||
* exclude has base (baselen long) implicitly |
||||
* in front of it. |
||||
*/ |
||||
int baselen = x->baselen; |
||||
if (*exclude == '/') |
||||
exclude++; |
||||
|
||||
if (pathlen < baselen || |
||||
(baselen && pathname[baselen-1] != '/') || |
||||
strncmp(pathname, x->base, baselen)) |
||||
continue; |
||||
|
||||
if (fnmatch(exclude, pathname+baselen, |
||||
FNM_PATHNAME) == 0) |
||||
return to_exclude; |
||||
} |
||||
} |
||||
} |
||||
return -1; /* undecided */ |
||||
} |
||||
|
||||
int excluded(struct dir_struct *dir, const char *pathname) |
||||
{ |
||||
int pathlen = strlen(pathname); |
||||
int st; |
||||
|
||||
for (st = EXC_CMDL; st <= EXC_FILE; st++) { |
||||
switch (excluded_1(pathname, pathlen, &dir->exclude_list[st])) { |
||||
case 0: |
||||
return 0; |
||||
case 1: |
||||
return 1; |
||||
} |
||||
} |
||||
return 0; |
||||
} |
||||
|
||||
static void add_name(struct dir_struct *dir, const char *pathname, int len) |
||||
{ |
||||
struct dir_entry *ent; |
||||
|
||||
if (cache_name_pos(pathname, len) >= 0) |
||||
return; |
||||
|
||||
if (dir->nr == dir->alloc) { |
||||
int alloc = alloc_nr(dir->alloc); |
||||
dir->alloc = alloc; |
||||
dir->entries = xrealloc(dir->entries, alloc*sizeof(ent)); |
||||
} |
||||
ent = xmalloc(sizeof(*ent) + len + 1); |
||||
ent->len = len; |
||||
memcpy(ent->name, pathname, len); |
||||
ent->name[len] = 0; |
||||
dir->entries[dir->nr++] = ent; |
||||
} |
||||
|
||||
static int dir_exists(const char *dirname, int len) |
||||
{ |
||||
int pos = cache_name_pos(dirname, len); |
||||
if (pos >= 0) |
||||
return 1; |
||||
pos = -pos-1; |
||||
if (pos >= active_nr) /* can't */ |
||||
return 0; |
||||
return !strncmp(active_cache[pos]->name, dirname, len); |
||||
} |
||||
|
||||
/* |
||||
* Read a directory tree. We currently ignore anything but |
||||
* directories, regular files and symlinks. That's because git |
||||
* doesn't handle them at all yet. Maybe that will change some |
||||
* day. |
||||
* |
||||
* Also, we ignore the name ".git" (even if it is not a directory). |
||||
* That likely will not change. |
||||
*/ |
||||
static int read_directory_recursive(struct dir_struct *dir, const char *path, const char *base, int baselen) |
||||
{ |
||||
DIR *fdir = opendir(path); |
||||
int contents = 0; |
||||
|
||||
if (fdir) { |
||||
int exclude_stk; |
||||
struct dirent *de; |
||||
char fullname[MAXPATHLEN + 1]; |
||||
memcpy(fullname, base, baselen); |
||||
|
||||
exclude_stk = push_exclude_per_directory(dir, base, baselen); |
||||
|
||||
while ((de = readdir(fdir)) != NULL) { |
||||
int len; |
||||
|
||||
if ((de->d_name[0] == '.') && |
||||
(de->d_name[1] == 0 || |
||||
!strcmp(de->d_name + 1, ".") || |
||||
!strcmp(de->d_name + 1, "git"))) |
||||
continue; |
||||
len = strlen(de->d_name); |
||||
memcpy(fullname + baselen, de->d_name, len+1); |
||||
if (excluded(dir, fullname) != dir->show_ignored) { |
||||
if (!dir->show_ignored || DTYPE(de) != DT_DIR) { |
||||
continue; |
||||
} |
||||
} |
||||
|
||||
switch (DTYPE(de)) { |
||||
struct stat st; |
||||
int subdir, rewind_base; |
||||
default: |
||||
continue; |
||||
case DT_UNKNOWN: |
||||
if (lstat(fullname, &st)) |
||||
continue; |
||||
if (S_ISREG(st.st_mode) || S_ISLNK(st.st_mode)) |
||||
break; |
||||
if (!S_ISDIR(st.st_mode)) |
||||
continue; |
||||
/* fallthrough */ |
||||
case DT_DIR: |
||||
memcpy(fullname + baselen + len, "/", 2); |
||||
len++; |
||||
rewind_base = dir->nr; |
||||
subdir = read_directory_recursive(dir, fullname, fullname, |
||||
baselen + len); |
||||
if (dir->show_other_directories && |
||||
(subdir || !dir->hide_empty_directories) && |
||||
!dir_exists(fullname, baselen + len)) { |
||||
// Rewind the read subdirectory |
||||
while (dir->nr > rewind_base) |
||||
free(dir->entries[--dir->nr]); |
||||
break; |
||||
} |
||||
contents += subdir; |
||||
continue; |
||||
case DT_REG: |
||||
case DT_LNK: |
||||
break; |
||||
} |
||||
add_name(dir, fullname, baselen + len); |
||||
contents++; |
||||
} |
||||
closedir(fdir); |
||||
|
||||
pop_exclude_per_directory(dir, exclude_stk); |
||||
} |
||||
|
||||
return contents; |
||||
} |
||||
|
||||
static int cmp_name(const void *p1, const void *p2) |
||||
{ |
||||
const struct dir_entry *e1 = *(const struct dir_entry **)p1; |
||||
const struct dir_entry *e2 = *(const struct dir_entry **)p2; |
||||
|
||||
return cache_name_compare(e1->name, e1->len, |
||||
e2->name, e2->len); |
||||
} |
||||
|
||||
int read_directory(struct dir_struct *dir, const char *path, const char *base, int baselen) |
||||
{ |
||||
/* |
||||
* Make sure to do the per-directory exclude for all the |
||||
* directories leading up to our base. |
||||
*/ |
||||
if (baselen) { |
||||
if (dir->exclude_per_dir) { |
||||
char *p, *pp = xmalloc(baselen+1); |
||||
memcpy(pp, base, baselen+1); |
||||
p = pp; |
||||
while (1) { |
||||
char save = *p; |
||||
*p = 0; |
||||
push_exclude_per_directory(dir, pp, p-pp); |
||||
*p++ = save; |
||||
if (!save) |
||||
break; |
||||
p = strchr(p, '/'); |
||||
if (p) |
||||
p++; |
||||
else |
||||
p = pp + baselen; |
||||
} |
||||
free(pp); |
||||
} |
||||
} |
||||
|
||||
read_directory_recursive(dir, path, base, baselen); |
||||
qsort(dir->entries, dir->nr, sizeof(struct dir_entry *), cmp_name); |
||||
return dir->nr; |
||||
} |
@ -0,0 +1,51 @@
@@ -0,0 +1,51 @@
|
||||
#ifndef DIR_H |
||||
#define DIR_H |
||||
|
||||
/* |
||||
* We maintain three exclude pattern lists: |
||||
* EXC_CMDL lists patterns explicitly given on the command line. |
||||
* EXC_DIRS lists patterns obtained from per-directory ignore files. |
||||
* EXC_FILE lists patterns from fallback ignore files. |
||||
*/ |
||||
#define EXC_CMDL 0 |
||||
#define EXC_DIRS 1 |
||||
#define EXC_FILE 2 |
||||
|
||||
|
||||
struct dir_entry { |
||||
int len; |
||||
char name[FLEX_ARRAY]; /* more */ |
||||
}; |
||||
|
||||
struct exclude_list { |
||||
int nr; |
||||
int alloc; |
||||
struct exclude { |
||||
const char *pattern; |
||||
const char *base; |
||||
int baselen; |
||||
} **excludes; |
||||
}; |
||||
|
||||
struct dir_struct { |
||||
int nr, alloc; |
||||
unsigned int show_ignored:1, |
||||
show_other_directories:1, |
||||
hide_empty_directories:1; |
||||
struct dir_entry **entries; |
||||
|
||||
/* Exclude info */ |
||||
const char *exclude_per_dir; |
||||
struct exclude_list exclude_list[3]; |
||||
}; |
||||
|
||||
extern int common_prefix(const char **pathspec); |
||||
extern int match_pathspec(const char **pathspec, const char *name, int namelen, int prefix, char *seen); |
||||
|
||||
extern int read_directory(struct dir_struct *, const char *path, const char *base, int baselen); |
||||
extern int excluded(struct dir_struct *, const char *); |
||||
extern void add_excludes_from_file(struct dir_struct *, const char *fname); |
||||
extern void add_exclude(const char *string, const char *base, |
||||
int baselen, struct exclude_list *which); |
||||
|
||||
#endif |
@ -1,56 +0,0 @@
@@ -1,56 +0,0 @@
|
||||
#!/bin/sh |
||||
|
||||
USAGE='[-n] [-v] <file>...' |
||||
SUBDIRECTORY_OK='Yes' |
||||
. git-sh-setup |
||||
|
||||
show_only= |
||||
verbose= |
||||
while : ; do |
||||
case "$1" in |
||||
-n) |
||||
show_only=true |
||||
;; |
||||
-v) |
||||
verbose=--verbose |
||||
;; |
||||
--) |
||||
shift |
||||
break |
||||
;; |
||||
-*) |
||||
usage |
||||
;; |
||||
*) |
||||
break |
||||
;; |
||||
esac |
||||
shift |
||||
done |
||||
|
||||
# Check misspelled pathspec |
||||
case "$#" in |
||||
0) ;; |
||||
*) |
||||
git-ls-files --error-unmatch --others --cached -- "$@" >/dev/null || { |
||||
echo >&2 "Maybe you misspelled it?" |
||||
exit 1 |
||||
} |
||||
;; |
||||
esac |
||||
|
||||
if test -f "$GIT_DIR/info/exclude" |
||||
then |
||||
git-ls-files -z \ |
||||
--exclude-from="$GIT_DIR/info/exclude" \ |
||||
--others --exclude-per-directory=.gitignore -- "$@" |
||||
else |
||||
git-ls-files -z \ |
||||
--others --exclude-per-directory=.gitignore -- "$@" |
||||
fi | |
||||
case "$show_only" in |
||||
true) |
||||
xargs -0 echo ;; |
||||
*) |
||||
git-update-index --add $verbose -z --stdin ;; |
||||
esac |
@ -1,344 +0,0 @@
@@ -1,344 +0,0 @@
|
||||
#!/bin/sh |
||||
# |
||||
# Copyright (c) 2005 Junio C Hamano |
||||
# |
||||
|
||||
USAGE='[-n | -k] [-o <dir> | --stdout] [--signoff] [--check] [--diff-options] [--attach] <his> [<mine>]' |
||||
LONG_USAGE='Prepare each commit with its patch since <mine> head forked from |
||||
<his> head, one file per patch formatted to resemble UNIX mailbox |
||||
format, for e-mail submission or use with git-am. |
||||
|
||||
Each output file is numbered sequentially from 1, and uses the |
||||
first line of the commit message (massaged for pathname safety) |
||||
as the filename. |
||||
|
||||
When -o is specified, output files are created in <dir>; otherwise |
||||
they are created in the current working directory. This option |
||||
is ignored if --stdout is specified. |
||||
|
||||
When -n is specified, instead of "[PATCH] Subject", the first |
||||
line is formatted as "[PATCH N/M] Subject", unless you have only |
||||
one patch. |
||||
|
||||
When --attach is specified, patches are attached, not inlined.' |
||||
|
||||
. git-sh-setup |
||||
|
||||
# Force diff to run in C locale. |
||||
LANG=C LC_ALL=C |
||||
export LANG LC_ALL |
||||
|
||||
diff_opts= |
||||
LF=' |
||||
' |
||||
|
||||
outdir=./ |
||||
while case "$#" in 0) break;; esac |
||||
do |
||||
case "$1" in |
||||
-c|--c|--ch|--che|--chec|--check) |
||||
check=t ;; |
||||
-a|--a|--au|--aut|--auth|--autho|--author|\ |
||||
-d|--d|--da|--dat|--date|\ |
||||
-m|--m|--mb|--mbo|--mbox) # now noop |
||||
;; |
||||
--at|--att|--atta|--attac|--attach) |
||||
attach=t ;; |
||||
-k|--k|--ke|--kee|--keep|--keep-|--keep-s|--keep-su|--keep-sub|\ |
||||
--keep-subj|--keep-subje|--keep-subjec|--keep-subject) |
||||
keep_subject=t ;; |
||||
-n|--n|--nu|--num|--numb|--numbe|--number|--numbere|--numbered) |
||||
numbered=t ;; |
||||
-s|--s|--si|--sig|--sign|--signo|--signof|--signoff) |
||||
signoff=t ;; |
||||
--st|--std|--stdo|--stdou|--stdout) |
||||
stdout=t ;; |
||||
-o=*|--o=*|--ou=*|--out=*|--outp=*|--outpu=*|--output=*|--output-=*|\ |
||||
--output-d=*|--output-di=*|--output-dir=*|--output-dire=*|\ |
||||
--output-direc=*|--output-direct=*|--output-directo=*|\ |
||||
--output-director=*|--output-directory=*) |
||||
outdir=`expr "$1" : '-[^=]*=\(.*\)'` ;; |
||||
-o|--o|--ou|--out|--outp|--outpu|--output|--output-|--output-d|\ |
||||
--output-di|--output-dir|--output-dire|--output-direc|--output-direct|\ |
||||
--output-directo|--output-director|--output-directory) |
||||
case "$#" in 1) usage ;; esac; shift |
||||
outdir="$1" ;; |
||||
-h|--h|--he|--hel|--help) |
||||
usage |
||||
;; |
||||
-*' '* | -*"$LF"* | -*' '*) |
||||
# Ignore diff option that has whitespace for now. |
||||
;; |
||||
-*) diff_opts="$diff_opts$1 " ;; |
||||
*) break ;; |
||||
esac |
||||
shift |
||||
done |
||||
|
||||
case "$keep_subject$numbered" in |
||||
tt) |
||||
die '--keep-subject and --numbered are incompatible.' ;; |
||||
esac |
||||
|
||||
tmp=.tmp-series$$ |
||||
trap 'rm -f $tmp-*' 0 1 2 3 15 |
||||
|
||||
series=$tmp-series |
||||
commsg=$tmp-commsg |
||||
filelist=$tmp-files |
||||
|
||||
# Backward compatible argument parsing hack. |
||||
# |
||||
# Historically, we supported: |
||||
# 1. "rev1" is equivalent to "rev1..HEAD" |
||||
# 2. "rev1..rev2" |
||||
# 3. "rev1" "rev2 is equivalent to "rev1..rev2" |
||||
# |
||||
# We want to take a sequence of "rev1..rev2" in general. |
||||
# Also, "rev1.." should mean "rev1..HEAD"; git-diff users are |
||||
# familiar with that syntax. |
||||
|
||||
case "$#,$1$2" in |
||||
1,?*..?*) |
||||
# single "rev1..rev2" |
||||
;; |
||||
1,?*..) |
||||
# single "rev1.." should mean "rev1..HEAD" |
||||
set x "$1"HEAD |
||||
shift |
||||
;; |
||||
1,*) |
||||
# single rev1 |
||||
set x "$1..HEAD" |
||||
shift |
||||
;; |
||||
2,?*..?*) |
||||
# not traditional "rev1" "rev2" |
||||
;; |
||||
2,*) |
||||
set x "$1..$2" |
||||
shift |
||||
;; |
||||
esac |
||||
|
||||
# Now we have what we want in $@ |
||||
for revpair |
||||
do |
||||
case "$revpair" in |
||||
?*..?*) |
||||
rev1=`expr "z$revpair" : 'z\(.*\)\.\.'` |
||||
rev2=`expr "z$revpair" : 'z.*\.\.\(.*\)'` |
||||
;; |
||||
*) |
||||
rev1="$revpair^" |
||||
rev2="$revpair" |
||||
;; |
||||
esac |
||||
git-rev-parse --verify "$rev1^0" >/dev/null 2>&1 || |
||||
die "Not a valid rev $rev1 ($revpair)" |
||||
git-rev-parse --verify "$rev2^0" >/dev/null 2>&1 || |
||||
die "Not a valid rev $rev2 ($revpair)" |
||||
git-cherry -v "$rev1" "$rev2" | |
||||
while read sign rev comment |
||||
do |
||||
case "$sign" in |
||||
'-') |
||||
echo >&2 "Merged already: $comment" |
||||
;; |
||||
*) |
||||
echo $rev |
||||
;; |
||||
esac |
||||
done |
||||
done >$series |
||||
|
||||
me=`git-var GIT_AUTHOR_IDENT | sed -e 's/>.*/>/'` |
||||
headers=`git-repo-config --get format.headers` |
||||
case "$attach" in |
||||
"") ;; |
||||
*) |
||||
mimemagic="050802040500080604070107" |
||||
esac |
||||
|
||||
case "$outdir" in |
||||
*/) ;; |
||||
*) outdir="$outdir/" ;; |
||||
esac |
||||
test -d "$outdir" || mkdir -p "$outdir" || exit |
||||
|
||||
titleScript=' |
||||
/./d |
||||
/^$/n |
||||
s/^\[PATCH[^]]*\] *// |
||||
s/[^-a-z.A-Z_0-9]/-/g |
||||
s/\.\.\.*/\./g |
||||
s/\.*$// |
||||
s/--*/-/g |
||||
s/^-// |
||||
s/-$// |
||||
s/$/./ |
||||
p |
||||
q |
||||
' |
||||
|
||||
process_one () { |
||||
perl -w -e ' |
||||
my ($keep_subject, $num, $signoff, $headers, $mimemagic, $commsg) = @ARGV; |
||||
my ($signoff_pattern, $done_header, $done_subject, $done_separator, $signoff_seen, |
||||
$last_was_signoff); |
||||
|
||||
if ($signoff) { |
||||
$signoff = "Signed-off-by: " . `git-var GIT_COMMITTER_IDENT`; |
||||
$signoff =~ s/>.*/>/; |
||||
$signoff_pattern = quotemeta($signoff); |
||||
} |
||||
|
||||
my @weekday_names = qw(Sun Mon Tue Wed Thu Fri Sat); |
||||
my @month_names = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); |
||||
|
||||
sub show_date { |
||||
my ($time, $tz) = @_; |
||||
my $minutes = abs($tz); |
||||
$minutes = int($minutes / 100) * 60 + ($minutes % 100); |
||||
if ($tz < 0) { |
||||
$minutes = -$minutes; |
||||
} |
||||
my $t = $time + $minutes * 60; |
||||
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) = gmtime($t); |
||||
return sprintf("%s, %d %s %d %02d:%02d:%02d %+05d", |
||||
$weekday_names[$wday], $mday, |
||||
$month_names[$mon], $year+1900, |
||||
$hour, $min, $sec, $tz); |
||||
} |
||||
|
||||
print "From nobody Mon Sep 17 00:00:00 2001\n"; |
||||
open FH, "git stripspace <$commsg |" or die "open $commsg pipe"; |
||||
while (<FH>) { |
||||
unless ($done_header) { |
||||
if (/^$/) { |
||||
$done_header = 1; |
||||
} |
||||
elsif (/^author (.*>) (.*)$/) { |
||||
my ($author_ident, $author_date) = ($1, $2); |
||||
my ($utc, $off) = ($author_date =~ /^(\d+) ([-+]?\d+)$/); |
||||
$author_date = show_date($utc, $off); |
||||
|
||||
print "From: $author_ident\n"; |
||||
print "Date: $author_date\n"; |
||||
} |
||||
next; |
||||
} |
||||
unless ($done_subject) { |
||||
unless ($keep_subject) { |
||||
s/^\[PATCH[^]]*\]\s*//; |
||||
s/^/[PATCH$num] /; |
||||
} |
||||
if ($headers) { |
||||
print "$headers\n"; |
||||
} |
||||
print "Subject: $_"; |
||||
if ($mimemagic) { |
||||
print "MIME-Version: 1.0\n"; |
||||
print "Content-Type: multipart/mixed;\n"; |
||||
print " boundary=\"------------$mimemagic\"\n"; |
||||
print "\n"; |
||||
print "This is a multi-part message in MIME format.\n"; |
||||
print "--------------$mimemagic\n"; |
||||
print "Content-Type: text/plain; charset=UTF-8; format=fixed\n"; |
||||
print "Content-Transfer-Encoding: 8bit\n"; |
||||
} |
||||
$done_subject = 1; |
||||
next; |
||||
} |
||||
unless ($done_separator) { |
||||
print "\n"; |
||||
$done_separator = 1; |
||||
next if (/^$/); |
||||
} |
||||
|
||||
$last_was_signoff = 0; |
||||
if (/Signed-off-by:/i) { |
||||
if ($signoff ne "" && /Signed-off-by:\s*$signoff_pattern$/i) { |
||||
$signoff_seen = 1; |
||||
} |
||||
} |
||||
print $_; |
||||
} |
||||
if (!$signoff_seen && $signoff ne "") { |
||||
if (!$last_was_signoff) { |
||||
print "\n"; |
||||
} |
||||
print "$signoff\n"; |
||||
} |
||||
print "\n---\n\n"; |
||||
close FH or die "close $commsg pipe"; |
||||
' "$keep_subject" "$num" "$signoff" "$headers" "$mimemagic" $commsg |
||||
|
||||
git-diff-tree -p --stat --summary $diff_opts "$commit" |
||||
echo |
||||
case "$mimemagic" in |
||||
'');; |
||||
*) |
||||
echo "--------------$mimemagic" |
||||
echo "Content-Type: text/x-patch;" |
||||
echo " name=\"$commit.diff\"" |
||||
echo "Content-Transfer-Encoding: 8bit" |
||||
echo "Content-Disposition: inline;" |
||||
echo " filename=\"$commit.diff\"" |
||||
echo |
||||
esac |
||||
git-diff-tree -p $diff_opts "$commit" |
||||
case "$mimemagic" in |
||||
'') |
||||
echo "-- " |
||||
echo "@@GIT_VERSION@@" |
||||
;; |
||||
*) |
||||
echo |
||||
echo "--------------$mimemagic--" |
||||
echo |
||||
;; |
||||
esac |
||||
echo |
||||
} |
||||
|
||||
total=`wc -l <$series | tr -dc "[0-9]"` |
||||
case "$total,$numbered" in |
||||
1,*) |
||||
numfmt='' ;; |
||||
*,t) |
||||
numfmt=`echo "$total" | wc -c` |
||||
numfmt=$(($numfmt-1)) |
||||
numfmt=" %0${numfmt}d/$total" |
||||
esac |
||||
|
||||
i=1 |
||||
while read commit |
||||
do |
||||
git-cat-file commit "$commit" | git-stripspace >$commsg |
||||
title=`sed -ne "$titleScript" <$commsg` |
||||
case "$numbered" in |
||||
'') num= ;; |
||||
*) |
||||
num=`printf "$numfmt" $i` ;; |
||||
esac |
||||
|
||||
file=`printf '%04d-%stxt' $i "$title"` |
||||
if test '' = "$stdout" |
||||
then |
||||
echo "$file" |
||||
process_one >"$outdir$file" |
||||
if test t = "$check" |
||||
then |
||||
# This is slightly modified from Andrew Morton's Perfect Patch. |
||||
# Lines you introduce should not have trailing whitespace. |
||||
# Also check for an indentation that has SP before a TAB. |
||||
grep -n '^+\([ ]* .*\|.*[ ]\)$' "$outdir$file" |
||||
: |
||||
fi |
||||
else |
||||
echo >&2 "$file" |
||||
process_one |
||||
fi |
||||
i=`expr "$i" + 1` |
||||
done <$series |
@ -1,70 +0,0 @@
@@ -1,70 +0,0 @@
|
||||
#!/bin/sh |
||||
|
||||
USAGE='[-f] [-n] [-v] [--] <file>...' |
||||
SUBDIRECTORY_OK='Yes' |
||||
. git-sh-setup |
||||
|
||||
remove_files= |
||||
show_only= |
||||
verbose= |
||||
while : ; do |
||||
case "$1" in |
||||
-f) |
||||
remove_files=true |
||||
;; |
||||
-n) |
||||
show_only=true |
||||
;; |
||||
-v) |
||||
verbose=--verbose |
||||
;; |
||||
--) |
||||
shift; break |
||||
;; |
||||
-*) |
||||
usage |
||||
;; |
||||
*) |
||||
break |
||||
;; |
||||
esac |
||||
shift |
||||
done |
||||
|
||||
# This is typo-proofing. If some paths match and some do not, we want |
||||
# to do nothing. |
||||
case "$#" in |
||||
0) ;; |
||||
*) |
||||
git-ls-files --error-unmatch -- "$@" >/dev/null || { |
||||
echo >&2 "Maybe you misspelled it?" |
||||
exit 1 |
||||
} |
||||
;; |
||||
esac |
||||
|
||||
if test -f "$GIT_DIR/info/exclude" |
||||
then |
||||
git-ls-files -z \ |
||||
--exclude-from="$GIT_DIR/info/exclude" \ |
||||
--exclude-per-directory=.gitignore -- "$@" |
||||
else |
||||
git-ls-files -z \ |
||||
--exclude-per-directory=.gitignore -- "$@" |
||||
fi | |
||||
case "$show_only,$remove_files" in |
||||
true,*) |
||||
xargs -0 echo |
||||
;; |
||||
*,true) |
||||
xargs -0 sh -c " |
||||
while [ \$# -gt 0 ]; do |
||||
file=\$1; shift |
||||
rm -- \"\$file\" && git-update-index --remove $verbose \"\$file\" |
||||
done |
||||
" inline |
||||
;; |
||||
*) |
||||
git-update-index --force-remove $verbose -z --stdin |
||||
;; |
||||
esac |
Loading…
Reference in new issue