Merge with git://kernel.org/pub/scm/git/git.git

This commit is contained in:
Martin Langhoff 2006-05-03 22:27:33 +12:00
commit 24e12579fc
11 changed files with 227 additions and 59 deletions

View File

@ -3,38 +3,54 @@ git-rebase(1)
NAME NAME
---- ----
git-rebase - Rebase local commits to new upstream head git-rebase - Rebase local commits to a new head
SYNOPSIS SYNOPSIS
-------- --------
'git-rebase' [--onto <newbase>] <upstream> [<branch>] 'git-rebase' [--onto <newbase>] <upstream> [<branch>]
'git-rebase' --continue
'git-rebase' --abort
DESCRIPTION DESCRIPTION
----------- -----------
git-rebase applies to <upstream> (or optionally to <newbase>) commits git-rebase replaces <branch> with a new branch of the same name. When
from <branch> that do not appear in <upstream>. When <branch> is not the --onto option is provided the new branch starts out with a HEAD equal
specified it defaults to the current branch (HEAD). to <newbase>, otherwise it is equal to <upstream>. It then attempts to
create a new commit for each commit from the original <branch> that does
not exist in the <upstream> branch.
When git-rebase is complete, <branch> will be updated to point to the It is possible that a merge failure will prevent this process from being
newly created line of commit objects, so the previous line will not be completely automatic. You will have to resolve any such merge failure
accessible unless there are other references to it already. and run `git rebase --continue`. If you can not resolve the merge
failure, running `git rebase --abort` will restore the original <branch>
and remove the working files found in the .dotest directory.
Note that if <branch> is not specified on the command line, the currently
checked out branch is used.
Assume the following history exists and the current branch is "topic": Assume the following history exists and the current branch is "topic":
------------
A---B---C topic A---B---C topic
/ /
D---E---F---G master D---E---F---G master
------------
From this point, the result of either of the following commands: From this point, the result of either of the following commands:
git-rebase master git-rebase master
git-rebase master topic git-rebase master topic
would be: would be:
------------
A'--B'--C' topic A'--B'--C' topic
/ /
D---E---F---G master D---E---F---G master
------------
While, starting from the same point, the result of either of the following While, starting from the same point, the result of either of the following
commands: commands:
@ -44,21 +60,33 @@ commands:
would be: would be:
------------
A'--B'--C' topic A'--B'--C' topic
/ /
D---E---F---G master D---E---F---G master
------------
In case of conflict, git-rebase will stop at the first problematic commit In case of conflict, git-rebase will stop at the first problematic commit
and leave conflict markers in the tree. After resolving the conflict manually and leave conflict markers in the tree. You can use git diff to locate
and updating the index with the desired resolution, you can continue the the markers (<<<<<<) and make edits to resolve the conflict. For each
rebasing process with file you edit, you need to tell git that the conflict has been resolved,
typically this would be done with
git update-index <filename>
After resolving the conflict manually and updating the index with the
desired resolution, you can continue the rebasing process with
git rebase --continue
git am --resolved --3way
Alternatively, you can undo the git-rebase with Alternatively, you can undo the git-rebase with
git reset --hard ORIG_HEAD
rm -r .dotest git rebase --abort
OPTIONS OPTIONS
------- -------
@ -73,6 +101,28 @@ OPTIONS
<branch>:: <branch>::
Working branch; defaults to HEAD. Working branch; defaults to HEAD.
--continue::
Restart the rebasing process after having resolved a merge conflict.
--abort::
Restore the original branch and abort the rebase operation.
NOTES
-----
When you rebase a branch, you are changing its history in a way that
will cause problems for anyone who already has a copy of the branch
in their repository and tries to pull updates from you. You should
understand the implications of using 'git rebase' on a repository that
you share.
When the git rebase command is run, it will first execute a "pre-rebase"
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.
Author Author
------ ------
Written by Junio C Hamano <junkio@cox.net> Written by Junio C Hamano <junkio@cox.net>

View File

@ -135,6 +135,7 @@ extern const char *setup_git_directory(void);
extern const char *prefix_path(const char *prefix, int len, const char *path); extern const char *prefix_path(const char *prefix, int len, const char *path);
extern const char *prefix_filename(const char *prefix, int len, const char *path); extern const char *prefix_filename(const char *prefix, int len, const char *path);
extern void verify_filename(const char *prefix, const char *name); extern void verify_filename(const char *prefix, const char *name);
extern void verify_non_filename(const char *prefix, const char *name);
#define alloc_nr(x) (((x)+16)*3/2) #define alloc_nr(x) (((x)+16)*3/2)

View File

