From c3e24a7d461abaacc16c014ee427b37ab0102ca7 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 18 Nov 2005 11:15:40 -0800 Subject: git-prune: quote possibly empty $dryrun as parameter to test Signed-off-by: Junio C Hamano --- git-prune.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-prune.sh b/git-prune.sh index aa79807313..c4de7f5f25 100755 --- a/git-prune.sh +++ b/git-prune.sh @@ -31,7 +31,7 @@ git-prune-packed $dryrun redundant=$(git-pack-redundant --all) if test "" != "$redundant" then - if test "" = $dryrun + if test "" = "$dryrun" then echo "$redundant" | xargs rm -f else -- cgit v1.2.3 From 3afd169480f1970baeb54be639a496c71ff1e0a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20Sandstr=C3=B6m?= Date: Fri, 18 Nov 2005 17:30:29 +0100 Subject: Fix bug introduced by the latest changes to git-pack-redundant MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I forgot to initialize part of the pll struct when copying it. Found by valgrind. Signed-off-by: Lukas Sandström Signed-off-by: Junio C Hamano --- pack-redundant.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pack-redundant.c b/pack-redundant.c index 51d7341b0b..36556092c9 100644 --- a/pack-redundant.c +++ b/pack-redundant.c @@ -439,7 +439,7 @@ void minimize(struct pack_list **min) break; /* ignore all larger permutations */ if (is_superset(perm->pl, missing)) { new_perm = xmalloc(sizeof(struct pll)); - new_perm->pl = perm->pl; + memcpy(new_perm, perm, sizeof(struct pll)); new_perm->next = perm_ok; perm_ok = new_perm; } -- cgit v1.2.3 From 583122cd1b37d12d6f9fb487302ae07f1b446f03 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Fri, 18 Nov 2005 08:31:55 -0800 Subject: Make "git fetch" less verbose by default When doing something like git fetch --tags origin the excessively verbose output of git fetch makes the result totally unreadable. It's impossible to tell if it actually fetched anything new or not, since the screen will fill up with an endless supply of ... * committish: 9165ec17fde255a1770886189359897dbb541012 tag 'v0.99.7c' of master.kernel.org:/pub/scm/git/git * refs/tags/v0.99.7c: same as tag 'v0.99.7c' of master.kernel.org:/pub/scm/git/git ... and any new tags that got fetched will be totally hidden. So add a new "--verbose" flag to "git fetch" to enable this verbose mode, but make the default be quiet. NOTE! The quiet mode will still report about new or changed heads, so if you are really fetching a new head, you'll see something like this: [torvalds@g5 git]$ git fetch --tags parent Packing 6 objects Unpacking 6 objects 100% (6/6) done * refs/tags/v1.0rc2: storing tag 'v1.0rc2' of master.kernel.org:/pub/scm/git/git * refs/tags/v1.0rc3: storing tag 'v1.0rc3' of master.kernel.org:/pub/scm/git/git * refs/tags/v1.0rc1: storing tag 'v1.0rc1' of master.kernel.org:/pub/scm/git/git which actually tells you something useful that isn't hidden by all the useless crud that you already had. Extensively tested (hey, for me, this _is_ extensive) by doing a rm .git/refs/tags/v1.0rc* and re-fetching with both --verbose and without. NOTE! This means that if the fetch didn't actually fetch anything at all, git fetch will be totally quiet. I think that's much better than being so verbose that you can't even tell whether something was fetched or not, but some people might prefer to get a "nothing to fetch" message in that case. Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- git-fetch.sh | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/git-fetch.sh b/git-fetch.sh index 8564cbfd7a..6586e773e6 100755 --- a/git-fetch.sh +++ b/git-fetch.sh @@ -12,6 +12,7 @@ IFS="$LF" tags= append= force= +verbose= update_head_ok= while case "$#" in 0) break ;; esac do @@ -30,6 +31,9 @@ do --update-head-o|--update-head-ok) update_head_ok=t ;; + -v|--verbose) + verbose=Yes + ;; *) break ;; @@ -91,12 +95,12 @@ append_fetch_head () { then headc_=$(git-rev-parse --verify "$head_^0") || exit echo "$headc_ $not_for_merge_ $note_" >>"$GIT_DIR/FETCH_HEAD" - echo >&2 "* committish: $head_" - echo >&2 " $note_" + [ "$verbose" ] && echo >&2 "* committish: $head_" + [ "$verbose" ] && echo >&2 " $note_" else echo "$head_ not-for-merge $note_" >>"$GIT_DIR/FETCH_HEAD" - echo >&2 "* non-commit: $head_" - echo >&2 " $note_" + [ "$verbose" ] && echo >&2 "* non-commit: $head_" + [ "$verbose" ] && echo >&2 " $note_" fi if test "$local_name_" != "" then @@ -116,7 +120,7 @@ fast_forward_local () { then if now_=$(cat "$GIT_DIR/$1") && test "$now_" = "$2" then - echo >&2 "* $1: same as $3" + [ "$verbose" ] && echo >&2 "* $1: same as $3" else echo >&2 "* $1: updating with $3" fi -- cgit v1.2.3 From a8aca418d6484400d6804e22717bd49ca06c28e9 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Fri, 18 Nov 2005 08:56:40 -0800 Subject: Teach "approxidate" about weekday syntax On Fri, 18 Nov 2005, David Roundy wrote: > > Don't forget "high noon"! (and perhaps "tea time"?) :) Done. [torvalds@g5 git]$ ./test-date "now" "midnight" "high noon" "tea-time" now -> bad -> Wed Dec 31 16:00:00 1969 now -> Fri Nov 18 08:50:54 2005 midnight -> bad -> Wed Dec 31 16:00:00 1969 midnight -> Fri Nov 18 00:00:00 2005 high noon -> bad -> Wed Dec 31 16:00:00 1969 high noon -> Thu Nov 17 12:00:00 2005 tea-time -> bad -> Wed Dec 31 16:00:00 1969 tea-time -> Thu Nov 17 17:00:00 2005 Thanks for pointing out tea-time. This is also written to easily extended to allow people to add their own important dates like Christmas and their own birthdays. Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- date.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 49 insertions(+), 5 deletions(-) diff --git a/date.c b/date.c index d2a67ccf07..3e11500eda 100644 --- a/date.c +++ b/date.c @@ -468,12 +468,52 @@ static void update_tm(struct tm *tm, unsigned long sec) localtime_r(&n, tm); } +static void date_yesterday(struct tm *tm, int *num) +{ + update_tm(tm, 24*60*60); +} + +static void date_time(struct tm *tm, int hour) +{ + if (tm->tm_hour < hour) + date_yesterday(tm, NULL); + tm->tm_hour = hour; + tm->tm_min = 0; + tm->tm_sec = 0; +} + +static void date_midnight(struct tm *tm, int *num) +{ + date_time(tm, 0); +} + +static void date_noon(struct tm *tm, int *num) +{ + date_time(tm, 12); +} + +static void date_tea(struct tm *tm, int *num) +{ + date_time(tm, 17); +} + +static const struct special { + const char *name; + void (*fn)(struct tm *, int *); +} special[] = { + { "yesterday", date_yesterday }, + { "noon", date_noon }, + { "midnight", date_midnight }, + { "tea", date_tea }, + { NULL } +}; + static const char *number_name[] = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", }; -static struct typelen { +static const struct typelen { const char *type; int length; } typelen[] = { @@ -487,7 +527,8 @@ static struct typelen { static const char *approxidate_alpha(const char *date, struct tm *tm, int *num) { - struct typelen *tl; + const struct typelen *tl; + const struct special *s; const char *end = date; int n = 1, i; @@ -502,9 +543,12 @@ static const char *approxidate_alpha(const char *date, struct tm *tm, int *num) } } - if (match_string(date, "yesterday") > 8) { - update_tm(tm, 24*60*60); - return end; + for (s = special; s->name; s++) { + int len = strlen(s->name); + if (match_string(date, s->name) == len) { + s->fn(tm, num); + return end; + } } if (!*num) { -- cgit v1.2.3 From 2e67a5f449f4026097494569f871d79bf263ab28 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 17 Nov 2005 11:29:47 -0800 Subject: Cygwin *might* be helped with NO_MMAP When HPA added Cygwin target, it ran just fine without NO_MMAP for him, but recently we are getting reports that for some people things break without it. For now, just suggest it in the Makefile without actually updating the default. Signed-off-by: Junio C Hamano --- Makefile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Makefile b/Makefile index 3bdd0597c1..d8bb375752 100644 --- a/Makefile +++ b/Makefile @@ -208,6 +208,10 @@ endif ifeq ($(uname_O),Cygwin) NO_STRCASESTR = YesPlease NEEDS_LIBICONV = YesPlease + # There are conflicting reports about this. + # On some boxes NO_MMAP is needed, and not so elsewhere. + # Try uncommenting this if you see things break -- YMMV. + # NO_MMAP = YesPlease NO_IPV6 = YesPlease X = .exe ALL_CFLAGS += -DUSE_SYMLINK_HEAD=0 -- cgit v1.2.3 From 0cb022e0525abb831d01bf581906e67257933d38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20Sandstr=C3=B6m?= Date: Fri, 18 Nov 2005 22:53:24 +0100 Subject: Fix a bug in get_all_permutations. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This line was missing in the previous patch for some reason. Signed-off-by: Lukas Sandström Signed-off-by: Junio C Hamano --- pack-redundant.c | 1 + 1 file changed, 1 insertion(+) diff --git a/pack-redundant.c b/pack-redundant.c index 36556092c9..3e3f33a80e 100644 --- a/pack-redundant.c +++ b/pack-redundant.c @@ -291,6 +291,7 @@ struct pll * get_all_permutations(struct pack_list *list) hint[0] = new_pll; new_pll->next = NULL; new_pll->pl = list; + new_pll->pl_size = 1; return new_pll; } -- cgit v1.2.3 From 4d16f8de16e4caa278c850f812eef2cde9980b35 Mon Sep 17 00:00:00 2001 From: "Luck, Tony" Date: Fri, 18 Nov 2005 14:04:58 -0800 Subject: Update pull/fetch --tags documentation When fetching/pulling from a remote repository the "--tags" option can be used to pull tags too. Document that it will limit the pull to only commits reachable from the tags. Signed-off-by: Tony Luck Signed-off-by: Junio C Hamano --- Documentation/fetch-options.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Documentation/fetch-options.txt b/Documentation/fetch-options.txt index 0e502ae68d..a25d04a4fa 100644 --- a/Documentation/fetch-options.txt +++ b/Documentation/fetch-options.txt @@ -8,7 +8,9 @@ -t, \--tags:: By default, the git core utilities will not fetch and store tags under the same name as the remote repository; ask it - to do so using `--tags`. + to do so using `--tags`. Using this option will bound the + list of objects pulled to the remote tags. Commits in branches + beyond the tags will be ignored. -u, \--update-head-ok:: By default `git-fetch` refuses to update the head which -- cgit v1.2.3 From 62af0b532b5ab94d231205db2db444a638a4ce49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20Sandstr=C3=B6m?= Date: Fri, 18 Nov 2005 21:36:12 +0100 Subject: Remove all old packfiles when doing "git repack -a -d" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit No point in running git-pack-redundant if we already know which packs are redundant. Signed-off-by: Lukas Sandström Signed-off-by: Junio C Hamano --- git-repack.sh | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/git-repack.sh b/git-repack.sh index e58fdd6d87..55a7b27dcd 100755 --- a/git-repack.sh +++ b/git-repack.sh @@ -63,9 +63,22 @@ exit if test "$remove_redundant" = t then sync - redundant=$(git-pack-redundant --all) - if test "$redundant" != "" ; then - echo $redundant | xargs rm + if test "$all_into_one" = t + then + cd "$PACKDIR" + existing=`find . -type f \( -name '*.pack' -o -name '*.idx' \) -print` + for e in $existing + do + case "$e" in + ./pack-$name.pack | ./pack-$name.idx) ;; + *) rm -f $e ;; + esac + done + else + redundant=$(git-pack-redundant --all) + if test "$redundant" != "" ; then + echo $redundant | xargs rm + fi fi fi -- cgit v1.2.3 From 06a45c8cc9fdd271903eb51d712ca9820a0cd799 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20Sandstr=C3=B6m?= Date: Fri, 18 Nov 2005 23:00:55 +0100 Subject: Improve the readability of git-pack-redundant MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Lukas Sandström Signed-off-by: Junio C Hamano --- pack-redundant.c | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/pack-redundant.c b/pack-redundant.c index 3e3f33a80e..fb6cb48502 100644 --- a/pack-redundant.c +++ b/pack-redundant.c @@ -497,7 +497,7 @@ void load_all_objects() } /* this scales like O(n^2) */ -void cmp_packs() +void cmp_local_packs() { struct pack_list *subset, *pl = local_packs; @@ -506,16 +506,21 @@ void cmp_packs() cmp_two_packs(pl, subset); pl = pl->next; } +} - pl = altodb_packs; - while (pl) { - subset = local_packs; - while (subset) { - llist_sorted_difference_inplace(subset->unique_objects, - pl->all_objects); - subset = subset->next; +void scan_alt_odb_packs() +{ + struct pack_list *local, *alt; + + alt = altodb_packs; + while (alt) { + local = local_packs; + while (local) { + llist_sorted_difference_inplace(local->unique_objects, + alt->all_objects); + local = local->next; } - pl = pl->next; + alt = alt->next; } } @@ -525,6 +530,9 @@ struct pack_list * add_pack(struct packed_git *p) size_t off; void *base; + if (!p->pack_local && !(alt_odb || verbose)) + return NULL; + l.pack = p; llist_init(&l.all_objects); @@ -532,14 +540,14 @@ struct pack_list * add_pack(struct packed_git *p) base = (void *)p->index_base; while (off <= p->index_size - 3 * 20) { llist_insert_back(l.all_objects, base + off); - off+=24; + off += 24; } /* this list will be pruned in cmp_two_packs later */ l.unique_objects = llist_copy(l.all_objects); if (p->pack_local) return pack_list_insert(&local_packs, &l); else - return alt_odb ? pack_list_insert(&altodb_packs, &l) : NULL; + return pack_list_insert(&altodb_packs, &l); } struct pack_list * add_pack_file(char *filename) @@ -607,11 +615,14 @@ int main(int argc, char **argv) if (local_packs == NULL) die("Zero packs found!\n"); - cmp_packs(); - load_all_objects(); + cmp_local_packs(); + if (alt_odb) + scan_alt_odb_packs(); + minimize(&min); + if (verbose) { fprintf(stderr, "There are %lu packs available in alt-odbs.\n", (unsigned long)pack_list_size(altodb_packs)); -- cgit v1.2.3 From 9a888b758f48d88d1e83c9765e33d4452710d5a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20Sandstr=C3=B6m?= Date: Fri, 18 Nov 2005 23:20:15 +0100 Subject: Document the "ignore objects" feature of git-pack-redundant MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Lukas Sandström Signed-off-by: Junio C Hamano --- Documentation/git-pack-redundant.txt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Documentation/git-pack-redundant.txt b/Documentation/git-pack-redundant.txt index 2e23cbc0f5..9fe86aef98 100644 --- a/Documentation/git-pack-redundant.txt +++ b/Documentation/git-pack-redundant.txt @@ -16,6 +16,14 @@ This program computes which packs in your repository are redundant. The output is suitable for piping to 'xargs rm' if you are in the root of the repository. +git-pack-redundant accepts a list of objects on standard input. Any objects +given will be ignored when checking which packs are required. This makes the +following command useful when wanting to remove packs which contain unreachable +objects. + +git-fsck-objects --full --unreachable | cut -d ' ' -f3 | \ +git-pack-redundant --all | xargs rm + OPTIONS ------- -- cgit v1.2.3 From f9039f30d56e3815eaab870d8b19c7b94aded8aa Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 18 Nov 2005 15:40:22 -0800 Subject: Do not show .exe in git command list. Truncate the result from readdir() in the exec-path if they end with .exe, to make it a bit more readable on Cygwin. Signed-off-by: Junio C Hamano --- git.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/git.c b/git.c index b9b8c62f47..bdd3f8d01c 100644 --- a/git.c +++ b/git.c @@ -59,7 +59,8 @@ static void add_cmdname(const char *name, int len) if (!ent) oom(); ent->len = len; - memcpy(ent->name, name, len+1); + memcpy(ent->name, name, len); + ent->name[len] = 0; cmdname[cmdname_cnt++] = ent; } @@ -132,6 +133,8 @@ static void list_commands(const char *exec_path, const char *pattern) continue; entlen = strlen(de->d_name); + if (4 < entlen && !strcmp(de->d_name + entlen - 4, ".exe")) + entlen -= 4; if (longest < entlen) longest = entlen; -- cgit v1.2.3 From eb777612f085fc42afd0ac6986ed8062f8b75cbd Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 11 Nov 2005 11:12:50 -0800 Subject: git-branch: -f to forcibly reset branch head. A new usage, 'git-branch -f branch [start]', resets the branch head at start (or current head). Should be considered a dangerous operation, but if you are like me to keep rewinding branches it is handy. Signed-off-by: Junio C Hamano --- git-branch.sh | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/git-branch.sh b/git-branch.sh index 11d52fd78e..2594518e9f 100755 --- a/git-branch.sh +++ b/git-branch.sh @@ -3,7 +3,7 @@ . git-sh-setup || die "Not a git archive" usage () { - echo >&2 "usage: $(basename $0)"' [-d ] | [ [start-point]] + echo >&2 "usage: $(basename $0)"' [-d ] | [[-f] [start-point]] If no arguments, show available branches and mark current branch with a star. If one argument, create a new branch based off of current HEAD. @@ -12,11 +12,12 @@ If two arguments, create a new branch based off of . exit 1 } +headref=$(GIT_DIR="$GIT_DIR" git-symbolic-ref HEAD | + sed -e 's|^refs/heads/||') + delete_branch () { option="$1" shift - headref=$(GIT_DIR="$GIT_DIR" git-symbolic-ref HEAD | - sed -e 's|^refs/heads/||') for branch_name do case ",$headref," in @@ -52,6 +53,7 @@ delete_branch () { exit 0 } +force= while case "$#,$1" in 0,*) break ;; *,-*) ;; *) break ;; esac do case "$1" in @@ -59,6 +61,9 @@ do delete_branch "$@" exit ;; + -f) + force="$1" + ;; --) shift break @@ -72,8 +77,6 @@ done case "$#" in 0) - headref=$(GIT_DIR="$GIT_DIR" git-symbolic-ref HEAD | - sed -e 's|^refs/heads/||') git-rev-parse --symbolic --all | sed -ne 's|^refs/heads/||p' | sort | @@ -97,10 +100,18 @@ branchname="$1" rev=$(git-rev-parse --verify "$head") || exit -[ -e "$GIT_DIR/refs/heads/$branchname" ] && - die "$branchname already exists." git-check-ref-format "heads/$branchname" || die "we do not like '$branchname' as a branch name." +if [ -e "$GIT_DIR/refs/heads/$branchname" ] +then + if test '' = "$force" + then + die "$branchname already exists." + elif test "$branchname" = "$headref" + then + die "cannot force-update the current branch." + fi +fi git update-ref "refs/heads/$branchname" $rev -- cgit v1.2.3 From 7f59dbbb8f8d479c1d31453eac06ec765436a780 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 14 Nov 2005 00:41:53 -0800 Subject: Rewrite rebase to use git-format-patch piped to git-am. The current rebase implementation finds commits in our tree but not in the upstream tree using git-cherry, and tries to apply them using git-cherry-pick (i.e. always use 3-way) one by one. Which is fine, but when some of the changes do not apply cleanly, it punts, and punts badly. Suppose you have commits A-B-C-D-E since you forked from the upstream and submitted the changes for inclusion. You fetch from upstream head U and find that B has been picked up. You run git-rebase to update your branch, which tries to apply changes contained in A-C-D-E, in this order, but replaying of C fails, because the upstream got changes that touch the same area from elsewhere. Now what? It notes that fact, and goes ahead to apply D and E, and at the very end tells you to deal with C by hand. Even if you somehow managed to replay C on top of the result, you would now end up with ...-B-...-U-A-D-E-C. Breaking the order between B and others was the conscious decision made by the upstream, so we would not worry about it, and even if it were worrisome, it is too late for us to fix now. What D and E do may well depend on having C applied before them, which is a problem for us. This rewrites rebase to use git-format-patch piped to git-am, and when the patch does not apply, have git-am fall back on 3-way merge. The updated diff/patch pair knows how to apply trivial binary patches as long as the pre- and post-images are locally available, so this should work on a repository with binary files as well. The primary benefit of this change is that it makes rebase easier to use when some of the changes do not replay cleanly. In the "unapplicable patch in the middle" case, this "rebase" works like this: - A series of patches in e-mail form is created that records what A-C-D-E do, and is fed to git-am. This is stored in .dotest/ directory, just like the case you tried to apply them from your mailbox. Your branch is rewound to the tip of upstream U, and the original head is kept in .git/ORIG_HEAD, so you could "git reset --hard ORIG_HEAD" in case the end result is really messy. - Patch A applies cleanly. This could either be a clean patch application on top of rewound head (i.e. same as upstream head), or git-am might have internally fell back on 3-way (i.e. it would have done the same thing as git-cherry-pick). In either case, a rebased commit A is made on top of U. - Patch C does not apply. git-am stops here, with conflicts to be resolved in the working tree. Yet-to-be-applied D and E are still kept in .dotest/ directory at this point. What the user does is exactly the same as fixing up unapplicable patch when running git-am: - Resolve conflict just like any merge conflicts. - "git am --resolved --3way" to continue applying the patches. - This applies the fixed-up patch so by definition it had better apply. "git am" knows the patch after the fixed-up one is D and then E; it applies them, and you will get the changes from A-C-D-E commits on top of U, in this order. I've been using this without noticing any problem, and as people may know I do a lot of rebases. Signed-off-by: Junio C Hamano --- git-rebase.sh | 72 +++++++++++++---------------------------------------------- 1 file changed, 16 insertions(+), 56 deletions(-) diff --git a/git-rebase.sh b/git-rebase.sh index fa95009091..5289762883 100755 --- a/git-rebase.sh +++ b/git-rebase.sh @@ -5,65 +5,25 @@ . git-sh-setup || die "Not a git archive." -usage="usage: $0 "' [] - -Uses output from git-cherry to rebase local commits to the new head of -upstream tree.' - -case "$#,$1" in -1,*..*) - upstream=$(expr "$1" : '\(.*\)\.\.') ours=$(expr "$1" : '.*\.\.\(.*\)$') - set x "$upstream" "$ours" - shift ;; -esac +# The other head is given +other=$(git-rev-parse --verify "$1^0") || exit +# The tree must be really really clean. git-update-index --refresh || exit +diff=$(git-diff-index --cached --name-status -r HEAD) +case "$different" in +?*) echo "$diff" + exit 1 + ;; +esac +# If the branch to rebase is given, first switch to it. case "$#" in -1) ours_symbolic=HEAD ;; -2) ours_symbolic="$2" ;; -*) die "$usage" ;; +2) + git-checkout "$2" || exit esac -upstream=`git-rev-parse --verify "$1"` && -ours=`git-rev-parse --verify "$ours_symbolic"` || exit -different1=$(git-diff-index --name-only --cached "$ours") && -different2=$(git-diff-index --name-only "$ours") && -test "$different1$different2" = "" || -die "Your working tree does not match $ours_symbolic." - -git-read-tree -m -u $ours $upstream && -new_head=$(git-rev-parse --verify "$upstream^0") && -git-update-ref HEAD "$new_head" || exit - -tmp=.rebase-tmp$$ -fail=$tmp-fail -trap "rm -rf $tmp-*" 1 2 3 15 - ->$fail - -git-cherry -v $upstream $ours | -while read sign commit msg -do - case "$sign" in - -) - echo >&2 "* Already applied: $msg" - continue ;; - esac - echo >&2 "* Applying: $msg" - S=$(git-rev-parse --verify HEAD) && - git-cherry-pick --replay $commit || { - echo >&2 "* Not applying the patch and continuing." - echo $commit >>$fail - git-reset --hard $S - } -done -if test -s $fail -then - echo >&2 Some commits could not be rebased, check by hand: - cat >&2 $fail - echo >&2 "(the same list of commits are found in $tmp)" - exit 1 -else - rm -f $fail -fi +# Rewind the head to "$other" +git-reset --hard "$other" +git-format-patch -k --stdout --full-index "$other" ORIG_HEAD | +git am --binary -3 -k -- cgit v1.2.3