mirror of
https://github.com/git/git.git
synced 2026-03-13 10:23:30 +01:00
Merge branch 'master' of git://repo.or.cz/alt-git
This commit is contained in:
@@ -21,6 +21,8 @@ Note that you can use `.` (current directory) as the
|
||||
<repository> to pull from the local repository -- this is useful
|
||||
when merging local branches into the current branch.
|
||||
|
||||
Also note that options meant for `git-pull` itself and underlying
|
||||
`git-merge` must be given before the options meant for `git-fetch`.
|
||||
|
||||
OPTIONS
|
||||
-------
|
||||
|
||||
@@ -262,8 +262,7 @@ hook if one exists. You can use this hook to do sanity checks and
|
||||
reject the rebase if it isn't appropriate. Please see the template
|
||||
pre-rebase hook script for an example.
|
||||
|
||||
You must be in the top directory of your project to start (or continue)
|
||||
a rebase. Upon completion, <branch> will be the current branch.
|
||||
Upon completion, <branch> will be the current branch.
|
||||
|
||||
INTERACTIVE MODE
|
||||
----------------
|
||||
|
||||
7
Makefile
7
Makefile
@@ -247,7 +247,7 @@ SCRIPT_SH = \
|
||||
SCRIPT_PERL = \
|
||||
git-add--interactive.perl \
|
||||
git-archimport.perl git-cvsimport.perl git-relink.perl \
|
||||
git-cvsserver.perl git-remote.perl git-cvsexportcommit.perl \
|
||||
git-cvsserver.perl git-cvsexportcommit.perl \
|
||||
git-send-email.perl git-svn.perl
|
||||
|
||||
SCRIPTS = $(patsubst %.sh,%,$(SCRIPT_SH)) \
|
||||
@@ -307,7 +307,7 @@ LIB_H = \
|
||||
run-command.h strbuf.h tag.h tree.h git-compat-util.h revision.h \
|
||||
tree-walk.h log-tree.h dir.h path-list.h unpack-trees.h builtin.h \
|
||||
utf8.h reflog-walk.h patch-ids.h attr.h decorate.h progress.h \
|
||||
mailmap.h remote.h parse-options.h transport.h diffcore.h hash.h fsck.h \
|
||||
mailmap.h remote.h parse-options.h transport.h diffcore.h hash.h ll-merge.h fsck.h \
|
||||
pack-revindex.h
|
||||
|
||||
DIFF_OBJS = \
|
||||
@@ -332,7 +332,7 @@ LIB_OBJS = \
|
||||
color.o wt-status.o archive-zip.o archive-tar.o shallow.o utf8.o \
|
||||
convert.o attr.o decorate.o progress.o mailmap.o symlinks.o remote.o \
|
||||
transport.o bundle.o walker.o parse-options.o ws.o archive.o branch.o \
|
||||
alias.o fsck.o pack-revindex.o
|
||||
ll-merge.o alias.o fsck.o pack-revindex.o
|
||||
|
||||
BUILTIN_OBJS = \
|
||||
builtin-add.o \
|
||||
@@ -384,6 +384,7 @@ BUILTIN_OBJS = \
|
||||
builtin-push.o \
|
||||
builtin-read-tree.o \
|
||||
builtin-reflog.o \
|
||||
builtin-remote.o \
|
||||
builtin-send-pack.o \
|
||||
builtin-config.o \
|
||||
builtin-rerere.o \
|
||||
|
||||
@@ -152,6 +152,7 @@ static int reset_to_new(struct tree *tree, int quiet)
|
||||
{
|
||||
struct unpack_trees_options opts;
|
||||
struct tree_desc tree_desc;
|
||||
|
||||
memset(&opts, 0, sizeof(opts));
|
||||
opts.head_idx = -1;
|
||||
opts.update = 1;
|
||||
@@ -159,6 +160,8 @@ static int reset_to_new(struct tree *tree, int quiet)
|
||||
opts.merge = 1;
|
||||
opts.fn = oneway_merge;
|
||||
opts.verbose_update = !quiet;
|
||||
opts.src_index = &the_index;
|
||||
opts.dst_index = &the_index;
|
||||
parse_tree(tree);
|
||||
init_tree_desc(&tree_desc, tree->buffer, tree->size);
|
||||
if (unpack_trees(1, &tree_desc, &opts))
|
||||
@@ -170,6 +173,7 @@ static void reset_clean_to_new(struct tree *tree, int quiet)
|
||||
{
|
||||
struct unpack_trees_options opts;
|
||||
struct tree_desc tree_desc;
|
||||
|
||||
memset(&opts, 0, sizeof(opts));
|
||||
opts.head_idx = -1;
|
||||
opts.skip_unmerged = 1;
|
||||
@@ -177,6 +181,8 @@ static void reset_clean_to_new(struct tree *tree, int quiet)
|
||||
opts.merge = 1;
|
||||
opts.fn = oneway_merge;
|
||||
opts.verbose_update = !quiet;
|
||||
opts.src_index = &the_index;
|
||||
opts.dst_index = &the_index;
|
||||
parse_tree(tree);
|
||||
init_tree_desc(&tree_desc, tree->buffer, tree->size);
|
||||
if (unpack_trees(1, &tree_desc, &opts))
|
||||
@@ -224,8 +230,11 @@ static int merge_working_tree(struct checkout_opts *opts,
|
||||
struct tree_desc trees[2];
|
||||
struct tree *tree;
|
||||
struct unpack_trees_options topts;
|
||||
|
||||
memset(&topts, 0, sizeof(topts));
|
||||
topts.head_idx = -1;
|
||||
topts.src_index = &the_index;
|
||||
topts.dst_index = &the_index;
|
||||
|
||||
refresh_cache(REFRESH_QUIET);
|
||||
|
||||
|
||||
@@ -198,6 +198,8 @@ static void create_base_index(void)
|
||||
opts.head_idx = 1;
|
||||
opts.index_only = 1;
|
||||
opts.merge = 1;
|
||||
opts.src_index = &the_index;
|
||||
opts.dst_index = &the_index;
|
||||
|
||||
opts.fn = oneway_merge;
|
||||
tree = parse_tree_indirect(head_sha1);
|
||||
|
||||
@@ -11,11 +11,11 @@
|
||||
#include "tree-walk.h"
|
||||
#include "diff.h"
|
||||
#include "diffcore.h"
|
||||
#include "run-command.h"
|
||||
#include "tag.h"
|
||||
#include "unpack-trees.h"
|
||||
#include "path-list.h"
|
||||
#include "xdiff-interface.h"
|
||||
#include "ll-merge.h"
|
||||
#include "interpolate.h"
|
||||
#include "attr.h"
|
||||
#include "merge-recursive.h"
|
||||
@@ -213,6 +213,8 @@ static int git_merge_trees(int index_only,
|
||||
opts.merge = 1;
|
||||
opts.head_idx = 2;
|
||||
opts.fn = threeway_merge;
|
||||
opts.src_index = &the_index;
|
||||
opts.dst_index = &the_index;
|
||||
|
||||
init_tree_desc_from_tree(t+0, common);
|
||||
init_tree_desc_from_tree(t+1, head);
|
||||
@@ -615,364 +617,16 @@ static void fill_mm(const unsigned char *sha1, mmfile_t *mm)
|
||||
mm->size = size;
|
||||
}
|
||||
|
||||
/*
|
||||
* Customizable low-level merge drivers support.
|
||||
*/
|
||||
|
||||
struct ll_merge_driver;
|
||||
typedef int (*ll_merge_fn)(const struct ll_merge_driver *,
|
||||
const char *path,
|
||||
mmfile_t *orig,
|
||||
mmfile_t *src1, const char *name1,
|
||||
mmfile_t *src2, const char *name2,
|
||||
mmbuffer_t *result);
|
||||
|
||||
struct ll_merge_driver {
|
||||
const char *name;
|
||||
const char *description;
|
||||
ll_merge_fn fn;
|
||||
const char *recursive;
|
||||
struct ll_merge_driver *next;
|
||||
char *cmdline;
|
||||
};
|
||||
|
||||
/*
|
||||
* Built-in low-levels
|
||||
*/
|
||||
static int ll_binary_merge(const struct ll_merge_driver *drv_unused,
|
||||
const char *path_unused,
|
||||
mmfile_t *orig,
|
||||
mmfile_t *src1, const char *name1,
|
||||
mmfile_t *src2, const char *name2,
|
||||
mmbuffer_t *result)
|
||||
{
|
||||
/*
|
||||
* The tentative merge result is "ours" for the final round,
|
||||
* or common ancestor for an internal merge. Still return
|
||||
* "conflicted merge" status.
|
||||
*/
|
||||
mmfile_t *stolen = index_only ? orig : src1;
|
||||
|
||||
result->ptr = stolen->ptr;
|
||||
result->size = stolen->size;
|
||||
stolen->ptr = NULL;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int ll_xdl_merge(const struct ll_merge_driver *drv_unused,
|
||||
const char *path_unused,
|
||||
mmfile_t *orig,
|
||||
mmfile_t *src1, const char *name1,
|
||||
mmfile_t *src2, const char *name2,
|
||||
mmbuffer_t *result)
|
||||
{
|
||||
xpparam_t xpp;
|
||||
|
||||
if (buffer_is_binary(orig->ptr, orig->size) ||
|
||||
buffer_is_binary(src1->ptr, src1->size) ||
|
||||
buffer_is_binary(src2->ptr, src2->size)) {
|
||||
warning("Cannot merge binary files: %s vs. %s\n",
|
||||
name1, name2);
|
||||
return ll_binary_merge(drv_unused, path_unused,
|
||||
orig, src1, name1,
|
||||
src2, name2,
|
||||
result);
|
||||
}
|
||||
|
||||
memset(&xpp, 0, sizeof(xpp));
|
||||
return xdl_merge(orig,
|
||||
src1, name1,
|
||||
src2, name2,
|
||||
&xpp, XDL_MERGE_ZEALOUS,
|
||||
result);
|
||||
}
|
||||
|
||||
static int ll_union_merge(const struct ll_merge_driver *drv_unused,
|
||||
const char *path_unused,
|
||||
mmfile_t *orig,
|
||||
mmfile_t *src1, const char *name1,
|
||||
mmfile_t *src2, const char *name2,
|
||||
mmbuffer_t *result)
|
||||
{
|
||||
char *src, *dst;
|
||||
long size;
|
||||
const int marker_size = 7;
|
||||
|
||||
int status = ll_xdl_merge(drv_unused, path_unused,
|
||||
orig, src1, NULL, src2, NULL, result);
|
||||
if (status <= 0)
|
||||
return status;
|
||||
size = result->size;
|
||||
src = dst = result->ptr;
|
||||
while (size) {
|
||||
char ch;
|
||||
if ((marker_size < size) &&
|
||||
(*src == '<' || *src == '=' || *src == '>')) {
|
||||
int i;
|
||||
ch = *src;
|
||||
for (i = 0; i < marker_size; i++)
|
||||
if (src[i] != ch)
|
||||
goto not_a_marker;
|
||||
if (src[marker_size] != '\n')
|
||||
goto not_a_marker;
|
||||
src += marker_size + 1;
|
||||
size -= marker_size + 1;
|
||||
continue;
|
||||
}
|
||||
not_a_marker:
|
||||
do {
|
||||
ch = *src++;
|
||||
*dst++ = ch;
|
||||
size--;
|
||||
} while (ch != '\n' && size);
|
||||
}
|
||||
result->size = dst - result->ptr;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define LL_BINARY_MERGE 0
|
||||
#define LL_TEXT_MERGE 1
|
||||
#define LL_UNION_MERGE 2
|
||||
static struct ll_merge_driver ll_merge_drv[] = {
|
||||
{ "binary", "built-in binary merge", ll_binary_merge },
|
||||
{ "text", "built-in 3-way text merge", ll_xdl_merge },
|
||||
{ "union", "built-in union merge", ll_union_merge },
|
||||
};
|
||||
|
||||
static void create_temp(mmfile_t *src, char *path)
|
||||
{
|
||||
int fd;
|
||||
|
||||
strcpy(path, ".merge_file_XXXXXX");
|
||||
fd = xmkstemp(path);
|
||||
if (write_in_full(fd, src->ptr, src->size) != src->size)
|
||||
die("unable to write temp-file");
|
||||
close(fd);
|
||||
}
|
||||
|
||||
/*
|
||||
* User defined low-level merge driver support.
|
||||
*/
|
||||
static int ll_ext_merge(const struct ll_merge_driver *fn,
|
||||
const char *path,
|
||||
mmfile_t *orig,
|
||||
mmfile_t *src1, const char *name1,
|
||||
mmfile_t *src2, const char *name2,
|
||||
mmbuffer_t *result)
|
||||
{
|
||||
char temp[3][50];
|
||||
char cmdbuf[2048];
|
||||
struct interp table[] = {
|
||||
{ "%O" },
|
||||
{ "%A" },
|
||||
{ "%B" },
|
||||
};
|
||||
struct child_process child;
|
||||
const char *args[20];
|
||||
int status, fd, i;
|
||||
struct stat st;
|
||||
|
||||
if (fn->cmdline == NULL)
|
||||
die("custom merge driver %s lacks command line.", fn->name);
|
||||
|
||||
result->ptr = NULL;
|
||||
result->size = 0;
|
||||
create_temp(orig, temp[0]);
|
||||
create_temp(src1, temp[1]);
|
||||
create_temp(src2, temp[2]);
|
||||
|
||||
interp_set_entry(table, 0, temp[0]);
|
||||
interp_set_entry(table, 1, temp[1]);
|
||||
interp_set_entry(table, 2, temp[2]);
|
||||
|
||||
output(1, "merging %s using %s", path,
|
||||
fn->description ? fn->description : fn->name);
|
||||
|
||||
interpolate(cmdbuf, sizeof(cmdbuf), fn->cmdline, table, 3);
|
||||
|
||||
memset(&child, 0, sizeof(child));
|
||||
child.argv = args;
|
||||
args[0] = "sh";
|
||||
args[1] = "-c";
|
||||
args[2] = cmdbuf;
|
||||
args[3] = NULL;
|
||||
|
||||
status = run_command(&child);
|
||||
if (status < -ERR_RUN_COMMAND_FORK)
|
||||
; /* failure in run-command */
|
||||
else
|
||||
status = -status;
|
||||
fd = open(temp[1], O_RDONLY);
|
||||
if (fd < 0)
|
||||
goto bad;
|
||||
if (fstat(fd, &st))
|
||||
goto close_bad;
|
||||
result->size = st.st_size;
|
||||
result->ptr = xmalloc(result->size + 1);
|
||||
if (read_in_full(fd, result->ptr, result->size) != result->size) {
|
||||
free(result->ptr);
|
||||
result->ptr = NULL;
|
||||
result->size = 0;
|
||||
}
|
||||
close_bad:
|
||||
close(fd);
|
||||
bad:
|
||||
for (i = 0; i < 3; i++)
|
||||
unlink(temp[i]);
|
||||
return status;
|
||||
}
|
||||
|
||||
/*
|
||||
* merge.default and merge.driver configuration items
|
||||
*/
|
||||
static struct ll_merge_driver *ll_user_merge, **ll_user_merge_tail;
|
||||
static const char *default_ll_merge;
|
||||
|
||||
static int read_merge_config(const char *var, const char *value)
|
||||
{
|
||||
struct ll_merge_driver *fn;
|
||||
const char *ep, *name;
|
||||
int namelen;
|
||||
|
||||
if (!strcmp(var, "merge.default")) {
|
||||
if (!value)
|
||||
return config_error_nonbool(var);
|
||||
default_ll_merge = strdup(value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* We are not interested in anything but "merge.<name>.variable";
|
||||
* especially, we do not want to look at variables such as
|
||||
* "merge.summary", "merge.tool", and "merge.verbosity".
|
||||
*/
|
||||
if (prefixcmp(var, "merge.") || (ep = strrchr(var, '.')) == var + 5)
|
||||
return 0;
|
||||
|
||||
/*
|
||||
* Find existing one as we might be processing merge.<name>.var2
|
||||
* after seeing merge.<name>.var1.
|
||||
*/
|
||||
name = var + 6;
|
||||
namelen = ep - name;
|
||||
for (fn = ll_user_merge; fn; fn = fn->next)
|
||||
if (!strncmp(fn->name, name, namelen) && !fn->name[namelen])
|
||||
break;
|
||||
if (!fn) {
|
||||
fn = xcalloc(1, sizeof(struct ll_merge_driver));
|
||||
fn->name = xmemdupz(name, namelen);
|
||||
fn->fn = ll_ext_merge;
|
||||
*ll_user_merge_tail = fn;
|
||||
ll_user_merge_tail = &(fn->next);
|
||||
}
|
||||
|
||||
ep++;
|
||||
|
||||
if (!strcmp("name", ep)) {
|
||||
if (!value)
|
||||
return config_error_nonbool(var);
|
||||
fn->description = strdup(value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!strcmp("driver", ep)) {
|
||||
if (!value)
|
||||
return config_error_nonbool(var);
|
||||
/*
|
||||
* merge.<name>.driver specifies the command line:
|
||||
*
|
||||
* command-line
|
||||
*
|
||||
* The command-line will be interpolated with the following
|
||||
* tokens and is given to the shell:
|
||||
*
|
||||
* %O - temporary file name for the merge base.
|
||||
* %A - temporary file name for our version.
|
||||
* %B - temporary file name for the other branches' version.
|
||||
*
|
||||
* The external merge driver should write the results in the
|
||||
* file named by %A, and signal that it has done with zero exit
|
||||
* status.
|
||||
*/
|
||||
fn->cmdline = strdup(value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!strcmp("recursive", ep)) {
|
||||
if (!value)
|
||||
return config_error_nonbool(var);
|
||||
fn->recursive = strdup(value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void initialize_ll_merge(void)
|
||||
{
|
||||
if (ll_user_merge_tail)
|
||||
return;
|
||||
ll_user_merge_tail = &ll_user_merge;
|
||||
git_config(read_merge_config);
|
||||
}
|
||||
|
||||
static const struct ll_merge_driver *find_ll_merge_driver(const char *merge_attr)
|
||||
{
|
||||
struct ll_merge_driver *fn;
|
||||
const char *name;
|
||||
int i;
|
||||
|
||||
initialize_ll_merge();
|
||||
|
||||
if (ATTR_TRUE(merge_attr))
|
||||
return &ll_merge_drv[LL_TEXT_MERGE];
|
||||
else if (ATTR_FALSE(merge_attr))
|
||||
return &ll_merge_drv[LL_BINARY_MERGE];
|
||||
else if (ATTR_UNSET(merge_attr)) {
|
||||
if (!default_ll_merge)
|
||||
return &ll_merge_drv[LL_TEXT_MERGE];
|
||||
else
|
||||
name = default_ll_merge;
|
||||
}
|
||||
else
|
||||
name = merge_attr;
|
||||
|
||||
for (fn = ll_user_merge; fn; fn = fn->next)
|
||||
if (!strcmp(fn->name, name))
|
||||
return fn;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(ll_merge_drv); i++)
|
||||
if (!strcmp(ll_merge_drv[i].name, name))
|
||||
return &ll_merge_drv[i];
|
||||
|
||||
/* default to the 3-way */
|
||||
return &ll_merge_drv[LL_TEXT_MERGE];
|
||||
}
|
||||
|
||||
static const char *git_path_check_merge(const char *path)
|
||||
{
|
||||
static struct git_attr_check attr_merge_check;
|
||||
|
||||
if (!attr_merge_check.attr)
|
||||
attr_merge_check.attr = git_attr("merge", 5);
|
||||
|
||||
if (git_checkattr(path, 1, &attr_merge_check))
|
||||
return NULL;
|
||||
return attr_merge_check.value;
|
||||
}
|
||||
|
||||
static int ll_merge(mmbuffer_t *result_buf,
|
||||
struct diff_filespec *o,
|
||||
struct diff_filespec *a,
|
||||
struct diff_filespec *b,
|
||||
const char *branch1,
|
||||
const char *branch2)
|
||||
static int merge_3way(mmbuffer_t *result_buf,
|
||||
struct diff_filespec *o,
|
||||
struct diff_filespec *a,
|
||||
struct diff_filespec *b,
|
||||
const char *branch1,
|
||||
const char *branch2)
|
||||
{
|
||||
mmfile_t orig, src1, src2;
|
||||
char *name1, *name2;
|
||||
int merge_status;
|
||||
const char *ll_driver_name;
|
||||
const struct ll_merge_driver *driver;
|
||||
|
||||
name1 = xstrdup(mkpath("%s:%s", branch1, a->path));
|
||||
name2 = xstrdup(mkpath("%s:%s", branch2, b->path));
|
||||
@@ -981,14 +635,9 @@ static int ll_merge(mmbuffer_t *result_buf,
|
||||
fill_mm(a->sha1, &src1);
|
||||
fill_mm(b->sha1, &src2);
|
||||
|
||||
ll_driver_name = git_path_check_merge(a->path);
|
||||
driver = find_ll_merge_driver(ll_driver_name);
|
||||
|
||||
if (index_only && driver->recursive)
|
||||
driver = find_ll_merge_driver(driver->recursive);
|
||||
merge_status = driver->fn(driver, a->path,
|
||||
&orig, &src1, name1, &src2, name2,
|
||||
result_buf);
|
||||
merge_status = ll_merge(result_buf, a->path, &orig,
|
||||
&src1, name1, &src2, name2,
|
||||
index_only);
|
||||
|
||||
free(name1);
|
||||
free(name2);
|
||||
@@ -1029,8 +678,8 @@ static struct merge_file_info merge_file(struct diff_filespec *o,
|
||||
mmbuffer_t result_buf;
|
||||
int merge_status;
|
||||
|
||||
merge_status = ll_merge(&result_buf, o, a, b,
|
||||
branch1, branch2);
|
||||
merge_status = merge_3way(&result_buf, o, a, b,
|
||||
branch1, branch2);
|
||||
|
||||
if ((merge_status < 0) || !result_buf.ptr)
|
||||
die("Failed to execute internal merge");
|
||||
|
||||
@@ -102,6 +102,8 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
|
||||
|
||||
memset(&opts, 0, sizeof(opts));
|
||||
opts.head_idx = -1;
|
||||
opts.src_index = &the_index;
|
||||
opts.dst_index = &the_index;
|
||||
|
||||
git_config(git_default_config);
|
||||
|
||||
@@ -220,27 +222,6 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
|
||||
if ((opts.dir && !opts.update))
|
||||
die("--exclude-per-directory is meaningless unless -u");
|
||||
|
||||
if (opts.prefix) {
|
||||
int pfxlen = strlen(opts.prefix);
|
||||
int pos;
|
||||
if (opts.prefix[pfxlen-1] != '/')
|
||||
die("prefix must end with /");
|
||||
if (stage != 2)
|
||||
die("binding merge takes only one tree");
|
||||
pos = cache_name_pos(opts.prefix, pfxlen);
|
||||
if (0 <= pos)
|
||||
die("corrupt index file");
|
||||
pos = -pos-1;
|
||||
if (pos < active_nr &&
|
||||
!strncmp(active_cache[pos]->name, opts.prefix, pfxlen))
|
||||
die("subdirectory '%s' already exists.", opts.prefix);
|
||||
pos = cache_name_pos(opts.prefix, pfxlen-1);
|
||||
if (0 <= pos)
|
||||
die("file '%.*s' already exists.",
|
||||
pfxlen-1, opts.prefix);
|
||||
opts.pos = -1 - pos;
|
||||
}
|
||||
|
||||
if (opts.merge) {
|
||||
if (stage < 2)
|
||||
die("just how do you expect me to merge %d trees?", stage-1);
|
||||
|
||||
605
builtin-remote.c
Normal file
605
builtin-remote.c
Normal file
@@ -0,0 +1,605 @@
|
||||
#include "cache.h"
|
||||
#include "parse-options.h"
|
||||
#include "transport.h"
|
||||
#include "remote.h"
|
||||
#include "path-list.h"
|
||||
#include "strbuf.h"
|
||||
#include "run-command.h"
|
||||
#include "refs.h"
|
||||
|
||||
static const char * const builtin_remote_usage[] = {
|
||||
"git remote",
|
||||
"git remote add <name> <url>",
|
||||
"git remote rm <name>",
|
||||
"git remote show <name>",
|
||||
"git remote prune <name>",
|
||||
"git remote update [group]",
|
||||
NULL
|
||||
};
|
||||
|
||||
static int verbose;
|
||||
|
||||
static inline int postfixcmp(const char *string, const char *postfix)
|
||||
{
|
||||
int len1 = strlen(string), len2 = strlen(postfix);
|
||||
if (len1 < len2)
|
||||
return 1;
|
||||
return strcmp(string + len1 - len2, postfix);
|
||||
}
|
||||
|
||||
static inline const char *skip_prefix(const char *name, const char *prefix)
|
||||
{
|
||||
return !name ? "" :
|
||||
prefixcmp(name, prefix) ? name : name + strlen(prefix);
|
||||
}
|
||||
|
||||
static int opt_parse_track(const struct option *opt, const char *arg, int not)
|
||||
{
|
||||
struct path_list *list = opt->value;
|
||||
if (not)
|
||||
path_list_clear(list, 0);
|
||||
else
|
||||
path_list_append(arg, list);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int fetch_remote(const char *name)
|
||||
{
|
||||
const char *argv[] = { "fetch", name, NULL };
|
||||
printf("Updating %s\n", name);
|
||||
if (run_command_v_opt(argv, RUN_GIT_CMD))
|
||||
return error("Could not fetch %s", name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int add(int argc, const char **argv)
|
||||
{
|
||||
int fetch = 0, mirror = 0;
|
||||
struct path_list track = { NULL, 0, 0 };
|
||||
const char *master = NULL;
|
||||
struct remote *remote;
|
||||
struct strbuf buf, buf2;
|
||||
const char *name, *url;
|
||||
int i;
|
||||
|
||||
struct option options[] = {
|
||||
OPT_GROUP("add specific options"),
|
||||
OPT_BOOLEAN('f', "fetch", &fetch, "fetch the remote branches"),
|
||||
OPT_CALLBACK('t', "track", &track, "branch",
|
||||
"branch(es) to track", opt_parse_track),
|
||||
OPT_STRING('m', "master", &master, "branch", "master branch"),
|
||||
OPT_BOOLEAN(0, "mirror", &mirror, "no separate remotes"),
|
||||
OPT_END()
|
||||
};
|
||||
|
||||
argc = parse_options(argc, argv, options, builtin_remote_usage, 0);
|
||||
|
||||
if (argc < 2)
|
||||
usage_with_options(builtin_remote_usage, options);
|
||||
|
||||
name = argv[0];
|
||||
url = argv[1];
|
||||
|
||||
remote = remote_get(name);
|
||||
if (remote && (remote->url_nr > 1 || strcmp(name, remote->url[0]) ||
|
||||
remote->fetch_refspec_nr))
|
||||
die("remote %s already exists.", name);
|
||||
|
||||
strbuf_init(&buf, 0);
|
||||
strbuf_init(&buf2, 0);
|
||||
|
||||
strbuf_addf(&buf, "remote.%s.url", name);
|
||||
if (git_config_set(buf.buf, url))
|
||||
return 1;
|
||||
|
||||
if (track.nr == 0)
|
||||
path_list_append("*", &track);
|
||||
for (i = 0; i < track.nr; i++) {
|
||||
struct path_list_item *item = track.items + i;
|
||||
|
||||
strbuf_reset(&buf);
|
||||
strbuf_addf(&buf, "remote.%s.fetch", name);
|
||||
|
||||
strbuf_reset(&buf2);
|
||||
if (mirror)
|
||||
strbuf_addf(&buf2, "refs/%s:refs/%s",
|
||||
item->path, item->path);
|
||||
else
|
||||
strbuf_addf(&buf2, "refs/heads/%s:refs/remotes/%s/%s",
|
||||
item->path, name, item->path);
|
||||
if (git_config_set_multivar(buf.buf, buf2.buf, "^$", 0))
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (fetch && fetch_remote(name))
|
||||
return 1;
|
||||
|
||||
if (master) {
|
||||
strbuf_reset(&buf);
|
||||
strbuf_addf(&buf, "refs/remotes/%s/HEAD", name);
|
||||
|
||||
strbuf_reset(&buf2);
|
||||
strbuf_addf(&buf2, "refs/remotes/%s/%s", name, master);
|
||||
|
||||
if (create_symref(buf.buf, buf2.buf, "remote add"))
|
||||
return error("Could not setup master '%s'", master);
|
||||
}
|
||||
|
||||
strbuf_release(&buf);
|
||||
strbuf_release(&buf2);
|
||||
path_list_clear(&track, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct branch_info {
|
||||
char *remote;
|
||||
struct path_list merge;
|
||||
};
|
||||
|
||||
static struct path_list branch_list;
|
||||
|
||||
static int config_read_branches(const char *key, const char *value)
|
||||
{
|
||||
if (!prefixcmp(key, "branch.")) {
|
||||
char *name;
|
||||
struct path_list_item *item;
|
||||
struct branch_info *info;
|
||||
enum { REMOTE, MERGE } type;
|
||||
|
||||
key += 7;
|
||||
if (!postfixcmp(key, ".remote")) {
|
||||
name = xstrndup(key, strlen(key) - 7);
|
||||
type = REMOTE;
|
||||
} else if (!postfixcmp(key, ".merge")) {
|
||||
name = xstrndup(key, strlen(key) - 6);
|
||||
type = MERGE;
|
||||
} else
|
||||
return 0;
|
||||
|
||||
item = path_list_insert(name, &branch_list);
|
||||
|
||||
if (!item->util)
|
||||
item->util = xcalloc(sizeof(struct branch_info), 1);
|
||||
info = item->util;
|
||||
if (type == REMOTE) {
|
||||
if (info->remote)
|
||||
warning("more than one branch.%s", key);
|
||||
info->remote = xstrdup(value);
|
||||
} else {
|
||||
char *space = strchr(value, ' ');
|
||||
value = skip_prefix(value, "refs/heads/");
|
||||
while (space) {
|
||||
char *merge;
|
||||
merge = xstrndup(value, space - value);
|
||||
path_list_append(merge, &info->merge);
|
||||
value = skip_prefix(space + 1, "refs/heads/");
|
||||
space = strchr(value, ' ');
|
||||
}
|
||||
path_list_append(xstrdup(value), &info->merge);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void read_branches(void)
|
||||
{
|
||||
if (branch_list.nr)
|
||||
return;
|
||||
git_config(config_read_branches);
|
||||
sort_path_list(&branch_list);
|
||||
}
|
||||
|
||||
struct ref_states {
|
||||
struct remote *remote;
|
||||
struct strbuf remote_prefix;
|
||||
struct path_list new, stale, tracked;
|
||||
};
|
||||
|
||||
static int handle_one_branch(const char *refname,
|
||||
const unsigned char *sha1, int flags, void *cb_data)
|
||||
{
|
||||
struct ref_states *states = cb_data;
|
||||
struct refspec refspec;
|
||||
|
||||
memset(&refspec, 0, sizeof(refspec));
|
||||
refspec.dst = (char *)refname;
|
||||
if (!remote_find_tracking(states->remote, &refspec)) {
|
||||
struct path_list_item *item;
|
||||
const char *name = skip_prefix(refspec.src, "refs/heads/");
|
||||
if (unsorted_path_list_has_path(&states->tracked, name) ||
|
||||
unsorted_path_list_has_path(&states->new,
|
||||
name))
|
||||
return 0;
|
||||
item = path_list_append(name, &states->stale);
|
||||
item->util = xstrdup(refname);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int get_ref_states(const struct ref *ref, struct ref_states *states)
|
||||
{
|
||||
struct ref *fetch_map = NULL, **tail = &fetch_map;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < states->remote->fetch_refspec_nr; i++)
|
||||
if (get_fetch_map(ref, states->remote->fetch + i, &tail, 1))
|
||||
die("Could not get fetch map for refspec %s",
|
||||
states->remote->fetch_refspec[i]);
|
||||
|
||||
states->new.strdup_paths = states->tracked.strdup_paths = 1;
|
||||
for (ref = fetch_map; ref; ref = ref->next) {
|
||||
struct path_list *target = &states->tracked;
|
||||
unsigned char sha1[20];
|
||||
void *util = NULL;
|
||||
|
||||
if (!ref->peer_ref || read_ref(ref->peer_ref->name, sha1))
|
||||
target = &states->new;
|
||||
else {
|
||||
target = &states->tracked;
|
||||
if (hashcmp(sha1, ref->new_sha1))
|
||||
util = &states;
|
||||
}
|
||||
path_list_append(skip_prefix(ref->name, "refs/heads/"),
|
||||
target)->util = util;
|
||||
}
|
||||
free_refs(fetch_map);
|
||||
|
||||
strbuf_addf(&states->remote_prefix,
|
||||
"refs/remotes/%s/", states->remote->name);
|
||||
for_each_ref(handle_one_branch, states);
|
||||
sort_path_list(&states->stale);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct branches_for_remote {
|
||||
const char *prefix;
|
||||
struct path_list *branches;
|
||||
};
|
||||
|
||||
static int add_branch_for_removal(const char *refname,
|
||||
const unsigned char *sha1, int flags, void *cb_data)
|
||||
{
|
||||
struct branches_for_remote *branches = cb_data;
|
||||
|
||||
if (!prefixcmp(refname, branches->prefix)) {
|
||||
struct path_list_item *item;
|
||||
|
||||
/* make sure that symrefs are deleted */
|
||||
if (flags & REF_ISSYMREF)
|
||||
return unlink(git_path(refname));
|
||||
|
||||
item = path_list_append(refname, branches->branches);
|
||||
item->util = xmalloc(20);
|
||||
hashcpy(item->util, sha1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int remove_branches(struct path_list *branches)
|
||||
{
|
||||
int i, result = 0;
|
||||
for (i = 0; i < branches->nr; i++) {
|
||||
struct path_list_item *item = branches->items + i;
|
||||
const char *refname = item->path;
|
||||
unsigned char *sha1 = item->util;
|
||||
|
||||
if (delete_ref(refname, sha1))
|
||||
result |= error("Could not remove branch %s", refname);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static int rm(int argc, const char **argv)
|
||||
{
|
||||
struct option options[] = {
|
||||
OPT_END()
|
||||
};
|
||||
struct remote *remote;
|
||||
struct strbuf buf;
|
||||
struct path_list branches = { NULL, 0, 0, 1 };
|
||||
struct branches_for_remote cb_data = { NULL, &branches };
|
||||
int i;
|
||||
|
||||
if (argc != 2)
|
||||
usage_with_options(builtin_remote_usage, options);
|
||||
|
||||
remote = remote_get(argv[1]);
|
||||
if (!remote)
|
||||
die("No such remote: %s", argv[1]);
|
||||
|
||||
strbuf_init(&buf, 0);
|
||||
strbuf_addf(&buf, "remote.%s", remote->name);
|
||||
if (git_config_rename_section(buf.buf, NULL) < 1)
|
||||
return error("Could not remove config section '%s'", buf.buf);
|
||||
|
||||
read_branches();
|
||||
for (i = 0; i < branch_list.nr; i++) {
|
||||
struct path_list_item *item = branch_list.items + i;
|
||||
struct branch_info *info = item->util;
|
||||
if (info->remote && !strcmp(info->remote, remote->name)) {
|
||||
const char *keys[] = { "remote", "merge", NULL }, **k;
|
||||
for (k = keys; *k; k++) {
|
||||
strbuf_reset(&buf);
|
||||
strbuf_addf(&buf, "branch.%s.%s",
|
||||
item->path, *k);
|
||||
if (git_config_set(buf.buf, NULL)) {
|
||||
strbuf_release(&buf);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* We cannot just pass a function to for_each_ref() which deletes
|
||||
* the branches one by one, since for_each_ref() relies on cached
|
||||
* refs, which are invalidated when deleting a branch.
|
||||
*/
|
||||
strbuf_reset(&buf);
|
||||
strbuf_addf(&buf, "refs/remotes/%s/", remote->name);
|
||||
cb_data.prefix = buf.buf;
|
||||
i = for_each_ref(add_branch_for_removal, &cb_data);
|
||||
strbuf_release(&buf);
|
||||
|
||||
if (!i)
|
||||
i = remove_branches(&branches);
|
||||
path_list_clear(&branches, 1);
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
static void show_list(const char *title, struct path_list *list)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (!list->nr)
|
||||
return;
|
||||
|
||||
printf(title, list->nr > 1 ? "es" : "");
|
||||
printf("\n ");
|
||||
for (i = 0; i < list->nr; i++)
|
||||
printf("%s%s", i ? " " : "", list->items[i].path);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
static int show_or_prune(int argc, const char **argv, int prune)
|
||||
{
|
||||
int dry_run = 0, result = 0;
|
||||
struct option options[] = {
|
||||
OPT_GROUP("show specific options"),
|
||||
OPT__DRY_RUN(&dry_run),
|
||||
OPT_END()
|
||||
};
|
||||
struct ref_states states;
|
||||
|
||||
argc = parse_options(argc, argv, options, builtin_remote_usage, 0);
|
||||
|
||||
if (argc < 1)
|
||||
usage_with_options(builtin_remote_usage, options);
|
||||
|
||||
memset(&states, 0, sizeof(states));
|
||||
for (; argc; argc--, argv++) {
|
||||
struct transport *transport;
|
||||
const struct ref *ref;
|
||||
struct strbuf buf;
|
||||
int i, got_states;
|
||||
|
||||
states.remote = remote_get(*argv);
|
||||
if (!states.remote)
|
||||
return error("No such remote: %s", *argv);
|
||||
transport = transport_get(NULL, states.remote->url_nr > 0 ?
|
||||
states.remote->url[0] : NULL);
|
||||
ref = transport_get_remote_refs(transport);
|
||||
transport_disconnect(transport);
|
||||
|
||||
read_branches();
|
||||
got_states = get_ref_states(ref, &states);
|
||||
if (got_states)
|
||||
result = error("Error getting local info for '%s'",
|
||||
states.remote->name);
|
||||
|
||||
if (prune) {
|
||||
struct strbuf buf;
|
||||
int prefix_len;
|
||||
|
||||
strbuf_init(&buf, 0);
|
||||
if (states.remote->fetch_refspec_nr == 1 &&
|
||||
states.remote->fetch->pattern &&
|
||||
!strcmp(states.remote->fetch->src,
|
||||
states.remote->fetch->dst))
|
||||
/* handle --mirror remote */
|
||||
strbuf_addstr(&buf, "refs/heads/");
|
||||
else
|
||||
strbuf_addf(&buf, "refs/remotes/%s/", *argv);
|
||||
prefix_len = buf.len;
|
||||
|
||||
for (i = 0; i < states.stale.nr; i++) {
|
||||
strbuf_setlen(&buf, prefix_len);
|
||||
strbuf_addstr(&buf, states.stale.items[i].path);
|
||||
result |= delete_ref(buf.buf, NULL);
|
||||
}
|
||||
|
||||
strbuf_release(&buf);
|
||||
goto cleanup_states;
|
||||
}
|
||||
|
||||
printf("* remote %s\n URL: %s\n", *argv,
|
||||
states.remote->url_nr > 0 ?
|
||||
states.remote->url[0] : "(no URL)");
|
||||
|
||||
for (i = 0; i < branch_list.nr; i++) {
|
||||
struct path_list_item *branch = branch_list.items + i;
|
||||
struct branch_info *info = branch->util;
|
||||
int j;
|
||||
|
||||
if (!info->merge.nr || strcmp(*argv, info->remote))
|
||||
continue;
|
||||
printf(" Remote branch%s merged with 'git pull' "
|
||||
"while on branch %s\n ",
|
||||
info->merge.nr > 1 ? "es" : "",
|
||||
branch->path);
|
||||
for (j = 0; j < info->merge.nr; j++)
|
||||
printf(" %s", info->merge.items[j].path);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
if (got_states)
|
||||
continue;
|
||||
strbuf_init(&buf, 0);
|
||||
strbuf_addf(&buf, " New remote branch%%s (next fetch will "
|
||||
"store in remotes/%s)", states.remote->name);
|
||||
show_list(buf.buf, &states.new);
|
||||
strbuf_release(&buf);
|
||||
show_list(" Stale tracking branch%s (use 'git remote prune')",
|
||||
&states.stale);
|
||||
show_list(" Tracked remote branch%s",
|
||||
&states.tracked);
|
||||
|
||||
if (states.remote->push_refspec_nr) {
|
||||
printf(" Local branch%s pushed with 'git push'\n ",
|
||||
states.remote->push_refspec_nr > 1 ?
|
||||
"es" : "");
|
||||
for (i = 0; i < states.remote->push_refspec_nr; i++) {
|
||||
struct refspec *spec = states.remote->push + i;
|
||||
printf(" %s%s%s%s", spec->force ? "+" : "",
|
||||
skip_prefix(spec->src, "refs/heads/"),
|
||||
spec->dst ? ":" : "",
|
||||
skip_prefix(spec->dst, "refs/heads/"));
|
||||
}
|
||||
}
|
||||
cleanup_states:
|
||||
/* NEEDSWORK: free remote */
|
||||
path_list_clear(&states.new, 0);
|
||||
path_list_clear(&states.stale, 0);
|
||||
path_list_clear(&states.tracked, 0);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static int get_one_remote_for_update(struct remote *remote, void *priv)
|
||||
{
|
||||
struct path_list *list = priv;
|
||||
if (!remote->skip_default_update)
|
||||
path_list_append(xstrdup(remote->name), list);
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct remote_group {
|
||||
const char *name;
|
||||
struct path_list *list;
|
||||
} remote_group;
|
||||
|
||||
static int get_remote_group(const char *key, const char *value)
|
||||
{
|
||||
if (!prefixcmp(key, "remotes.") &&
|
||||
!strcmp(key + 8, remote_group.name)) {
|
||||
/* split list by white space */
|
||||
int space = strcspn(value, " \t\n");
|
||||
while (*value) {
|
||||
if (space > 1)
|
||||
path_list_append(xstrndup(value, space),
|
||||
remote_group.list);
|
||||
value += space + (value[space] != '\0');
|
||||
space = strcspn(value, " \t\n");
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int update(int argc, const char **argv)
|
||||
{
|
||||
int i, result = 0;
|
||||
struct path_list list = { NULL, 0, 0, 0 };
|
||||
static const char *default_argv[] = { NULL, "default", NULL };
|
||||
|
||||
if (argc < 2) {
|
||||
argc = 2;
|
||||
argv = default_argv;
|
||||
}
|
||||
|
||||
remote_group.list = &list;
|
||||
for (i = 1; i < argc; i++) {
|
||||
remote_group.name = argv[i];
|
||||
result = git_config(get_remote_group);
|
||||
}
|
||||
|
||||
if (!result && !list.nr && argc == 2 && !strcmp(argv[1], "default"))
|
||||
result = for_each_remote(get_one_remote_for_update, &list);
|
||||
|
||||
for (i = 0; i < list.nr; i++)
|
||||
result |= fetch_remote(list.items[i].path);
|
||||
|
||||
/* all names were strdup()ed or strndup()ed */
|
||||
list.strdup_paths = 1;
|
||||
path_list_clear(&list, 0);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static int get_one_entry(struct remote *remote, void *priv)
|
||||
{
|
||||
struct path_list *list = priv;
|
||||
|
||||
path_list_append(remote->name, list)->util = remote->url_nr ?
|
||||
(void *)remote->url[0] : NULL;
|
||||
if (remote->url_nr > 1)
|
||||
warning("Remote %s has more than one URL", remote->name);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int show_all(void)
|
||||
{
|
||||
struct path_list list = { NULL, 0, 0 };
|
||||
int result = for_each_remote(get_one_entry, &list);
|
||||
|
||||
if (!result) {
|
||||
int i;
|
||||
|
||||
sort_path_list(&list);
|
||||
for (i = 0; i < list.nr; i++) {
|
||||
struct path_list_item *item = list.items + i;
|
||||
printf("%s%s%s\n", item->path,
|
||||
verbose ? "\t" : "",
|
||||
verbose && item->util ?
|
||||
(const char *)item->util : "");
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int cmd_remote(int argc, const char **argv, const char *prefix)
|
||||
{
|
||||
struct option options[] = {
|
||||
OPT__VERBOSE(&verbose),
|
||||
OPT_END()
|
||||
};
|
||||
int result;
|
||||
|
||||
argc = parse_options(argc, argv, options, builtin_remote_usage,
|
||||
PARSE_OPT_STOP_AT_NON_OPTION);
|
||||
|
||||
if (argc < 1)
|
||||
result = show_all();
|
||||
else if (!strcmp(argv[0], "add"))
|
||||
result = add(argc, argv);
|
||||
else if (!strcmp(argv[0], "rm"))
|
||||
result = rm(argc, argv);
|
||||
else if (!strcmp(argv[0], "show"))
|
||||
result = show_or_prune(argc, argv, 0);
|
||||
else if (!strcmp(argv[0], "prune"))
|
||||
result = show_or_prune(argc, argv, 1);
|
||||
else if (!strcmp(argv[0], "update"))
|
||||
result = update(argc, argv);
|
||||
else {
|
||||
error("Unknown subcommand: %s", argv[0]);
|
||||
usage_with_options(builtin_remote_usage, options);
|
||||
}
|
||||
|
||||
return result ? 1 : 0;
|
||||
}
|
||||
@@ -50,12 +50,15 @@ void launch_editor(const char *path, struct strbuf *buffer, const char *const *e
|
||||
size_t len = strlen(editor);
|
||||
int i = 0;
|
||||
const char *args[6];
|
||||
struct strbuf arg0;
|
||||
|
||||
strbuf_init(&arg0, 0);
|
||||
if (strcspn(editor, "$ \t'") != len) {
|
||||
/* there are specials */
|
||||
strbuf_addf(&arg0, "%s \"$@\"", editor);
|
||||
args[i++] = "sh";
|
||||
args[i++] = "-c";
|
||||
args[i++] = "$0 \"$@\"";
|
||||
args[i++] = arg0.buf;
|
||||
}
|
||||
args[i++] = editor;
|
||||
args[i++] = path;
|
||||
@@ -63,6 +66,7 @@ void launch_editor(const char *path, struct strbuf *buffer, const char *const *e
|
||||
|
||||
if (run_command_v_opt_cd_env(args, 0, NULL, env))
|
||||
die("There was a problem with the editor %s.", editor);
|
||||
strbuf_release(&arg0);
|
||||
}
|
||||
|
||||
if (!buffer)
|
||||
|
||||
@@ -67,6 +67,7 @@ extern int cmd_prune_packed(int argc, const char **argv, const char *prefix);
|
||||
extern int cmd_push(int argc, const char **argv, const char *prefix);
|
||||
extern int cmd_read_tree(int argc, const char **argv, const char *prefix);
|
||||
extern int cmd_reflog(int argc, const char **argv, const char *prefix);
|
||||
extern int cmd_remote(int argc, const char **argv, const char *prefix);
|
||||
extern int cmd_config(int argc, const char **argv, const char *prefix);
|
||||
extern int cmd_rerere(int argc, const char **argv, const char *prefix);
|
||||
extern int cmd_reset(int argc, const char **argv, const char *prefix);
|
||||
|
||||
14
cache.h
14
cache.h
@@ -346,12 +346,12 @@ extern void verify_non_filename(const char *prefix, const char *name);
|
||||
/* Initialize and use the cache information */
|
||||
extern int read_index(struct index_state *);
|
||||
extern int read_index_from(struct index_state *, const char *path);
|
||||
extern int write_index(struct index_state *, int newfd);
|
||||
extern int write_index(const struct index_state *, int newfd);
|
||||
extern int discard_index(struct index_state *);
|
||||
extern int unmerged_index(struct index_state *);
|
||||
extern int unmerged_index(const struct index_state *);
|
||||
extern int verify_path(const char *path);
|
||||
extern int index_name_exists(struct index_state *istate, const char *name, int namelen);
|
||||
extern int index_name_pos(struct index_state *, const char *name, int namelen);
|
||||
extern int index_name_pos(const struct index_state *, const char *name, int namelen);
|
||||
#define ADD_CACHE_OK_TO_ADD 1 /* Ok to add */
|
||||
#define ADD_CACHE_OK_TO_REPLACE 2 /* Ok to replace file/directory */
|
||||
#define ADD_CACHE_SKIP_DFCHECK 4 /* Ok to skip DF conflict checks */
|
||||
@@ -368,8 +368,8 @@ extern int ce_same_name(struct cache_entry *a, struct cache_entry *b);
|
||||
#define CE_MATCH_IGNORE_VALID 01
|
||||
/* do not check the contents but report dirty on racily-clean entries */
|
||||
#define CE_MATCH_RACY_IS_DIRTY 02
|
||||
extern int ie_match_stat(struct index_state *, struct cache_entry *, struct stat *, unsigned int);
|
||||
extern int ie_modified(struct index_state *, struct cache_entry *, struct stat *, unsigned int);
|
||||
extern int ie_match_stat(const struct index_state *, struct cache_entry *, struct stat *, unsigned int);
|
||||
extern int ie_modified(const struct index_state *, struct cache_entry *, struct stat *, unsigned int);
|
||||
|
||||
extern int ce_path_match(const struct cache_entry *ce, const char **pathspec);
|
||||
extern int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object, enum object_type type, const char *path);
|
||||
@@ -536,6 +536,7 @@ extern int create_symref(const char *ref, const char *refs_heads_master, const c
|
||||
extern int validate_headref(const char *ref);
|
||||
|
||||
extern int base_name_compare(const char *name1, int len1, int mode1, const char *name2, int len2, int mode2);
|
||||
extern int df_name_compare(const char *name1, int len1, int mode1, const char *name2, int len2, int mode2);
|
||||
extern int cache_name_compare(const char *name1, int len1, const char *name2, int len2);
|
||||
|
||||
extern void *read_object_with_reference(const unsigned char *sha1,
|
||||
@@ -543,6 +544,9 @@ extern void *read_object_with_reference(const unsigned char *sha1,
|
||||
unsigned long *size,
|
||||
unsigned char *sha1_ret);
|
||||
|
||||
extern struct object *peel_to_type(const char *name, int namelen,
|
||||
struct object *o, enum object_type);
|
||||
|
||||
enum date_mode {
|
||||
DATE_NORMAL = 0,
|
||||
DATE_RELATIVE,
|
||||
|
||||
@@ -83,17 +83,17 @@ __git_ps1 ()
|
||||
elif [ -f "$g/.dotest-merge/interactive" ]
|
||||
then
|
||||
r="|REBASE-i"
|
||||
b="$(cat $g/.dotest-merge/head-name)"
|
||||
b="$(cat "$g/.dotest-merge/head-name")"
|
||||
elif [ -d "$g/.dotest-merge" ]
|
||||
then
|
||||
r="|REBASE-m"
|
||||
b="$(cat $g/.dotest-merge/head-name)"
|
||||
b="$(cat "$g/.dotest-merge/head-name")"
|
||||
elif [ -f "$g/MERGE_HEAD" ]
|
||||
then
|
||||
r="|MERGING"
|
||||
b="$(git symbolic-ref HEAD 2>/dev/null)"
|
||||
else
|
||||
if [ -f $g/BISECT_LOG ]
|
||||
if [ -f "$g/BISECT_LOG" ]
|
||||
then
|
||||
r="|BISECTING"
|
||||
fi
|
||||
@@ -101,7 +101,7 @@ __git_ps1 ()
|
||||
then
|
||||
if ! b="$(git describe --exact-match HEAD 2>/dev/null)"
|
||||
then
|
||||
b="$(cut -c1-7 $g/HEAD)..."
|
||||
b="$(cut -c1-7 "$g/HEAD")..."
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
@@ -121,13 +121,21 @@ __gitcomp ()
|
||||
if [ $# -gt 2 ]; then
|
||||
cur="$3"
|
||||
fi
|
||||
for c in $1; do
|
||||
case "$c$4" in
|
||||
--*=*) all="$all$c$4$s" ;;
|
||||
*.) all="$all$c$4$s" ;;
|
||||
*) all="$all$c$4 $s" ;;
|
||||
esac
|
||||
done
|
||||
case "$cur" in
|
||||
--*=)
|
||||
COMPREPLY=()
|
||||
return
|
||||
;;
|
||||
*)
|
||||
for c in $1; do
|
||||
case "$c$4" in
|
||||
--*=*) all="$all$c$4$s" ;;
|
||||
*.) all="$all$c$4$s" ;;
|
||||
*) all="$all$c$4 $s" ;;
|
||||
esac
|
||||
done
|
||||
;;
|
||||
esac
|
||||
IFS=$s
|
||||
COMPREPLY=($(compgen -P "$2" -W "$all" -- "$cur"))
|
||||
return
|
||||
@@ -384,7 +392,6 @@ __git_commands ()
|
||||
show-index) : plumbing;;
|
||||
ssh-*) : transport;;
|
||||
stripspace) : plumbing;;
|
||||
svn) : import export;;
|
||||
symbolic-ref) : plumbing;;
|
||||
tar-tree) : deprecated;;
|
||||
unpack-file) : plumbing;;
|
||||
@@ -428,6 +435,22 @@ __git_aliased_command ()
|
||||
done
|
||||
}
|
||||
|
||||
__git_find_subcommand ()
|
||||
{
|
||||
local word subcommand c=1
|
||||
|
||||
while [ $c -lt $COMP_CWORD ]; do
|
||||
word="${COMP_WORDS[c]}"
|
||||
for subcommand in $1; do
|
||||
if [ "$subcommand" = "$word" ]; then
|
||||
echo "$subcommand"
|
||||
return
|
||||
fi
|
||||
done
|
||||
c=$((++c))
|
||||
done
|
||||
}
|
||||
|
||||
__git_whitespacelist="nowarn warn error error-all strip"
|
||||
|
||||
_git_am ()
|
||||
@@ -485,24 +508,14 @@ _git_add ()
|
||||
|
||||
_git_bisect ()
|
||||
{
|
||||
local i c=1 command
|
||||
while [ $c -lt $COMP_CWORD ]; do
|
||||
i="${COMP_WORDS[c]}"
|
||||
case "$i" in
|
||||
start|bad|good|reset|visualize|replay|log)
|
||||
command="$i"
|
||||
break
|
||||
;;
|
||||
esac
|
||||
c=$((++c))
|
||||
done
|
||||
|
||||
if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
|
||||
__gitcomp "start bad good reset visualize replay log"
|
||||
local subcommands="start bad good reset visualize replay log"
|
||||
local subcommand="$(__git_find_subcommand "$subcommands")"
|
||||
if [ -z "$subcommand" ]; then
|
||||
__gitcomp "$subcommands"
|
||||
return
|
||||
fi
|
||||
|
||||
case "$command" in
|
||||
case "$subcommand" in
|
||||
bad|good|reset)
|
||||
__gitcomp "$(__git_refs)"
|
||||
;;
|
||||
@@ -836,8 +849,8 @@ _git_push ()
|
||||
|
||||
_git_rebase ()
|
||||
{
|
||||
local cur="${COMP_WORDS[COMP_CWORD]}"
|
||||
if [ -d .dotest ] || [ -d .git/.dotest-merge ]; then
|
||||
local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
|
||||
if [ -d .dotest ] || [ -d "$dir"/.dotest-merge ]; then
|
||||
__gitcomp "--continue --skip --abort"
|
||||
return
|
||||
fi
|
||||
@@ -956,7 +969,6 @@ _git_config ()
|
||||
core.sharedRepository
|
||||
core.warnAmbiguousRefs
|
||||
core.compression
|
||||
core.legacyHeaders
|
||||
core.packedGitWindowSize
|
||||
core.packedGitLimit
|
||||
clean.requireForce
|
||||
@@ -1033,21 +1045,13 @@ _git_config ()
|
||||
|
||||
_git_remote ()
|
||||
{
|
||||
local i c=1 command
|
||||
while [ $c -lt $COMP_CWORD ]; do
|
||||
i="${COMP_WORDS[c]}"
|
||||
case "$i" in
|
||||
add|rm|show|prune|update) command="$i"; break ;;
|
||||
esac
|
||||
c=$((++c))
|
||||
done
|
||||
|
||||
if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
|
||||
__gitcomp "add rm show prune update"
|
||||
local subcommands="add rm show prune update"
|
||||
local subcommand="$(__git_find_subcommand "$subcommands")"
|
||||
if [ -z "$subcommand" ]; then
|
||||
return
|
||||
fi
|
||||
|
||||
case "$command" in
|
||||
case "$subcommand" in
|
||||
rm|show|prune)
|
||||
__gitcomp "$(__git_remotes)"
|
||||
;;
|
||||
@@ -1121,34 +1125,107 @@ _git_show ()
|
||||
|
||||
_git_stash ()
|
||||
{
|
||||
__gitcomp 'list show apply clear'
|
||||
local subcommands='save list show apply clear drop pop create'
|
||||
if [ -z "$(__git_find_subcommand "$subcommands")" ]; then
|
||||
__gitcomp "$subcommands"
|
||||
fi
|
||||
}
|
||||
|
||||
_git_submodule ()
|
||||
{
|
||||
local i c=1 command
|
||||
while [ $c -lt $COMP_CWORD ]; do
|
||||
i="${COMP_WORDS[c]}"
|
||||
case "$i" in
|
||||
add|status|init|update) command="$i"; break ;;
|
||||
esac
|
||||
c=$((++c))
|
||||
done
|
||||
|
||||
if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
|
||||
local subcommands="add status init update"
|
||||
if [ -z "$(__git_find_subcommand "$subcommands")" ]; then
|
||||
local cur="${COMP_WORDS[COMP_CWORD]}"
|
||||
case "$cur" in
|
||||
--*)
|
||||
__gitcomp "--quiet --cached"
|
||||
;;
|
||||
*)
|
||||
__gitcomp "add status init update"
|
||||
__gitcomp "$subcommands"
|
||||
;;
|
||||
esac
|
||||
return
|
||||
fi
|
||||
}
|
||||
|
||||
_git_svn ()
|
||||
{
|
||||
local subcommands="
|
||||
init fetch clone rebase dcommit log find-rev
|
||||
set-tree commit-diff info create-ignore propget
|
||||
proplist show-ignore show-externals
|
||||
"
|
||||
local subcommand="$(__git_find_subcommand "$subcommands")"
|
||||
if [ -z "$subcommand" ]; then
|
||||
__gitcomp "$subcommands"
|
||||
else
|
||||
local remote_opts="--username= --config-dir= --no-auth-cache"
|
||||
local fc_opts="
|
||||
--follow-parent --authors-file= --repack=
|
||||
--no-metadata --use-svm-props --use-svnsync-props
|
||||
--log-window-size= --no-checkout --quiet
|
||||
--repack-flags --user-log-author $remote_opts
|
||||
"
|
||||
local init_opts="
|
||||
--template= --shared= --trunk= --tags=
|
||||
--branches= --stdlayout --minimize-url
|
||||
--no-metadata --use-svm-props --use-svnsync-props
|
||||
--rewrite-root= $remote_opts
|
||||
"
|
||||
local cmt_opts="
|
||||
--edit --rmdir --find-copies-harder --copy-similarity=
|
||||
"
|
||||
|
||||
local cur="${COMP_WORDS[COMP_CWORD]}"
|
||||
case "$subcommand,$cur" in
|
||||
fetch,--*)
|
||||
__gitcomp "--revision= --fetch-all $fc_opts"
|
||||
;;
|
||||
clone,--*)
|
||||
__gitcomp "--revision= $fc_opts $init_opts"
|
||||
;;
|
||||
init,--*)
|
||||
__gitcomp "$init_opts"
|
||||
;;
|
||||
dcommit,--*)
|
||||
__gitcomp "
|
||||
--merge --strategy= --verbose --dry-run
|
||||
--fetch-all --no-rebase $cmt_opts $fc_opts
|
||||
"
|
||||
;;
|
||||
set-tree,--*)
|
||||
__gitcomp "--stdin $cmt_opts $fc_opts"
|
||||
;;
|
||||
create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
|
||||
show-externals,--*)
|
||||
__gitcomp "--revision="
|
||||
;;
|
||||
log,--*)
|
||||
__gitcomp "
|
||||
--limit= --revision= --verbose --incremental
|
||||
--oneline --show-commit --non-recursive
|
||||
--authors-file=
|
||||
"
|
||||
;;
|
||||
rebase,--*)
|
||||
__gitcomp "
|
||||
--merge --verbose --strategy= --local
|
||||
--fetch-all $fc_opts
|
||||
"
|
||||
;;
|
||||
commit-diff,--*)
|
||||
__gitcomp "--message= --file= --revision= $cmt_opts"
|
||||
;;
|
||||
info,--*)
|
||||
__gitcomp "--url"
|
||||
;;
|
||||
*)
|
||||
COMPREPLY=()
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
}
|
||||
|
||||
_git_tag ()
|
||||
{
|
||||
local i c=1 f=0
|
||||
@@ -1198,15 +1275,18 @@ _git ()
|
||||
c=$((++c))
|
||||
done
|
||||
|
||||
if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
|
||||
if [ -z "$command" ]; then
|
||||
case "${COMP_WORDS[COMP_CWORD]}" in
|
||||
--*=*) COMPREPLY=() ;;
|
||||
--*) __gitcomp "
|
||||
--paginate
|
||||
--no-pager
|
||||
--git-dir=
|
||||
--bare
|
||||
--version
|
||||
--exec-path
|
||||
--work-tree=
|
||||
--help
|
||||
"
|
||||
;;
|
||||
*) __gitcomp "$(__git_commands) $(__git_aliases)" ;;
|
||||
@@ -1250,6 +1330,7 @@ _git ()
|
||||
show-branch) _git_log ;;
|
||||
stash) _git_stash ;;
|
||||
submodule) _git_submodule ;;
|
||||
svn) _git_svn ;;
|
||||
tag) _git_tag ;;
|
||||
whatchanged) _git_log ;;
|
||||
*) COMPREPLY=() ;;
|
||||
@@ -1300,6 +1381,7 @@ complete -o default -o nospace -F _git_shortlog git-shortlog
|
||||
complete -o default -o nospace -F _git_show git-show
|
||||
complete -o default -o nospace -F _git_stash git-stash
|
||||
complete -o default -o nospace -F _git_submodule git-submodule
|
||||
complete -o default -o nospace -F _git_svn git-svn
|
||||
complete -o default -o nospace -F _git_log git-show-branch
|
||||
complete -o default -o nospace -F _git_tag git-tag
|
||||
complete -o default -o nospace -F _git_log git-whatchanged
|
||||
|
||||
53
diff-lib.c
53
diff-lib.c
@@ -600,8 +600,7 @@ static void mark_merge_entries(void)
|
||||
*/
|
||||
static void do_oneway_diff(struct unpack_trees_options *o,
|
||||
struct cache_entry *idx,
|
||||
struct cache_entry *tree,
|
||||
int idx_pos, int idx_nr)
|
||||
struct cache_entry *tree)
|
||||
{
|
||||
struct rev_info *revs = o->unpack_data;
|
||||
int match_missing, cached;
|
||||
@@ -642,32 +641,19 @@ static void do_oneway_diff(struct unpack_trees_options *o,
|
||||
show_modified(revs, tree, idx, 1, cached, match_missing);
|
||||
}
|
||||
|
||||
/*
|
||||
* Count how many index entries go with the first one
|
||||
*/
|
||||
static inline int count_skip(const struct cache_entry *src, int pos)
|
||||
static inline void skip_same_name(struct cache_entry *ce, struct unpack_trees_options *o)
|
||||
{
|
||||
int skip = 1;
|
||||
int len = ce_namelen(ce);
|
||||
const struct index_state *index = o->src_index;
|
||||
|
||||
/* We can only have multiple entries if the first one is not stage-0 */
|
||||
if (ce_stage(src)) {
|
||||
struct cache_entry **p = active_cache + pos;
|
||||
int namelen = ce_namelen(src);
|
||||
|
||||
for (;;) {
|
||||
const struct cache_entry *ce;
|
||||
pos++;
|
||||
if (pos >= active_nr)
|
||||
break;
|
||||
ce = *++p;
|
||||
if (ce_namelen(ce) != namelen)
|
||||
break;
|
||||
if (memcmp(ce->name, src->name, namelen))
|
||||
break;
|
||||
skip++;
|
||||
}
|
||||
while (o->pos < index->cache_nr) {
|
||||
struct cache_entry *next = index->cache[o->pos];
|
||||
if (len != ce_namelen(next))
|
||||
break;
|
||||
if (memcmp(ce->name, next->name, len))
|
||||
break;
|
||||
o->pos++;
|
||||
}
|
||||
return skip;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -685,17 +671,14 @@ static inline int count_skip(const struct cache_entry *src, int pos)
|
||||
* the fairly complex unpack_trees() semantic requirements, including
|
||||
* the skipping, the path matching, the type conflict cases etc.
|
||||
*/
|
||||
static int oneway_diff(struct cache_entry **src,
|
||||
struct unpack_trees_options *o,
|
||||
int index_pos)
|
||||
static int oneway_diff(struct cache_entry **src, struct unpack_trees_options *o)
|
||||
{
|
||||
int skip = 0;
|
||||
struct cache_entry *idx = src[0];
|
||||
struct cache_entry *tree = src[1];
|
||||
struct rev_info *revs = o->unpack_data;
|
||||
|
||||
if (index_pos >= 0)
|
||||
skip = count_skip(idx, index_pos);
|
||||
if (idx && ce_stage(idx))
|
||||
skip_same_name(idx, o);
|
||||
|
||||
/*
|
||||
* Unpack-trees generates a DF/conflict entry if
|
||||
@@ -707,9 +690,9 @@ static int oneway_diff(struct cache_entry **src,
|
||||
tree = NULL;
|
||||
|
||||
if (ce_path_match(idx ? idx : tree, revs->prune_data))
|
||||
do_oneway_diff(o, idx, tree, index_pos, skip);
|
||||
do_oneway_diff(o, idx, tree);
|
||||
|
||||
return skip;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int run_diff_index(struct rev_info *revs, int cached)
|
||||
@@ -734,6 +717,8 @@ int run_diff_index(struct rev_info *revs, int cached)
|
||||
opts.merge = 1;
|
||||
opts.fn = oneway_diff;
|
||||
opts.unpack_data = revs;
|
||||
opts.src_index = &the_index;
|
||||
opts.dst_index = NULL;
|
||||
|
||||
init_tree_desc(&t, tree->buffer, tree->size);
|
||||
if (unpack_trees(1, &t, &opts))
|
||||
@@ -787,6 +772,8 @@ int do_diff_cache(const unsigned char *tree_sha1, struct diff_options *opt)
|
||||
opts.merge = 1;
|
||||
opts.fn = oneway_diff;
|
||||
opts.unpack_data = &revs;
|
||||
opts.src_index = &the_index;
|
||||
opts.dst_index = &the_index;
|
||||
|
||||
init_tree_desc(&t, tree->buffer, tree->size);
|
||||
if (unpack_trees(1, &t, &opts))
|
||||
|
||||
@@ -221,14 +221,9 @@ ifdef NO_MSGFMT
|
||||
MSGFMT ?= $(TCL_PATH) po/po2msg.sh
|
||||
else
|
||||
MSGFMT ?= msgfmt
|
||||
ifeq ($(shell $(MSGFMT) >/dev/null 2>&1 || echo $$?),127)
|
||||
ifneq ($(shell $(MSGFMT) --tcl -l C -d . /dev/null 2>/dev/null; echo $$?),0)
|
||||
MSGFMT := $(TCL_PATH) po/po2msg.sh
|
||||
endif
|
||||
ifeq (msgfmt,$(MSGFMT))
|
||||
ifeq ($(shell $(MSGFMT) --tcl -l C -d . /dev/null 2>/dev/null || echo $?),1)
|
||||
MSGFMT := $(TCL_PATH) po/po2msg.sh
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
msgsdir = $(gg_libdir)/msgs
|
||||
|
||||
@@ -611,6 +611,7 @@ set default_config(gui.matchtrackingbranch) false
|
||||
set default_config(gui.pruneduringfetch) false
|
||||
set default_config(gui.trustmtime) false
|
||||
set default_config(gui.diffcontext) 5
|
||||
set default_config(gui.commitmsgwidth) 75
|
||||
set default_config(gui.newbranchtemplate) {}
|
||||
set default_config(gui.spellingdictionary) {}
|
||||
set default_config(gui.fontui) [font configure font_ui]
|
||||
@@ -2289,8 +2290,9 @@ pack .vpane -anchor n -side top -fill both -expand 1
|
||||
#
|
||||
frame .vpane.files.index -height 100 -width 200
|
||||
label .vpane.files.index.title -text [mc "Staged Changes (Will Commit)"] \
|
||||
-background lightgreen
|
||||
text $ui_index -background white -borderwidth 0 \
|
||||
-background lightgreen -foreground black
|
||||
text $ui_index -background white -foreground black \
|
||||
-borderwidth 0 \
|
||||
-width 20 -height 10 \
|
||||
-wrap none \
|
||||
-cursor $cursor_ptr \
|
||||
@@ -2308,8 +2310,9 @@ pack $ui_index -side left -fill both -expand 1
|
||||
#
|
||||
frame .vpane.files.workdir -height 100 -width 200
|
||||
label .vpane.files.workdir.title -text [mc "Unstaged Changes"] \
|
||||
-background lightsalmon
|
||||
text $ui_workdir -background white -borderwidth 0 \
|
||||
-background lightsalmon -foreground black
|
||||
text $ui_workdir -background white -foreground black \
|
||||
-borderwidth 0 \
|
||||
-width 20 -height 10 \
|
||||
-wrap none \
|
||||
-cursor $cursor_ptr \
|
||||
@@ -2416,12 +2419,13 @@ pack $ui_coml -side left -fill x
|
||||
pack .vpane.lower.commarea.buffer.header.amend -side right
|
||||
pack .vpane.lower.commarea.buffer.header.new -side right
|
||||
|
||||
text $ui_comm -background white -borderwidth 1 \
|
||||
text $ui_comm -background white -foreground black \
|
||||
-borderwidth 1 \
|
||||
-undo true \
|
||||
-maxundo 20 \
|
||||
-autoseparators true \
|
||||
-relief sunken \
|
||||
-width 75 -height 9 -wrap none \
|
||||
-width $repo_config(gui.commitmsgwidth) -height 9 -wrap none \
|
||||
-font font_diff \
|
||||
-yscrollcommand {.vpane.lower.commarea.buffer.sby set}
|
||||
scrollbar .vpane.lower.commarea.buffer.sby \
|
||||
@@ -2493,15 +2497,18 @@ trace add variable current_diff_path write trace_current_diff_path
|
||||
frame .vpane.lower.diff.header -background gold
|
||||
label .vpane.lower.diff.header.status \
|
||||
-background gold \
|
||||
-foreground black \
|
||||
-width $max_status_desc \
|
||||
-anchor w \
|
||||
-justify left
|
||||
label .vpane.lower.diff.header.file \
|
||||
-background gold \
|
||||
-foreground black \
|
||||
-anchor w \
|
||||
-justify left
|
||||
label .vpane.lower.diff.header.path \
|
||||
-background gold \
|
||||
-foreground black \
|
||||
-anchor w \
|
||||
-justify left
|
||||
pack .vpane.lower.diff.header.status -side left
|
||||
@@ -2525,7 +2532,8 @@ bind_button3 .vpane.lower.diff.header.path "tk_popup $ctxm %X %Y"
|
||||
#
|
||||
frame .vpane.lower.diff.body
|
||||
set ui_diff .vpane.lower.diff.body.t
|
||||
text $ui_diff -background white -borderwidth 0 \
|
||||
text $ui_diff -background white -foreground black \
|
||||
-borderwidth 0 \
|
||||
-width 80 -height 15 -wrap none \
|
||||
-font font_diff \
|
||||
-xscrollcommand {.vpane.lower.diff.body.sbx set} \
|
||||
|
||||
@@ -80,6 +80,7 @@ constructor new {i_commit i_path} {
|
||||
label $w.header.commit_l \
|
||||
-text [mc "Commit:"] \
|
||||
-background gold \
|
||||
-foreground black \
|
||||
-anchor w \
|
||||
-justify left
|
||||
set w_back $w.header.commit_b
|
||||
@@ -89,6 +90,7 @@ constructor new {i_commit i_path} {
|
||||
-relief flat \
|
||||
-state disabled \
|
||||
-background gold \
|
||||
-foreground black \
|
||||
-activebackground gold
|
||||
bind $w_back <Button-1> "
|
||||
if {\[$w_back cget -state\] eq {normal}} {
|
||||
@@ -98,16 +100,19 @@ constructor new {i_commit i_path} {
|
||||
label $w.header.commit \
|
||||
-textvariable @commit \
|
||||
-background gold \
|
||||
-foreground black \
|
||||
-anchor w \
|
||||
-justify left
|
||||
label $w.header.path_l \
|
||||
-text [mc "File:"] \
|
||||
-background gold \
|
||||
-foreground black \
|
||||
-anchor w \
|
||||
-justify left
|
||||
set w_path $w.header.path
|
||||
label $w_path \
|
||||
-background gold \
|
||||
-foreground black \
|
||||
-anchor w \
|
||||
-justify left
|
||||
pack $w.header.commit_l -side left
|
||||
@@ -135,7 +140,9 @@ constructor new {i_commit i_path} {
|
||||
-takefocus 0 \
|
||||
-highlightthickness 0 \
|
||||
-padx 0 -pady 0 \
|
||||
-background white -borderwidth 0 \
|
||||
-background white \
|
||||
-foreground black \
|
||||
-borderwidth 0 \
|
||||
-state disabled \
|
||||
-wrap none \
|
||||
-height 40 \
|
||||
@@ -148,7 +155,9 @@ constructor new {i_commit i_path} {
|
||||
-takefocus 0 \
|
||||
-highlightthickness 0 \
|
||||
-padx 0 -pady 0 \
|
||||
-background white -borderwidth 0 \
|
||||
-background white \
|
||||
-foreground black \
|
||||
-borderwidth 0 \
|
||||
-state disabled \
|
||||
-wrap none \
|
||||
-height 40 \
|
||||
@@ -166,7 +175,9 @@ constructor new {i_commit i_path} {
|
||||
-takefocus 0 \
|
||||
-highlightthickness 0 \
|
||||
-padx 0 -pady 0 \
|
||||
-background white -borderwidth 0 \
|
||||
-background white \
|
||||
-foreground black \
|
||||
-borderwidth 0 \
|
||||
-state disabled \
|
||||
-wrap none \
|
||||
-height 40 \
|
||||
@@ -184,7 +195,9 @@ constructor new {i_commit i_path} {
|
||||
-takefocus 0 \
|
||||
-highlightthickness 0 \
|
||||
-padx 0 -pady 0 \
|
||||
-background white -borderwidth 0 \
|
||||
-background white \
|
||||
-foreground black \
|
||||
-borderwidth 0 \
|
||||
-state disabled \
|
||||
-wrap none \
|
||||
-height 40 \
|
||||
@@ -213,7 +226,9 @@ constructor new {i_commit i_path} {
|
||||
|
||||
set w_cviewer $w.file_pane.cm.t
|
||||
text $w_cviewer \
|
||||
-background white -borderwidth 0 \
|
||||
-background white \
|
||||
-foreground black \
|
||||
-borderwidth 0 \
|
||||
-state disabled \
|
||||
-wrap none \
|
||||
-height 10 \
|
||||
|
||||
@@ -39,7 +39,8 @@ constructor new {commit {path {}}} {
|
||||
|
||||
frame $w.list
|
||||
set w_list $w.list.l
|
||||
text $w_list -background white -borderwidth 0 \
|
||||
text $w_list -background white -foreground black \
|
||||
-borderwidth 0 \
|
||||
-cursor $cursor_ptr \
|
||||
-state disabled \
|
||||
-wrap none \
|
||||
|
||||
@@ -55,6 +55,7 @@ constructor pick {path title a_family a_size} {
|
||||
set w_family $w.inner.family.v
|
||||
text $w_family \
|
||||
-background white \
|
||||
-foreground black \
|
||||
-borderwidth 1 \
|
||||
-relief sunken \
|
||||
-cursor $::cursor_ptr \
|
||||
@@ -92,6 +93,7 @@ constructor pick {path title a_family a_size} {
|
||||
set w_example $w.example.t
|
||||
text $w_example \
|
||||
-background white \
|
||||
-foreground black \
|
||||
-borderwidth 1 \
|
||||
-relief sunken \
|
||||
-height 3 \
|
||||
|
||||
@@ -46,7 +46,9 @@ method _init {} {
|
||||
-justify left \
|
||||
-font font_uibold
|
||||
text $w_t \
|
||||
-background white -borderwidth 1 \
|
||||
-background white \
|
||||
-foreground black \
|
||||
-borderwidth 1 \
|
||||
-relief sunken \
|
||||
-width 80 -height 10 \
|
||||
-wrap none \
|
||||
@@ -180,7 +182,8 @@ method done {ok} {
|
||||
if {$ok} {
|
||||
if {[winfo exists $w.m.s]} {
|
||||
bind $w.m.s <Destroy> [list delete_this $this]
|
||||
$w.m.s conf -background green -text [mc "Success"]
|
||||
$w.m.s conf -background green -foreground black \
|
||||
-text [mc "Success"]
|
||||
if {$is_toplevel} {
|
||||
$w.ok conf -state normal
|
||||
focus $w.ok
|
||||
@@ -193,7 +196,8 @@ method done {ok} {
|
||||
_init $this
|
||||
}
|
||||
bind $w.m.s <Destroy> [list delete_this $this]
|
||||
$w.m.s conf -background red -text [mc "Error: Command Failed"]
|
||||
$w.m.s conf -background red -foreground black \
|
||||
-text [mc "Error: Command Failed"]
|
||||
if {$is_toplevel} {
|
||||
$w.ok conf -state normal
|
||||
focus $w.ok
|
||||
|
||||
@@ -80,7 +80,9 @@ proc hook_failed_popup {hook msg {is_fatal 1}} {
|
||||
-justify left \
|
||||
-font font_uibold
|
||||
text $w.m.t \
|
||||
-background white -borderwidth 1 \
|
||||
-background white \
|
||||
-foreground black \
|
||||
-borderwidth 1 \
|
||||
-relief sunken \
|
||||
-width 80 -height 10 \
|
||||
-font font_diff \
|
||||
|
||||
@@ -124,6 +124,7 @@ proc do_options {} {
|
||||
{b gui.pruneduringfetch {mc "Prune Tracking Branches During Fetch"}}
|
||||
{b gui.matchtrackingbranch {mc "Match Tracking Branches"}}
|
||||
{i-0..99 gui.diffcontext {mc "Number of Diff Context Lines"}}
|
||||
{i-0..99 gui.commitmsgwidth {mc "Commit Message Text Width"}}
|
||||
{t gui.newbranchtemplate {mc "New Branch Name Template"}}
|
||||
} {
|
||||
set type [lindex $option 0]
|
||||
|
||||
1321
git-gui/po/zh_cn.po
1321
git-gui/po/zh_cn.po
File diff suppressed because it is too large
Load Diff
@@ -18,8 +18,7 @@ original <branch> and remove the .dotest working files, use the command
|
||||
git rebase --abort instead.
|
||||
|
||||
Note that if <branch> is not specified on the command line, the
|
||||
currently checked out branch is used. You must be in the top
|
||||
directory of your project to start (or continue) a rebase.
|
||||
currently checked out branch is used.
|
||||
|
||||
Example: git-rebase master~1 topic
|
||||
|
||||
|
||||
@@ -522,7 +522,8 @@ sub cmd_dcommit {
|
||||
}
|
||||
|
||||
sub cmd_find_rev {
|
||||
my $revision_or_hash = shift;
|
||||
my $revision_or_hash = shift or die "SVN or git revision required ",
|
||||
"as a command-line argument\n";
|
||||
my $result;
|
||||
if ($revision_or_hash =~ /^r\d+$/) {
|
||||
my $head = shift;
|
||||
|
||||
1
git.c
1
git.c
@@ -334,6 +334,7 @@ static void handle_internal_command(int argc, const char **argv)
|
||||
{ "push", cmd_push, RUN_SETUP },
|
||||
{ "read-tree", cmd_read_tree, RUN_SETUP },
|
||||
{ "reflog", cmd_reflog, RUN_SETUP },
|
||||
{ "remote", cmd_remote, RUN_SETUP },
|
||||
{ "repo-config", cmd_config },
|
||||
{ "rerere", cmd_rerere, RUN_SETUP },
|
||||
{ "reset", cmd_reset, RUN_SETUP },
|
||||
|
||||
6
hash.c
6
hash.c
@@ -9,7 +9,7 @@
|
||||
* the existing entry, or the empty slot if none existed. The caller
|
||||
* can then look at the (*ptr) to see whether it existed or not.
|
||||
*/
|
||||
static struct hash_table_entry *lookup_hash_entry(unsigned int hash, struct hash_table *table)
|
||||
static struct hash_table_entry *lookup_hash_entry(unsigned int hash, const struct hash_table *table)
|
||||
{
|
||||
unsigned int size = table->size, nr = hash % size;
|
||||
struct hash_table_entry *array = table->array;
|
||||
@@ -66,7 +66,7 @@ static void grow_hash_table(struct hash_table *table)
|
||||
free(old_array);
|
||||
}
|
||||
|
||||
void *lookup_hash(unsigned int hash, struct hash_table *table)
|
||||
void *lookup_hash(unsigned int hash, const struct hash_table *table)
|
||||
{
|
||||
if (!table->array)
|
||||
return NULL;
|
||||
@@ -81,7 +81,7 @@ void **insert_hash(unsigned int hash, void *ptr, struct hash_table *table)
|
||||
return insert_hash_entry(hash, ptr, table);
|
||||
}
|
||||
|
||||
int for_each_hash(struct hash_table *table, int (*fn)(void *))
|
||||
int for_each_hash(const struct hash_table *table, int (*fn)(void *))
|
||||
{
|
||||
int sum = 0;
|
||||
unsigned int i;
|
||||
|
||||
4
hash.h
4
hash.h
@@ -28,9 +28,9 @@ struct hash_table {
|
||||
struct hash_table_entry *array;
|
||||
};
|
||||
|
||||
extern void *lookup_hash(unsigned int hash, struct hash_table *table);
|
||||
extern void *lookup_hash(unsigned int hash, const struct hash_table *table);
|
||||
extern void **insert_hash(unsigned int hash, void *ptr, struct hash_table *table);
|
||||
extern int for_each_hash(struct hash_table *table, int (*fn)(void *));
|
||||
extern int for_each_hash(const struct hash_table *table, int (*fn)(void *));
|
||||
extern void free_hash(struct hash_table *table);
|
||||
|
||||
static inline void init_hash(struct hash_table *table)
|
||||
|
||||
379
ll-merge.c
Normal file
379
ll-merge.c
Normal file
@@ -0,0 +1,379 @@
|
||||
/*
|
||||
* Low level 3-way in-core file merge.
|
||||
*
|
||||
* Copyright (c) 2007 Junio C Hamano
|
||||
*/
|
||||
|
||||
#include "cache.h"
|
||||
#include "attr.h"
|
||||
#include "xdiff-interface.h"
|
||||
#include "run-command.h"
|
||||
#include "interpolate.h"
|
||||
#include "ll-merge.h"
|
||||
|
||||
struct ll_merge_driver;
|
||||
|
||||
typedef int (*ll_merge_fn)(const struct ll_merge_driver *,
|
||||
mmbuffer_t *result,
|
||||
const char *path,
|
||||
mmfile_t *orig,
|
||||
mmfile_t *src1, const char *name1,
|
||||
mmfile_t *src2, const char *name2,
|
||||
int virtual_ancestor);
|
||||
|
||||
struct ll_merge_driver {
|
||||
const char *name;
|
||||
const char *description;
|
||||
ll_merge_fn fn;
|
||||
const char *recursive;
|
||||
struct ll_merge_driver *next;
|
||||
char *cmdline;
|
||||
};
|
||||
|
||||
/*
|
||||
* Built-in low-levels
|
||||
*/
|
||||
static int ll_binary_merge(const struct ll_merge_driver *drv_unused,
|
||||
mmbuffer_t *result,
|
||||
const char *path_unused,
|
||||
mmfile_t *orig,
|
||||
mmfile_t *src1, const char *name1,
|
||||
mmfile_t *src2, const char *name2,
|
||||
int virtual_ancestor)
|
||||
{
|
||||
/*
|
||||
* The tentative merge result is "ours" for the final round,
|
||||
* or common ancestor for an internal merge. Still return
|
||||
* "conflicted merge" status.
|
||||
*/
|
||||
mmfile_t *stolen = virtual_ancestor ? orig : src1;
|
||||
|
||||
result->ptr = stolen->ptr;
|
||||
result->size = stolen->size;
|
||||
stolen->ptr = NULL;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int ll_xdl_merge(const struct ll_merge_driver *drv_unused,
|
||||
mmbuffer_t *result,
|
||||
const char *path_unused,
|
||||
mmfile_t *orig,
|
||||
mmfile_t *src1, const char *name1,
|
||||
mmfile_t *src2, const char *name2,
|
||||
int virtual_ancestor)
|
||||
{
|
||||
xpparam_t xpp;
|
||||
|
||||
if (buffer_is_binary(orig->ptr, orig->size) ||
|
||||
buffer_is_binary(src1->ptr, src1->size) ||
|
||||
buffer_is_binary(src2->ptr, src2->size)) {
|
||||
warning("Cannot merge binary files: %s vs. %s\n",
|
||||
name1, name2);
|
||||
return ll_binary_merge(drv_unused, result,
|
||||
path_unused,
|
||||
orig, src1, name1,
|
||||
src2, name2,
|
||||
virtual_ancestor);
|
||||
}
|
||||
|
||||
memset(&xpp, 0, sizeof(xpp));
|
||||
return xdl_merge(orig,
|
||||
src1, name1,
|
||||
src2, name2,
|
||||
&xpp, XDL_MERGE_ZEALOUS,
|
||||
result);
|
||||
}
|
||||
|
||||
static int ll_union_merge(const struct ll_merge_driver *drv_unused,
|
||||
mmbuffer_t *result,
|
||||
const char *path_unused,
|
||||
mmfile_t *orig,
|
||||
mmfile_t *src1, const char *name1,
|
||||
mmfile_t *src2, const char *name2,
|
||||
int virtual_ancestor)
|
||||
{
|
||||
char *src, *dst;
|
||||
long size;
|
||||
const int marker_size = 7;
|
||||
|
||||
int status = ll_xdl_merge(drv_unused, result, path_unused,
|
||||
orig, src1, NULL, src2, NULL,
|
||||
virtual_ancestor);
|
||||
if (status <= 0)
|
||||
return status;
|
||||
size = result->size;
|
||||
src = dst = result->ptr;
|
||||
while (size) {
|
||||
char ch;
|
||||
if ((marker_size < size) &&
|
||||
(*src == '<' || *src == '=' || *src == '>')) {
|
||||
int i;
|
||||
ch = *src;
|
||||
for (i = 0; i < marker_size; i++)
|
||||
if (src[i] != ch)
|
||||
goto not_a_marker;
|
||||
if (src[marker_size] != '\n')
|
||||
goto not_a_marker;
|
||||
src += marker_size + 1;
|
||||
size -= marker_size + 1;
|
||||
continue;
|
||||
}
|
||||
not_a_marker:
|
||||
do {
|
||||
ch = *src++;
|
||||
*dst++ = ch;
|
||||
size--;
|
||||
} while (ch != '\n' && size);
|
||||
}
|
||||
result->size = dst - result->ptr;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define LL_BINARY_MERGE 0
|
||||
#define LL_TEXT_MERGE 1
|
||||
#define LL_UNION_MERGE 2
|
||||
static struct ll_merge_driver ll_merge_drv[] = {
|
||||
{ "binary", "built-in binary merge", ll_binary_merge },
|
||||
{ "text", "built-in 3-way text merge", ll_xdl_merge },
|
||||
{ "union", "built-in union merge", ll_union_merge },
|
||||
};
|
||||
|
||||
static void create_temp(mmfile_t *src, char *path)
|
||||
{
|
||||
int fd;
|
||||
|
||||
strcpy(path, ".merge_file_XXXXXX");
|
||||
fd = xmkstemp(path);
|
||||
if (write_in_full(fd, src->ptr, src->size) != src->size)
|
||||
die("unable to write temp-file");
|
||||
close(fd);
|
||||
}
|
||||
|
||||
/*
|
||||
* User defined low-level merge driver support.
|
||||
*/
|
||||
static int ll_ext_merge(const struct ll_merge_driver *fn,
|
||||
mmbuffer_t *result,
|
||||
const char *path,
|
||||
mmfile_t *orig,
|
||||
mmfile_t *src1, const char *name1,
|
||||
mmfile_t *src2, const char *name2,
|
||||
int virtual_ancestor)
|
||||
{
|
||||
char temp[3][50];
|
||||
char cmdbuf[2048];
|
||||
struct interp table[] = {
|
||||
{ "%O" },
|
||||
{ "%A" },
|
||||
{ "%B" },
|
||||
};
|
||||
struct child_process child;
|
||||
const char *args[20];
|
||||
int status, fd, i;
|
||||
struct stat st;
|
||||
|
||||
if (fn->cmdline == NULL)
|
||||
die("custom merge driver %s lacks command line.", fn->name);
|
||||
|
||||
result->ptr = NULL;
|
||||
result->size = 0;
|
||||
create_temp(orig, temp[0]);
|
||||
create_temp(src1, temp[1]);
|
||||
create_temp(src2, temp[2]);
|
||||
|
||||
interp_set_entry(table, 0, temp[0]);
|
||||
interp_set_entry(table, 1, temp[1]);
|
||||
interp_set_entry(table, 2, temp[2]);
|
||||
|
||||
interpolate(cmdbuf, sizeof(cmdbuf), fn->cmdline, table, 3);
|
||||
|
||||
memset(&child, 0, sizeof(child));
|
||||
child.argv = args;
|
||||
args[0] = "sh";
|
||||
args[1] = "-c";
|
||||
args[2] = cmdbuf;
|
||||
args[3] = NULL;
|
||||
|
||||
status = run_command(&child);
|
||||
if (status < -ERR_RUN_COMMAND_FORK)
|
||||
; /* failure in run-command */
|
||||
else
|
||||
status = -status;
|
||||
fd = open(temp[1], O_RDONLY);
|
||||
if (fd < 0)
|
||||
goto bad;
|
||||
if (fstat(fd, &st))
|
||||
goto close_bad;
|
||||
result->size = st.st_size;
|
||||
result->ptr = xmalloc(result->size + 1);
|
||||
if (read_in_full(fd, result->ptr, result->size) != result->size) {
|
||||
free(result->ptr);
|
||||
result->ptr = NULL;
|
||||
result->size = 0;
|
||||
}
|
||||
close_bad:
|
||||
close(fd);
|
||||
bad:
|
||||
for (i = 0; i < 3; i++)
|
||||
unlink(temp[i]);
|
||||
return status;
|
||||
}
|
||||
|
||||
/*
|
||||
* merge.default and merge.driver configuration items
|
||||
*/
|
||||
static struct ll_merge_driver *ll_user_merge, **ll_user_merge_tail;
|
||||
static const char *default_ll_merge;
|
||||
|
||||
static int read_merge_config(const char *var, const char *value)
|
||||
{
|
||||
struct ll_merge_driver *fn;
|
||||
const char *ep, *name;
|
||||
int namelen;
|
||||
|
||||
if (!strcmp(var, "merge.default")) {
|
||||
if (value)
|
||||
default_ll_merge = strdup(value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* We are not interested in anything but "merge.<name>.variable";
|
||||
* especially, we do not want to look at variables such as
|
||||
* "merge.summary", "merge.tool", and "merge.verbosity".
|
||||
*/
|
||||
if (prefixcmp(var, "merge.") || (ep = strrchr(var, '.')) == var + 5)
|
||||
return 0;
|
||||
|
||||
/*
|
||||
* Find existing one as we might be processing merge.<name>.var2
|
||||
* after seeing merge.<name>.var1.
|
||||
*/
|
||||
name = var + 6;
|
||||
namelen = ep - name;
|
||||
for (fn = ll_user_merge; fn; fn = fn->next)
|
||||
if (!strncmp(fn->name, name, namelen) && !fn->name[namelen])
|
||||
break;
|
||||
if (!fn) {
|
||||
fn = xcalloc(1, sizeof(struct ll_merge_driver));
|
||||
fn->name = xmemdupz(name, namelen);
|
||||
fn->fn = ll_ext_merge;
|
||||
*ll_user_merge_tail = fn;
|
||||
ll_user_merge_tail = &(fn->next);
|
||||
}
|
||||
|
||||
ep++;
|
||||
|
||||
if (!strcmp("name", ep)) {
|
||||
if (!value)
|
||||
return error("%s: lacks value", var);
|
||||
fn->description = strdup(value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!strcmp("driver", ep)) {
|
||||
if (!value)
|
||||
return error("%s: lacks value", var);
|
||||
/*
|
||||
* merge.<name>.driver specifies the command line:
|
||||
*
|
||||
* command-line
|
||||
*
|
||||
* The command-line will be interpolated with the following
|
||||
* tokens and is given to the shell:
|
||||
*
|
||||
* %O - temporary file name for the merge base.
|
||||
* %A - temporary file name for our version.
|
||||
* %B - temporary file name for the other branches' version.
|
||||
*
|
||||
* The external merge driver should write the results in the
|
||||
* file named by %A, and signal that it has done with zero exit
|
||||
* status.
|
||||
*/
|
||||
fn->cmdline = strdup(value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!strcmp("recursive", ep)) {
|
||||
if (!value)
|
||||
return error("%s: lacks value", var);
|
||||
fn->recursive = strdup(value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void initialize_ll_merge(void)
|
||||
{
|
||||
if (ll_user_merge_tail)
|
||||
return;
|
||||
ll_user_merge_tail = &ll_user_merge;
|
||||
git_config(read_merge_config);
|
||||
}
|
||||
|
||||
static const struct ll_merge_driver *find_ll_merge_driver(const char *merge_attr)
|
||||
{
|
||||
struct ll_merge_driver *fn;
|
||||
const char *name;
|
||||
int i;
|
||||
|
||||
initialize_ll_merge();
|
||||
|
||||
if (ATTR_TRUE(merge_attr))
|
||||
return &ll_merge_drv[LL_TEXT_MERGE];
|
||||
else if (ATTR_FALSE(merge_attr))
|
||||
return &ll_merge_drv[LL_BINARY_MERGE];
|
||||
else if (ATTR_UNSET(merge_attr)) {
|
||||
if (!default_ll_merge)
|
||||
return &ll_merge_drv[LL_TEXT_MERGE];
|
||||
else
|
||||
name = default_ll_merge;
|
||||
}
|
||||
else
|
||||
name = merge_attr;
|
||||
|
||||
for (fn = ll_user_merge; fn; fn = fn->next)
|
||||
if (!strcmp(fn->name, name))
|
||||
return fn;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(ll_merge_drv); i++)
|
||||
if (!strcmp(ll_merge_drv[i].name, name))
|
||||
return &ll_merge_drv[i];
|
||||
|
||||
/* default to the 3-way */
|
||||
return &ll_merge_drv[LL_TEXT_MERGE];
|
||||
}
|
||||
|
||||
static const char *git_path_check_merge(const char *path)
|
||||
{
|
||||
static struct git_attr_check attr_merge_check;
|
||||
|
||||
if (!attr_merge_check.attr)
|
||||
attr_merge_check.attr = git_attr("merge", 5);
|
||||
|
||||
if (git_checkattr(path, 1, &attr_merge_check))
|
||||
return NULL;
|
||||
return attr_merge_check.value;
|
||||
}
|
||||
|
||||
int ll_merge(mmbuffer_t *result_buf,
|
||||
const char *path,
|
||||
mmfile_t *ancestor,
|
||||
mmfile_t *ours, const char *our_label,
|
||||
mmfile_t *theirs, const char *their_label,
|
||||
int virtual_ancestor)
|
||||
{
|
||||
const char *ll_driver_name;
|
||||
const struct ll_merge_driver *driver;
|
||||
|
||||
ll_driver_name = git_path_check_merge(path);
|
||||
driver = find_ll_merge_driver(ll_driver_name);
|
||||
|
||||
if (virtual_ancestor && driver->recursive)
|
||||
driver = find_ll_merge_driver(driver->recursive);
|
||||
return driver->fn(driver, result_buf, path,
|
||||
ancestor,
|
||||
ours, our_label,
|
||||
theirs, their_label, virtual_ancestor);
|
||||
}
|
||||
15
ll-merge.h
Normal file
15
ll-merge.h
Normal file
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
* Low level 3-way in-core file merge.
|
||||
*/
|
||||
|
||||
#ifndef LL_MERGE_H
|
||||
#define LL_MERGE_H
|
||||
|
||||
int ll_merge(mmbuffer_t *result_buf,
|
||||
const char *path,
|
||||
mmfile_t *ancestor,
|
||||
mmfile_t *ours, const char *our_label,
|
||||
mmfile_t *theirs, const char *their_label,
|
||||
int virtual_ancestor);
|
||||
|
||||
#endif
|
||||
58
merge-tree.c
58
merge-tree.c
@@ -168,7 +168,13 @@ static struct merge_list *create_entry(unsigned stage, unsigned mode, const unsi
|
||||
return res;
|
||||
}
|
||||
|
||||
static void resolve(const char *base, struct name_entry *branch1, struct name_entry *result)
|
||||
static char *traverse_path(const struct traverse_info *info, const struct name_entry *n)
|
||||
{
|
||||
char *path = xmalloc(traverse_path_len(info, n) + 1);
|
||||
return make_traverse_path(path, info, n);
|
||||
}
|
||||
|
||||
static void resolve(const struct traverse_info *info, struct name_entry *branch1, struct name_entry *result)
|
||||
{
|
||||
struct merge_list *orig, *final;
|
||||
const char *path;
|
||||
@@ -177,7 +183,7 @@ static void resolve(const char *base, struct name_entry *branch1, struct name_en
|
||||
if (!branch1)
|
||||
return;
|
||||
|
||||
path = xstrdup(mkpath("%s%s", base, result->path));
|
||||
path = traverse_path(info, result);
|
||||
orig = create_entry(2, branch1->mode, branch1->sha1, path);
|
||||
final = create_entry(0, result->mode, result->sha1, path);
|
||||
|
||||
@@ -186,9 +192,8 @@ static void resolve(const char *base, struct name_entry *branch1, struct name_en
|
||||
add_merge_entry(final);
|
||||
}
|
||||
|
||||
static int unresolved_directory(const char *base, struct name_entry n[3])
|
||||
static int unresolved_directory(const struct traverse_info *info, struct name_entry n[3])
|
||||
{
|
||||
int baselen, pathlen;
|
||||
char *newbase;
|
||||
struct name_entry *p;
|
||||
struct tree_desc t[3];
|
||||
@@ -204,13 +209,7 @@ static int unresolved_directory(const char *base, struct name_entry n[3])
|
||||
}
|
||||
if (!S_ISDIR(p->mode))
|
||||
return 0;
|
||||
baselen = strlen(base);
|
||||
pathlen = tree_entry_len(p->path, p->sha1);
|
||||
newbase = xmalloc(baselen + pathlen + 2);
|
||||
memcpy(newbase, base, baselen);
|
||||
memcpy(newbase + baselen, p->path, pathlen);
|
||||
memcpy(newbase + baselen + pathlen, "/", 2);
|
||||
|
||||
newbase = traverse_path(info, p);
|
||||
buf0 = fill_tree_descriptor(t+0, n[0].sha1);
|
||||
buf1 = fill_tree_descriptor(t+1, n[1].sha1);
|
||||
buf2 = fill_tree_descriptor(t+2, n[2].sha1);
|
||||
@@ -224,7 +223,7 @@ static int unresolved_directory(const char *base, struct name_entry n[3])
|
||||
}
|
||||
|
||||
|
||||
static struct merge_list *link_entry(unsigned stage, const char *base, struct name_entry *n, struct merge_list *entry)
|
||||
static struct merge_list *link_entry(unsigned stage, const struct traverse_info *info, struct name_entry *n, struct merge_list *entry)
|
||||
{
|
||||
const char *path;
|
||||
struct merge_list *link;
|
||||
@@ -234,17 +233,17 @@ static struct merge_list *link_entry(unsigned stage, const char *base, struct na
|
||||
if (entry)
|
||||
path = entry->path;
|
||||
else
|
||||
path = xstrdup(mkpath("%s%s", base, n->path));
|
||||
path = traverse_path(info, n);
|
||||
link = create_entry(stage, n->mode, n->sha1, path);
|
||||
link->link = entry;
|
||||
return link;
|
||||
}
|
||||
|
||||
static void unresolved(const char *base, struct name_entry n[3])
|
||||
static void unresolved(const struct traverse_info *info, struct name_entry n[3])
|
||||
{
|
||||
struct merge_list *entry = NULL;
|
||||
|
||||
if (unresolved_directory(base, n))
|
||||
if (unresolved_directory(info, n))
|
||||
return;
|
||||
|
||||
/*
|
||||
@@ -252,9 +251,9 @@ static void unresolved(const char *base, struct name_entry n[3])
|
||||
* list has the stages in order - link_entry adds new
|
||||
* links at the front.
|
||||
*/
|
||||
entry = link_entry(3, base, n + 2, entry);
|
||||
entry = link_entry(2, base, n + 1, entry);
|
||||
entry = link_entry(1, base, n + 0, entry);
|
||||
entry = link_entry(3, info, n + 2, entry);
|
||||
entry = link_entry(2, info, n + 1, entry);
|
||||
entry = link_entry(1, info, n + 0, entry);
|
||||
|
||||
add_merge_entry(entry);
|
||||
}
|
||||
@@ -288,36 +287,41 @@ static void unresolved(const char *base, struct name_entry n[3])
|
||||
* The successful merge rules are the same as for the three-way merge
|
||||
* in git-read-tree.
|
||||
*/
|
||||
static void threeway_callback(int n, unsigned long mask, struct name_entry *entry, const char *base)
|
||||
static int threeway_callback(int n, unsigned long mask, unsigned long dirmask, struct name_entry *entry, struct traverse_info *info)
|
||||
{
|
||||
/* Same in both? */
|
||||
if (same_entry(entry+1, entry+2)) {
|
||||
if (entry[0].sha1) {
|
||||
resolve(base, NULL, entry+1);
|
||||
return;
|
||||
resolve(info, NULL, entry+1);
|
||||
return mask;
|
||||
}
|
||||
}
|
||||
|
||||
if (same_entry(entry+0, entry+1)) {
|
||||
if (entry[2].sha1 && !S_ISDIR(entry[2].mode)) {
|
||||
resolve(base, entry+1, entry+2);
|
||||
return;
|
||||
resolve(info, entry+1, entry+2);
|
||||
return mask;
|
||||
}
|
||||
}
|
||||
|
||||
if (same_entry(entry+0, entry+2)) {
|
||||
if (entry[1].sha1 && !S_ISDIR(entry[1].mode)) {
|
||||
resolve(base, NULL, entry+1);
|
||||
return;
|
||||
resolve(info, NULL, entry+1);
|
||||
return mask;
|
||||
}
|
||||
}
|
||||
|
||||
unresolved(base, entry);
|
||||
unresolved(info, entry);
|
||||
return mask;
|
||||
}
|
||||
|
||||
static void merge_trees(struct tree_desc t[3], const char *base)
|
||||
{
|
||||
traverse_trees(3, t, base, threeway_callback);
|
||||
struct traverse_info info;
|
||||
|
||||
setup_traverse_info(&info, base);
|
||||
info.fn = threeway_callback;
|
||||
traverse_trees(3, t, &info);
|
||||
}
|
||||
|
||||
static void *get_tree_descriptor(struct tree_desc *desc, const char *rev)
|
||||
|
||||
@@ -259,6 +259,8 @@ int parse_options(int argc, const char **argv, const struct option *options,
|
||||
const char *arg = args.argv[0];
|
||||
|
||||
if (*arg != '-' || !arg[1]) {
|
||||
if (flags & PARSE_OPT_STOP_AT_NON_OPTION)
|
||||
break;
|
||||
args.out[args.cpidx++] = args.argv[0];
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ enum parse_opt_type {
|
||||
|
||||
enum parse_opt_flags {
|
||||
PARSE_OPT_KEEP_DASHDASH = 1,
|
||||
PARSE_OPT_STOP_AT_NON_OPTION = 2,
|
||||
};
|
||||
|
||||
enum parse_opt_option_flags {
|
||||
|
||||
30
path-list.c
30
path-list.c
@@ -102,3 +102,33 @@ void print_path_list(const char *text, const struct path_list *p)
|
||||
for (i = 0; i < p->nr; i++)
|
||||
printf("%s:%p\n", p->items[i].path, p->items[i].util);
|
||||
}
|
||||
|
||||
struct path_list_item *path_list_append(const char *path, struct path_list *list)
|
||||
{
|
||||
ALLOC_GROW(list->items, list->nr + 1, list->alloc);
|
||||
list->items[list->nr].path =
|
||||
list->strdup_paths ? xstrdup(path) : (char *)path;
|
||||
return list->items + list->nr++;
|
||||
}
|
||||
|
||||
static int cmp_items(const void *a, const void *b)
|
||||
{
|
||||
const struct path_list_item *one = a;
|
||||
const struct path_list_item *two = b;
|
||||
return strcmp(one->path, two->path);
|
||||
}
|
||||
|
||||
void sort_path_list(struct path_list *list)
|
||||
{
|
||||
qsort(list->items, list->nr, sizeof(*list->items), cmp_items);
|
||||
}
|
||||
|
||||
int unsorted_path_list_has_path(struct path_list *list, const char *path)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < list->nr; i++)
|
||||
if (!strcmp(path, list->items[i].path))
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
10
path-list.h
10
path-list.h
@@ -13,10 +13,16 @@ struct path_list
|
||||
};
|
||||
|
||||
void print_path_list(const char *text, const struct path_list *p);
|
||||
|
||||
int path_list_has_path(const struct path_list *list, const char *path);
|
||||
void path_list_clear(struct path_list *list, int free_util);
|
||||
|
||||
/* Use these functions only on sorted lists: */
|
||||
int path_list_has_path(const struct path_list *list, const char *path);
|
||||
struct path_list_item *path_list_insert(const char *path, struct path_list *list);
|
||||
struct path_list_item *path_list_lookup(const char *path, struct path_list *list);
|
||||
|
||||
/* Use these functions only on unsorted lists: */
|
||||
struct path_list_item *path_list_append(const char *path, struct path_list *list);
|
||||
void sort_path_list(struct path_list *list);
|
||||
int unsorted_path_list_has_path(struct path_list *list, const char *path);
|
||||
|
||||
#endif /* PATH_LIST_H */
|
||||
|
||||
47
read-cache.c
47
read-cache.c
@@ -255,13 +255,13 @@ static int ce_match_stat_basic(struct cache_entry *ce, struct stat *st)
|
||||
return changed;
|
||||
}
|
||||
|
||||
static int is_racy_timestamp(struct index_state *istate, struct cache_entry *ce)
|
||||
static int is_racy_timestamp(const struct index_state *istate, struct cache_entry *ce)
|
||||
{
|
||||
return (istate->timestamp &&
|
||||
((unsigned int)istate->timestamp) <= ce->ce_mtime);
|
||||
}
|
||||
|
||||
int ie_match_stat(struct index_state *istate,
|
||||
int ie_match_stat(const struct index_state *istate,
|
||||
struct cache_entry *ce, struct stat *st,
|
||||
unsigned int options)
|
||||
{
|
||||
@@ -304,7 +304,7 @@ int ie_match_stat(struct index_state *istate,
|
||||
return changed;
|
||||
}
|
||||
|
||||
int ie_modified(struct index_state *istate,
|
||||
int ie_modified(const struct index_state *istate,
|
||||
struct cache_entry *ce, struct stat *st, unsigned int options)
|
||||
{
|
||||
int changed, changed_fs;
|
||||
@@ -351,6 +351,41 @@ int base_name_compare(const char *name1, int len1, int mode1,
|
||||
return (c1 < c2) ? -1 : (c1 > c2) ? 1 : 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* df_name_compare() is identical to base_name_compare(), except it
|
||||
* compares conflicting directory/file entries as equal. Note that
|
||||
* while a directory name compares as equal to a regular file, they
|
||||
* then individually compare _differently_ to a filename that has
|
||||
* a dot after the basename (because '\0' < '.' < '/').
|
||||
*
|
||||
* This is used by routines that want to traverse the git namespace
|
||||
* but then handle conflicting entries together when possible.
|
||||
*/
|
||||
int df_name_compare(const char *name1, int len1, int mode1,
|
||||
const char *name2, int len2, int mode2)
|
||||
{
|
||||
int len = len1 < len2 ? len1 : len2, cmp;
|
||||
unsigned char c1, c2;
|
||||
|
||||
cmp = memcmp(name1, name2, len);
|
||||
if (cmp)
|
||||
return cmp;
|
||||
/* Directories and files compare equal (same length, same name) */
|
||||
if (len1 == len2)
|
||||
return 0;
|
||||
c1 = name1[len];
|
||||
if (!c1 && S_ISDIR(mode1))
|
||||
c1 = '/';
|
||||
c2 = name2[len];
|
||||
if (!c2 && S_ISDIR(mode2))
|
||||
c2 = '/';
|
||||
if (c1 == '/' && !c2)
|
||||
return 0;
|
||||
if (c2 == '/' && !c1)
|
||||
return 0;
|
||||
return c1 - c2;
|
||||
}
|
||||
|
||||
int cache_name_compare(const char *name1, int flags1, const char *name2, int flags2)
|
||||
{
|
||||
int len1 = flags1 & CE_NAMEMASK;
|
||||
@@ -377,7 +412,7 @@ int cache_name_compare(const char *name1, int flags1, const char *name2, int fla
|
||||
return 0;
|
||||
}
|
||||
|
||||
int index_name_pos(struct index_state *istate, const char *name, int namelen)
|
||||
int index_name_pos(const struct index_state *istate, const char *name, int namelen)
|
||||
{
|
||||
int first, last;
|
||||
|
||||
@@ -1166,7 +1201,7 @@ int discard_index(struct index_state *istate)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int unmerged_index(struct index_state *istate)
|
||||
int unmerged_index(const struct index_state *istate)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < istate->cache_nr; i++) {
|
||||
@@ -1311,7 +1346,7 @@ static int ce_write_entry(SHA_CTX *c, int fd, struct cache_entry *ce)
|
||||
return ce_write(c, fd, ondisk, size);
|
||||
}
|
||||
|
||||
int write_index(struct index_state *istate, int newfd)
|
||||
int write_index(const struct index_state *istate, int newfd)
|
||||
{
|
||||
SHA_CTX c;
|
||||
struct cache_header hdr;
|
||||
|
||||
3
remote.c
3
remote.c
@@ -357,7 +357,8 @@ static int handle_config(const char *key, const char *value)
|
||||
remote->fetch_tags = -1;
|
||||
} else if (!strcmp(subkey, ".proxy")) {
|
||||
remote->http_proxy = xstrdup(value);
|
||||
}
|
||||
} else if (!strcmp(subkey, ".skipdefaultupdate"))
|
||||
remote->skip_default_update = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
1
remote.h
1
remote.h
@@ -25,6 +25,7 @@ struct remote {
|
||||
* 2 to always fetch tags
|
||||
*/
|
||||
int fetch_tags;
|
||||
int skip_default_update;
|
||||
|
||||
const char *receivepack;
|
||||
const char *uploadpack;
|
||||
|
||||
60
sha1_name.c
60
sha1_name.c
@@ -422,6 +422,37 @@ static int get_nth_ancestor(const char *name, int len,
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct object *peel_to_type(const char *name, int namelen,
|
||||
struct object *o, enum object_type expected_type)
|
||||
{
|
||||
if (name && !namelen)
|
||||
namelen = strlen(name);
|
||||
if (!o) {
|
||||
unsigned char sha1[20];
|
||||
if (get_sha1_1(name, namelen, sha1))
|
||||
return NULL;
|
||||
o = parse_object(sha1);
|
||||
}
|
||||
while (1) {
|
||||
if (!o || (!o->parsed && !parse_object(o->sha1)))
|
||||
return NULL;
|
||||
if (o->type == expected_type)
|
||||
return o;
|
||||
if (o->type == OBJ_TAG)
|
||||
o = ((struct tag*) o)->tagged;
|
||||
else if (o->type == OBJ_COMMIT)
|
||||
o = &(((struct commit *) o)->tree->object);
|
||||
else {
|
||||
if (name)
|
||||
error("%.*s: expected %s type, but the object "
|
||||
"dereferences to %s type",
|
||||
namelen, name, typename(expected_type),
|
||||
typename(o->type));
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int peel_onion(const char *name, int len, unsigned char *sha1)
|
||||
{
|
||||
unsigned char outer[20];
|
||||
@@ -473,32 +504,17 @@ static int peel_onion(const char *name, int len, unsigned char *sha1)
|
||||
hashcpy(sha1, o->sha1);
|
||||
}
|
||||
else {
|
||||
/* At this point, the syntax look correct, so
|
||||
/*
|
||||
* At this point, the syntax look correct, so
|
||||
* if we do not get the needed object, we should
|
||||
* barf.
|
||||
*/
|
||||
|
||||
while (1) {
|
||||
if (!o || (!o->parsed && !parse_object(o->sha1)))
|
||||
return -1;
|
||||
if (o->type == expected_type) {
|
||||
hashcpy(sha1, o->sha1);
|
||||
return 0;
|
||||
}
|
||||
if (o->type == OBJ_TAG)
|
||||
o = ((struct tag*) o)->tagged;
|
||||
else if (o->type == OBJ_COMMIT)
|
||||
o = &(((struct commit *) o)->tree->object);
|
||||
else
|
||||
return error("%.*s: expected %s type, but the object dereferences to %s type",
|
||||
len, name, typename(expected_type),
|
||||
typename(o->type));
|
||||
if (!o)
|
||||
return -1;
|
||||
if (!o->parsed)
|
||||
if (!parse_object(o->sha1))
|
||||
return -1;
|
||||
o = peel_to_type(name, len, o, expected_type);
|
||||
if (o) {
|
||||
hashcpy(sha1, o->sha1);
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,9 @@ test_description='blob conversion via gitattributes'
|
||||
. ./test-lib.sh
|
||||
|
||||
cat <<\EOF >rot13.sh
|
||||
tr '[a-zA-Z]' '[n-za-mN-ZA-M]'
|
||||
tr \
|
||||
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' \
|
||||
'nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM'
|
||||
EOF
|
||||
chmod +x rot13.sh
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ test_expect_success 'setup' '
|
||||
git commit -m two
|
||||
'
|
||||
|
||||
test_expect_failure 'reset should work' '
|
||||
test_expect_success 'reset should work' '
|
||||
git read-tree -u --reset HEAD^ &&
|
||||
git ls-files >actual &&
|
||||
diff -u expect actual
|
||||
|
||||
@@ -10,10 +10,12 @@ setup_repository () {
|
||||
git init &&
|
||||
>file &&
|
||||
git add file &&
|
||||
test_tick &&
|
||||
git commit -m "Initial" &&
|
||||
git checkout -b side &&
|
||||
>elif &&
|
||||
git add elif &&
|
||||
test_tick &&
|
||||
git commit -m "Second" &&
|
||||
git checkout master
|
||||
)
|
||||
@@ -78,6 +80,7 @@ test_expect_success 'add another remote' '
|
||||
test_expect_success 'remove remote' '
|
||||
(
|
||||
cd test &&
|
||||
git symbolic-ref refs/remotes/second/HEAD refs/remotes/second/master &&
|
||||
git remote rm second
|
||||
)
|
||||
'
|
||||
@@ -94,4 +97,144 @@ test_expect_success 'remove remote' '
|
||||
)
|
||||
'
|
||||
|
||||
cat > test/expect << EOF
|
||||
* remote origin
|
||||
URL: $(pwd)/one/.git
|
||||
Remote branch merged with 'git pull' while on branch master
|
||||
master
|
||||
New remote branch (next fetch will store in remotes/origin)
|
||||
master
|
||||
Tracked remote branches
|
||||
side master
|
||||
EOF
|
||||
|
||||
test_expect_success 'show' '
|
||||
(cd test &&
|
||||
git config --add remote.origin.fetch \
|
||||
refs/heads/master:refs/heads/upstream &&
|
||||
git fetch &&
|
||||
git branch -d -r origin/master &&
|
||||
(cd ../one &&
|
||||
echo 1 > file &&
|
||||
test_tick &&
|
||||
git commit -m update file) &&
|
||||
git remote show origin > output &&
|
||||
git diff expect output)
|
||||
'
|
||||
|
||||
test_expect_success 'prune' '
|
||||
(cd one &&
|
||||
git branch -m side side2) &&
|
||||
(cd test &&
|
||||
git fetch origin &&
|
||||
git remote prune origin &&
|
||||
git rev-parse refs/remotes/origin/side2 &&
|
||||
! git rev-parse refs/remotes/origin/side)
|
||||
'
|
||||
|
||||
test_expect_success 'add --mirror && prune' '
|
||||
(mkdir mirror &&
|
||||
cd mirror &&
|
||||
git init &&
|
||||
git remote add --mirror -f origin ../one) &&
|
||||
(cd one &&
|
||||
git branch -m side2 side) &&
|
||||
(cd mirror &&
|
||||
git rev-parse --verify refs/heads/side2 &&
|
||||
! git rev-parse --verify refs/heads/side &&
|
||||
git fetch origin &&
|
||||
git remote prune origin &&
|
||||
! git rev-parse --verify refs/heads/side2 &&
|
||||
git rev-parse --verify refs/heads/side)
|
||||
'
|
||||
|
||||
cat > one/expect << EOF
|
||||
apis/master
|
||||
apis/side
|
||||
drosophila/another
|
||||
drosophila/master
|
||||
drosophila/side
|
||||
EOF
|
||||
|
||||
test_expect_success 'update' '
|
||||
|
||||
(cd one &&
|
||||
git remote add drosophila ../two &&
|
||||
git remote add apis ../mirror &&
|
||||
git remote update &&
|
||||
git branch -r > output &&
|
||||
git diff expect output)
|
||||
|
||||
'
|
||||
|
||||
cat > one/expect << EOF
|
||||
drosophila/another
|
||||
drosophila/master
|
||||
drosophila/side
|
||||
manduca/master
|
||||
manduca/side
|
||||
megaloprepus/master
|
||||
megaloprepus/side
|
||||
EOF
|
||||
|
||||
test_expect_success 'update with arguments' '
|
||||
|
||||
(cd one &&
|
||||
for b in $(git branch -r)
|
||||
do
|
||||
git branch -r -d $b || break
|
||||
done &&
|
||||
git remote add manduca ../mirror &&
|
||||
git remote add megaloprepus ../mirror &&
|
||||
git config remotes.phobaeticus "drosophila megaloprepus" &&
|
||||
git config remotes.titanus manduca &&
|
||||
git remote update phobaeticus titanus &&
|
||||
git branch -r > output &&
|
||||
git diff expect output)
|
||||
|
||||
'
|
||||
|
||||
cat > one/expect << EOF
|
||||
apis/master
|
||||
apis/side
|
||||
manduca/master
|
||||
manduca/side
|
||||
megaloprepus/master
|
||||
megaloprepus/side
|
||||
EOF
|
||||
|
||||
test_expect_success 'update default' '
|
||||
|
||||
(cd one &&
|
||||
for b in $(git branch -r)
|
||||
do
|
||||
git branch -r -d $b || break
|
||||
done &&
|
||||
git config remote.drosophila.skipDefaultUpdate true &&
|
||||
git remote update default &&
|
||||
git branch -r > output &&
|
||||
git diff expect output)
|
||||
|
||||
'
|
||||
|
||||
cat > one/expect << EOF
|
||||
drosophila/another
|
||||
drosophila/master
|
||||
drosophila/side
|
||||
EOF
|
||||
|
||||
test_expect_success 'update default (overridden, with funny whitespace)' '
|
||||
|
||||
(cd one &&
|
||||
for b in $(git branch -r)
|
||||
do
|
||||
git branch -r -d $b || break
|
||||
done &&
|
||||
git config remotes.default "$(printf "\t drosophila \n")" &&
|
||||
git remote update default &&
|
||||
git branch -r > output &&
|
||||
git diff expect output)
|
||||
|
||||
'
|
||||
|
||||
test_done
|
||||
|
||||
@@ -89,6 +89,33 @@ do
|
||||
'
|
||||
done
|
||||
|
||||
test_expect_success 'editor with a space' '
|
||||
|
||||
if echo "echo space > \"\$1\"" > "e space.sh"
|
||||
then
|
||||
chmod a+x "e space.sh" &&
|
||||
GIT_EDITOR="./e\ space.sh" git commit --amend &&
|
||||
test space = "$(git show -s --pretty=format:%s)"
|
||||
else
|
||||
say "Skipping; FS does not support spaces in filenames"
|
||||
fi
|
||||
|
||||
'
|
||||
|
||||
unset GIT_EDITOR
|
||||
test_expect_success 'core.editor with a space' '
|
||||
|
||||
if test -f "e space.sh"
|
||||
then
|
||||
git config core.editor \"./e\ space.sh\" &&
|
||||
git commit --amend &&
|
||||
test space = "$(git show -s --pretty=format:%s)"
|
||||
else
|
||||
say "Skipping; FS does not support spaces in filenames"
|
||||
fi
|
||||
|
||||
'
|
||||
|
||||
TERM="$OLD_TERM"
|
||||
|
||||
test_done
|
||||
|
||||
62
tree-walk.c
62
tree-walk.c
@@ -62,7 +62,7 @@ void *fill_tree_descriptor(struct tree_desc *desc, const unsigned char *sha1)
|
||||
|
||||
static int entry_compare(struct name_entry *a, struct name_entry *b)
|
||||
{
|
||||
return base_name_compare(
|
||||
return df_name_compare(
|
||||
a->path, tree_entry_len(a->path, a->sha1), a->mode,
|
||||
b->path, tree_entry_len(b->path, b->sha1), b->mode);
|
||||
}
|
||||
@@ -104,12 +104,48 @@ int tree_entry(struct tree_desc *desc, struct name_entry *entry)
|
||||
return 1;
|
||||
}
|
||||
|
||||
void traverse_trees(int n, struct tree_desc *t, const char *base, traverse_callback_t callback)
|
||||
void setup_traverse_info(struct traverse_info *info, const char *base)
|
||||
{
|
||||
int pathlen = strlen(base);
|
||||
static struct traverse_info dummy;
|
||||
|
||||
memset(info, 0, sizeof(*info));
|
||||
if (pathlen && base[pathlen-1] == '/')
|
||||
pathlen--;
|
||||
info->pathlen = pathlen ? pathlen + 1 : 0;
|
||||
info->name.path = base;
|
||||
info->name.sha1 = (void *)(base + pathlen + 1);
|
||||
if (pathlen)
|
||||
info->prev = &dummy;
|
||||
}
|
||||
|
||||
char *make_traverse_path(char *path, const struct traverse_info *info, const struct name_entry *n)
|
||||
{
|
||||
int len = tree_entry_len(n->path, n->sha1);
|
||||
int pathlen = info->pathlen;
|
||||
|
||||
path[pathlen + len] = 0;
|
||||
for (;;) {
|
||||
memcpy(path + pathlen, n->path, len);
|
||||
if (!pathlen)
|
||||
break;
|
||||
path[--pathlen] = '/';
|
||||
n = &info->name;
|
||||
len = tree_entry_len(n->path, n->sha1);
|
||||
info = info->prev;
|
||||
pathlen -= len;
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
int traverse_trees(int n, struct tree_desc *t, struct traverse_info *info)
|
||||
{
|
||||
int ret = 0;
|
||||
struct name_entry *entry = xmalloc(n*sizeof(*entry));
|
||||
|
||||
for (;;) {
|
||||
unsigned long mask = 0;
|
||||
unsigned long dirmask = 0;
|
||||
int i, last;
|
||||
|
||||
last = -1;
|
||||
@@ -134,25 +170,35 @@ void traverse_trees(int n, struct tree_desc *t, const char *base, traverse_callb
|
||||
mask = 0;
|
||||
}
|
||||
mask |= 1ul << i;
|
||||
if (S_ISDIR(entry[i].mode))
|
||||
dirmask |= 1ul << i;
|
||||
last = i;
|
||||
}
|
||||
if (!mask)
|
||||
break;
|
||||
dirmask &= mask;
|
||||
|
||||
/*
|
||||
* Update the tree entries we've walked, and clear
|
||||
* all the unused name-entries.
|
||||
* Clear all the unused name-entries.
|
||||
*/
|
||||
for (i = 0; i < n; i++) {
|
||||
if (mask & (1ul << i)) {
|
||||
update_tree_entry(t+i);
|
||||
if (mask & (1ul << i))
|
||||
continue;
|
||||
}
|
||||
entry_clear(entry + i);
|
||||
}
|
||||
callback(n, mask, entry, base);
|
||||
ret = info->fn(n, mask, dirmask, entry, info);
|
||||
if (ret < 0)
|
||||
break;
|
||||
if (ret)
|
||||
mask &= ret;
|
||||
ret = 0;
|
||||
for (i = 0; i < n; i++) {
|
||||
if (mask & (1ul << i))
|
||||
update_tree_entry(t + i);
|
||||
}
|
||||
}
|
||||
free(entry);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int find_tree_entry(struct tree_desc *t, const char *name, unsigned char *result, unsigned *mode)
|
||||
|
||||
21
tree-walk.h
21
tree-walk.h
@@ -33,10 +33,27 @@ int tree_entry(struct tree_desc *, struct name_entry *);
|
||||
|
||||
void *fill_tree_descriptor(struct tree_desc *desc, const unsigned char *sha1);
|
||||
|
||||
typedef void (*traverse_callback_t)(int n, unsigned long mask, struct name_entry *entry, const char *base);
|
||||
struct traverse_info;
|
||||
typedef int (*traverse_callback_t)(int n, unsigned long mask, unsigned long dirmask, struct name_entry *entry, struct traverse_info *);
|
||||
int traverse_trees(int n, struct tree_desc *t, struct traverse_info *info);
|
||||
|
||||
void traverse_trees(int n, struct tree_desc *t, const char *base, traverse_callback_t callback);
|
||||
struct traverse_info {
|
||||
struct traverse_info *prev;
|
||||
struct name_entry name;
|
||||
int pathlen;
|
||||
|
||||
unsigned long conflicts;
|
||||
traverse_callback_t fn;
|
||||
void *data;
|
||||
};
|
||||
|
||||
int get_tree_entry(const unsigned char *, const char *, unsigned char *, unsigned *);
|
||||
extern char *make_traverse_path(char *path, const struct traverse_info *info, const struct name_entry *n);
|
||||
extern void setup_traverse_info(struct traverse_info *info, const char *base);
|
||||
|
||||
static inline int traverse_path_len(const struct traverse_info *info, const struct name_entry *n)
|
||||
{
|
||||
return info->pathlen + tree_entry_len(n->path, n->sha1);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
636
unpack-trees.c
636
unpack-trees.c
@@ -1,3 +1,4 @@
|
||||
#define NO_THE_INDEX_COMPATIBILITY_MACROS
|
||||
#include "cache.h"
|
||||
#include "dir.h"
|
||||
#include "tree.h"
|
||||
@@ -7,268 +8,18 @@
|
||||
#include "progress.h"
|
||||
#include "refs.h"
|
||||
|
||||
#define DBRT_DEBUG 1
|
||||
|
||||
struct tree_entry_list {
|
||||
struct tree_entry_list *next;
|
||||
unsigned int mode;
|
||||
const char *name;
|
||||
const unsigned char *sha1;
|
||||
};
|
||||
|
||||
static struct tree_entry_list *create_tree_entry_list(struct tree_desc *desc)
|
||||
static void add_entry(struct unpack_trees_options *o, struct cache_entry *ce,
|
||||
unsigned int set, unsigned int clear)
|
||||
{
|
||||
struct name_entry one;
|
||||
struct tree_entry_list *ret = NULL;
|
||||
struct tree_entry_list **list_p = &ret;
|
||||
unsigned int size = ce_size(ce);
|
||||
struct cache_entry *new = xmalloc(size);
|
||||
|
||||
while (tree_entry(desc, &one)) {
|
||||
struct tree_entry_list *entry;
|
||||
clear |= CE_HASHED | CE_UNHASHED;
|
||||
|
||||
entry = xmalloc(sizeof(struct tree_entry_list));
|
||||
entry->name = one.path;
|
||||
entry->sha1 = one.sha1;
|
||||
entry->mode = one.mode;
|
||||
entry->next = NULL;
|
||||
|
||||
*list_p = entry;
|
||||
list_p = &entry->next;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int entcmp(const char *name1, int dir1, const char *name2, int dir2)
|
||||
{
|
||||
int len1 = strlen(name1);
|
||||
int len2 = strlen(name2);
|
||||
int len = len1 < len2 ? len1 : len2;
|
||||
int ret = memcmp(name1, name2, len);
|
||||
unsigned char c1, c2;
|
||||
if (ret)
|
||||
return ret;
|
||||
c1 = name1[len];
|
||||
c2 = name2[len];
|
||||
if (!c1 && dir1)
|
||||
c1 = '/';
|
||||
if (!c2 && dir2)
|
||||
c2 = '/';
|
||||
ret = (c1 < c2) ? -1 : (c1 > c2) ? 1 : 0;
|
||||
if (c1 && c2 && !ret)
|
||||
ret = len1 - len2;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline void remove_entry(int remove)
|
||||
{
|
||||
if (remove >= 0)
|
||||
remove_cache_entry_at(remove);
|
||||
}
|
||||
|
||||
static int unpack_trees_rec(struct tree_entry_list **posns, int len,
|
||||
const char *base, struct unpack_trees_options *o,
|
||||
struct tree_entry_list *df_conflict_list)
|
||||
{
|
||||
int remove;
|
||||
int baselen = strlen(base);
|
||||
int src_size = len + 1;
|
||||
int retval = 0;
|
||||
|
||||
do {
|
||||
int i;
|
||||
const char *first;
|
||||
int firstdir = 0;
|
||||
int pathlen;
|
||||
unsigned ce_size;
|
||||
struct tree_entry_list **subposns;
|
||||
struct cache_entry **src;
|
||||
int any_files = 0;
|
||||
int any_dirs = 0;
|
||||
char *cache_name;
|
||||
int ce_stage;
|
||||
int skip_entry = 0;
|
||||
|
||||
/* Find the first name in the input. */
|
||||
|
||||
first = NULL;
|
||||
cache_name = NULL;
|
||||
|
||||
/* Check the cache */
|
||||
if (o->merge && o->pos < active_nr) {
|
||||
/* This is a bit tricky: */
|
||||
/* If the index has a subdirectory (with
|
||||
* contents) as the first name, it'll get a
|
||||
* filename like "foo/bar". But that's after
|
||||
* "foo", so the entry in trees will get
|
||||
* handled first, at which point we'll go into
|
||||
* "foo", and deal with "bar" from the index,
|
||||
* because the base will be "foo/". The only
|
||||
* way we can actually have "foo/bar" first of
|
||||
* all the things is if the trees don't
|
||||
* contain "foo" at all, in which case we'll
|
||||
* handle "foo/bar" without going into the
|
||||
* directory, but that's fine (and will return
|
||||
* an error anyway, with the added unknown
|
||||
* file case.
|
||||
*/
|
||||
|
||||
cache_name = active_cache[o->pos]->name;
|
||||
if (strlen(cache_name) > baselen &&
|
||||
!memcmp(cache_name, base, baselen)) {
|
||||
cache_name += baselen;
|
||||
first = cache_name;
|
||||
} else {
|
||||
cache_name = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
#if DBRT_DEBUG > 1
|
||||
if (first)
|
||||
fprintf(stderr, "index %s\n", first);
|
||||
#endif
|
||||
for (i = 0; i < len; i++) {
|
||||
if (!posns[i] || posns[i] == df_conflict_list)
|
||||
continue;
|
||||
#if DBRT_DEBUG > 1
|
||||
fprintf(stderr, "%d %s\n", i + 1, posns[i]->name);
|
||||
#endif
|
||||
if (!first || entcmp(first, firstdir,
|
||||
posns[i]->name,
|
||||
S_ISDIR(posns[i]->mode)) > 0) {
|
||||
first = posns[i]->name;
|
||||
firstdir = S_ISDIR(posns[i]->mode);
|
||||
}
|
||||
}
|
||||
/* No name means we're done */
|
||||
if (!first)
|
||||
goto leave_directory;
|
||||
|
||||
pathlen = strlen(first);
|
||||
ce_size = cache_entry_size(baselen + pathlen);
|
||||
|
||||
src = xcalloc(src_size, sizeof(struct cache_entry *));
|
||||
|
||||
subposns = xcalloc(len, sizeof(struct tree_list_entry *));
|
||||
|
||||
remove = -1;
|
||||
if (cache_name && !strcmp(cache_name, first)) {
|
||||
any_files = 1;
|
||||
src[0] = active_cache[o->pos];
|
||||
remove = o->pos;
|
||||
if (o->skip_unmerged && ce_stage(src[0]))
|
||||
skip_entry = 1;
|
||||
}
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
struct cache_entry *ce;
|
||||
|
||||
if (!posns[i] ||
|
||||
(posns[i] != df_conflict_list &&
|
||||
strcmp(first, posns[i]->name))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (posns[i] == df_conflict_list) {
|
||||
src[i + o->merge] = o->df_conflict_entry;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (S_ISDIR(posns[i]->mode)) {
|
||||
struct tree *tree = lookup_tree(posns[i]->sha1);
|
||||
struct tree_desc t;
|
||||
any_dirs = 1;
|
||||
parse_tree(tree);
|
||||
init_tree_desc(&t, tree->buffer, tree->size);
|
||||
subposns[i] = create_tree_entry_list(&t);
|
||||
posns[i] = posns[i]->next;
|
||||
src[i + o->merge] = o->df_conflict_entry;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (skip_entry) {
|
||||
subposns[i] = df_conflict_list;
|
||||
posns[i] = posns[i]->next;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!o->merge)
|
||||
ce_stage = 0;
|
||||
else if (i + 1 < o->head_idx)
|
||||
ce_stage = 1;
|
||||
else if (i + 1 > o->head_idx)
|
||||
ce_stage = 3;
|
||||
else
|
||||
ce_stage = 2;
|
||||
|
||||
ce = xcalloc(1, ce_size);
|
||||
ce->ce_mode = create_ce_mode(posns[i]->mode);
|
||||
ce->ce_flags = create_ce_flags(baselen + pathlen,
|
||||
ce_stage);
|
||||
memcpy(ce->name, base, baselen);
|
||||
memcpy(ce->name + baselen, first, pathlen + 1);
|
||||
|
||||
any_files = 1;
|
||||
|
||||
hashcpy(ce->sha1, posns[i]->sha1);
|
||||
src[i + o->merge] = ce;
|
||||
subposns[i] = df_conflict_list;
|
||||
posns[i] = posns[i]->next;
|
||||
}
|
||||
if (any_files) {
|
||||
if (skip_entry) {
|
||||
o->pos++;
|
||||
while (o->pos < active_nr &&
|
||||
!strcmp(active_cache[o->pos]->name,
|
||||
src[0]->name))
|
||||
o->pos++;
|
||||
} else if (o->merge) {
|
||||
int ret;
|
||||
|
||||
#if DBRT_DEBUG > 1
|
||||
fprintf(stderr, "%s:\n", first);
|
||||
for (i = 0; i < src_size; i++) {
|
||||
fprintf(stderr, " %d ", i);
|
||||
if (src[i])
|
||||
fprintf(stderr, "%06x %s\n", src[i]->ce_mode, sha1_to_hex(src[i]->sha1));
|
||||
else
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
#endif
|
||||
ret = o->fn(src, o, remove);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
#if DBRT_DEBUG > 1
|
||||
fprintf(stderr, "Added %d entries\n", ret);
|
||||
#endif
|
||||
o->pos += ret;
|
||||
} else {
|
||||
remove_entry(remove);
|
||||
for (i = 0; i < src_size; i++) {
|
||||
if (src[i]) {
|
||||
add_cache_entry(src[i], ADD_CACHE_OK_TO_ADD|ADD_CACHE_SKIP_DFCHECK);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (any_dirs) {
|
||||
char *newbase = xmalloc(baselen + 2 + pathlen);
|
||||
memcpy(newbase, base, baselen);
|
||||
memcpy(newbase + baselen, first, pathlen);
|
||||
newbase[baselen + pathlen] = '/';
|
||||
newbase[baselen + pathlen + 1] = '\0';
|
||||
if (unpack_trees_rec(subposns, len, newbase, o,
|
||||
df_conflict_list)) {
|
||||
retval = -1;
|
||||
goto leave_directory;
|
||||
}
|
||||
free(newbase);
|
||||
}
|
||||
free(subposns);
|
||||
free(src);
|
||||
} while (1);
|
||||
|
||||
leave_directory:
|
||||
return retval;
|
||||
memcpy(new, ce, size);
|
||||
new->next = NULL;
|
||||
new->ce_flags = (new->ce_flags & ~clear) | set;
|
||||
add_index_entry(&o->result, new, ADD_CACHE_OK_TO_ADD|ADD_CACHE_OK_TO_REPLACE|ADD_CACHE_SKIP_DFCHECK);
|
||||
}
|
||||
|
||||
/* Unlink the last component and attempt to remove leading
|
||||
@@ -308,11 +59,12 @@ static void check_updates(struct unpack_trees_options *o)
|
||||
unsigned cnt = 0, total = 0;
|
||||
struct progress *progress = NULL;
|
||||
char last_symlink[PATH_MAX];
|
||||
struct index_state *index = &o->result;
|
||||
int i;
|
||||
|
||||
if (o->update && o->verbose_update) {
|
||||
for (total = cnt = 0; cnt < active_nr; cnt++) {
|
||||
struct cache_entry *ce = active_cache[cnt];
|
||||
for (total = cnt = 0; cnt < index->cache_nr; cnt++) {
|
||||
struct cache_entry *ce = index->cache[cnt];
|
||||
if (ce->ce_flags & (CE_UPDATE | CE_REMOVE))
|
||||
total++;
|
||||
}
|
||||
@@ -323,15 +75,15 @@ static void check_updates(struct unpack_trees_options *o)
|
||||
}
|
||||
|
||||
*last_symlink = '\0';
|
||||
for (i = 0; i < active_nr; i++) {
|
||||
struct cache_entry *ce = active_cache[i];
|
||||
for (i = 0; i < index->cache_nr; i++) {
|
||||
struct cache_entry *ce = index->cache[i];
|
||||
|
||||
if (ce->ce_flags & (CE_UPDATE | CE_REMOVE))
|
||||
display_progress(progress, ++cnt);
|
||||
if (ce->ce_flags & CE_REMOVE) {
|
||||
if (o->update)
|
||||
unlink_entry(ce->name, last_symlink);
|
||||
remove_cache_entry_at(i);
|
||||
remove_index_entry_at(&o->result, i);
|
||||
i--;
|
||||
continue;
|
||||
}
|
||||
@@ -346,21 +98,244 @@ static void check_updates(struct unpack_trees_options *o)
|
||||
stop_progress(&progress);
|
||||
}
|
||||
|
||||
static inline int call_unpack_fn(struct cache_entry **src, struct unpack_trees_options *o)
|
||||
{
|
||||
int ret = o->fn(src, o);
|
||||
if (ret > 0)
|
||||
ret = 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int unpack_index_entry(struct cache_entry *ce, struct unpack_trees_options *o)
|
||||
{
|
||||
struct cache_entry *src[5] = { ce, };
|
||||
|
||||
o->pos++;
|
||||
if (ce_stage(ce)) {
|
||||
if (o->skip_unmerged) {
|
||||
add_entry(o, ce, 0, 0);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return call_unpack_fn(src, o);
|
||||
}
|
||||
|
||||
int traverse_trees_recursive(int n, unsigned long dirmask, unsigned long df_conflicts, struct name_entry *names, struct traverse_info *info)
|
||||
{
|
||||
int i;
|
||||
struct tree_desc t[3];
|
||||
struct traverse_info newinfo;
|
||||
struct name_entry *p;
|
||||
|
||||
p = names;
|
||||
while (!p->mode)
|
||||
p++;
|
||||
|
||||
newinfo = *info;
|
||||
newinfo.prev = info;
|
||||
newinfo.name = *p;
|
||||
newinfo.pathlen += tree_entry_len(p->path, p->sha1) + 1;
|
||||
newinfo.conflicts |= df_conflicts;
|
||||
|
||||
for (i = 0; i < n; i++, dirmask >>= 1) {
|
||||
const unsigned char *sha1 = NULL;
|
||||
if (dirmask & 1)
|
||||
sha1 = names[i].sha1;
|
||||
fill_tree_descriptor(t+i, sha1);
|
||||
}
|
||||
return traverse_trees(n, t, &newinfo);
|
||||
}
|
||||
|
||||
/*
|
||||
* Compare the traverse-path to the cache entry without actually
|
||||
* having to generate the textual representation of the traverse
|
||||
* path.
|
||||
*
|
||||
* NOTE! This *only* compares up to the size of the traverse path
|
||||
* itself - the caller needs to do the final check for the cache
|
||||
* entry having more data at the end!
|
||||
*/
|
||||
static int do_compare_entry(const struct cache_entry *ce, const struct traverse_info *info, const struct name_entry *n)
|
||||
{
|
||||
int len, pathlen, ce_len;
|
||||
const char *ce_name;
|
||||
|
||||
if (info->prev) {
|
||||
int cmp = do_compare_entry(ce, info->prev, &info->name);
|
||||
if (cmp)
|
||||
return cmp;
|
||||
}
|
||||
pathlen = info->pathlen;
|
||||
ce_len = ce_namelen(ce);
|
||||
|
||||
/* If ce_len < pathlen then we must have previously hit "name == directory" entry */
|
||||
if (ce_len < pathlen)
|
||||
return -1;
|
||||
|
||||
ce_len -= pathlen;
|
||||
ce_name = ce->name + pathlen;
|
||||
|
||||
len = tree_entry_len(n->path, n->sha1);
|
||||
return df_name_compare(ce_name, ce_len, S_IFREG, n->path, len, n->mode);
|
||||
}
|
||||
|
||||
static int compare_entry(const struct cache_entry *ce, const struct traverse_info *info, const struct name_entry *n)
|
||||
{
|
||||
int cmp = do_compare_entry(ce, info, n);
|
||||
if (cmp)
|
||||
return cmp;
|
||||
|
||||
/*
|
||||
* Even if the beginning compared identically, the ce should
|
||||
* compare as bigger than a directory leading up to it!
|
||||
*/
|
||||
return ce_namelen(ce) > traverse_path_len(info, n);
|
||||
}
|
||||
|
||||
static struct cache_entry *create_ce_entry(const struct traverse_info *info, const struct name_entry *n, int stage)
|
||||
{
|
||||
int len = traverse_path_len(info, n);
|
||||
struct cache_entry *ce = xcalloc(1, cache_entry_size(len));
|
||||
|
||||
ce->ce_mode = create_ce_mode(n->mode);
|
||||
ce->ce_flags = create_ce_flags(len, stage);
|
||||
hashcpy(ce->sha1, n->sha1);
|
||||
make_traverse_path(ce->name, info, n);
|
||||
|
||||
return ce;
|
||||
}
|
||||
|
||||
static int unpack_nondirectories(int n, unsigned long mask, unsigned long dirmask, struct cache_entry *src[5],
|
||||
const struct name_entry *names, const struct traverse_info *info)
|
||||
{
|
||||
int i;
|
||||
struct unpack_trees_options *o = info->data;
|
||||
unsigned long conflicts;
|
||||
|
||||
/* Do we have *only* directories? Nothing to do */
|
||||
if (mask == dirmask && !src[0])
|
||||
return 0;
|
||||
|
||||
conflicts = info->conflicts;
|
||||
if (o->merge)
|
||||
conflicts >>= 1;
|
||||
conflicts |= dirmask;
|
||||
|
||||
/*
|
||||
* Ok, we've filled in up to any potential index entry in src[0],
|
||||
* now do the rest.
|
||||
*/
|
||||
for (i = 0; i < n; i++) {
|
||||
int stage;
|
||||
unsigned int bit = 1ul << i;
|
||||
if (conflicts & bit) {
|
||||
src[i + o->merge] = o->df_conflict_entry;
|
||||
continue;
|
||||
}
|
||||
if (!(mask & bit))
|
||||
continue;
|
||||
if (!o->merge)
|
||||
stage = 0;
|
||||
else if (i + 1 < o->head_idx)
|
||||
stage = 1;
|
||||
else if (i + 1 > o->head_idx)
|
||||
stage = 3;
|
||||
else
|
||||
stage = 2;
|
||||
src[i + o->merge] = create_ce_entry(info, names + i, stage);
|
||||
}
|
||||
|
||||
if (o->merge)
|
||||
return call_unpack_fn(src, o);
|
||||
|
||||
n += o->merge;
|
||||
for (i = 0; i < n; i++)
|
||||
add_entry(o, src[i], 0, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int unpack_callback(int n, unsigned long mask, unsigned long dirmask, struct name_entry *names, struct traverse_info *info)
|
||||
{
|
||||
struct cache_entry *src[5] = { NULL, };
|
||||
struct unpack_trees_options *o = info->data;
|
||||
const struct name_entry *p = names;
|
||||
|
||||
/* Find first entry with a real name (we could use "mask" too) */
|
||||
while (!p->mode)
|
||||
p++;
|
||||
|
||||
/* Are we supposed to look at the index too? */
|
||||
if (o->merge) {
|
||||
while (o->pos < o->src_index->cache_nr) {
|
||||
struct cache_entry *ce = o->src_index->cache[o->pos];
|
||||
int cmp = compare_entry(ce, info, p);
|
||||
if (cmp < 0) {
|
||||
if (unpack_index_entry(ce, o) < 0)
|
||||
return -1;
|
||||
continue;
|
||||
}
|
||||
if (!cmp) {
|
||||
o->pos++;
|
||||
if (ce_stage(ce)) {
|
||||
/*
|
||||
* If we skip unmerged index entries, we'll skip this
|
||||
* entry *and* the tree entries associated with it!
|
||||
*/
|
||||
if (o->skip_unmerged) {
|
||||
add_entry(o, ce, 0, 0);
|
||||
return mask;
|
||||
}
|
||||
}
|
||||
src[0] = ce;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (unpack_nondirectories(n, mask, dirmask, src, names, info) < 0)
|
||||
return -1;
|
||||
|
||||
/* Now handle any directories.. */
|
||||
if (dirmask) {
|
||||
unsigned long conflicts = mask & ~dirmask;
|
||||
if (o->merge) {
|
||||
conflicts <<= 1;
|
||||
if (src[0])
|
||||
conflicts |= 1;
|
||||
}
|
||||
if (traverse_trees_recursive(n, dirmask, conflicts,
|
||||
names, info) < 0)
|
||||
return -1;
|
||||
return mask;
|
||||
}
|
||||
|
||||
return mask;
|
||||
}
|
||||
|
||||
static int unpack_failed(struct unpack_trees_options *o, const char *message)
|
||||
{
|
||||
discard_index(&o->result);
|
||||
if (!o->gently) {
|
||||
if (message)
|
||||
return error(message);
|
||||
return -1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options *o)
|
||||
{
|
||||
struct tree_entry_list **posns;
|
||||
int i;
|
||||
struct tree_entry_list df_conflict_list;
|
||||
static struct cache_entry *dfc;
|
||||
|
||||
memset(&df_conflict_list, 0, sizeof(df_conflict_list));
|
||||
df_conflict_list.next = &df_conflict_list;
|
||||
if (len > 4)
|
||||
die("unpack_trees takes at most four trees");
|
||||
memset(&state, 0, sizeof(state));
|
||||
state.base_dir = "";
|
||||
state.force = 1;
|
||||
state.quiet = 1;
|
||||
state.refresh_cache = 1;
|
||||
|
||||
memset(&o->result, 0, sizeof(o->result));
|
||||
o->merge_size = len;
|
||||
|
||||
if (!dfc)
|
||||
@@ -368,30 +343,33 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
|
||||
o->df_conflict_entry = dfc;
|
||||
|
||||
if (len) {
|
||||
posns = xmalloc(len * sizeof(struct tree_entry_list *));
|
||||
for (i = 0; i < len; i++)
|
||||
posns[i] = create_tree_entry_list(t+i);
|
||||
const char *prefix = o->prefix ? o->prefix : "";
|
||||
struct traverse_info info;
|
||||
|
||||
if (unpack_trees_rec(posns, len, o->prefix ? o->prefix : "",
|
||||
o, &df_conflict_list)) {
|
||||
if (o->gently) {
|
||||
discard_cache();
|
||||
read_cache();
|
||||
}
|
||||
return -1;
|
||||
setup_traverse_info(&info, prefix);
|
||||
info.fn = unpack_callback;
|
||||
info.data = o;
|
||||
|
||||
if (traverse_trees(len, t, &info) < 0)
|
||||
return unpack_failed(o, NULL);
|
||||
}
|
||||
|
||||
/* Any left-over entries in the index? */
|
||||
if (o->merge) {
|
||||
while (o->pos < o->src_index->cache_nr) {
|
||||
struct cache_entry *ce = o->src_index->cache[o->pos];
|
||||
if (unpack_index_entry(ce, o) < 0)
|
||||
return unpack_failed(o, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
if (o->trivial_merges_only && o->nontrivial_merge) {
|
||||
if (o->gently) {
|
||||
discard_cache();
|
||||
read_cache();
|
||||
}
|
||||
return o->gently ? -1 :
|
||||
error("Merge requires file-level merging");
|
||||
}
|
||||
if (o->trivial_merges_only && o->nontrivial_merge)
|
||||
return unpack_failed(o, "Merge requires file-level merging");
|
||||
|
||||
o->src_index = NULL;
|
||||
check_updates(o);
|
||||
if (o->dst_index)
|
||||
*o->dst_index = o->result;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -427,7 +405,7 @@ static int verify_uptodate(struct cache_entry *ce,
|
||||
return 0;
|
||||
|
||||
if (!lstat(ce->name, &st)) {
|
||||
unsigned changed = ce_match_stat(ce, &st, CE_MATCH_IGNORE_VALID);
|
||||
unsigned changed = ie_match_stat(o->src_index, ce, &st, CE_MATCH_IGNORE_VALID);
|
||||
if (!changed)
|
||||
return 0;
|
||||
/*
|
||||
@@ -447,10 +425,10 @@ static int verify_uptodate(struct cache_entry *ce,
|
||||
error("Entry '%s' not uptodate. Cannot merge.", ce->name);
|
||||
}
|
||||
|
||||
static void invalidate_ce_path(struct cache_entry *ce)
|
||||
static void invalidate_ce_path(struct cache_entry *ce, struct unpack_trees_options *o)
|
||||
{
|
||||
if (ce)
|
||||
cache_tree_invalidate_path(active_cache_tree, ce->name);
|
||||
cache_tree_invalidate_path(o->src_index->cache_tree, ce->name);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -495,12 +473,12 @@ static int verify_clean_subdirectory(struct cache_entry *ce, const char *action,
|
||||
* in that directory.
|
||||
*/
|
||||
namelen = strlen(ce->name);
|
||||
pos = cache_name_pos(ce->name, namelen);
|
||||
pos = index_name_pos(o->src_index, ce->name, namelen);
|
||||
if (0 <= pos)
|
||||
return cnt; /* we have it as nondirectory */
|
||||
pos = -pos - 1;
|
||||
for (i = pos; i < active_nr; i++) {
|
||||
struct cache_entry *ce = active_cache[i];
|
||||
for (i = pos; i < o->src_index->cache_nr; i++) {
|
||||
struct cache_entry *ce = o->src_index->cache[i];
|
||||
int len = ce_namelen(ce);
|
||||
if (len < namelen ||
|
||||
strncmp(ce->name, ce->name, namelen) ||
|
||||
@@ -512,7 +490,7 @@ static int verify_clean_subdirectory(struct cache_entry *ce, const char *action,
|
||||
if (!ce_stage(ce)) {
|
||||
if (verify_uptodate(ce, o))
|
||||
return -1;
|
||||
ce->ce_flags |= CE_REMOVE;
|
||||
add_entry(o, ce, CE_REMOVE, 0);
|
||||
}
|
||||
cnt++;
|
||||
}
|
||||
@@ -598,9 +576,9 @@ static int verify_absent(struct cache_entry *ce, const char *action,
|
||||
* delete this path, which is in a subdirectory that
|
||||
* is being replaced with a blob.
|
||||
*/
|
||||
cnt = cache_name_pos(ce->name, strlen(ce->name));
|
||||
cnt = index_name_pos(&o->result, ce->name, strlen(ce->name));
|
||||
if (0 <= cnt) {
|
||||
struct cache_entry *ce = active_cache[cnt];
|
||||
struct cache_entry *ce = o->result.cache[cnt];
|
||||
if (ce->ce_flags & CE_REMOVE)
|
||||
return 0;
|
||||
}
|
||||
@@ -615,7 +593,6 @@ static int verify_absent(struct cache_entry *ce, const char *action,
|
||||
static int merged_entry(struct cache_entry *merge, struct cache_entry *old,
|
||||
struct unpack_trees_options *o)
|
||||
{
|
||||
merge->ce_flags |= CE_UPDATE;
|
||||
if (old) {
|
||||
/*
|
||||
* See if we can re-use the old CE directly?
|
||||
@@ -629,38 +606,38 @@ static int merged_entry(struct cache_entry *merge, struct cache_entry *old,
|
||||
} else {
|
||||
if (verify_uptodate(old, o))
|
||||
return -1;
|
||||
invalidate_ce_path(old);
|
||||
invalidate_ce_path(old, o);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (verify_absent(merge, "overwritten", o))
|
||||
return -1;
|
||||
invalidate_ce_path(merge);
|
||||
invalidate_ce_path(merge, o);
|
||||
}
|
||||
|
||||
merge->ce_flags &= ~CE_STAGEMASK;
|
||||
add_cache_entry(merge, ADD_CACHE_OK_TO_ADD|ADD_CACHE_OK_TO_REPLACE);
|
||||
add_entry(o, merge, CE_UPDATE, CE_STAGEMASK);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int deleted_entry(struct cache_entry *ce, struct cache_entry *old,
|
||||
struct unpack_trees_options *o)
|
||||
{
|
||||
if (old) {
|
||||
if (verify_uptodate(old, o))
|
||||
return -1;
|
||||
} else
|
||||
/* Did it exist in the index? */
|
||||
if (!old) {
|
||||
if (verify_absent(ce, "removed", o))
|
||||
return -1;
|
||||
ce->ce_flags |= CE_REMOVE;
|
||||
add_cache_entry(ce, ADD_CACHE_OK_TO_ADD|ADD_CACHE_OK_TO_REPLACE);
|
||||
invalidate_ce_path(ce);
|
||||
return 0;
|
||||
}
|
||||
if (verify_uptodate(old, o))
|
||||
return -1;
|
||||
add_entry(o, ce, CE_REMOVE, 0);
|
||||
invalidate_ce_path(ce, o);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int keep_entry(struct cache_entry *ce, struct unpack_trees_options *o)
|
||||
{
|
||||
add_cache_entry(ce, ADD_CACHE_OK_TO_ADD);
|
||||
add_entry(o, ce, 0, 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -680,9 +657,7 @@ static void show_stage_entry(FILE *o,
|
||||
}
|
||||
#endif
|
||||
|
||||
int threeway_merge(struct cache_entry **stages,
|
||||
struct unpack_trees_options *o,
|
||||
int remove)
|
||||
int threeway_merge(struct cache_entry **stages, struct unpack_trees_options *o)
|
||||
{
|
||||
struct cache_entry *index;
|
||||
struct cache_entry *head;
|
||||
@@ -759,10 +734,8 @@ int threeway_merge(struct cache_entry **stages,
|
||||
}
|
||||
|
||||
/* #1 */
|
||||
if (!head && !remote && any_anc_missing) {
|
||||
remove_entry(remove);
|
||||
if (!head && !remote && any_anc_missing)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Under the new "aggressive" rule, we resolve mostly trivial
|
||||
* cases that we historically had git-merge-one-file resolve.
|
||||
@@ -794,10 +767,9 @@ int threeway_merge(struct cache_entry **stages,
|
||||
if ((head_deleted && remote_deleted) ||
|
||||
(head_deleted && remote && remote_match) ||
|
||||
(remote_deleted && head && head_match)) {
|
||||
remove_entry(remove);
|
||||
if (index)
|
||||
return deleted_entry(index, index, o);
|
||||
else if (ce && !head_deleted) {
|
||||
if (ce && !head_deleted) {
|
||||
if (verify_absent(ce, "removed", o))
|
||||
return -1;
|
||||
}
|
||||
@@ -820,7 +792,6 @@ int threeway_merge(struct cache_entry **stages,
|
||||
return -1;
|
||||
}
|
||||
|
||||
remove_entry(remove);
|
||||
o->nontrivial_merge = 1;
|
||||
|
||||
/* #2, #3, #4, #6, #7, #9, #10, #11. */
|
||||
@@ -855,9 +826,7 @@ int threeway_merge(struct cache_entry **stages,
|
||||
* "carry forward" rule, please see <Documentation/git-read-tree.txt>.
|
||||
*
|
||||
*/
|
||||
int twoway_merge(struct cache_entry **src,
|
||||
struct unpack_trees_options *o,
|
||||
int remove)
|
||||
int twoway_merge(struct cache_entry **src, struct unpack_trees_options *o)
|
||||
{
|
||||
struct cache_entry *current = src[0];
|
||||
struct cache_entry *oldtree = src[1];
|
||||
@@ -885,7 +854,6 @@ int twoway_merge(struct cache_entry **src,
|
||||
}
|
||||
else if (oldtree && !newtree && same(current, oldtree)) {
|
||||
/* 10 or 11 */
|
||||
remove_entry(remove);
|
||||
return deleted_entry(oldtree, current, o);
|
||||
}
|
||||
else if (oldtree && newtree &&
|
||||
@@ -895,7 +863,6 @@ int twoway_merge(struct cache_entry **src,
|
||||
}
|
||||
else {
|
||||
/* all other failures */
|
||||
remove_entry(remove);
|
||||
if (oldtree)
|
||||
return o->gently ? -1 : reject_merge(oldtree);
|
||||
if (current)
|
||||
@@ -907,7 +874,6 @@ int twoway_merge(struct cache_entry **src,
|
||||
}
|
||||
else if (newtree)
|
||||
return merged_entry(newtree, current, o);
|
||||
remove_entry(remove);
|
||||
return deleted_entry(oldtree, current, o);
|
||||
}
|
||||
|
||||
@@ -918,8 +884,7 @@ int twoway_merge(struct cache_entry **src,
|
||||
* stage0 does not have anything there.
|
||||
*/
|
||||
int bind_merge(struct cache_entry **src,
|
||||
struct unpack_trees_options *o,
|
||||
int remove)
|
||||
struct unpack_trees_options *o)
|
||||
{
|
||||
struct cache_entry *old = src[0];
|
||||
struct cache_entry *a = src[1];
|
||||
@@ -929,7 +894,7 @@ int bind_merge(struct cache_entry **src,
|
||||
o->merge_size);
|
||||
if (a && old)
|
||||
return o->gently ? -1 :
|
||||
error("Entry '%s' overlaps. Cannot bind.", a->name);
|
||||
error("Entry '%s' overlaps with '%s'. Cannot bind.", a->name, old->name);
|
||||
if (!a)
|
||||
return keep_entry(old, o);
|
||||
else
|
||||
@@ -942,9 +907,7 @@ int bind_merge(struct cache_entry **src,
|
||||
* The rule is:
|
||||
* - take the stat information from stage0, take the data from stage1
|
||||
*/
|
||||
int oneway_merge(struct cache_entry **src,
|
||||
struct unpack_trees_options *o,
|
||||
int remove)
|
||||
int oneway_merge(struct cache_entry **src, struct unpack_trees_options *o)
|
||||
{
|
||||
struct cache_entry *old = src[0];
|
||||
struct cache_entry *a = src[1];
|
||||
@@ -953,18 +916,19 @@ int oneway_merge(struct cache_entry **src,
|
||||
return error("Cannot do a oneway merge of %d trees",
|
||||
o->merge_size);
|
||||
|
||||
if (!a) {
|
||||
remove_entry(remove);
|
||||
if (!a)
|
||||
return deleted_entry(old, old, o);
|
||||
}
|
||||
|
||||
if (old && same(old, a)) {
|
||||
int update = 0;
|
||||
if (o->reset) {
|
||||
struct stat st;
|
||||
if (lstat(old->name, &st) ||
|
||||
ce_match_stat(old, &st, CE_MATCH_IGNORE_VALID))
|
||||
old->ce_flags |= CE_UPDATE;
|
||||
ie_match_stat(o->src_index, old, &st, CE_MATCH_IGNORE_VALID))
|
||||
update |= CE_UPDATE;
|
||||
}
|
||||
return keep_entry(old, o);
|
||||
add_entry(o, old, update, 0);
|
||||
return 0;
|
||||
}
|
||||
return merged_entry(a, old, o);
|
||||
}
|
||||
|
||||
@@ -4,8 +4,7 @@
|
||||
struct unpack_trees_options;
|
||||
|
||||
typedef int (*merge_fn_t)(struct cache_entry **src,
|
||||
struct unpack_trees_options *options,
|
||||
int remove);
|
||||
struct unpack_trees_options *options);
|
||||
|
||||
struct unpack_trees_options {
|
||||
int reset;
|
||||
@@ -28,14 +27,18 @@ struct unpack_trees_options {
|
||||
|
||||
struct cache_entry *df_conflict_entry;
|
||||
void *unpack_data;
|
||||
|
||||
struct index_state *dst_index;
|
||||
const struct index_state *src_index;
|
||||
struct index_state result;
|
||||
};
|
||||
|
||||
extern int unpack_trees(unsigned n, struct tree_desc *t,
|
||||
struct unpack_trees_options *options);
|
||||
|
||||
int threeway_merge(struct cache_entry **stages, struct unpack_trees_options *o, int);
|
||||
int twoway_merge(struct cache_entry **src, struct unpack_trees_options *o, int);
|
||||
int bind_merge(struct cache_entry **src, struct unpack_trees_options *o, int);
|
||||
int oneway_merge(struct cache_entry **src, struct unpack_trees_options *o, int);
|
||||
int threeway_merge(struct cache_entry **stages, struct unpack_trees_options *o);
|
||||
int twoway_merge(struct cache_entry **src, struct unpack_trees_options *o);
|
||||
int bind_merge(struct cache_entry **src, struct unpack_trees_options *o);
|
||||
int oneway_merge(struct cache_entry **src, struct unpack_trees_options *o);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user