@ -60,6 +60,12 @@ static char *parse_value(void)
space = 1; space = 1;
continue; continue;
} }
if (!quote) {
if (c == ';' || c == '#') {
comment = 1;
continue;
}
}
if (space) { if (space) {
if (len) if (len)
value[len++] = ' '; value[len++] = ' ';
@ -93,12 +99,6 @@ static char *parse_value(void)
quote = 1-quote; quote = 1-quote;
continue; continue;
} }
if (!quote) {
if (c == ';' || c == '#') {
comment = 1;
continue;
}
}
value[len++] = c; value[len++] = c;
} }
} }

View File

@ -14,6 +14,26 @@ stop_here () {
exit 1 exit 1
} }
stop_here_user_resolve () {
cmdline=$(basename $0)
if test '' != "$interactive"
then
cmdline="$cmdline -i"
fi
if test '' != "$threeway"
then
cmdline="$cmdline -3"
fi
if test '.dotest' != "$dotest"
then
cmdline="$cmdline -d=$dotest"
fi
echo "When you have resolved this problem run \"$cmdline --resolved\"."
echo "If you would prefer to skip this patch, instead run \"$cmdline --skip\"."
stop_here $1
}
go_next () { go_next () {
rm -f "$dotest/$msgnum" "$dotest/msg" "$dotest/msg-clean" \ rm -f "$dotest/$msgnum" "$dotest/msg" "$dotest/msg-clean" \
"$dotest/patch" "$dotest/info" "$dotest/patch" "$dotest/info"
@ -374,14 +394,14 @@ do
if test '' = "$changed" if test '' = "$changed"
then then
echo "No changes - did you forget update-index?" echo "No changes - did you forget update-index?"
stop_here $this stop_here_user_resolve $this
fi fi
unmerged=$(git-ls-files -u) unmerged=$(git-ls-files -u)
if test -n "$unmerged" if test -n "$unmerged"
then then
echo "You still have unmerged paths in your index" echo "You still have unmerged paths in your index"
echo "did you forget update-index?" echo "did you forget update-index?"
stop_here $this stop_here_user_resolve $this
fi fi
apply_status=0 apply_status=0
;; ;;
@ -407,7 +427,7 @@ do
if test $apply_status != 0 if test $apply_status != 0
then then
echo Patch failed at $msgnum. echo Patch failed at $msgnum.
stop_here $this stop_here_user_resolve $this
fi fi
if test -x "$GIT_DIR"/hooks/pre-applypatch if test -x "$GIT_DIR"/hooks/pre-applypatch

View File

@ -270,14 +270,22 @@ fetch_main () {
if [ -n "$GIT_SSL_NO_VERIFY" ]; then if [ -n "$GIT_SSL_NO_VERIFY" ]; then
curl_extra_args="-k" curl_extra_args="-k"
fi fi
remote_name_quoted=$(perl -e ' max_depth=5
depth=0
head="ref: $remote_name"
while (expr "z$head" : "zref:" && expr $depth \< $max_depth) >/dev/null
do
remote_name_quoted=$(perl -e '
my $u = $ARGV[0]; my $u = $ARGV[0];
$u =~ s/^ref:\s*//;
$u =~ s{([^-a-zA-Z0-9/.])}{sprintf"%%%02x",ord($1)}eg; $u =~ s{([^-a-zA-Z0-9/.])}{sprintf"%%%02x",ord($1)}eg;
print "$u"; print "$u";
' "$remote_name") ' "$head")
head=$(curl -nsfL $curl_extra_args "$remote/$remote_name_quoted") && head=$(curl -nsfL $curl_extra_args "$remote/$remote_name_quoted")
depth=$( expr \( $depth + 1 \) )
done
expr "z$head" : "z$_x40\$" >/dev/null || expr "z$head" : "z$_x40\$" >/dev/null ||
die "Failed to fetch $remote_name from $remote" die "Failed to fetch $remote_name from $remote"
echo >&2 Fetching "$remote_name from $remote" using http echo >&2 Fetching "$remote_name from $remote" using http
git-http-fetch -v -a "$head" "$remote/" || exit git-http-fetch -v -a "$head" "$remote/" || exit
;; ;;

View File

@ -4,37 +4,51 @@
# #
USAGE='[--onto <newbase>] <upstream> [<branch>]' USAGE='[--onto <newbase>] <upstream> [<branch>]'
LONG_USAGE='git-rebase applies to <upstream> (or optionally to <newbase>) commits LONG_USAGE='git-rebase replaces <branch> with a new branch of the
from <branch> that do not appear in <upstream>. When <branch> is not same name. When the --onto option is provided the new branch starts
specified it defaults to the current branch (HEAD). out with a HEAD equal to <newbase>, otherwise it is equal to <upstream>
It then attempts to create a new commit for each commit from the original
<branch> that does not exist in the <upstream> branch.
When git-rebase is complete, <branch> will be updated to point to the It is possible that a merge failure will prevent this process from being
newly created line of commit objects, so the previous line will not be completely automatic. You will have to resolve any such merge failure
accessible unless there are other references to it already. and run git-rebase --continue. If you can not resolve the merge failure,
running git-rebase --abort will restore the original <branch> and remove
the working files found in the .dotest directory.
Assuming the following history: 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.
A---B---C topic Example: git-rebase master~1 topic
/
D---E---F---G master
The result of the following command: A---B---C topic A'\''--B'\''--C'\'' topic
/ --> /
git-rebase --onto master~1 master topic D---E---F---G master D---E---F---G master
would be:
A'\''--B'\''--C'\'' topic
/
D---E---F---G master
' '
. git-sh-setup . git-sh-setup
unset newbase unset newbase
while case "$#" in 0) break ;; esac while case "$#" in 0) break ;; esac
do do
case "$1" in case "$1" in
--continue)
diff=$(git-diff-files)
case "$diff" in
?*) echo "You must edit all merge conflicts and then"
echo "mark them as resolved using git update-index"
exit 1
;;
esac
git am --resolved --3way
exit
;;
--abort)
[ -d .dotest ] || die "No rebase in progress?"
git reset --hard ORIG_HEAD
rm -r .dotest
exit
;;
--onto) --onto)
test 2 -le "$#" || usage test 2 -le "$#" || usage
newbase="$2" newbase="$2"

View File

@ -291,6 +291,13 @@ sub send_message
my $to = join (",\n\t", @recipients); my $to = join (",\n\t", @recipients);
@recipients = unique_email_list(@recipients,@cc); @recipients = unique_email_list(@recipients,@cc);
my $date = strftime('%a, %d %b %Y %H:%M:%S %z', localtime($time++)); my $date = strftime('%a, %d %b %Y %H:%M:%S %z', localtime($time++));
my $gitversion = '@@GIT_VERSION@@';
if ($gitversion =~ m/..GIT_VERSION../) {
$gitversion = `git --version`;
chomp $gitversion;
# keep only what's after the last space
$gitversion =~ s/^.* //;
}
my $header = "From: $from my $header = "From: $from
To: $to To: $to
@ -299,7 +306,7 @@ Subject: $subject
Reply-To: $from Reply-To: $from
Date: $date Date: $date
Message-Id: $message_id Message-Id: $message_id
X-Mailer: git-send-email @@GIT_VERSION@@ X-Mailer: git-send-email $gitversion
"; ";
$header .= "In-Reply-To: $reply_to\n" if $reply_to; $header .= "In-Reply-To: $reply_to\n" if $reply_to;

View File

@ -1032,12 +1032,6 @@ static int try_delta(struct unpacked *cur, struct unpacked *old, unsigned max_de
max_depth -= cur_entry->delta_limit; max_depth -= cur_entry->delta_limit;
} }
size = cur_entry->size;
oldsize = old_entry->size;
sizediff = oldsize > size ? oldsize - size : size - oldsize;
if (size < 50)
return -1;
if (old_entry->depth >= max_depth) if (old_entry->depth >= max_depth)
return 0; return 0;
@ -1048,9 +1042,12 @@ static int try_delta(struct unpacked *cur, struct unpacked *old, unsigned max_de
* more space-efficient (deletes don't have to say _what_ they * more space-efficient (deletes don't have to say _what_ they
* delete). * delete).
*/ */
size = cur_entry->size;
max_size = size / 2 - 20; max_size = size / 2 - 20;
if (cur_entry->delta) if (cur_entry->delta)
max_size = cur_entry->delta_size-1; max_size = cur_entry->delta_size-1;
oldsize = old_entry->size;
sizediff = oldsize < size ? size - oldsize : 0;
if (sizediff >= max_size) if (sizediff >= max_size)
return 0; return 0;
delta_buf = diff_delta(old->data, oldsize, delta_buf = diff_delta(old->data, oldsize,
@ -1109,6 +1106,9 @@ static void find_deltas(struct object_entry **list, int window, int depth)
*/ */
continue; continue;
if (entry->size < 50)
continue;
free(n->data); free(n->data);
n->entry = entry; n->entry = entry;
n->data = read_sha1_file(entry->sha1, type, &size); n->data = read_sha1_file(entry->sha1, type, &size);

View File

@ -102,15 +102,14 @@ int main(int argc, const char **argv)
type = T_INT; type = T_INT;
else if (!strcmp(argv[1], "--bool")) else if (!strcmp(argv[1], "--bool"))
type = T_BOOL; type = T_BOOL;
else if (!strcmp(argv[1], "--list") || !strcmp(argv[1], "-l"))
return git_config(show_all_config);
else else
break; break;
argc--; argc--;
argv++; argv++;
} }
if (!strcmp(argv[1], "--list") || !strcmp(argv[1], "-l"))
return git_config(show_all_config);
switch (argc) { switch (argc) {
case 2: case 2:
return get_value(argv[1], NULL); return get_value(argv[1], NULL);

View File

@ -477,6 +477,36 @@ static void handle_all(struct rev_info *revs, unsigned flags)
for_each_ref(handle_one_ref); for_each_ref(handle_one_ref);
} }
static int add_parents_only(struct rev_info *revs, const char *arg, int flags)
{
unsigned char sha1[20];
struct object *it;
struct commit *commit;
struct commit_list *parents;
if (*arg == '^') {
flags ^= UNINTERESTING;
arg++;
}
if (get_sha1(arg, sha1))
return 0;
while (1) {
it = get_reference(revs, arg, sha1, 0);
if (strcmp(it->type, tag_type))
break;
memcpy(sha1, ((struct tag*)it)->tagged->sha1, 20);
}
if (strcmp(it->type, commit_type))
return 0;
commit = (struct commit *)it;
for (parents = commit->parents; parents; parents = parents->next) {
it = &parents->item->object;
it->flags |= flags;
add_pending_object(revs, it, arg);
}
return 1;
}
void init_revisions(struct rev_info *revs) void init_revisions(struct rev_info *revs)
{ {
memset(revs, 0, sizeof(*revs)); memset(revs, 0, sizeof(*revs));
@ -740,12 +770,24 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
include = get_reference(revs, next, sha1, flags); include = get_reference(revs, next, sha1, flags);
if (!exclude || !include) if (!exclude || !include)
die("Invalid revision range %s..%s", arg, next); die("Invalid revision range %s..%s", arg, next);
if (!seen_dashdash) {
*dotdot = '.';
verify_non_filename(revs->prefix, arg);
}
add_pending_object(revs, exclude, this); add_pending_object(revs, exclude, this);
add_pending_object(revs, include, next); add_pending_object(revs, include, next);
continue; continue;
} }
*dotdot = '.'; *dotdot = '.';
} }
dotdot = strstr(arg, "^@");
if (dotdot && !dotdot[2]) {
*dotdot = 0;
if (add_parents_only(revs, arg, flags))
continue;
*dotdot = '^';
}
local_flags = 0; local_flags = 0;
if (*arg == '^') { if (*arg == '^') {
local_flags = UNINTERESTING; local_flags = UNINTERESTING;
@ -757,13 +799,20 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
if (seen_dashdash || local_flags) if (seen_dashdash || local_flags)
die("bad revision '%s'", arg); die("bad revision '%s'", arg);
/* If we didn't have a "--", all filenames must exist */ /* If we didn't have a "--":
* (1) all filenames must exist;
* (2) all rev-args must not be interpretable
* as a valid filename.
* but the latter we have checked in the main loop.
*/
for (j = i; j < argc; j++) for (j = i; j < argc; j++)
verify_filename(revs->prefix, argv[j]); verify_filename(revs->prefix, argv[j]);
revs->prune_data = get_pathspec(revs->prefix, argv + i); revs->prune_data = get_pathspec(revs->prefix, argv + i);
break; break;
} }
if (!seen_dashdash)
verify_non_filename(revs->prefix, arg);
object = get_reference(revs, arg, sha1, flags ^ local_flags); object = get_reference(revs, arg, sha1, flags ^ local_flags);
add_pending_object(revs, object, arg); add_pending_object(revs, object, arg);
} }

24
setup.c
View File

@ -80,11 +80,31 @@ void verify_filename(const char *prefix, const char *arg)
if (!lstat(name, &st)) if (!lstat(name, &st))
return; return;
if (errno == ENOENT) if (errno == ENOENT)
die("ambiguous argument '%s': unknown revision or filename\n" die("ambiguous argument '%s': unknown revision or path not in the working tree.\n"
"Use '--' to separate filenames from revisions", arg); "Use '--' to separate paths from revisions", arg);
die("'%s': %s", arg, strerror(errno)); die("'%s': %s", arg, strerror(errno));
} }
/*
* Opposite of the above: the command line did not have -- marker
* and we parsed the arg as a refname. It should not be interpretable
* as a filename.
*/
void verify_non_filename(const char *prefix, const char *arg)
{
const char *name;
struct stat st;
if (*arg == '-')
return; /* flag */
name = prefix ? prefix_filename(prefix, strlen(prefix), arg) : arg;
if (!lstat(name, &st))
die("ambiguous argument '%s': both revision and filename\n"
"Use '--' to separate filenames from revisions", arg);
if (errno != ENOENT)
die("'%s': %s", arg, strerror(errno));
}
const char **get_pathspec(const char *prefix, const char **pathspec) const char **get_pathspec(const char *prefix, const char **pathspec)
{ {
const char *entry = *pathspec; const char *entry = *pathspec;