diff --git a/NEWS b/NEWS index c74384cb..07176044 100755 --- a/NEWS +++ b/NEWS @@ -1,10 +1,13 @@ -0.8.0 for Linux and Mac (Sat Jan 14): +0.8.0 for Linux and Mac (Sun Jan 22): Hylke: - Show syncing progress in the status icon - Hide dock icon on Mac until you open a window - Update dates in the event log after midnight - Don't let git compress already compressed files (.jpg .ogg .zip, etc.) + - Limit git's memory usage + - Ignore history of any added git/hg/bzr repositories, just add the files + - Spin status icon on syncing changes made before startup 0.6.0 for Linux and Mac (Sun Dec 25 2011): diff --git a/README.md b/README.md index f00504b1..40e9d0e6 100644 --- a/README.md +++ b/README.md @@ -23,17 +23,17 @@ Requirements: - git >= 1.7.0 - gtk-sharp2 - - gvfs - - intltool - - libnotify - mono-core >= 2.8 - notify-sharp - - nautilus-python - - openssh - - pygtk - - webkitgtk - webkit-sharp +Optional: + + - nautilus-python + - gvfs + - libappindicator + + Run the service, either click the SparkleShare launcher or: ```bash @@ -135,11 +135,11 @@ MonoDevelop and start the build. To create the SparkleShare.app, make sure the project is focused and select Project from the menu bar and click "Create Mac Installer...". Make sure to select "Don't link assemblies". -Save the SparkleShare.app somewhere. Paste the contents of -the following file in `SparkleShare.app/Contents/MonoBundle/config`: +Save the SparkleShare.app somewhere. Copy `SparkleShare/Mac/config` to + `SparkleShare.app/Contents/MonoBundle/config` (adjust the paths to where you saved the .app): ``` -https://raw.github.com/gist/1aeffa61bac73fc08eca/0c0f09ef9e36864c35f34fd5e8bf4f99886be193/gistfile1.txt +cp SparkleShare/Mac/config SparkleShare.app/Contents/MonoBundle/config ``` Copy `/Library/Frameworks/Mono.framework/Versions/Current/lib/libintl.dylib` to `SparkleShare.app/Contents/Resources` diff --git a/SparkleLib/Git/SparkleGit.cs b/SparkleLib/Git/SparkleGit.cs index 308d73f2..88199245 100644 --- a/SparkleLib/Git/SparkleGit.cs +++ b/SparkleLib/Git/SparkleGit.cs @@ -22,20 +22,27 @@ namespace SparkleLib { public class SparkleGit : Process { + public static string ExecPath = null; + + public SparkleGit (string path, string args) : base () { EnableRaisingEvents = true; StartInfo.FileName = SparkleBackend.DefaultBackend.Path; - StartInfo.Arguments = args; StartInfo.RedirectStandardOutput = true; StartInfo.UseShellExecute = false; StartInfo.WorkingDirectory = path; + + if (!string.IsNullOrEmpty (ExecPath)) + StartInfo.Arguments = "--exec-path=\"" + ExecPath + "\" " + args; + else + StartInfo.Arguments = args; } new public void Start () { - SparkleHelpers.DebugInfo ("Cmd", StartInfo.FileName + " " + StartInfo.Arguments); + SparkleHelpers.DebugInfo ("Cmd", "git " + StartInfo.Arguments); base.Start (); } } diff --git a/SparkleShare/Mac/SparkleController.cs b/SparkleShare/Mac/SparkleController.cs index 78f24a15..9c9b0669 100755 --- a/SparkleShare/Mac/SparkleController.cs +++ b/SparkleShare/Mac/SparkleController.cs @@ -42,20 +42,25 @@ namespace SparkleShare { public SparkleController () : base () { string content_path = - Directory.GetParent (System.AppDomain.CurrentDomain.BaseDirectory) - .ToString (); + Directory.GetParent (System.AppDomain.CurrentDomain.BaseDirectory).ToString (); string app_path = Directory.GetParent (content_path).ToString (); string growl_path = Path.Combine (app_path, "Frameworks", "Growl.framework", "Growl"); + // Needed for Growl Dlfcn.dlopen (growl_path, 0); NSApplication.Init (); + // Let's use the bundled git first SparkleBackend.DefaultBackend.Path = Path.Combine (NSBundle.MainBundle.ResourcePath, - "git", "bin", "git"); + "git", "libexec", "git-core", "git"); + + SparkleGit.ExecPath = + Path.Combine (NSBundle.MainBundle.ResourcePath, + "git", "libexec", "git-core"); } diff --git a/SparkleShare/Mac/SparkleShare.csproj b/SparkleShare/Mac/SparkleShare.csproj index af1d84e8..fbf786bc 100755 --- a/SparkleShare/Mac/SparkleShare.csproj +++ b/SparkleShare/Mac/SparkleShare.csproj @@ -59,7 +59,7 @@ False - + False ..\..\bin\SparkleLib.dll @@ -145,42 +145,42 @@ sparkleshare.icns - - Pixmaps\idle0-active.png + + Pixmaps\process-syncing-sparkleshare-mac-i-active.png - - Pixmaps\idle0.png + + Pixmaps\process-syncing-sparkleshare-mac-i.png - - Pixmaps\idle1-active.png + + Pixmaps\process-syncing-sparkleshare-mac-ii-active.png - - Pixmaps\idle1.png + + Pixmaps\process-syncing-sparkleshare-mac-ii.png - - Pixmaps\idle2-active.png + + Pixmaps\process-syncing-sparkleshare-mac-iii-active.png - - Pixmaps\idle2.png + + Pixmaps\process-syncing-sparkleshare-mac-iii.png - - Pixmaps\idle3-active.png + + Pixmaps\process-syncing-sparkleshare-mac-iiii-active.png - - Pixmaps\idle3.png + + Pixmaps\process-syncing-sparkleshare-mac-iiii.png - - Pixmaps\idle4-active.png + + Pixmaps\process-syncing-sparkleshare-mac-iiiii-active.png - - Pixmaps\idle4.png + + Pixmaps\process-syncing-sparkleshare-mac-iiiii.png - - Pixmaps\error.png + + Pixmaps\sparkleshare-syncing-error-mac.png - - Pixmaps\error-active.png + + Pixmaps\sparkleshare-syncing-error-mac-active.png Pixmaps\document-added-12.png diff --git a/SparkleShare/Mac/SparkleStatusIcon.cs b/SparkleShare/Mac/SparkleStatusIcon.cs index f0e75ef0..55d45537 100755 --- a/SparkleShare/Mac/SparkleStatusIcon.cs +++ b/SparkleShare/Mac/SparkleStatusIcon.cs @@ -70,8 +70,8 @@ namespace SparkleShare { { using (var a = new NSAutoreleasePool ()) { - ErrorImage = new NSImage (NSBundle.MainBundle.ResourcePath + "/Pixmaps/error.png"); - ErrorImageActive = new NSImage (NSBundle.MainBundle.ResourcePath + "/Pixmaps/error-active.png"); + ErrorImage = new NSImage (NSBundle.MainBundle.ResourcePath + "/Pixmaps/sparkleshare-syncing-error-mac.png"); + ErrorImageActive = new NSImage (NSBundle.MainBundle.ResourcePath + "/Pixmaps/sparkleshare-syncing-error-mac-active.png"); FolderImage = NSImage.ImageNamed ("NSFolder"); CautionImage = NSImage.ImageNamed ("NSCaution"); SparkleShareImage = NSImage.ImageNamed ("sparkleshare-mac"); @@ -111,9 +111,9 @@ namespace SparkleShare { case IconState.Syncing: - StateText = _("Syncing… " + + StateText = _("Syncing… ") + Controller.ProgressPercentage + "% " + - Controller.ProgressSpeed); + Controller.ProgressSpeed; StateMenuItem.Title = StateText; @@ -342,19 +342,19 @@ namespace SparkleShare { FrameNumber = 0; AnimationFrames = new NSImage [] { - new NSImage (Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "idle0.png")), - new NSImage (Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "idle1.png")), - new NSImage (Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "idle2.png")), - new NSImage (Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "idle3.png")), - new NSImage (Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "idle4.png")) + new NSImage (Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "process-syncing-sparkleshare-mac-i.png")), + new NSImage (Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "process-syncing-sparkleshare-mac-ii.png")), + new NSImage (Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "process-syncing-sparkleshare-mac-iii.png")), + new NSImage (Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "process-syncing-sparkleshare-mac-iiii.png")), + new NSImage (Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "process-syncing-sparkleshare-mac-iiiii.png")) }; AnimationFramesActive = new NSImage [] { - new NSImage (Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "idle0-active.png")), - new NSImage (Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "idle1-active.png")), - new NSImage (Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "idle2-active.png")), - new NSImage (Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "idle3-active.png")), - new NSImage (Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "idle4-active.png")) + new NSImage (Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "process-syncing-sparkleshare-mac-i-active.png")), + new NSImage (Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "process-syncing-sparkleshare-mac-ii-active.png")), + new NSImage (Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "process-syncing-sparkleshare-mac-iii-active.png")), + new NSImage (Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "process-syncing-sparkleshare-mac-iiii-active.png")), + new NSImage (Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "process-syncing-sparkleshare-mac-iiiii-active.png")) }; Timer Animation = new Timer () { diff --git a/SparkleShare/Mac/config b/SparkleShare/Mac/config new file mode 100644 index 00000000..e15ba99e --- /dev/null +++ b/SparkleShare/Mac/config @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/SparkleShare/Mac/git/libexec/git-core/git-add--interactive b/SparkleShare/Mac/git/libexec/git-core/git-add--interactive index 57ec163b..e5e18210 100755 --- a/SparkleShare/Mac/git/libexec/git-core/git-add--interactive +++ b/SparkleShare/Mac/git/libexec/git-core/git-add--interactive @@ -46,6 +46,9 @@ my ($diff_new_color) = my $normal_color = $repo->get_color("", "reset"); my $use_readkey = 0; +my $use_termcap = 0; +my %term_escapes; + sub ReadMode; sub ReadKey; if ($repo->config_bool("interactive.singlekey")) { @@ -54,6 +57,14 @@ if ($repo->config_bool("interactive.singlekey")) { Term::ReadKey->import; $use_readkey = 1; }; + eval { + require Term::Cap; + my $termcap = Term::Cap->Tgetent; + foreach (values %$termcap) { + $term_escapes{$_} = 1 if /^\e/; + } + $use_termcap = 1; + }; } sub colored { @@ -706,7 +717,7 @@ sub add_untracked_cmd { sub run_git_apply { my $cmd = shift; my $fh; - open $fh, '| git ' . $cmd; + open $fh, '| git ' . $cmd . " --recount --allow-overlap"; print $fh @_; return close $fh; } @@ -1051,7 +1062,7 @@ EOF sub diff_applies { my $fh; - return run_git_apply($patch_mode_flavour{APPLY_CHECK} . ' --recount --check', + return run_git_apply($patch_mode_flavour{APPLY_CHECK} . ' --check', map { @{$_->{TEXT}} } @_); } @@ -1068,6 +1079,14 @@ sub prompt_single_character { ReadMode 'cbreak'; my $key = ReadKey 0; ReadMode 'restore'; + if ($use_termcap and $key eq "\e") { + while (!defined $term_escapes{$key}) { + my $next = ReadKey 0.5; + last if (!defined $next); + $key .= $next; + } + $key =~ s/\e/^[/; + } print "$key" if defined $key; print "\n"; return $key; @@ -1140,7 +1159,7 @@ EOF sub apply_patch { my $cmd = shift; - my $ret = run_git_apply $cmd . ' --recount', @_; + my $ret = run_git_apply $cmd, @_; if (!$ret) { print STDERR @_; } @@ -1149,17 +1168,17 @@ sub apply_patch { sub apply_patch_for_checkout_commit { my $reverse = shift; - my $applies_index = run_git_apply 'apply '.$reverse.' --cached --recount --check', @_; - my $applies_worktree = run_git_apply 'apply '.$reverse.' --recount --check', @_; + my $applies_index = run_git_apply 'apply '.$reverse.' --cached --check', @_; + my $applies_worktree = run_git_apply 'apply '.$reverse.' --check', @_; if ($applies_worktree && $applies_index) { - run_git_apply 'apply '.$reverse.' --cached --recount', @_; - run_git_apply 'apply '.$reverse.' --recount', @_; + run_git_apply 'apply '.$reverse.' --cached', @_; + run_git_apply 'apply '.$reverse, @_; return 1; } elsif (!$applies_index) { print colored $error_color, "The selected hunks do not apply to the index!\n"; if (prompt_yesno "Apply them to the worktree anyway? ") { - return run_git_apply 'apply '.$reverse.' --recount', @_; + return run_git_apply 'apply '.$reverse, @_; } else { print colored $error_color, "Nothing was applied.\n"; return 0; @@ -1367,14 +1386,13 @@ sub patch_update_file { next; } elsif ($line =~ /^q/i) { - while ($ix < $num) { - if (!defined $hunk[$ix]{USE}) { - $hunk[$ix]{USE} = 0; + for ($i = 0; $i < $num; $i++) { + if (!defined $hunk[$i]{USE}) { + $hunk[$i]{USE} = 0; } - $ix++; } $quit = 1; - next; + last; } elsif ($line =~ m|^/(.*)|) { my $regex = $1; diff --git a/SparkleShare/Mac/git/libexec/git-core/git-am b/SparkleShare/Mac/git/libexec/git-core/git-am index 6cdd5910..f1a03c91 100755 --- a/SparkleShare/Mac/git/libexec/git-core/git-am +++ b/SparkleShare/Mac/git/libexec/git-core/git-am @@ -507,6 +507,8 @@ else fi fi +git update-index -q --refresh + case "$resolved" in '') case "$HAS_HEAD" in diff --git a/SparkleShare/Mac/git/libexec/git-core/git-bisect b/SparkleShare/Mac/git/libexec/git-core/git-bisect index c21e33c8..415a8d04 100755 --- a/SparkleShare/Mac/git/libexec/git-core/git-bisect +++ b/SparkleShare/Mac/git/libexec/git-core/git-bisect @@ -288,10 +288,12 @@ bisect_visualize() { if test $# = 0 then - case "${DISPLAY+set}${SESSIONNAME+set}${MSYSTEM+set}${SECURITYSESSIONID+set}" in - '') set git log ;; - set*) set gitk ;; - esac + if test -n "${DISPLAY+set}${SESSIONNAME+set}${MSYSTEM+set}${SECURITYSESSIONID+set}" && + type gitk >/dev/null 2>&1; then + set gitk + else + set git log + fi else case "$1" in git*|tig) ;; diff --git a/SparkleShare/Mac/git/libexec/git-core/git-citool b/SparkleShare/Mac/git/libexec/git-core/git-citool index d2499def..47458bef 100755 --- a/SparkleShare/Mac/git/libexec/git-core/git-citool +++ b/SparkleShare/Mac/git/libexec/git-core/git-citool @@ -2,7 +2,7 @@ if test "z$*" = zversion || test "z$*" = z--version then - echo 'git-gui version 0.13.0.8.g8f85' + echo 'git-gui version 0.14.0-dirty' else exec '/usr/local/git/share/git-gui/lib/Git Gui.app/Contents/MacOS/Wish' "$0" "$@" fi diff --git a/SparkleShare/Mac/git/libexec/git-core/git-cvsimport b/SparkleShare/Mac/git/libexec/git-core/git-cvsimport index cffa6e01..47eccc29 100755 --- a/SparkleShare/Mac/git/libexec/git-core/git-cvsimport +++ b/SparkleShare/Mac/git/libexec/git-core/git-cvsimport @@ -228,6 +228,31 @@ sub new { return $self; } +sub find_password_entry { + my ($cvspass, @cvsroot) = @_; + my ($file, $delim) = @$cvspass; + my $pass; + local ($_); + + if (open(my $fh, $file)) { + # :pserver:cvs@mea.tmt.tele.fi:/cvsroot/zmailer Ah) { + chomp; + s/^\/\d+\s+//; + my ($w, $p) = split($delim,$_,2); + for my $cvsroot (@cvsroot) { + if ($w eq $cvsroot) { + $pass = $p; + last CVSPASSFILE; + } + } + } + close($fh); + } + return $pass; +} + sub conn { my $self = shift; my $repo = $self->{'fullrep'}; @@ -260,19 +285,23 @@ sub conn { if ($pass) { $pass = $self->_scramble($pass); } else { - open(H,$ENV{'HOME'}."/.cvspass") and do { - # :pserver:cvs@mea.tmt.tele.fi:/cvsroot/zmailer Ah) { - chomp; - s/^\/\d+\s+//; - my ($w,$p) = split(/\s/,$_,2); - if ($w eq $rr or $w eq $rr2) { - $pass = $p; - last; - } + my @cvspass = ([$ENV{'HOME'}."/.cvspass", qr/\s/], + [$ENV{'HOME'}."/.cvs/cvspass", qr/=/]); + my @loc = (); + foreach my $cvspass (@cvspass) { + my $p = find_password_entry($cvspass, $rr, $rr2); + if ($p) { + push @loc, $cvspass->[0]; + $pass = $p; } - }; - $pass = "A" unless $pass; + } + + if (1 < @loc) { + die("Multiple cvs password files have ". + "entries for CVSROOT $opt_d: @loc"); + } elsif (!$pass) { + $pass = "A"; + } } my ($s, $rep); @@ -367,7 +396,9 @@ sub conn { $self->{'socketo'}->write("valid-requests\n"); $self->{'socketo'}->flush(); - chomp(my $rep=$self->readline()); + my $rep=$self->readline(); + die "Failed to read from server" unless defined $rep; + chomp($rep); if ($rep !~ s/^Valid-requests\s*//) { $rep="" unless $rep; die "Expected Valid-requests from server, but got: $rep\n"; diff --git a/SparkleShare/Mac/git/libexec/git-core/git-cvsserver b/SparkleShare/Mac/git/libexec/git-core/git-cvsserver index 49d193f9..cafb11f4 100755 --- a/SparkleShare/Mac/git/libexec/git-core/git-cvsserver +++ b/SparkleShare/Mac/git/libexec/git-core/git-cvsserver @@ -27,7 +27,7 @@ use File::Path qw/rmtree/; use File::Basename; use Getopt::Long qw(:config require_order no_ignore_case); -my $VERSION = '1.7.4'; +my $VERSION = '1.7.6.1'; my $log = GITCVS::log->new(); my $cfg; diff --git a/SparkleShare/Mac/git/libexec/git-core/git-daemon b/SparkleShare/Mac/git/libexec/git-core/git-daemon index 14974413..212112dc 100755 Binary files a/SparkleShare/Mac/git/libexec/git-core/git-daemon and b/SparkleShare/Mac/git/libexec/git-core/git-daemon differ diff --git a/SparkleShare/Mac/git/libexec/git-core/git-fast-import b/SparkleShare/Mac/git/libexec/git-core/git-fast-import index c869fe01..58424d92 100755 Binary files a/SparkleShare/Mac/git/libexec/git-core/git-fast-import and b/SparkleShare/Mac/git/libexec/git-core/git-fast-import differ diff --git a/SparkleShare/Mac/git/libexec/git-core/git-filter-branch b/SparkleShare/Mac/git/libexec/git-core/git-filter-branch index ae602e37..e550b6cc 100755 --- a/SparkleShare/Mac/git/libexec/git-core/git-filter-branch +++ b/SparkleShare/Mac/git/libexec/git-core/git-filter-branch @@ -363,7 +363,7 @@ while read commit parents; do sed -e '1,/^$/d' <../commit | \ eval "$filter_msg" > ../message || die "msg filter failed: $filter_msg" - /bin/sh -c "$filter_commit" "git commit-tree" \ + workdir=$workdir /bin/sh -c "$filter_commit" "git commit-tree" \ $(git write-tree) $parentstr < ../message > ../map/$commit || die "could not write rewritten commit" done <../revs diff --git a/SparkleShare/Mac/git/libexec/git-core/git-gui b/SparkleShare/Mac/git/libexec/git-core/git-gui index d2499def..47458bef 100755 --- a/SparkleShare/Mac/git/libexec/git-core/git-gui +++ b/SparkleShare/Mac/git/libexec/git-core/git-gui @@ -2,7 +2,7 @@ if test "z$*" = zversion || test "z$*" = z--version then - echo 'git-gui version 0.13.0.8.g8f85' + echo 'git-gui version 0.14.0-dirty' else exec '/usr/local/git/share/git-gui/lib/Git Gui.app/Contents/MacOS/Wish' "$0" "$@" fi diff --git a/SparkleShare/Mac/git/libexec/git-core/git-http-backend b/SparkleShare/Mac/git/libexec/git-core/git-http-backend index 9b7ecc0f..c3e208b0 100755 Binary files a/SparkleShare/Mac/git/libexec/git-core/git-http-backend and b/SparkleShare/Mac/git/libexec/git-core/git-http-backend differ diff --git a/SparkleShare/Mac/git/libexec/git-core/git-http-fetch b/SparkleShare/Mac/git/libexec/git-core/git-http-fetch index 3b407068..2ff93dae 100755 Binary files a/SparkleShare/Mac/git/libexec/git-core/git-http-fetch and b/SparkleShare/Mac/git/libexec/git-core/git-http-fetch differ diff --git a/SparkleShare/Mac/git/libexec/git-core/git-http-push b/SparkleShare/Mac/git/libexec/git-core/git-http-push index 0171a071..b19c1e8f 100755 Binary files a/SparkleShare/Mac/git/libexec/git-core/git-http-push and b/SparkleShare/Mac/git/libexec/git-core/git-http-push differ diff --git a/SparkleShare/Mac/git/libexec/git-core/git-imap-send b/SparkleShare/Mac/git/libexec/git-core/git-imap-send index 63f35543..cf03f855 100755 Binary files a/SparkleShare/Mac/git/libexec/git-core/git-imap-send and b/SparkleShare/Mac/git/libexec/git-core/git-imap-send differ diff --git a/SparkleShare/Mac/git/libexec/git-core/git-instaweb b/SparkleShare/Mac/git/libexec/git-core/git-instaweb index 67bd4fcc..aa1ccdff 100755 --- a/SparkleShare/Mac/git/libexec/git-core/git-instaweb +++ b/SparkleShare/Mac/git/libexec/git-core/git-instaweb @@ -558,12 +558,14 @@ my \$app = builder { # make it runnable as standalone app, # like it would be run via 'plackup' utility -if (__FILE__ eq \$0) { +if (caller) { + return \$app; +} else { require Plack::Runner; my \$runner = Plack::Runner->new(); \$runner->parse_options(qw(--env deployment --port $port), - "$local" ? qw(--host 127.0.0.1) : ()); + "$local" ? qw(--host 127.0.0.1) : ()); \$runner->run(\$app); } __END__ diff --git a/SparkleShare/Mac/git/libexec/git-core/git-merge-one-file b/SparkleShare/Mac/git/libexec/git-core/git-merge-one-file index d067894b..bb64a72a 100755 --- a/SparkleShare/Mac/git/libexec/git-core/git-merge-one-file +++ b/SparkleShare/Mac/git/libexec/git-core/git-merge-one-file @@ -22,6 +22,11 @@ LONG_USAGE="Usage: git merge-one-file $USAGE Blob ids and modes should be empty for missing files." +SUBDIRECTORY_OK=Yes +. git-sh-setup +cd_to_toplevel +require_work_tree + if ! test "$#" -eq 7 then echo "$LONG_USAGE" @@ -132,7 +137,7 @@ case "${1:-.}${2:-.}${3:-.}" in # Create the working tree file, using "our tree" version from the # index, and then store the result of the merge. - git checkout-index -f --stage=2 -- "$4" && cat "$src1" >"$4" + git checkout-index -f --stage=2 -- "$4" && cat "$src1" >"$4" || exit 1 rm -f -- "$orig" "$src1" "$src2" if [ "$6" != "$7" ]; then diff --git a/SparkleShare/Mac/git/libexec/git-core/git-mergetool b/SparkleShare/Mac/git/libexec/git-core/git-mergetool index 2f8dc441..3aab5aae 100755 --- a/SparkleShare/Mac/git/libexec/git-core/git-mergetool +++ b/SparkleShare/Mac/git/libexec/git-core/git-mergetool @@ -21,6 +21,10 @@ is_symlink () { test "$1" = 120000 } +is_submodule () { + test "$1" = 160000 +} + local_present () { test -n "$local_mode" } @@ -35,7 +39,8 @@ base_present () { cleanup_temp_files () { if test "$1" = --save-backup ; then - mv -- "$BACKUP" "$MERGED.orig" + rm -rf -- "$MERGED.orig" + test -e "$BACKUP" && mv -- "$BACKUP" "$MERGED.orig" rm -f -- "$LOCAL" "$REMOTE" "$BASE" else rm -f -- "$LOCAL" "$REMOTE" "$BASE" "$BACKUP" @@ -52,11 +57,13 @@ describe_file () { echo "deleted" elif is_symlink "$mode" ; then echo "a symbolic link -> '$(cat "$file")'" + elif is_submodule "$mode" ; then + echo "submodule commit $file" else if base_present; then - echo "modified" + echo "modified file" else - echo "created" + echo "created file" fi fi } @@ -112,6 +119,67 @@ resolve_deleted_merge () { done } +resolve_submodule_merge () { + while true; do + printf "Use (l)ocal or (r)emote, or (a)bort? " + read ans + case "$ans" in + [lL]*) + if ! local_present; then + if test -n "$(git ls-tree HEAD -- "$MERGED")"; then + # Local isn't present, but it's a subdirectory + git ls-tree --full-name -r HEAD -- "$MERGED" | git update-index --index-info || exit $? + else + test -e "$MERGED" && mv -- "$MERGED" "$BACKUP" + git update-index --force-remove "$MERGED" + cleanup_temp_files --save-backup + fi + elif is_submodule "$local_mode"; then + stage_submodule "$MERGED" "$local_sha1" + else + git checkout-index -f --stage=2 -- "$MERGED" + git add -- "$MERGED" + fi + return 0 + ;; + [rR]*) + if ! remote_present; then + if test -n "$(git ls-tree MERGE_HEAD -- "$MERGED")"; then + # Remote isn't present, but it's a subdirectory + git ls-tree --full-name -r MERGE_HEAD -- "$MERGED" | git update-index --index-info || exit $? + else + test -e "$MERGED" && mv -- "$MERGED" "$BACKUP" + git update-index --force-remove "$MERGED" + fi + elif is_submodule "$remote_mode"; then + ! is_submodule "$local_mode" && test -e "$MERGED" && mv -- "$MERGED" "$BACKUP" + stage_submodule "$MERGED" "$remote_sha1" + else + test -e "$MERGED" && mv -- "$MERGED" "$BACKUP" + git checkout-index -f --stage=3 -- "$MERGED" + git add -- "$MERGED" + fi + cleanup_temp_files --save-backup + return 0 + ;; + [aA]*) + return 1 + ;; + esac + done +} + +stage_submodule () { + path="$1" + submodule_sha1="$2" + mkdir -p "$path" || die "fatal: unable to create directory for module at $path" + # Find $path relative to work tree + work_tree_root=$(cd_to_toplevel && pwd) + work_rel_path=$(cd "$path" && GIT_WORK_TREE="${work_tree_root}" git rev-parse --show-prefix) + test -n "$work_rel_path" || die "fatal: unable to get path of module $path relative to work tree" + git update-index --add --replace --cacheinfo 160000 "$submodule_sha1" "${work_rel_path%/}" || die +} + checkout_staged_file () { tmpfile=$(expr "$(git checkout-index --temp --stage="$1" "$2")" : '\([^ ]*\) ') @@ -139,13 +207,23 @@ merge_file () { REMOTE="./$MERGED.REMOTE.$ext" BASE="./$MERGED.BASE.$ext" - mv -- "$MERGED" "$BACKUP" - cp -- "$BACKUP" "$MERGED" - base_mode=$(git ls-files -u -- "$MERGED" | awk '{if ($3==1) print $1;}') local_mode=$(git ls-files -u -- "$MERGED" | awk '{if ($3==2) print $1;}') remote_mode=$(git ls-files -u -- "$MERGED" | awk '{if ($3==3) print $1;}') + if is_submodule "$local_mode" || is_submodule "$remote_mode"; then + echo "Submodule merge conflict for '$MERGED':" + local_sha1=$(git ls-files -u -- "$MERGED" | awk '{if ($3==2) print $2;}') + remote_sha1=$(git ls-files -u -- "$MERGED" | awk '{if ($3==3) print $2;}') + describe_file "$local_mode" "local" "$local_sha1" + describe_file "$remote_mode" "remote" "$remote_sha1" + resolve_submodule_merge + return + fi + + mv -- "$MERGED" "$BACKUP" + cp -- "$BACKUP" "$MERGED" + base_present && checkout_staged_file 1 "$MERGED" "$BASE" local_present && checkout_staged_file 2 "$MERGED" "$LOCAL" remote_present && checkout_staged_file 3 "$MERGED" "$REMOTE" @@ -269,7 +347,7 @@ rerere=false files_to_merge() { if test "$rerere" = true then - git rerere status + git rerere remaining else git ls-files -u | sed -e 's/^[^ ]* //' | sort -u fi diff --git a/SparkleShare/Mac/git/libexec/git-core/git-mergetool--lib b/SparkleShare/Mac/git/libexec/git-core/git-mergetool--lib index 77d4aee2..4db92123 100644 --- a/SparkleShare/Mac/git/libexec/git-core/git-mergetool--lib +++ b/SparkleShare/Mac/git/libexec/git-core/git-mergetool--lib @@ -10,17 +10,20 @@ merge_mode() { translate_merge_tool_path () { case "$1" in - vimdiff|vimdiff2) - echo vim + araxis) + echo compare ;; - gvimdiff|gvimdiff2) - echo gvim + bc3) + echo bcompare ;; emerge) echo emacs ;; - araxis) - echo compare + gvimdiff|gvimdiff2) + echo gvim + ;; + vimdiff|vimdiff2) + echo vim ;; *) echo "$1" @@ -46,17 +49,16 @@ check_unchanged () { valid_tool () { case "$1" in - kdiff3 | tkdiff | xxdiff | meld | opendiff | \ - vimdiff | gvimdiff | vimdiff2 | gvimdiff2 | \ - emerge | ecmerge | diffuse | araxis | p4merge) + araxis | bc3 | diffuse | ecmerge | emerge | gvimdiff | gvimdiff2 | \ + kdiff3 | meld | opendiff | p4merge | tkdiff | vimdiff | vimdiff2 | xxdiff) ;; # happy - tortoisemerge) - if ! merge_mode; then + kompare) + if ! diff_mode; then return 1 fi ;; - kompare) - if ! diff_mode; then + tortoisemerge) + if ! merge_mode; then return 1 fi ;; @@ -89,66 +91,34 @@ run_merge_tool () { status=0 case "$1" in - kdiff3) + araxis) if merge_mode; then + touch "$BACKUP" if $base_present; then - ("$merge_tool_path" --auto \ - --L1 "$MERGED (Base)" \ - --L2 "$MERGED (Local)" \ - --L3 "$MERGED (Remote)" \ - -o "$MERGED" \ - "$BASE" "$LOCAL" "$REMOTE" \ - > /dev/null 2>&1) + "$merge_tool_path" -wait -merge -3 -a1 \ + "$BASE" "$LOCAL" "$REMOTE" "$MERGED" \ + >/dev/null 2>&1 else - ("$merge_tool_path" --auto \ - --L1 "$MERGED (Local)" \ - --L2 "$MERGED (Remote)" \ - -o "$MERGED" \ - "$LOCAL" "$REMOTE" \ - > /dev/null 2>&1) - fi - status=$? - else - ("$merge_tool_path" --auto \ - --L1 "$MERGED (A)" \ - --L2 "$MERGED (B)" "$LOCAL" "$REMOTE" \ - > /dev/null 2>&1) - fi - ;; - kompare) - "$merge_tool_path" "$LOCAL" "$REMOTE" - ;; - tkdiff) - if merge_mode; then - if $base_present; then - "$merge_tool_path" -a "$BASE" \ - -o "$MERGED" "$LOCAL" "$REMOTE" - else - "$merge_tool_path" \ - -o "$MERGED" "$LOCAL" "$REMOTE" - fi - status=$? - else - "$merge_tool_path" "$LOCAL" "$REMOTE" - fi - ;; - p4merge) - if merge_mode; then - touch "$BACKUP" - if $base_present; then - "$merge_tool_path" "$BASE" "$LOCAL" "$REMOTE" "$MERGED" - else - "$merge_tool_path" "$LOCAL" "$LOCAL" "$REMOTE" "$MERGED" + "$merge_tool_path" -wait -2 \ + "$LOCAL" "$REMOTE" "$MERGED" \ + >/dev/null 2>&1 fi check_unchanged else - "$merge_tool_path" "$LOCAL" "$REMOTE" + "$merge_tool_path" -wait -2 "$LOCAL" "$REMOTE" \ + >/dev/null 2>&1 fi ;; - meld) + bc3) if merge_mode; then touch "$BACKUP" - "$merge_tool_path" "$LOCAL" "$MERGED" "$REMOTE" + if $base_present; then + "$merge_tool_path" "$LOCAL" "$REMOTE" "$BASE" \ + -mergeoutput="$MERGED" + else + "$merge_tool_path" "$LOCAL" "$REMOTE" \ + -mergeoutput="$MERGED" + fi check_unchanged else "$merge_tool_path" "$LOCAL" "$REMOTE" @@ -170,75 +140,6 @@ run_merge_tool () { "$merge_tool_path" "$LOCAL" "$REMOTE" | cat fi ;; - vimdiff|gvimdiff) - if merge_mode; then - touch "$BACKUP" - if $base_present; then - "$merge_tool_path" -f -d -c "wincmd J" \ - "$MERGED" "$LOCAL" "$BASE" "$REMOTE" - else - "$merge_tool_path" -f -d -c "wincmd l" \ - "$LOCAL" "$MERGED" "$REMOTE" - fi - check_unchanged - else - "$merge_tool_path" -f -d -c "wincmd l" \ - "$LOCAL" "$REMOTE" - fi - ;; - vimdiff2|gvimdiff2) - if merge_mode; then - touch "$BACKUP" - "$merge_tool_path" -f -d -c "wincmd l" \ - "$LOCAL" "$MERGED" "$REMOTE" - check_unchanged - else - "$merge_tool_path" -f -d -c "wincmd l" \ - "$LOCAL" "$REMOTE" - fi - ;; - xxdiff) - if merge_mode; then - touch "$BACKUP" - if $base_present; then - "$merge_tool_path" -X --show-merged-pane \ - -R 'Accel.SaveAsMerged: "Ctrl-S"' \ - -R 'Accel.Search: "Ctrl+F"' \ - -R 'Accel.SearchForward: "Ctrl-G"' \ - --merged-file "$MERGED" \ - "$LOCAL" "$BASE" "$REMOTE" - else - "$merge_tool_path" -X $extra \ - -R 'Accel.SaveAsMerged: "Ctrl-S"' \ - -R 'Accel.Search: "Ctrl+F"' \ - -R 'Accel.SearchForward: "Ctrl-G"' \ - --merged-file "$MERGED" \ - "$LOCAL" "$REMOTE" - fi - check_unchanged - else - "$merge_tool_path" \ - -R 'Accel.Search: "Ctrl+F"' \ - -R 'Accel.SearchForward: "Ctrl-G"' \ - "$LOCAL" "$REMOTE" - fi - ;; - opendiff) - if merge_mode; then - touch "$BACKUP" - if $base_present; then - "$merge_tool_path" "$LOCAL" "$REMOTE" \ - -ancestor "$BASE" \ - -merge "$MERGED" | cat - else - "$merge_tool_path" "$LOCAL" "$REMOTE" \ - -merge "$MERGED" | cat - fi - check_unchanged - else - "$merge_tool_path" "$LOCAL" "$REMOTE" | cat - fi - ;; ecmerge) if merge_mode; then touch "$BACKUP" @@ -274,6 +175,111 @@ run_merge_tool () { "$LOCAL" "$REMOTE" fi ;; + gvimdiff|vimdiff) + if merge_mode; then + touch "$BACKUP" + if $base_present; then + "$merge_tool_path" -f -d -c "wincmd J" \ + "$MERGED" "$LOCAL" "$BASE" "$REMOTE" + else + "$merge_tool_path" -f -d -c "wincmd l" \ + "$LOCAL" "$MERGED" "$REMOTE" + fi + check_unchanged + else + "$merge_tool_path" -R -f -d -c "wincmd l" \ + "$LOCAL" "$REMOTE" + fi + ;; + gvimdiff2|vimdiff2) + if merge_mode; then + touch "$BACKUP" + "$merge_tool_path" -f -d -c "wincmd l" \ + "$LOCAL" "$MERGED" "$REMOTE" + check_unchanged + else + "$merge_tool_path" -R -f -d -c "wincmd l" \ + "$LOCAL" "$REMOTE" + fi + ;; + kdiff3) + if merge_mode; then + if $base_present; then + ("$merge_tool_path" --auto \ + --L1 "$MERGED (Base)" \ + --L2 "$MERGED (Local)" \ + --L3 "$MERGED (Remote)" \ + -o "$MERGED" \ + "$BASE" "$LOCAL" "$REMOTE" \ + > /dev/null 2>&1) + else + ("$merge_tool_path" --auto \ + --L1 "$MERGED (Local)" \ + --L2 "$MERGED (Remote)" \ + -o "$MERGED" \ + "$LOCAL" "$REMOTE" \ + > /dev/null 2>&1) + fi + status=$? + else + ("$merge_tool_path" --auto \ + --L1 "$MERGED (A)" \ + --L2 "$MERGED (B)" "$LOCAL" "$REMOTE" \ + > /dev/null 2>&1) + fi + ;; + kompare) + "$merge_tool_path" "$LOCAL" "$REMOTE" + ;; + meld) + if merge_mode; then + touch "$BACKUP" + "$merge_tool_path" "$LOCAL" "$MERGED" "$REMOTE" + check_unchanged + else + "$merge_tool_path" "$LOCAL" "$REMOTE" + fi + ;; + opendiff) + if merge_mode; then + touch "$BACKUP" + if $base_present; then + "$merge_tool_path" "$LOCAL" "$REMOTE" \ + -ancestor "$BASE" \ + -merge "$MERGED" | cat + else + "$merge_tool_path" "$LOCAL" "$REMOTE" \ + -merge "$MERGED" | cat + fi + check_unchanged + else + "$merge_tool_path" "$LOCAL" "$REMOTE" | cat + fi + ;; + p4merge) + if merge_mode; then + touch "$BACKUP" + $base_present || >"$BASE" + "$merge_tool_path" "$BASE" "$LOCAL" "$REMOTE" "$MERGED" + check_unchanged + else + "$merge_tool_path" "$LOCAL" "$REMOTE" + fi + ;; + tkdiff) + if merge_mode; then + if $base_present; then + "$merge_tool_path" -a "$BASE" \ + -o "$MERGED" "$LOCAL" "$REMOTE" + else + "$merge_tool_path" \ + -o "$MERGED" "$LOCAL" "$REMOTE" + fi + status=$? + else + "$merge_tool_path" "$LOCAL" "$REMOTE" + fi + ;; tortoisemerge) if $base_present; then touch "$BACKUP" @@ -286,22 +292,30 @@ run_merge_tool () { status=1 fi ;; - araxis) + xxdiff) if merge_mode; then touch "$BACKUP" if $base_present; then - "$merge_tool_path" -wait -merge -3 -a1 \ - "$BASE" "$LOCAL" "$REMOTE" "$MERGED" \ - >/dev/null 2>&1 + "$merge_tool_path" -X --show-merged-pane \ + -R 'Accel.SaveAsMerged: "Ctrl-S"' \ + -R 'Accel.Search: "Ctrl+F"' \ + -R 'Accel.SearchForward: "Ctrl-G"' \ + --merged-file "$MERGED" \ + "$LOCAL" "$BASE" "$REMOTE" else - "$merge_tool_path" -wait -2 \ - "$LOCAL" "$REMOTE" "$MERGED" \ - >/dev/null 2>&1 + "$merge_tool_path" -X $extra \ + -R 'Accel.SaveAsMerged: "Ctrl-S"' \ + -R 'Accel.Search: "Ctrl+F"' \ + -R 'Accel.SearchForward: "Ctrl-G"' \ + --merged-file "$MERGED" \ + "$LOCAL" "$REMOTE" fi check_unchanged else - "$merge_tool_path" -wait -2 "$LOCAL" "$REMOTE" \ - >/dev/null 2>&1 + "$merge_tool_path" \ + -R 'Accel.Search: "Ctrl+F"' \ + -R 'Accel.SearchForward: "Ctrl-G"' \ + "$LOCAL" "$REMOTE" fi ;; *) @@ -343,7 +357,7 @@ guess_merge_tool () { else tools="opendiff kdiff3 tkdiff xxdiff meld $tools" fi - tools="$tools gvimdiff diffuse ecmerge p4merge araxis" + tools="$tools gvimdiff diffuse ecmerge p4merge araxis bc3" fi case "${VISUAL:-$EDITOR}" in *vim*) diff --git a/SparkleShare/Mac/git/libexec/git-core/git-parse-remote b/SparkleShare/Mac/git/libexec/git-core/git-parse-remote index 1cc2ba6e..b24119d6 100644 --- a/SparkleShare/Mac/git/libexec/git-core/git-parse-remote +++ b/SparkleShare/Mac/git/libexec/git-core/git-parse-remote @@ -4,58 +4,9 @@ # this would fail in that case and would issue an error message. GIT_DIR=$(git rev-parse -q --git-dir) || :; -get_data_source () { - case "$1" in - */*) - echo '' - ;; - .) - echo self - ;; - *) - if test "$(git config --get "remote.$1.url")" - then - echo config - elif test -f "$GIT_DIR/remotes/$1" - then - echo remotes - elif test -f "$GIT_DIR/branches/$1" - then - echo branches - else - echo '' - fi ;; - esac -} - -get_remote_url () { - data_source=$(get_data_source "$1") - case "$data_source" in - '') - echo "$1" - ;; - self) - echo "$1" - ;; - config) - git config --get "remote.$1.url" - ;; - remotes) - sed -ne '/^URL: */{ - s///p - q - }' "$GIT_DIR/remotes/$1" - ;; - branches) - sed -e 's/#.*//' "$GIT_DIR/branches/$1" - ;; - *) - die "internal error: get-remote-url $1" ;; - esac -} - get_default_remote () { - curr_branch=$(git symbolic-ref -q HEAD | sed -e 's|^refs/heads/||') + curr_branch=$(git symbolic-ref -q HEAD) + curr_branch="${curr_branch#refs/heads/}" origin=$(git config --get "branch.$curr_branch.remote") echo ${origin:-origin} } @@ -99,3 +50,41 @@ get_remote_merge_branch () { esac esac } + +error_on_missing_default_upstream () { + cmd="$1" + op_type="$2" + op_prep="$3" + example="$4" + branch_name=$(git symbolic-ref -q HEAD) + if test -z "$branch_name" + then + echo "You are not currently on a branch, so I cannot use any +'branch..merge' in your configuration file. +Please specify which branch you want to $op_type $op_prep on the command +line and try again (e.g. '$example'). +See git-${cmd}(1) for details." + else + echo "You asked me to $cmd without telling me which branch you +want to $op_type $op_prep, and 'branch.${branch_name#refs/heads/}.merge' in +your configuration file does not tell me, either. Please +specify which branch you want to use on the command line and +try again (e.g. '$example'). +See git-${cmd}(1) for details. + +If you often $op_type $op_prep the same branch, you may want to +use something like the following in your configuration file: + [branch \"${branch_name#refs/heads/}\"] + remote = + merge = " + test rebase = "$op_type" && + echo " rebase = true" + echo " + [remote \"\"] + url = + fetch = + +See git-config(1) for details." + fi + exit 1 +} diff --git a/SparkleShare/Mac/git/libexec/git-core/git-pull b/SparkleShare/Mac/git/libexec/git-core/git-pull index eb87f490..28441aca 100755 --- a/SparkleShare/Mac/git/libexec/git-core/git-pull +++ b/SparkleShare/Mac/git/libexec/git-core/git-pull @@ -9,7 +9,7 @@ LONG_USAGE='Fetch one or more remote refs and merge it/them into the current HEA SUBDIRECTORY_OK=Yes OPTIONS_SPEC= . git-sh-setup -set_reflog_action "pull $*" +set_reflog_action "pull${1+ $*}" require_work_tree cd_to_toplevel @@ -53,6 +53,8 @@ do verbosity="$verbosity -v" ;; --progress) progress=--progress ;; + --no-progress) + progress=--no-progress ;; -n|--no-stat|--no-summary) diffstat=--no-stat ;; --stat|--summary) @@ -108,13 +110,16 @@ do --recurse-submodules) recurse_submodules=--recurse-submodules ;; + --recurse-submodules=*) + recurse_submodules="$1" + ;; --no-recurse-submodules) recurse_submodules=--no-recurse-submodules ;; --d|--dr|--dry|--dry-|--dry-r|--dry-ru|--dry-run) dry_run=--dry-run ;; - -h|--h|--he|--hel|--help) + -h|--h|--he|--hel|--help|--help-|--help-a|--help-al|--help-all) usage ;; *) @@ -163,34 +168,10 @@ error_on_no_merge_candidates () { echo "You asked to pull from the remote '$1', but did not specify" echo "a branch. Because this is not the default configured remote" echo "for your current branch, you must specify a branch on the command line." - elif [ -z "$curr_branch" ]; then - echo "You are not currently on a branch, so I cannot use any" - echo "'branch..merge' in your configuration file." - echo "Please specify which remote branch you want to use on the command" - echo "line and try again (e.g. 'git pull ')." - echo "See git-pull(1) for details." - elif [ -z "$upstream" ]; then - echo "You asked me to pull without telling me which branch you" - echo "want to $op_type $op_prep, and 'branch.${curr_branch}.merge' in" - echo "your configuration file does not tell me, either. Please" - echo "specify which branch you want to use on the command line and" - echo "try again (e.g. 'git pull ')." - echo "See git-pull(1) for details." - echo - echo "If you often $op_type $op_prep the same branch, you may want to" - echo "use something like the following in your configuration file:" - echo - echo " [branch \"${curr_branch}\"]" - echo " remote = " - echo " merge = " - test rebase = "$op_type" && - echo " rebase = true" - echo - echo " [remote \"\"]" - echo " url = " - echo " fetch = " - echo - echo "See git-config(1) for details." + elif [ -z "$curr_branch" -o -z "$upstream" ]; then + . git-parse-remote + error_on_missing_default_upstream "pull" $op_type $op_prep \ + "git pull " else echo "Your configuration specifies to $op_type $op_prep the ref '${upstream#refs/heads/}'" echo "from the remote, but no such ref was fetched." @@ -272,7 +253,7 @@ esac if test -z "$orig_head" then git update-ref -m "initial pull" HEAD $merge_head "$curr_head" && - git read-tree --reset -u HEAD || exit 1 + git read-tree -m -u HEAD || exit 1 exit fi @@ -293,8 +274,8 @@ true) ;; *) eval="git-merge $diffstat $no_commit $squash $no_ff $ff_only" - eval="$eval $log_arg $strategy_args $merge_args" - eval="$eval \"\$merge_name\" HEAD $merge_head $verbosity" + eval="$eval $log_arg $strategy_args $merge_args $verbosity $progress" + eval="$eval \"\$merge_name\" HEAD $merge_head" ;; esac eval "exec $eval" diff --git a/SparkleShare/Mac/git/libexec/git-core/git-rebase b/SparkleShare/Mac/git/libexec/git-core/git-rebase index cbb0ea90..38cbee7d 100755 --- a/SparkleShare/Mac/git/libexec/git-core/git-rebase +++ b/SparkleShare/Mac/git/libexec/git-core/git-rebase @@ -3,7 +3,7 @@ # Copyright (c) 2005 Junio C Hamano. # -USAGE='[--interactive | -i] [-v] [--force-rebase | -f] [--no-ff] [--onto ] (|--root) [] [--quiet | -q]' +USAGE='[--interactive | -i] [-v] [--force-rebase | -f] [--no-ff] [--onto ] [|--root] [] [--quiet | -q]' LONG_USAGE='git-rebase replaces with a new branch of the same name. When the --onto option is provided the new branch starts out with a HEAD equal to , otherwise it is equal to @@ -13,7 +13,7 @@ It then attempts to create a new commit for each commit from the original It is possible that a merge failure will prevent this process from being completely automatic. You will have to resolve any such merge failure and run git rebase --continue. Another option is to bypass the commit -that caused the merge failure with git rebase --skip. To restore the +that caused the merge failure with git rebase --skip. To check out the original and remove the .git/rebase-apply working files, use the command git rebase --abort instead. @@ -28,7 +28,39 @@ Example: git-rebase master~1 topic ' SUBDIRECTORY_OK=Yes -OPTIONS_SPEC= +OPTIONS_KEEPDASHDASH= +OPTIONS_SPEC="\ +git rebase [-i] [options] [--onto ] [] [] +git rebase [-i] [options] --onto --root [] +git-rebase [-i] --continue | --abort | --skip +-- + Available options are +v,verbose! display a diffstat of what changed upstream +q,quiet! be quiet. implies --no-stat +onto=! rebase onto given branch instead of upstream +p,preserve-merges! try to recreate merges instead of ignoring them +s,strategy=! use the given merge strategy +no-ff! cherry-pick all commits, even if unchanged +m,merge! use merging strategies to rebase +i,interactive! let the user edit the list of commits to rebase +f,force-rebase! force rebase even if branch is up to date +X,strategy-option=! pass the argument through to the merge strategy +stat! display a diffstat of what changed upstream +n,no-stat! do not show diffstat of what changed upstream +verify allow pre-rebase hook to run +rerere-autoupdate allow rerere to update index with resolved conflicts +root! rebase all reachable commits up to the root(s) +autosquash move commits that begin with squash!/fixup! under -i +committer-date-is-author-date! passed to 'git am' +ignore-date! passed to 'git am' +whitespace=! passed to 'git apply' +ignore-whitespace! passed to 'git apply' +C=! passed to 'git apply' + Actions: +continue! continue +abort! abort and check out the original branch +skip! skip current patch and continue +" . git-sh-setup set_reflog_action rebase require_work_tree @@ -36,18 +68,18 @@ cd_to_toplevel LF=' ' -OK_TO_SKIP_PRE_REBASE= -RESOLVEMSG=" +ok_to_skip_pre_rebase= +resolvemsg=" When you have resolved this problem run \"git rebase --continue\". If you would prefer to skip this patch, instead run \"git rebase --skip\". -To restore the original branch and stop rebasing run \"git rebase --abort\". +To check out the original branch and stop rebasing run \"git rebase --abort\". " -unset newbase -strategy=recursive +unset onto +strategy= strategy_opts= do_merge= -dotest="$GIT_DIR"/rebase-merge -prec=4 +merge_dir="$GIT_DIR"/rebase-merge +apply_dir="$GIT_DIR"/rebase-apply verbose= diffstat= test "$(git config --bool rebase.stat)" = true && diffstat=t @@ -55,139 +87,90 @@ git_am_opt= rebase_root= force_rebase= allow_rerere_autoupdate= +# Non-empty if a rebase was in progress when 'git rebase' was invoked +in_progress= +# One of {am, merge, interactive} +type= +# One of {"$GIT_DIR"/rebase-apply, "$GIT_DIR"/rebase-merge} +state_dir= +# One of {'', continue, skip, abort}, as parsed from command line +action= +preserve_merges= +autosquash= +test "$(git config --bool rebase.autosquash)" = "true" && autosquash=t -continue_merge () { - test -n "$prev_head" || die "prev_head must be defined" - test -d "$dotest" || die "$dotest directory does not exist" - - unmerged=$(git ls-files -u) - if test -n "$unmerged" +read_basic_state () { + head_name=$(cat "$state_dir"/head-name) && + onto=$(cat "$state_dir"/onto) && + # We always write to orig-head, but interactive rebase used to write to + # head. Fall back to reading from head to cover for the case that the + # user upgraded git with an ongoing interactive rebase. + if test -f "$state_dir"/orig-head then - echo "You still have unmerged paths in your index" - echo "did you forget to use git add?" - die "$RESOLVEMSG" - fi - - cmt=`cat "$dotest/current"` - if ! git diff-index --quiet --ignore-submodules HEAD -- - then - if ! git commit --no-verify -C "$cmt" - then - echo "Commit failed, please do not call \"git commit\"" - echo "directly, but instead do one of the following: " - die "$RESOLVEMSG" - fi - if test -z "$GIT_QUIET" - then - printf "Committed: %0${prec}d " $msgnum - fi - echo "$cmt $(git rev-parse HEAD^0)" >> "$dotest/rewritten" + orig_head=$(cat "$state_dir"/orig-head) else - if test -z "$GIT_QUIET" - then - printf "Already applied: %0${prec}d " $msgnum - fi - fi - test -z "$GIT_QUIET" && - GIT_PAGER='' git log --format=%s -1 "$cmt" - - prev_head=`git rev-parse HEAD^0` - # save the resulting commit so we can read-tree on it later - echo "$prev_head" > "$dotest/prev_head" - - # onto the next patch: - msgnum=$(($msgnum + 1)) - echo "$msgnum" >"$dotest/msgnum" + orig_head=$(cat "$state_dir"/head) + fi && + GIT_QUIET=$(cat "$state_dir"/quiet) && + test -f "$state_dir"/verbose && verbose=t + test -f "$state_dir"/strategy && strategy="$(cat "$state_dir"/strategy)" + test -f "$state_dir"/strategy_opts && + strategy_opts="$(cat "$state_dir"/strategy_opts)" + test -f "$state_dir"/allow_rerere_autoupdate && + allow_rerere_autoupdate="$(cat "$state_dir"/allow_rerere_autoupdate)" } -call_merge () { - cmt="$(cat "$dotest/cmt.$1")" - echo "$cmt" > "$dotest/current" - hd=$(git rev-parse --verify HEAD) - cmt_name=$(git symbolic-ref HEAD 2> /dev/null || echo HEAD) - msgnum=$(cat "$dotest/msgnum") - end=$(cat "$dotest/end") - eval GITHEAD_$cmt='"${cmt_name##refs/heads/}~$(($end - $msgnum))"' - eval GITHEAD_$hd='$(cat "$dotest/onto_name")' - export GITHEAD_$cmt GITHEAD_$hd - if test -n "$GIT_QUIET" - then - GIT_MERGE_VERBOSITY=1 && export GIT_MERGE_VERBOSITY - fi - eval 'git-merge-$strategy' $strategy_opts '"$cmt^" -- "$hd" "$cmt"' - rv=$? - case "$rv" in - 0) - unset GITHEAD_$cmt GITHEAD_$hd - return - ;; - 1) - git rerere $allow_rerere_autoupdate - die "$RESOLVEMSG" - ;; - 2) - echo "Strategy: $rv $strategy failed, try another" 1>&2 - die "$RESOLVEMSG" +write_basic_state () { + echo "$head_name" > "$state_dir"/head-name && + echo "$onto" > "$state_dir"/onto && + echo "$orig_head" > "$state_dir"/orig-head && + echo "$GIT_QUIET" > "$state_dir"/quiet && + test t = "$verbose" && : > "$state_dir"/verbose + test -n "$strategy" && echo "$strategy" > "$state_dir"/strategy + test -n "$strategy_opts" && echo "$strategy_opts" > \ + "$state_dir"/strategy_opts + test -n "$allow_rerere_autoupdate" && echo "$allow_rerere_autoupdate" > \ + "$state_dir"/allow_rerere_autoupdate +} + +output () { + case "$verbose" in + '') + output=$("$@" 2>&1 ) + status=$? + test $status != 0 && printf "%s\n" "$output" + return $status ;; *) - die "Unknown exit code ($rv) from command:" \ - "git-merge-$strategy $cmt^ -- HEAD $cmt" + "$@" ;; esac } move_to_original_branch () { - test -z "$head_name" && - head_name="$(cat "$dotest"/head-name)" && - onto="$(cat "$dotest"/onto)" && - orig_head="$(cat "$dotest"/orig-head)" case "$head_name" in refs/*) message="rebase finished: $head_name onto $onto" git update-ref -m "$message" \ $head_name $(git rev-parse HEAD) $orig_head && - git symbolic-ref HEAD $head_name || + git symbolic-ref \ + -m "rebase finished: returning to $head_name" \ + HEAD $head_name || die "Could not move back to $head_name" ;; esac } -finish_rb_merge () { - move_to_original_branch - git notes copy --for-rewrite=rebase < "$dotest"/rewritten - if test -x "$GIT_DIR"/hooks/post-rewrite && - test -s "$dotest"/rewritten; then - "$GIT_DIR"/hooks/post-rewrite rebase < "$dotest"/rewritten - fi - rm -r "$dotest" - say All done. -} - -is_interactive () { - while test $# != 0 - do - case "$1" in - -i|--interactive) - interactive_rebase=explicit - break - ;; - -p|--preserve-merges) - interactive_rebase=implied - ;; - esac - shift - done - +run_specific_rebase () { if [ "$interactive_rebase" = implied ]; then GIT_EDITOR=: export GIT_EDITOR fi - - test -n "$interactive_rebase" || test -f "$dotest"/interactive + . git-rebase--$type } run_pre_rebase_hook () { - if test -z "$OK_TO_SKIP_PRE_REBASE" && + if test -z "$ok_to_skip_pre_rebase" && test -x "$GIT_DIR/hooks/pre-rebase" then "$GIT_DIR/hooks/pre-rebase" ${1+"$@"} || @@ -195,163 +178,94 @@ run_pre_rebase_hook () { fi } -test -f "$GIT_DIR"/rebase-apply/applying && +test -f "$apply_dir"/applying && die 'It looks like git-am is in progress. Cannot rebase.' -is_interactive "$@" && exec git-rebase--interactive "$@" +if test -d "$apply_dir" +then + type=am + state_dir="$apply_dir" +elif test -d "$merge_dir" +then + if test -f "$merge_dir"/interactive + then + type=interactive + interactive_rebase=explicit + else + type=merge + fi + state_dir="$merge_dir" +fi +test -n "$type" && in_progress=t +total_argc=$# while test $# != 0 do case "$1" in --no-verify) - OK_TO_SKIP_PRE_REBASE=yes + ok_to_skip_pre_rebase=yes ;; --verify) - OK_TO_SKIP_PRE_REBASE= + ok_to_skip_pre_rebase= ;; - --continue) - test -d "$dotest" -o -d "$GIT_DIR"/rebase-apply || - die "No rebase in progress?" - - git update-index --ignore-submodules --refresh && - git diff-files --quiet --ignore-submodules || { - echo "You must edit all merge conflicts and then" - echo "mark them as resolved using git add" - exit 1 - } - if test -d "$dotest" - then - prev_head=$(cat "$dotest/prev_head") - end=$(cat "$dotest/end") - msgnum=$(cat "$dotest/msgnum") - onto=$(cat "$dotest/onto") - GIT_QUIET=$(cat "$dotest/quiet") - continue_merge - while test "$msgnum" -le "$end" - do - call_merge "$msgnum" - continue_merge - done - finish_rb_merge - exit - fi - head_name=$(cat "$GIT_DIR"/rebase-apply/head-name) && - onto=$(cat "$GIT_DIR"/rebase-apply/onto) && - orig_head=$(cat "$GIT_DIR"/rebase-apply/orig-head) && - GIT_QUIET=$(cat "$GIT_DIR"/rebase-apply/quiet) - git am --resolved --3way --resolvemsg="$RESOLVEMSG" && - move_to_original_branch - exit - ;; - --skip) - test -d "$dotest" -o -d "$GIT_DIR"/rebase-apply || - die "No rebase in progress?" - - git reset --hard HEAD || exit $? - if test -d "$dotest" - then - git rerere clear - prev_head=$(cat "$dotest/prev_head") - end=$(cat "$dotest/end") - msgnum=$(cat "$dotest/msgnum") - msgnum=$(($msgnum + 1)) - onto=$(cat "$dotest/onto") - GIT_QUIET=$(cat "$dotest/quiet") - while test "$msgnum" -le "$end" - do - call_merge "$msgnum" - continue_merge - done - finish_rb_merge - exit - fi - head_name=$(cat "$GIT_DIR"/rebase-apply/head-name) && - onto=$(cat "$GIT_DIR"/rebase-apply/onto) && - orig_head=$(cat "$GIT_DIR"/rebase-apply/orig-head) && - GIT_QUIET=$(cat "$GIT_DIR"/rebase-apply/quiet) - git am -3 --skip --resolvemsg="$RESOLVEMSG" && - move_to_original_branch - exit - ;; - --abort) - test -d "$dotest" -o -d "$GIT_DIR"/rebase-apply || - die "No rebase in progress?" - - git rerere clear - - test -d "$dotest" || dotest="$GIT_DIR"/rebase-apply - - head_name="$(cat "$dotest"/head-name)" && - case "$head_name" in - refs/*) - git symbolic-ref HEAD $head_name || - die "Could not move back to $head_name" - ;; - esac - git reset --hard $(cat "$dotest/orig-head") - rm -r "$dotest" - exit + --continue|--skip|--abort) + test $total_argc -eq 2 || usage + action=${1##--} ;; --onto) test 2 -le "$#" || usage - newbase="$2" + onto="$2" shift ;; - -M|-m|--m|--me|--mer|--merg|--merge) + -i) + interactive_rebase=explicit + ;; + -p) + preserve_merges=t + test -z "$interactive_rebase" && interactive_rebase=implied + ;; + --autosquash) + autosquash=t + ;; + --no-autosquash) + autosquash= + ;; + -M|-m) do_merge=t ;; - -X*|--strategy-option*) - case "$#,$1" in - 1,-X|1,--strategy-option) - usage ;; - *,-X|*,--strategy-option) - newopt="$2" - shift ;; - *,--strategy-option=*) - newopt="$(expr " $1" : ' --strategy-option=\(.*\)')" ;; - *,-X*) - newopt="$(expr " $1" : ' -X\(.*\)')" ;; - 1,*) - usage ;; - esac - strategy_opts="$strategy_opts $(git rev-parse --sq-quote "--$newopt")" + -X) + shift + strategy_opts="$strategy_opts $(git rev-parse --sq-quote "--$1")" + do_merge=t + test -z "$strategy" && strategy=recursive + ;; + -s) + shift + strategy="$1" do_merge=t ;; - -s=*|--s=*|--st=*|--str=*|--stra=*|--strat=*|--strate=*|\ - --strateg=*|--strategy=*|\ - -s|--s|--st|--str|--stra|--strat|--strate|--strateg|--strategy) - case "$#,$1" in - *,*=*) - strategy=`expr "z$1" : 'z-[^=]*=\(.*\)'` ;; - 1,*) - usage ;; - *) - strategy="$2" - shift ;; - esac - do_merge=t - ;; - -n|--no-stat) + -n) diffstat= ;; --stat) diffstat=t ;; - -v|--verbose) + -v) verbose=t diffstat=t GIT_QUIET= ;; - -q|--quiet) + -q) GIT_QUIET=t git_am_opt="$git_am_opt -q" verbose= diffstat= ;; - --whitespace=*) - git_am_opt="$git_am_opt $1" + --whitespace) + shift + git_am_opt="$git_am_opt --whitespace=$1" case "$1" in - --whitespace=fix|--whitespace=strip) + fix|strip) force_rebase=t ;; esac @@ -363,22 +277,21 @@ do git_am_opt="$git_am_opt $1" force_rebase=t ;; - -C*) - git_am_opt="$git_am_opt $1" + -C) + shift + git_am_opt="$git_am_opt -C$1" ;; --root) rebase_root=t ;; - -f|--f|--fo|--for|--forc|--force|--force-r|--force-re|--force-reb|--force-reba|--force-rebas|--force-rebase|--no-ff) + -f|--no-ff) force_rebase=t ;; --rerere-autoupdate|--no-rerere-autoupdate) allow_rerere_autoupdate="$1" ;; - -*) - usage - ;; - *) + --) + shift break ;; esac @@ -386,58 +299,106 @@ do done test $# -gt 2 && usage -if test $# -eq 0 && test -z "$rebase_root" +if test -n "$action" then - test -d "$dotest" -o -d "$GIT_DIR"/rebase-apply || usage - test -d "$dotest" -o -f "$GIT_DIR"/rebase-apply/rebasing && - die 'A rebase is in progress, try --continue, --skip or --abort.' + test -z "$in_progress" && die "No rebase in progress?" + # Only interactive rebase uses detailed reflog messages + if test "$type" = interactive && test "$GIT_REFLOG_ACTION" = rebase + then + GIT_REFLOG_ACTION="rebase -i ($action)" + export GIT_REFLOG_ACTION + fi fi -# Make sure we do not have $GIT_DIR/rebase-apply -if test -z "$do_merge" +case "$action" in +continue) + # Sanity check + git rev-parse --verify HEAD >/dev/null || + die "Cannot read HEAD" + git update-index --ignore-submodules --refresh && + git diff-files --quiet --ignore-submodules || { + echo "You must edit all merge conflicts and then" + echo "mark them as resolved using git add" + exit 1 + } + read_basic_state + run_specific_rebase + ;; +skip) + output git reset --hard HEAD || exit $? + read_basic_state + run_specific_rebase + ;; +abort) + git rerere clear + read_basic_state + case "$head_name" in + refs/*) + git symbolic-ref -m "rebase: aborting" HEAD $head_name || + die "Could not move back to $head_name" + ;; + esac + output git reset --hard $orig_head + rm -r "$state_dir" + exit + ;; +esac + +# Make sure no rebase is in progress +if test -n "$in_progress" then - if mkdir "$GIT_DIR"/rebase-apply 2>/dev/null - then - rmdir "$GIT_DIR"/rebase-apply - else - echo >&2 ' -It seems that I cannot create a rebase-apply directory, and -I wonder if you are in the middle of patch application or another -rebase. If that is not the case, please - rm -fr '"$GIT_DIR"'/rebase-apply + die ' +It seems that there is already a '"${state_dir##*/}"' directory, and +I wonder if you are in the middle of another rebase. If that is the +case, please try + git rebase (--continue | --abort | --skip) +If that is not the case, please + rm -fr '"$state_dir"' and run me again. I am stopping in case you still have something valuable there.' - exit 1 - fi -else - if test -d "$dotest" - then - die "previous rebase directory $dotest still exists." \ - 'Try git rebase (--continue | --abort | --skip)' - fi fi -require_clean_work_tree "rebase" "Please commit or stash them." +if test -n "$interactive_rebase" +then + type=interactive + state_dir="$merge_dir" +elif test -n "$do_merge" +then + type=merge + state_dir="$merge_dir" +else + type=am + state_dir="$apply_dir" +fi if test -z "$rebase_root" then - # The upstream head must be given. Make sure it is valid. - upstream_name="$1" - shift + case "$#" in + 0) + if ! upstream_name=$(git rev-parse --symbolic-full-name \ + --verify -q @{upstream} 2>/dev/null) + then + . git-parse-remote + error_on_missing_default_upstream "rebase" "rebase" \ + "against" "git rebase " + fi + ;; + *) upstream_name="$1" + shift + ;; + esac upstream=`git rev-parse --verify "${upstream_name}^0"` || die "invalid upstream $upstream_name" - unset root_flag upstream_arg="$upstream_name" else - test -z "$newbase" && die "--root must be used with --onto" + test -z "$onto" && die "You must specify --onto when using --root" unset upstream_name unset upstream - root_flag="--root" - upstream_arg="$root_flag" + upstream_arg=--root fi # Make sure the branch to rebase onto is valid. -onto_name=${newbase-"$upstream_name"} +onto_name=${onto-"$upstream_name"} case "$onto_name" in *...*) if left=${onto_name%...*} right=${onto_name#*...} && @@ -456,13 +417,11 @@ case "$onto_name" in fi ;; *) - onto=$(git rev-parse --verify "${onto_name}^0") || exit + onto=$(git rev-parse --verify "${onto_name}^0") || + die "Does not point to a valid commit: $1" ;; esac -# If a hook exists, give it a chance to interrupt -run_pre_rebase_hook "$upstream_arg" "$@" - # If the branch to rebase is given, that is the branch we will rebase # $branch_name -- branch being rebased, or HEAD (already detached) # $orig_head -- commit object name of tip of the branch before rebasing @@ -475,10 +434,10 @@ case "$#" in switch_to="$1" if git show-ref --verify --quiet -- "refs/heads/$1" && - branch=$(git rev-parse -q --verify "refs/heads/$1") + orig_head=$(git rev-parse -q --verify "refs/heads/$1") then head_name="refs/heads/$1" - elif branch=$(git rev-parse -q --verify "$1") + elif orig_head=$(git rev-parse -q --verify "$1") then head_name="detached HEAD" else @@ -496,20 +455,23 @@ case "$#" in head_name="detached HEAD" branch_name=HEAD ;# detached fi - branch=$(git rev-parse --verify "${branch_name}^0") || exit + orig_head=$(git rev-parse --verify "${branch_name}^0") || exit ;; esac -orig_head=$branch -# Now we are rebasing commits $upstream..$branch (or with --root, -# everything leading up to $branch) on top of $onto +require_clean_work_tree "rebase" "Please commit or stash them." + +# Now we are rebasing commits $upstream..$orig_head (or with --root, +# everything leading up to $orig_head) on top of $onto # Check if we are already based on $onto with linear history, -# but this should be done only when upstream and onto are the same. -mb=$(git merge-base "$onto" "$branch") -if test "$upstream" = "$onto" && test "$mb" = "$onto" && +# but this should be done only when upstream and onto are the same +# and if this is not an interactive rebase. +mb=$(git merge-base "$onto" "$orig_head") +if test "$type" != interactive && test "$upstream" = "$onto" && + test "$mb" = "$onto" && # linear history? - ! (git rev-list --parents "$onto".."$branch" | sane_grep " .* ") > /dev/null + ! (git rev-list --parents "$onto".."$orig_head" | sane_grep " .* ") > /dev/null then if test -z "$force_rebase" then @@ -522,10 +484,8 @@ then fi fi -# Detach HEAD and reset the tree -say "First, rewinding head to replay your work on top of it..." -git checkout -q "$onto^0" || die "could not detach HEAD" -git update-ref ORIG_HEAD $branch +# If a hook exists, give it a chance to interrupt +run_pre_rebase_hook "$upstream_arg" "$@" if test -n "$diffstat" then @@ -537,9 +497,16 @@ then GIT_PAGER='' git diff --stat --summary "$mb" "$onto" fi +test "$type" = interactive && run_specific_rebase + +# Detach HEAD and reset the tree +say "First, rewinding head to replay your work on top of it..." +git checkout -q "$onto^0" || die "could not detach HEAD" +git update-ref ORIG_HEAD $orig_head + # If the $onto is a proper descendant of the tip of the branch, then # we just fast-forwarded. -if test "$mb" = "$branch" +if test "$mb" = "$orig_head" then say "Fast-forwarded $branch_name to $onto_name." move_to_original_branch @@ -553,51 +520,4 @@ else revisions="$upstream..$orig_head" fi -if test -z "$do_merge" -then - git format-patch -k --stdout --full-index --ignore-if-in-upstream \ - --src-prefix=a/ --dst-prefix=b/ \ - --no-renames $root_flag "$revisions" | - git am $git_am_opt --rebasing --resolvemsg="$RESOLVEMSG" && - move_to_original_branch - ret=$? - test 0 != $ret -a -d "$GIT_DIR"/rebase-apply && - echo $head_name > "$GIT_DIR"/rebase-apply/head-name && - echo $onto > "$GIT_DIR"/rebase-apply/onto && - echo $orig_head > "$GIT_DIR"/rebase-apply/orig-head && - echo "$GIT_QUIET" > "$GIT_DIR"/rebase-apply/quiet - exit $ret -fi - -# start doing a rebase with git-merge -# this is rename-aware if the recursive (default) strategy is used - -mkdir -p "$dotest" -echo "$onto" > "$dotest/onto" -echo "$onto_name" > "$dotest/onto_name" -prev_head=$orig_head -echo "$prev_head" > "$dotest/prev_head" -echo "$orig_head" > "$dotest/orig-head" -echo "$head_name" > "$dotest/head-name" -echo "$GIT_QUIET" > "$dotest/quiet" - -msgnum=0 -for cmt in `git rev-list --reverse --no-merges "$revisions"` -do - msgnum=$(($msgnum + 1)) - echo "$cmt" > "$dotest/cmt.$msgnum" -done - -echo 1 >"$dotest/msgnum" -echo $msgnum >"$dotest/end" - -end=$msgnum -msgnum=1 - -while test "$msgnum" -le "$end" -do - call_merge "$msgnum" - continue_merge -done - -finish_rb_merge +run_specific_rebase diff --git a/SparkleShare/Mac/git/libexec/git-core/git-rebase--am b/SparkleShare/Mac/git/libexec/git-core/git-rebase--am new file mode 100644 index 00000000..c815a241 --- /dev/null +++ b/SparkleShare/Mac/git/libexec/git-core/git-rebase--am @@ -0,0 +1,30 @@ +#!/bin/sh +# +# Copyright (c) 2010 Junio C Hamano. +# + +. git-sh-setup + +case "$action" in +continue) + git am --resolved --resolvemsg="$resolvemsg" && + move_to_original_branch + exit + ;; +skip) + git am --skip --resolvemsg="$resolvemsg" && + move_to_original_branch + exit + ;; +esac + +test -n "$rebase_root" && root_flag=--root + +git format-patch -k --stdout --full-index --ignore-if-in-upstream \ + --src-prefix=a/ --dst-prefix=b/ \ + --no-renames $root_flag "$revisions" | +git am $git_am_opt --rebasing --resolvemsg="$resolvemsg" && +move_to_original_branch +ret=$? +test 0 != $ret -a -d "$state_dir" && write_basic_state +exit $ret diff --git a/SparkleShare/Mac/git/libexec/git-core/git-rebase--interactive b/SparkleShare/Mac/git/libexec/git-core/git-rebase--interactive old mode 100755 new mode 100644 index 4ae02c0c..25920430 --- a/SparkleShare/Mac/git/libexec/git-core/git-rebase--interactive +++ b/SparkleShare/Mac/git/libexec/git-core/git-rebase--interactive @@ -10,48 +10,22 @@ # The original idea comes from Eric W. Biederman, in # http://article.gmane.org/gmane.comp.version-control.git/22407 -OPTIONS_KEEPDASHDASH= -OPTIONS_SPEC="\ -git-rebase [-i] [options] [--] [] -git-rebase [-i] (--continue | --abort | --skip) --- - Available options are -v,verbose display a diffstat of what changed upstream -onto= rebase onto given branch instead of upstream -p,preserve-merges try to recreate merges instead of ignoring them -s,strategy= use the given merge strategy -no-ff cherry-pick all commits, even if unchanged -m,merge always used (no-op) -i,interactive always used (no-op) - Actions: -continue continue rebasing process -abort abort rebasing process and restore original branch -skip skip current patch and continue rebasing process -no-verify override pre-rebase hook from stopping the operation -verify allow pre-rebase hook to run -root rebase all reachable commmits up to the root(s) -autosquash move commits that begin with squash!/fixup! under -i -" - . git-sh-setup -require_work_tree - -DOTEST="$GIT_DIR/rebase-merge" # The file containing rebase commands, comments, and empty lines. # This file is created by "git rebase -i" then edited by the user. As # the lines are processed, they are removed from the front of this -# file and written to the tail of $DONE. -TODO="$DOTEST"/git-rebase-todo +# file and written to the tail of $done. +todo="$state_dir"/git-rebase-todo # The rebase command lines that have already been processed. A line # is moved here when it is first handled, before any associated user # actions. -DONE="$DOTEST"/done +done="$state_dir"/done # The commit message that is planned to be used for any changes that # need to be committed following a user interaction. -MSG="$DOTEST"/message +msg="$state_dir"/message # The file into which is accumulated the suggested commit message for # squash/fixup commands. When the first of a series of squash/fixups @@ -61,34 +35,34 @@ MSG="$DOTEST"/message # is appended to the file as it is processed. # # The first line of the file is of the form -# # This is a combination of $COUNT commits. -# where $COUNT is the number of commits whose messages have been +# # This is a combination of $count commits. +# where $count is the number of commits whose messages have been # written to the file so far (including the initial "pick" commit). # Each time that a commit message is processed, this line is read and # updated. It is deleted just before the combined commit is made. -SQUASH_MSG="$DOTEST"/message-squash +squash_msg="$state_dir"/message-squash # If the current series of squash/fixups has not yet included a squash # command, then this file exists and holds the commit message of the # original "pick" commit. (If the series ends without a "squash" # command, then this can be used as the commit message of the combined # commit without opening the editor.) -FIXUP_MSG="$DOTEST"/message-fixup +fixup_msg="$state_dir"/message-fixup -# $REWRITTEN is the name of a directory containing files for each -# commit that is reachable by at least one merge base of $HEAD and -# $UPSTREAM. They are not necessarily rewritten, but their children +# $rewritten is the name of a directory containing files for each +# commit that is reachable by at least one merge base of $head and +# $upstream. They are not necessarily rewritten, but their children # might be. This ensures that commits on merged, but otherwise # unrelated side branches are left alone. (Think "X" in the man page's # example.) -REWRITTEN="$DOTEST"/rewritten +rewritten="$state_dir"/rewritten -DROPPED="$DOTEST"/dropped +dropped="$state_dir"/dropped # A script to set the GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL, and # GIT_AUTHOR_DATE that will be used for the commit that is currently # being rebased. -AUTHOR_SCRIPT="$DOTEST"/author-script +author_script="$state_dir"/author-script # When an "edit" rebase command is being processed, the SHA1 of the # commit to be edited is recorded in this file. When "git rebase @@ -96,69 +70,31 @@ AUTHOR_SCRIPT="$DOTEST"/author-script # will be amended to the HEAD commit, but only provided the HEAD # commit is still the commit to be edited. When any other rebase # command is processed, this file is deleted. -AMEND="$DOTEST"/amend +amend="$state_dir"/amend # For the post-rewrite hook, we make a list of rewritten commits and # their new sha1s. The rewritten-pending list keeps the sha1s of # commits that have been processed, but not committed yet, # e.g. because they are waiting for a 'squash' command. -REWRITTEN_LIST="$DOTEST"/rewritten-list -REWRITTEN_PENDING="$DOTEST"/rewritten-pending +rewritten_list="$state_dir"/rewritten-list +rewritten_pending="$state_dir"/rewritten-pending -PRESERVE_MERGES= -STRATEGY= -ONTO= -VERBOSE= -OK_TO_SKIP_PRE_REBASE= -REBASE_ROOT= -AUTOSQUASH= -test "$(git config --bool rebase.autosquash)" = "true" && AUTOSQUASH=t -NEVER_FF= - -GIT_CHERRY_PICK_HELP="\ -hint: after resolving the conflicts, mark the corrected paths -hint: with 'git add ' and run 'git rebase --continue'" +GIT_CHERRY_PICK_HELP="$resolvemsg" export GIT_CHERRY_PICK_HELP warn () { printf '%s\n' "$*" >&2 } -output () { - case "$VERBOSE" in - '') - output=$("$@" 2>&1 ) - status=$? - test $status != 0 && printf "%s\n" "$output" - return $status - ;; - *) - "$@" - ;; - esac -} - # Output the commit message for the specified commit. commit_message () { git cat-file commit "$1" | sed "1,/^$/d" } -run_pre_rebase_hook () { - if test -z "$OK_TO_SKIP_PRE_REBASE" && - test -x "$GIT_DIR/hooks/pre-rebase" - then - "$GIT_DIR/hooks/pre-rebase" ${1+"$@"} || { - echo >&2 "The pre-rebase hook refused to rebase." - exit 1 - } - fi -} - - -ORIG_REFLOG_ACTION="$GIT_REFLOG_ACTION" +orig_reflog_action="$GIT_REFLOG_ACTION" comment_for_reflog () { - case "$ORIG_REFLOG_ACTION" in + case "$orig_reflog_action" in ''|rebase*) GIT_REFLOG_ACTION="rebase -i ($1)" export GIT_REFLOG_ACTION @@ -168,16 +104,16 @@ comment_for_reflog () { last_count= mark_action_done () { - sed -e 1q < "$TODO" >> "$DONE" - sed -e 1d < "$TODO" >> "$TODO".new - mv -f "$TODO".new "$TODO" - count=$(sane_grep -c '^[^#]' < "$DONE") - total=$(($count+$(sane_grep -c '^[^#]' < "$TODO"))) - if test "$last_count" != "$count" + sed -e 1q < "$todo" >> "$done" + sed -e 1d < "$todo" >> "$todo".new + mv -f "$todo".new "$todo" + new_count=$(sane_grep -c '^[^#]' < "$done") + total=$(($new_count+$(sane_grep -c '^[^#]' < "$todo"))) + if test "$last_count" != "$new_count" then - last_count=$count - printf "Rebasing (%d/%d)\r" $count $total - test -z "$VERBOSE" || echo + last_count=$new_count + printf "Rebasing (%d/%d)\r" $new_count $total + test -z "$verbose" || echo fi } @@ -193,22 +129,22 @@ make_patch () { *) echo "Root commit" ;; - esac > "$DOTEST"/patch - test -f "$MSG" || - commit_message "$1" > "$MSG" - test -f "$AUTHOR_SCRIPT" || - get_author_ident_from_commit "$1" > "$AUTHOR_SCRIPT" + esac > "$state_dir"/patch + test -f "$msg" || + commit_message "$1" > "$msg" + test -f "$author_script" || + get_author_ident_from_commit "$1" > "$author_script" } die_with_patch () { - echo "$1" > "$DOTEST"/stopped-sha + echo "$1" > "$state_dir"/stopped-sha make_patch "$1" git rerere die "$2" } die_abort () { - rm -rf "$DOTEST" + rm -rf "$state_dir" die "$1" } @@ -228,15 +164,10 @@ do_with_author () { pick_one () { ff=--ff case "$1" in -n) sha1=$2; ff= ;; *) sha1=$1 ;; esac - case "$NEVER_FF" in '') ;; ?*) ff= ;; esac + case "$force_rebase" in '') ;; ?*) ff= ;; esac output git rev-parse --verify $sha1 || die "Invalid commit name: $sha1" - test -d "$REWRITTEN" && + test -d "$rewritten" && pick_one_preserving_merges "$@" && return - if test -n "$REBASE_ROOT" - then - output git cherry-pick "$@" - return - fi output git cherry-pick $ff "$@" } @@ -253,20 +184,20 @@ pick_one_preserving_merges () { esac sha1=$(git rev-parse $sha1) - if test -f "$DOTEST"/current-commit + if test -f "$state_dir"/current-commit then if test "$fast_forward" = t then while read current_commit do - git rev-parse HEAD > "$REWRITTEN"/$current_commit - done <"$DOTEST"/current-commit - rm "$DOTEST"/current-commit || + git rev-parse HEAD > "$rewritten"/$current_commit + done <"$state_dir"/current-commit + rm "$state_dir"/current-commit || die "Cannot write current commit's replacement sha1" fi fi - echo $sha1 >> "$DOTEST"/current-commit + echo $sha1 >> "$state_dir"/current-commit # rewrite parents; if none were rewritten, we can fast-forward. new_parents= @@ -280,9 +211,9 @@ pick_one_preserving_merges () { p=$(expr "$pend" : ' \([^ ]*\)') pend="${pend# $p}" - if test -f "$REWRITTEN"/$p + if test -f "$rewritten"/$p then - new_p=$(cat "$REWRITTEN"/$p) + new_p=$(cat "$rewritten"/$p) # If the todo reordered commits, and our parent is marked for # rewriting, but hasn't been gotten to yet, assume the user meant to @@ -301,10 +232,10 @@ pick_one_preserving_merges () { ;; esac else - if test -f "$DROPPED"/$p + if test -f "$dropped"/$p then fast_forward=f - replacement="$(cat "$DROPPED"/$p)" + replacement="$(cat "$dropped"/$p)" test -z "$replacement" && replacement=root pend=" $replacement$pend" else @@ -333,18 +264,19 @@ pick_one_preserving_merges () { test "a$1" = a-n && die "Refusing to squash a merge: $sha1" # redo merge - author_script=$(get_author_ident_from_commit $sha1) - eval "$author_script" - msg="$(commit_message $sha1)" + author_script_content=$(get_author_ident_from_commit $sha1) + eval "$author_script_content" + msg_content="$(commit_message $sha1)" # No point in merging the first parent, that's HEAD new_parents=${new_parents# $first_parent} if ! do_with_author output \ - git merge $STRATEGY -m "$msg" $new_parents + git merge --no-ff ${strategy:+-s $strategy} -m \ + "$msg_content" $new_parents then - printf "%s\n" "$msg" > "$GIT_DIR"/MERGE_MSG + printf "%s\n" "$msg_content" > "$GIT_DIR"/MERGE_MSG die_with_patch $sha1 "Error redoing merge $sha1" fi - echo "$sha1 $(git rev-parse HEAD^0)" >> "$REWRITTEN_LIST" + echo "$sha1 $(git rev-parse HEAD^0)" >> "$rewritten_list" ;; *) output git cherry-pick "$@" || @@ -365,46 +297,46 @@ nth_string () { } update_squash_messages () { - if test -f "$SQUASH_MSG"; then - mv "$SQUASH_MSG" "$SQUASH_MSG".bak || exit - COUNT=$(($(sed -n \ + if test -f "$squash_msg"; then + mv "$squash_msg" "$squash_msg".bak || exit + count=$(($(sed -n \ -e "1s/^# This is a combination of \(.*\) commits\./\1/p" \ - -e "q" < "$SQUASH_MSG".bak)+1)) + -e "q" < "$squash_msg".bak)+1)) { - echo "# This is a combination of $COUNT commits." + echo "# This is a combination of $count commits." sed -e 1d -e '2,/^./{ /^$/d - }' <"$SQUASH_MSG".bak - } >"$SQUASH_MSG" + }' <"$squash_msg".bak + } >"$squash_msg" else - commit_message HEAD > "$FIXUP_MSG" || die "Cannot write $FIXUP_MSG" - COUNT=2 + commit_message HEAD > "$fixup_msg" || die "Cannot write $fixup_msg" + count=2 { echo "# This is a combination of 2 commits." echo "# The first commit's message is:" echo - cat "$FIXUP_MSG" - } >"$SQUASH_MSG" + cat "$fixup_msg" + } >"$squash_msg" fi case $1 in squash) - rm -f "$FIXUP_MSG" + rm -f "$fixup_msg" echo - echo "# This is the $(nth_string $COUNT) commit message:" + echo "# This is the $(nth_string $count) commit message:" echo commit_message $2 ;; fixup) echo - echo "# The $(nth_string $COUNT) commit message will be skipped:" + echo "# The $(nth_string $count) commit message will be skipped:" echo commit_message $2 | sed -e 's/^/# /' ;; - esac >>"$SQUASH_MSG" + esac >>"$squash_msg" } peek_next_command () { - sed -n -e "/^#/d" -e '/^$/d' -e "s/ .*//p" -e "q" < "$TODO" + sed -n -e "/^#/d" -e '/^$/d' -e "s/ .*//p" -e "q" < "$todo" } # A squash/fixup has failed. Prepare the long version of the squash @@ -414,24 +346,24 @@ peek_next_command () { # messages, effectively causing the combined commit to be used as the # new basis for any further squash/fixups. Args: sha1 rest die_failed_squash() { - mv "$SQUASH_MSG" "$MSG" || exit - rm -f "$FIXUP_MSG" - cp "$MSG" "$GIT_DIR"/MERGE_MSG || exit + mv "$squash_msg" "$msg" || exit + rm -f "$fixup_msg" + cp "$msg" "$GIT_DIR"/MERGE_MSG || exit warn warn "Could not apply $1... $2" die_with_patch $1 "" } flush_rewritten_pending() { - test -s "$REWRITTEN_PENDING" || return + test -s "$rewritten_pending" || return newsha1="$(git rev-parse HEAD^0)" - sed "s/$/ $newsha1/" < "$REWRITTEN_PENDING" >> "$REWRITTEN_LIST" - rm -f "$REWRITTEN_PENDING" + sed "s/$/ $newsha1/" < "$rewritten_pending" >> "$rewritten_list" + rm -f "$rewritten_pending" } record_in_rewritten() { oldsha1="$(git rev-parse $1)" - echo "$oldsha1" >> "$REWRITTEN_PENDING" + echo "$oldsha1" >> "$rewritten_pending" case "$(peek_next_command)" in squash|s|fixup|f) @@ -443,8 +375,8 @@ record_in_rewritten() { } do_next () { - rm -f "$MSG" "$AUTHOR_SCRIPT" "$AMEND" || exit - read -r command sha1 rest < "$TODO" + rm -f "$msg" "$author_script" "$amend" || exit + read -r command sha1 rest < "$todo" case "$command" in '#'*|''|noop) mark_action_done @@ -472,9 +404,9 @@ do_next () { mark_action_done pick_one $sha1 || die_with_patch $sha1 "Could not apply $sha1... $rest" - echo "$sha1" > "$DOTEST"/stopped-sha + echo "$sha1" > "$state_dir"/stopped-sha make_patch $sha1 - git rev-parse --verify HEAD > "$AMEND" + git rev-parse --verify HEAD > "$amend" warn "Stopped at $sha1... $rest" warn "You can amend the commit now, with" warn @@ -497,47 +429,47 @@ do_next () { esac comment_for_reflog $squash_style - test -f "$DONE" && has_action "$DONE" || + test -f "$done" && has_action "$done" || die "Cannot '$squash_style' without a previous commit" mark_action_done update_squash_messages $squash_style $sha1 - author_script=$(get_author_ident_from_commit HEAD) - echo "$author_script" > "$AUTHOR_SCRIPT" - eval "$author_script" + author_script_content=$(get_author_ident_from_commit HEAD) + echo "$author_script_content" > "$author_script" + eval "$author_script_content" output git reset --soft HEAD^ pick_one -n $sha1 || die_failed_squash $sha1 "$rest" case "$(peek_next_command)" in squash|s|fixup|f) # This is an intermediate commit; its message will only be # used in case of trouble. So use the long version: - do_with_author output git commit --no-verify -F "$SQUASH_MSG" || + do_with_author output git commit --no-verify -F "$squash_msg" || die_failed_squash $sha1 "$rest" ;; *) # This is the final command of this squash/fixup group - if test -f "$FIXUP_MSG" + if test -f "$fixup_msg" then - do_with_author git commit --no-verify -F "$FIXUP_MSG" || + do_with_author git commit --no-verify -F "$fixup_msg" || die_failed_squash $sha1 "$rest" else - cp "$SQUASH_MSG" "$GIT_DIR"/SQUASH_MSG || exit + cp "$squash_msg" "$GIT_DIR"/SQUASH_MSG || exit rm -f "$GIT_DIR"/MERGE_MSG do_with_author git commit --no-verify -e || die_failed_squash $sha1 "$rest" fi - rm -f "$SQUASH_MSG" "$FIXUP_MSG" + rm -f "$squash_msg" "$fixup_msg" ;; esac record_in_rewritten $sha1 ;; x|"exec") - read -r command rest < "$TODO" + read -r command rest < "$todo" mark_action_done printf 'Executing: %s\n' "$rest" # "exec" command doesn't take a sha1 in the todo-list. # => can't just use $sha1 here. - git rev-parse --verify HEAD > "$DOTEST"/stopped-sha + git rev-parse --verify HEAD > "$state_dir"/stopped-sha ${SHELL:-/bin/sh} -c "$rest" # Actual execution status=$? if test "$status" -ne 0 @@ -563,42 +495,42 @@ do_next () { warn "Unknown command: $command $sha1 $rest" if git rev-parse --verify -q "$sha1" >/dev/null then - die_with_patch $sha1 "Please fix this in the file $TODO." + die_with_patch $sha1 "Please fix this in the file $todo." else - die "Please fix this in the file $TODO." + die "Please fix this in the file $todo." fi ;; esac - test -s "$TODO" && return + test -s "$todo" && return comment_for_reflog finish && - HEADNAME=$(cat "$DOTEST"/head-name) && - OLDHEAD=$(cat "$DOTEST"/head) && - SHORTONTO=$(git rev-parse --short $(cat "$DOTEST"/onto)) && - NEWHEAD=$(git rev-parse HEAD) && - case $HEADNAME in + shortonto=$(git rev-parse --short $onto) && + newhead=$(git rev-parse HEAD) && + case $head_name in refs/*) - message="$GIT_REFLOG_ACTION: $HEADNAME onto $SHORTONTO" && - git update-ref -m "$message" $HEADNAME $NEWHEAD $OLDHEAD && - git symbolic-ref HEAD $HEADNAME + message="$GIT_REFLOG_ACTION: $head_name onto $shortonto" && + git update-ref -m "$message" $head_name $newhead $orig_head && + git symbolic-ref \ + -m "$GIT_REFLOG_ACTION: returning to $head_name" \ + HEAD $head_name ;; esac && { - test ! -f "$DOTEST"/verbose || - git diff-tree --stat $(cat "$DOTEST"/head)..HEAD + test ! -f "$state_dir"/verbose || + git diff-tree --stat $orig_head..HEAD } && { - test -s "$REWRITTEN_LIST" && - git notes copy --for-rewrite=rebase < "$REWRITTEN_LIST" || + test -s "$rewritten_list" && + git notes copy --for-rewrite=rebase < "$rewritten_list" || true # we don't care if this copying failed } && if test -x "$GIT_DIR"/hooks/post-rewrite && - test -s "$REWRITTEN_LIST"; then - "$GIT_DIR"/hooks/post-rewrite rebase < "$REWRITTEN_LIST" + test -s "$rewritten_list"; then + "$GIT_DIR"/hooks/post-rewrite rebase < "$rewritten_list" true # we don't care if this hook failed fi && - rm -rf "$DOTEST" && + rm -rf "$state_dir" && git gc --auto && - warn "Successfully rebased and updated $HEADNAME." + warn "Successfully rebased and updated $head_name." exit } @@ -618,11 +550,11 @@ skip_unnecessary_picks () { # fd=3 means we skip the command case "$fd,$command" in 3,pick|3,p) - # pick a commit whose parent is current $ONTO -> skip + # pick a commit whose parent is current $onto -> skip sha1=${rest%% *} case "$(git rev-parse --verify --quiet "$sha1"^)" in - "$ONTO"*) - ONTO=$sha1 + "$onto"*) + onto=$sha1 ;; *) fd=1 @@ -637,32 +569,16 @@ skip_unnecessary_picks () { ;; esac printf '%s\n' "$command${rest:+ }$rest" >&$fd - done <"$TODO" >"$TODO.new" 3>>"$DONE" && - mv -f "$TODO".new "$TODO" && + done <"$todo" >"$todo.new" 3>>"$done" && + mv -f "$todo".new "$todo" && case "$(peek_next_command)" in squash|s|fixup|f) - record_in_rewritten "$ONTO" + record_in_rewritten "$onto" ;; esac || die "Could not skip unnecessary pick commands" } -# check if no other options are set -is_standalone () { - test $# -eq 2 -a "$2" = '--' && - test -z "$ONTO" && - test -z "$PRESERVE_MERGES" && - test -z "$STRATEGY" && - test -z "$VERBOSE" -} - -get_saved_options () { - test -d "$REWRITTEN" && PRESERVE_MERGES=t - test -f "$DOTEST"/strategy && STRATEGY="$(cat "$DOTEST"/strategy)" - test -f "$DOTEST"/verbose && VERBOSE=t - test -f "$DOTEST"/rebase-root && REBASE_ROOT=t -} - # Rearrange the todo list that has both "pick sha1 msg" and # "pick sha1 fixup!/squash! msg" appears in it so that the latter # comes immediately after the former, and change "pick" to @@ -699,7 +615,7 @@ rearrange_squash () { esac printf '%s\n' "$pick $sha1 $message" used="$used$sha1 " - while read -r squash action msg + while read -r squash action msg_content do case " $used" in *" $squash "*) continue ;; @@ -709,13 +625,13 @@ rearrange_squash () { +*) action="${action#+}" # full sha1 prefix test - case "$msg" in "$sha1"*) emit=1;; esac ;; + case "$msg_content" in "$sha1"*) emit=1;; esac ;; *) # message prefix test - case "$message" in "$msg"*) emit=1;; esac ;; + case "$message" in "$msg_content"*) emit=1;; esac ;; esac if test $emit = 1; then - printf '%s\n' "$action $squash $action! $msg" + printf '%s\n' "$action $squash $action! $msg_content" used="$used$squash " fi done <"$1.sq" @@ -724,296 +640,158 @@ rearrange_squash () { rm -f "$1.sq" "$1.rearranged" } -LF=' -' -parse_onto () { - case "$1" in - *...*) - if left=${1%...*} right=${1#*...} && - onto=$(git merge-base --all ${left:-HEAD} ${right:-HEAD}) +case "$action" in +continue) + # do we have anything to commit? + if git diff-index --cached --quiet --ignore-submodules HEAD -- + then + : Nothing to commit -- skip this + else + . "$author_script" || + die "Cannot find the author identity" + current_head= + if test -f "$amend" then - case "$onto" in - ?*"$LF"?* | '') - exit 1 ;; - esac - echo "$onto" - exit 0 - fi - esac - git rev-parse --verify "$1^0" -} - -while test $# != 0 -do - case "$1" in - --no-verify) - OK_TO_SKIP_PRE_REBASE=yes - ;; - --verify) - OK_TO_SKIP_PRE_REBASE= - ;; - --continue) - is_standalone "$@" || usage - get_saved_options - comment_for_reflog continue - - test -d "$DOTEST" || die "No interactive rebase running" - - # Sanity check - git rev-parse --verify HEAD >/dev/null || - die "Cannot read HEAD" - git update-index --ignore-submodules --refresh && - git diff-files --quiet --ignore-submodules || - die "Working tree is dirty" - - # do we have anything to commit? - if git diff-index --cached --quiet --ignore-submodules HEAD -- - then - : Nothing to commit -- skip this - else - . "$AUTHOR_SCRIPT" || - die "Cannot find the author identity" - amend= - if test -f "$AMEND" - then - amend=$(git rev-parse --verify HEAD) - test "$amend" = $(cat "$AMEND") || - die "\ + current_head=$(git rev-parse --verify HEAD) + test "$current_head" = $(cat "$amend") || + die "\ You have uncommitted changes in your working tree. Please, commit them first and then run 'git rebase --continue' again." - git reset --soft HEAD^ || - die "Cannot rewind the HEAD" - fi - do_with_author git commit --no-verify -F "$MSG" -e || { - test -n "$amend" && git reset --soft $amend - die "Could not commit staged changes." - } + git reset --soft HEAD^ || + die "Cannot rewind the HEAD" fi + do_with_author git commit --no-verify -F "$msg" -e || { + test -n "$current_head" && git reset --soft $current_head + die "Could not commit staged changes." + } + fi - record_in_rewritten "$(cat "$DOTEST"/stopped-sha)" + record_in_rewritten "$(cat "$state_dir"/stopped-sha)" - require_clean_work_tree "rebase" - do_rest - ;; - --abort) - is_standalone "$@" || usage - get_saved_options - comment_for_reflog abort + require_clean_work_tree "rebase" + do_rest + ;; +skip) + git rerere clear - git rerere clear - test -d "$DOTEST" || die "No interactive rebase running" + do_rest + ;; +esac - HEADNAME=$(cat "$DOTEST"/head-name) - HEAD=$(cat "$DOTEST"/head) - case $HEADNAME in - refs/*) - git symbolic-ref HEAD $HEADNAME - ;; - esac && - output git reset --hard $HEAD && - rm -rf "$DOTEST" - exit - ;; - --skip) - is_standalone "$@" || usage - get_saved_options - comment_for_reflog skip +git var GIT_COMMITTER_IDENT >/dev/null || + die "You need to set your committer info first" - git rerere clear - test -d "$DOTEST" || die "No interactive rebase running" +comment_for_reflog start - output git reset --hard && do_rest - ;; - -s) - case "$#,$1" in - *,*=*) - STRATEGY="-s "$(expr "z$1" : 'z-[^=]*=\(.*\)') ;; - 1,*) - usage ;; - *) - STRATEGY="-s $2" - shift ;; - esac - ;; - -m) - # we use merge anyway - ;; - -v) - VERBOSE=t - ;; - -p) - PRESERVE_MERGES=t - ;; - -i) - # yeah, we know - ;; - --no-ff) - NEVER_FF=t - ;; - --root) - REBASE_ROOT=t - ;; - --autosquash) - AUTOSQUASH=t - ;; - --no-autosquash) - AUTOSQUASH= - ;; - --onto) - shift - ONTO=$(parse_onto "$1") || - die "Does not point to a valid commit: $1" - ;; - --) - shift - test -z "$REBASE_ROOT" -a $# -ge 1 -a $# -le 2 || - test ! -z "$REBASE_ROOT" -a $# -le 1 || usage - test -d "$DOTEST" && - die "Interactive rebase already started" +if test ! -z "$switch_to" +then + output git checkout "$switch_to" -- || + die "Could not checkout $switch_to" +fi - git var GIT_COMMITTER_IDENT >/dev/null || - die "You need to set your committer info first" +orig_head=$(git rev-parse --verify HEAD) || die "No HEAD?" +mkdir "$state_dir" || die "Could not create temporary $state_dir" - if test -z "$REBASE_ROOT" - then - UPSTREAM_ARG="$1" - UPSTREAM=$(git rev-parse --verify "$1") || die "Invalid base" - test -z "$ONTO" && ONTO=$UPSTREAM - shift - else - UPSTREAM= - UPSTREAM_ARG=--root - test -z "$ONTO" && - die "You must specify --onto when using --root" - fi - run_pre_rebase_hook "$UPSTREAM_ARG" "$@" - - comment_for_reflog start - - require_clean_work_tree "rebase" "Please commit or stash them." - - if test ! -z "$1" - then - output git checkout "$1" -- || - die "Could not checkout $1" - fi - - HEAD=$(git rev-parse --verify HEAD) || die "No HEAD?" - mkdir "$DOTEST" || die "Could not create temporary $DOTEST" - - : > "$DOTEST"/interactive || die "Could not mark as interactive" - git symbolic-ref HEAD > "$DOTEST"/head-name 2> /dev/null || - echo "detached HEAD" > "$DOTEST"/head-name - - echo $HEAD > "$DOTEST"/head - case "$REBASE_ROOT" in - '') - rm -f "$DOTEST"/rebase-root ;; - *) - : >"$DOTEST"/rebase-root ;; - esac - echo $ONTO > "$DOTEST"/onto - test -z "$STRATEGY" || echo "$STRATEGY" > "$DOTEST"/strategy - test t = "$VERBOSE" && : > "$DOTEST"/verbose - if test t = "$PRESERVE_MERGES" - then - if test -z "$REBASE_ROOT" - then - mkdir "$REWRITTEN" && - for c in $(git merge-base --all $HEAD $UPSTREAM) - do - echo $ONTO > "$REWRITTEN"/$c || - die "Could not init rewritten commits" - done - else - mkdir "$REWRITTEN" && - echo $ONTO > "$REWRITTEN"/root || - die "Could not init rewritten commits" - fi - # No cherry-pick because our first pass is to determine - # parents to rewrite and skipping dropped commits would - # prematurely end our probe - MERGES_OPTION= - first_after_upstream="$(git rev-list --reverse --first-parent $UPSTREAM..$HEAD | head -n 1)" - else - MERGES_OPTION="--no-merges --cherry-pick" - fi - - SHORTHEAD=$(git rev-parse --short $HEAD) - SHORTONTO=$(git rev-parse --short $ONTO) - if test -z "$REBASE_ROOT" - # this is now equivalent to ! -z "$UPSTREAM" - then - SHORTUPSTREAM=$(git rev-parse --short $UPSTREAM) - REVISIONS=$UPSTREAM...$HEAD - SHORTREVISIONS=$SHORTUPSTREAM..$SHORTHEAD - else - REVISIONS=$ONTO...$HEAD - SHORTREVISIONS=$SHORTHEAD - fi - git rev-list $MERGES_OPTION --pretty=oneline --abbrev-commit \ - --abbrev=7 --reverse --left-right --topo-order \ - $REVISIONS | \ - sed -n "s/^>//p" | - while read -r shortsha1 rest +: > "$state_dir"/interactive || die "Could not mark as interactive" +write_basic_state +if test t = "$preserve_merges" +then + if test -z "$rebase_root" + then + mkdir "$rewritten" && + for c in $(git merge-base --all $orig_head $upstream) do - if test t != "$PRESERVE_MERGES" - then - printf '%s\n' "pick $shortsha1 $rest" >> "$TODO" - else - sha1=$(git rev-parse $shortsha1) - if test -z "$REBASE_ROOT" + echo $onto > "$rewritten"/$c || + die "Could not init rewritten commits" + done + else + mkdir "$rewritten" && + echo $onto > "$rewritten"/root || + die "Could not init rewritten commits" + fi + # No cherry-pick because our first pass is to determine + # parents to rewrite and skipping dropped commits would + # prematurely end our probe + merges_option= +else + merges_option="--no-merges --cherry-pick" +fi + +shorthead=$(git rev-parse --short $orig_head) +shortonto=$(git rev-parse --short $onto) +if test -z "$rebase_root" + # this is now equivalent to ! -z "$upstream" +then + shortupstream=$(git rev-parse --short $upstream) + revisions=$upstream...$orig_head + shortrevisions=$shortupstream..$shorthead +else + revisions=$onto...$orig_head + shortrevisions=$shorthead +fi +git rev-list $merges_option --pretty=oneline --abbrev-commit \ + --abbrev=7 --reverse --left-right --topo-order \ + $revisions | \ + sed -n "s/^>//p" | +while read -r shortsha1 rest +do + if test t != "$preserve_merges" + then + printf '%s\n' "pick $shortsha1 $rest" >> "$todo" + else + sha1=$(git rev-parse $shortsha1) + if test -z "$rebase_root" + then + preserve=t + for p in $(git rev-list --parents -1 $sha1 | cut -d' ' -s -f2-) + do + if test -f "$rewritten"/$p then - preserve=t - for p in $(git rev-list --parents -1 $sha1 | cut -d' ' -s -f2-) - do - if test -f "$REWRITTEN"/$p -a \( $p != $ONTO -o $sha1 = $first_after_upstream \) - then - preserve=f - fi - done - else preserve=f fi - if test f = "$preserve" - then - touch "$REWRITTEN"/$sha1 - printf '%s\n' "pick $shortsha1 $rest" >> "$TODO" - fi - fi - done - - # Watch for commits that been dropped by --cherry-pick - if test t = "$PRESERVE_MERGES" - then - mkdir "$DROPPED" - # Save all non-cherry-picked changes - git rev-list $REVISIONS --left-right --cherry-pick | \ - sed -n "s/^>//p" > "$DOTEST"/not-cherry-picks - # Now all commits and note which ones are missing in - # not-cherry-picks and hence being dropped - git rev-list $REVISIONS | - while read rev - do - if test -f "$REWRITTEN"/$rev -a "$(sane_grep "$rev" "$DOTEST"/not-cherry-picks)" = "" - then - # Use -f2 because if rev-list is telling us this commit is - # not worthwhile, we don't want to track its multiple heads, - # just the history of its first-parent for others that will - # be rebasing on top of it - git rev-list --parents -1 $rev | cut -d' ' -s -f2 > "$DROPPED"/$rev - short=$(git rev-list -1 --abbrev-commit --abbrev=7 $rev) - sane_grep -v "^[a-z][a-z]* $short" <"$TODO" > "${TODO}2" ; mv "${TODO}2" "$TODO" - rm "$REWRITTEN"/$rev - fi done + else + preserve=f fi + if test f = "$preserve" + then + touch "$rewritten"/$sha1 + printf '%s\n' "pick $shortsha1 $rest" >> "$todo" + fi + fi +done - test -s "$TODO" || echo noop >> "$TODO" - test -n "$AUTOSQUASH" && rearrange_squash "$TODO" - cat >> "$TODO" << EOF +# Watch for commits that been dropped by --cherry-pick +if test t = "$preserve_merges" +then + mkdir "$dropped" + # Save all non-cherry-picked changes + git rev-list $revisions --left-right --cherry-pick | \ + sed -n "s/^>//p" > "$state_dir"/not-cherry-picks + # Now all commits and note which ones are missing in + # not-cherry-picks and hence being dropped + git rev-list $revisions | + while read rev + do + if test -f "$rewritten"/$rev -a "$(sane_grep "$rev" "$state_dir"/not-cherry-picks)" = "" + then + # Use -f2 because if rev-list is telling us this commit is + # not worthwhile, we don't want to track its multiple heads, + # just the history of its first-parent for others that will + # be rebasing on top of it + git rev-list --parents -1 $rev | cut -d' ' -s -f2 > "$dropped"/$rev + short=$(git rev-list -1 --abbrev-commit --abbrev=7 $rev) + sane_grep -v "^[a-z][a-z]* $short" <"$todo" > "${todo}2" ; mv "${todo}2" "$todo" + rm "$rewritten"/$rev + fi + done +fi -# Rebase $SHORTREVISIONS onto $SHORTONTO +test -s "$todo" || echo noop >> "$todo" +test -n "$autosquash" && rearrange_squash "$todo" +cat >> "$todo" << EOF + +# Rebase $shortrevisions onto $shortonto # # Commands: # p, pick = use commit @@ -1028,22 +806,18 @@ first and then run 'git rebase --continue' again." # EOF - has_action "$TODO" || - die_abort "Nothing to do" +has_action "$todo" || + die_abort "Nothing to do" - cp "$TODO" "$TODO".backup - git_editor "$TODO" || - die_abort "Could not execute editor" +cp "$todo" "$todo".backup +git_editor "$todo" || + die_abort "Could not execute editor" - has_action "$TODO" || - die_abort "Nothing to do" +has_action "$todo" || + die_abort "Nothing to do" - test -d "$REWRITTEN" || test -n "$NEVER_FF" || skip_unnecessary_picks +test -d "$rewritten" || test -n "$force_rebase" || skip_unnecessary_picks - output git checkout $ONTO || die_abort "could not detach HEAD" - git update-ref ORIG_HEAD $HEAD - do_rest - ;; - esac - shift -done +output git checkout $onto || die_abort "could not detach HEAD" +git update-ref ORIG_HEAD $orig_head +do_rest diff --git a/SparkleShare/Mac/git/libexec/git-core/git-rebase--merge b/SparkleShare/Mac/git/libexec/git-core/git-rebase--merge new file mode 100644 index 00000000..26afc75c --- /dev/null +++ b/SparkleShare/Mac/git/libexec/git-core/git-rebase--merge @@ -0,0 +1,151 @@ +#!/bin/sh +# +# Copyright (c) 2010 Junio C Hamano. +# + +. git-sh-setup + +prec=4 + +read_state () { + onto_name=$(cat "$state_dir"/onto_name) && + end=$(cat "$state_dir"/end) && + msgnum=$(cat "$state_dir"/msgnum) +} + +continue_merge () { + test -d "$state_dir" || die "$state_dir directory does not exist" + + unmerged=$(git ls-files -u) + if test -n "$unmerged" + then + echo "You still have unmerged paths in your index" + echo "did you forget to use git add?" + die "$resolvemsg" + fi + + cmt=`cat "$state_dir/current"` + if ! git diff-index --quiet --ignore-submodules HEAD -- + then + if ! git commit --no-verify -C "$cmt" + then + echo "Commit failed, please do not call \"git commit\"" + echo "directly, but instead do one of the following: " + die "$resolvemsg" + fi + if test -z "$GIT_QUIET" + then + printf "Committed: %0${prec}d " $msgnum + fi + echo "$cmt $(git rev-parse HEAD^0)" >> "$state_dir/rewritten" + else + if test -z "$GIT_QUIET" + then + printf "Already applied: %0${prec}d " $msgnum + fi + fi + test -z "$GIT_QUIET" && + GIT_PAGER='' git log --format=%s -1 "$cmt" + + # onto the next patch: + msgnum=$(($msgnum + 1)) + echo "$msgnum" >"$state_dir/msgnum" +} + +call_merge () { + cmt="$(cat "$state_dir/cmt.$1")" + echo "$cmt" > "$state_dir/current" + hd=$(git rev-parse --verify HEAD) + cmt_name=$(git symbolic-ref HEAD 2> /dev/null || echo HEAD) + msgnum=$(cat "$state_dir/msgnum") + eval GITHEAD_$cmt='"${cmt_name##refs/heads/}~$(($end - $msgnum))"' + eval GITHEAD_$hd='$onto_name' + export GITHEAD_$cmt GITHEAD_$hd + if test -n "$GIT_QUIET" + then + GIT_MERGE_VERBOSITY=1 && export GIT_MERGE_VERBOSITY + fi + test -z "$strategy" && strategy=recursive + eval 'git-merge-$strategy' $strategy_opts '"$cmt^" -- "$hd" "$cmt"' + rv=$? + case "$rv" in + 0) + unset GITHEAD_$cmt GITHEAD_$hd + return + ;; + 1) + git rerere $allow_rerere_autoupdate + die "$resolvemsg" + ;; + 2) + echo "Strategy: $strategy failed, try another" 1>&2 + die "$resolvemsg" + ;; + *) + die "Unknown exit code ($rv) from command:" \ + "git-merge-$strategy $cmt^ -- HEAD $cmt" + ;; + esac +} + +finish_rb_merge () { + move_to_original_branch + git notes copy --for-rewrite=rebase < "$state_dir"/rewritten + if test -x "$GIT_DIR"/hooks/post-rewrite && + test -s "$state_dir"/rewritten; then + "$GIT_DIR"/hooks/post-rewrite rebase < "$state_dir"/rewritten + fi + rm -r "$state_dir" + say All done. +} + +case "$action" in +continue) + read_state + continue_merge + while test "$msgnum" -le "$end" + do + call_merge "$msgnum" + continue_merge + done + finish_rb_merge + exit + ;; +skip) + read_state + git rerere clear + msgnum=$(($msgnum + 1)) + while test "$msgnum" -le "$end" + do + call_merge "$msgnum" + continue_merge + done + finish_rb_merge + exit + ;; +esac + +mkdir -p "$state_dir" +echo "$onto_name" > "$state_dir/onto_name" +write_basic_state + +msgnum=0 +for cmt in `git rev-list --reverse --no-merges "$revisions"` +do + msgnum=$(($msgnum + 1)) + echo "$cmt" > "$state_dir/cmt.$msgnum" +done + +echo 1 >"$state_dir/msgnum" +echo $msgnum >"$state_dir/end" + +end=$msgnum +msgnum=1 + +while test "$msgnum" -le "$end" +do + call_merge "$msgnum" + continue_merge +done + +finish_rb_merge diff --git a/SparkleShare/Mac/git/libexec/git-core/git-remote-ftp b/SparkleShare/Mac/git/libexec/git-core/git-remote-ftp index 3f1687eb..a251bc74 100755 Binary files a/SparkleShare/Mac/git/libexec/git-core/git-remote-ftp and b/SparkleShare/Mac/git/libexec/git-core/git-remote-ftp differ diff --git a/SparkleShare/Mac/git/libexec/git-core/git-remote-ftps b/SparkleShare/Mac/git/libexec/git-core/git-remote-ftps index 3f1687eb..a251bc74 100755 Binary files a/SparkleShare/Mac/git/libexec/git-core/git-remote-ftps and b/SparkleShare/Mac/git/libexec/git-core/git-remote-ftps differ diff --git a/SparkleShare/Mac/git/libexec/git-core/git-remote-http b/SparkleShare/Mac/git/libexec/git-core/git-remote-http index 3f1687eb..a251bc74 100755 Binary files a/SparkleShare/Mac/git/libexec/git-core/git-remote-http and b/SparkleShare/Mac/git/libexec/git-core/git-remote-http differ diff --git a/SparkleShare/Mac/git/libexec/git-core/git-remote-https b/SparkleShare/Mac/git/libexec/git-core/git-remote-https index 3f1687eb..a251bc74 100755 Binary files a/SparkleShare/Mac/git/libexec/git-core/git-remote-https and b/SparkleShare/Mac/git/libexec/git-core/git-remote-https differ diff --git a/SparkleShare/Mac/git/libexec/git-core/git-remote-testgit b/SparkleShare/Mac/git/libexec/git-core/git-remote-testgit index 40cea61a..8324eb61 100755 --- a/SparkleShare/Mac/git/libexec/git-core/git-remote-testgit +++ b/SparkleShare/Mac/git/libexec/git-core/git-remote-testgit @@ -9,7 +9,7 @@ except ImportError: _digest = sha.new import sys import os -sys.path.insert(0, os.getenv("GITPYTHONLIB","/usr/local/git/lib/python2.6/site-packages")) +sys.path.insert(0, os.getenv("GITPYTHONLIB","/usr/local/git/lib/python2.7/site-packages")) from git_remote_helpers.util import die, debug, warn from git_remote_helpers.git.repo import GitRepo diff --git a/SparkleShare/Mac/git/libexec/git-core/git-request-pull b/SparkleShare/Mac/git/libexec/git-core/git-request-pull index 6fdea397..fc080cc5 100755 --- a/SparkleShare/Mac/git/libexec/git-core/git-request-pull +++ b/SparkleShare/Mac/git/libexec/git-core/git-request-pull @@ -15,7 +15,6 @@ p show patch text as well ' . git-sh-setup -. git-parse-remote GIT_PAGER= export GIT_PAGER @@ -55,7 +54,7 @@ branch=$(git ls-remote "$url" \ p q }") -url=$(get_remote_url "$url") +url=$(git ls-remote --get-url "$url") if [ -z "$branch" ]; then echo "warn: No branch of $url is at:" >&2 git log --max-count=1 --pretty='tformat:warn: %h: %s' $headrev >&2 diff --git a/SparkleShare/Mac/git/libexec/git-core/git-send-email b/SparkleShare/Mac/git/libexec/git-core/git-send-email index 01d5a74e..51c4055a 100755 --- a/SparkleShare/Mac/git/libexec/git-core/git-send-email +++ b/SparkleShare/Mac/git/libexec/git-core/git-send-email @@ -969,7 +969,7 @@ sub send_message { @recipients = unique_email_list(@recipients,@cc,@bcclist); @recipients = (map { extract_valid_address($_) } @recipients); my $date = format_2822_time($time++); - my $gitversion = '1.7.4'; + my $gitversion = '1.7.6.1'; if ($gitversion =~ m/..GIT_VERSION../) { $gitversion = Git::version(); } @@ -1092,7 +1092,7 @@ X-Mailer: git-send-email $gitversion "VALUES: server=$smtp_server ", "encryption=$smtp_encryption ", "hello=$smtp_domain", - defined $smtp_server_port ? "port=$smtp_server_port" : ""; + defined $smtp_server_port ? " port=$smtp_server_port" : ""; } if (defined $smtp_authuser) { diff --git a/SparkleShare/Mac/git/libexec/git-core/git-sh-i18n b/SparkleShare/Mac/git/libexec/git-core/git-sh-i18n new file mode 100644 index 00000000..32ca59de --- /dev/null +++ b/SparkleShare/Mac/git/libexec/git-core/git-sh-i18n @@ -0,0 +1,29 @@ +#!/bin/sh +# +# Copyright (c) 2010 Ævar Arnfjörð Bjarmason +# +# This is a skeleton no-op implementation of gettext for Git. It'll be +# replaced by something that uses gettext.sh in a future patch series. + +if test -z "$GIT_GETTEXT_POISON" +then + gettext () { + printf "%s" "$1" + } + + eval_gettext () { + printf "%s" "$1" | ( + export PATH $(git sh-i18n--envsubst --variables "$1"); + git sh-i18n--envsubst "$1" + ) + } +else + gettext () { + printf "%s" "# GETTEXT POISON #" + } + + eval_gettext () { + printf "%s" "# GETTEXT POISON #" + } +fi + diff --git a/SparkleShare/Mac/git/libexec/git-core/git-sh-i18n--envsubst b/SparkleShare/Mac/git/libexec/git-core/git-sh-i18n--envsubst new file mode 100755 index 00000000..009471b8 Binary files /dev/null and b/SparkleShare/Mac/git/libexec/git-core/git-sh-i18n--envsubst differ diff --git a/SparkleShare/Mac/git/libexec/git-core/git-sh-setup b/SparkleShare/Mac/git/libexec/git-core/git-sh-setup index b5ede679..6fd2c2f7 100644 --- a/SparkleShare/Mac/git/libexec/git-core/git-sh-setup +++ b/SparkleShare/Mac/git/libexec/git-core/git-sh-setup @@ -139,6 +139,13 @@ cd_to_toplevel () { } } +require_work_tree_exists () { + if test "z$(git rev-parse --is-bare-repository)" != zfalse + then + die "fatal: $0 cannot be used without a working tree." + fi +} + require_work_tree () { test "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = true || die "fatal: $0 cannot be used without a working tree." diff --git a/SparkleShare/Mac/git/libexec/git-core/git-shell b/SparkleShare/Mac/git/libexec/git-core/git-shell index 0e3b853d..647fe452 100755 Binary files a/SparkleShare/Mac/git/libexec/git-core/git-shell and b/SparkleShare/Mac/git/libexec/git-core/git-shell differ diff --git a/SparkleShare/Mac/git/libexec/git-core/git-show-index b/SparkleShare/Mac/git/libexec/git-core/git-show-index index 54d8da40..8d7dc10f 100755 Binary files a/SparkleShare/Mac/git/libexec/git-core/git-show-index and b/SparkleShare/Mac/git/libexec/git-core/git-show-index differ diff --git a/SparkleShare/Mac/git/libexec/git-core/git-stash b/SparkleShare/Mac/git/libexec/git-core/git-stash index 7561b374..0a940365 100755 --- a/SparkleShare/Mac/git/libexec/git-core/git-stash +++ b/SparkleShare/Mac/git/libexec/git-core/git-stash @@ -12,12 +12,14 @@ USAGE="list [] SUBDIRECTORY_OK=Yes OPTIONS_SPEC= +START_DIR=`pwd` . git-sh-setup require_work_tree cd_to_toplevel TMP="$GIT_DIR/.git-stash.$$" -trap 'rm -f "$TMP-*"' 0 +TMPindex=${GIT_INDEX_FILE-"$GIT_DIR/index"}.stash.$$ +trap 'rm -f "$TMP-"* "$TMPindex"' 0 ref_stash=refs/stash @@ -81,14 +83,12 @@ create_stash () { # state of the working tree w_tree=$( ( - rm -f "$TMP-index" && - cp -p ${GIT_INDEX_FILE-"$GIT_DIR/index"} "$TMP-index" && - GIT_INDEX_FILE="$TMP-index" && + git read-tree --index-output="$TMPindex" -m $i_tree && + GIT_INDEX_FILE="$TMPindex" && export GIT_INDEX_FILE && - git read-tree -m $i_tree && git diff --name-only -z HEAD | git update-index -z --add --remove --stdin && git write-tree && - rm -f "$TMP-index" + rm -f "$TMPindex" ) ) || die "Cannot save the current worktree state" @@ -136,11 +136,12 @@ save_stash () { keep_index=t ;; --no-keep-index) - keep_index= + keep_index=n ;; -p|--patch) patch_mode=t - keep_index=t + # only default to keep if we don't already have an override + test -z "$keep_index" && keep_index=t ;; -q|--quiet) GIT_QUIET=t @@ -185,7 +186,7 @@ save_stash () { then git reset --hard ${GIT_QUIET:+-q} - if test -n "$keep_index" && test -n $i_tree + if test "$keep_index" = "t" && test -n $i_tree then git read-tree --reset -u $i_tree fi @@ -193,7 +194,7 @@ save_stash () { git apply -R < "$TMP-patch" || die "Cannot remove worktree changes" - if test -z "$keep_index" + if test "$keep_index" != "t" then git reset fi @@ -264,7 +265,7 @@ parse_flags_and_rev() b_tree= i_tree= - REV=$(git rev-parse --no-flags --symbolic "$@" 2>/dev/null) + REV=$(git rev-parse --no-flags --symbolic "$@") || exit 1 FLAGS= for opt @@ -310,16 +311,6 @@ parse_flags_and_rev() IS_STASH_LIKE=t && test "$ref_stash" = "$(git rev-parse --symbolic-full-name "${REV%@*}")" && IS_STASH_REF=t - - if test "${REV}" != "${REV%{*\}}" - then - # maintainers: it would be better if git rev-parse indicated - # this condition with a non-zero status code but as of 1.7.2.1 it - # it did not. So, we use non-empty stderr output as a proxy for the - # condition of interest. - test -z "$(git rev-parse "$REV" 2>&1 >/dev/null)" || die "$REV does not exist in the stash log" - fi - } is_stash_like() @@ -344,9 +335,7 @@ apply_stash () { assert_stash_like "$@" - git update-index -q --refresh && - git diff-files --quiet --ignore-submodules || - die 'Cannot apply to a dirty working tree, please stage your changes' + git update-index -q --refresh || die 'unable to refresh index' # current index state c_tree=$(git write-tree) || @@ -394,7 +383,7 @@ apply_stash () { then squelch='>/dev/null 2>&1' fi - eval "git status $squelch" || : + (cd "$START_DIR" && eval "git status $squelch") || : else # Merge conflict; keep the exit status from merge-recursive status=$? diff --git a/SparkleShare/Mac/git/libexec/git-core/git-submodule b/SparkleShare/Mac/git/libexec/git-core/git-submodule index 8b905897..c94218b8 100755 --- a/SparkleShare/Mac/git/libexec/git-core/git-submodule +++ b/SparkleShare/Mac/git/libexec/git-core/git-submodule @@ -8,7 +8,7 @@ dashless=$(basename "$0" | sed -e 's/-/ /') USAGE="[--quiet] add [-b branch] [-f|--force] [--reference ] [--] [] or: $dashless [--quiet] status [--cached] [--recursive] [--] [...] or: $dashless [--quiet] init [--] [...] - or: $dashless [--quiet] update [--init] [-N|--no-fetch] [--rebase] [--reference ] [--merge] [--recursive] [--] [...] + or: $dashless [--quiet] update [--init] [-N|--no-fetch] [-f|--force] [--rebase] [--reference ] [--merge] [--recursive] [--] [...] or: $dashless [--quiet] summary [--cached|--files] [--summary-limit ] [commit] [--] [...] or: $dashless [--quiet] foreach [--recursive] or: $dashless [--quiet] sync [--] [...]" @@ -34,7 +34,7 @@ resolve_relative_url () { remote=$(get_default_remote) remoteurl=$(git config "remote.$remote.url") || - die "remote ($remote) does not have a url defined in .git/config" + remoteurl=$(pwd) # the repository is its own authoritative upstream url="$1" remoteurl=${remoteurl%/} sep=/ @@ -72,7 +72,24 @@ resolve_relative_url () # module_list() { - git ls-files --error-unmatch --stage -- "$@" | sane_grep '^160000 ' + git ls-files --error-unmatch --stage -- "$@" | + perl -e ' + my %unmerged = (); + my ($null_sha1) = ("0" x 40); + while () { + chomp; + my ($mode, $sha1, $stage, $path) = + /^([0-7]+) ([0-9a-f]{40}) ([0-3])\t(.*)$/; + next unless $mode eq "160000"; + if ($stage ne "0") { + if (!$unmerged{$path}++) { + print "$mode $null_sha1 U\t$path\n"; + } + next; + } + print "$_\n"; + } + ' } # @@ -104,12 +121,17 @@ module_clone() path=$1 url=$2 reference="$3" + quiet= + if test -n "$GIT_QUIET" + then + quiet=-q + fi if test -n "$reference" then - git-clone "$reference" -n "$url" "$path" + git-clone $quiet "$reference" -n "$url" "$path" else - git-clone -n "$url" "$path" + git-clone $quiet -n "$url" "$path" fi || die "Clone of '$url' into submodule path '$path' failed" } @@ -221,15 +243,6 @@ cmd_add() die "'$path' already exists and is not a valid git repo" fi - case "$repo" in - ./*|../*) - url=$(resolve_relative_url "$repo") || exit - ;; - *) - url="$repo" - ;; - esac - git config submodule."$path".url "$url" else module_clone "$path" "$realrepo" "$reference" || exit @@ -243,6 +256,7 @@ cmd_add() esac ) || die "Unable to checkout submodule '$path'" fi + git config submodule."$path".url "$realrepo" git add $force "$path" || die "Failed to add submodule '$path'" @@ -283,6 +297,10 @@ cmd_foreach() toplevel=$(pwd) + # dup stdin so that it can be restored when running the external + # command in the subshell (and a recursive call to this function) + exec 3<&0 + module_list | while read mode sha1 stage path do @@ -299,7 +317,7 @@ cmd_foreach() then cmd_foreach "--recursive" "$@" fi - ) || + ) <&3 3<&- || die "Stopping at '$path'; script returned non-zero status." fi done @@ -338,25 +356,26 @@ cmd_init() do # Skip already registered paths name=$(module_name "$path") || exit - url=$(git config submodule."$name".url) - test -z "$url" || continue + if test -z "$(git config "submodule.$name.url")" + then + url=$(git config -f .gitmodules submodule."$name".url) + test -z "$url" && + die "No url found for submodule path '$path' in .gitmodules" - url=$(git config -f .gitmodules submodule."$name".url) - test -z "$url" && - die "No url found for submodule path '$path' in .gitmodules" - - # Possibly a url relative to parent - case "$url" in - ./*|../*) - url=$(resolve_relative_url "$url") || exit - ;; - esac - - git config submodule."$name".url "$url" || - die "Failed to register url for submodule path '$path'" + # Possibly a url relative to parent + case "$url" in + ./*|../*) + url=$(resolve_relative_url "$url") || exit + ;; + esac + git config submodule."$name".url "$url" || + die "Failed to register url for submodule path '$path'" + fi + # Copy "update" setting when it is not set yet upd="$(git config -f .gitmodules submodule."$name".update)" test -z "$upd" || + test -n "$(git config submodule."$name".update)" || git config submodule."$name".update "$upd" || die "Failed to register update mode for submodule path '$path'" @@ -385,6 +404,9 @@ cmd_update() -N|--no-fetch) nofetch=1 ;; + -f|--force) + force=$1 + ;; -r|--rebase) update="rebase" ;; @@ -423,9 +445,15 @@ cmd_update() cmd_init "--" "$@" || return fi + cloned_modules= module_list "$@" | while read mode sha1 stage path do + if test "$stage" = U + then + echo >&2 "Skipping unmerged submodule $path" + continue + fi name=$(module_name "$path") || exit url=$(git config submodule."$name".url) update_module=$(git config submodule."$name".update) @@ -442,6 +470,7 @@ cmd_update() if ! test -d "$path"/.git -o -f "$path"/.git then module_clone "$path" "$url" "$reference"|| exit + cloned_modules="$cloned_modules;$name" subsha1= else subsha1=$(clear_local_git_env; cd "$path" && @@ -456,19 +485,30 @@ cmd_update() if test "$subsha1" != "$sha1" then - force= - if test -z "$subsha1" + subforce=$force + # If we don't already have a -f flag and the submodule has never been checked out + if test -z "$subsha1" -a -z "$force" then - force="-f" + subforce="-f" fi if test -z "$nofetch" then + # Run fetch only if $sha1 isn't present or it + # is not reachable from a ref. (clear_local_git_env; cd "$path" && - git-fetch) || + ( (rev=$(git rev-list -n 1 $sha1 --not --all 2>/dev/null) && + test -z "$rev") || git-fetch)) || die "Unable to fetch in submodule path '$path'" fi + # Is this something we just cloned? + case ";$cloned_modules;" in + *";$name;"*) + # then there is no local change to integrate + update_module= ;; + esac + case "$update_module" in rebase) command="git rebase" @@ -481,7 +521,7 @@ cmd_update() msg="merged in" ;; *) - command="git checkout $force -q" + command="git checkout $subforce -q" action="checkout" msg="checked out" ;; @@ -761,6 +801,11 @@ cmd_status() name=$(module_name "$path") || exit url=$(git config submodule."$name".url) displaypath="$prefix$path" + if test "$stage" = U + then + say "U$sha1 $displaypath" + continue + fi if test -z "$url" || ! test -d "$path"/.git -o -f "$path"/.git then say "-$sha1 $displaypath" @@ -831,17 +876,20 @@ cmd_sync() ;; esac - say "Synchronizing submodule url for '$name'" - git config submodule."$name".url "$url" - - if test -e "$path"/.git + if git config "submodule.$name.url" >/dev/null 2>/dev/null then - ( - clear_local_git_env - cd "$path" - remote=$(get_default_remote) - git config remote."$remote".url "$url" - ) + say "Synchronizing submodule url for '$name'" + git config submodule."$name".url "$url" + + if test -e "$path"/.git + then + ( + clear_local_git_env + cd "$path" + remote=$(get_default_remote) + git config remote."$remote".url "$url" + ) + fi fi done } diff --git a/SparkleShare/Mac/git/libexec/git-core/git-svn b/SparkleShare/Mac/git/libexec/git-core/git-svn index 557dc935..a907bb2a 100755 --- a/SparkleShare/Mac/git/libexec/git-core/git-svn +++ b/SparkleShare/Mac/git/libexec/git-core/git-svn @@ -9,7 +9,7 @@ use vars qw/ $AUTHOR $VERSION $sha1 $sha1_short $_revision $_repository $_q $_authors $_authors_prog %users/; $AUTHOR = 'Eric Wong '; -$VERSION = '1.7.4'; +$VERSION = '1.7.6.1'; # From which subdir have we been invoked? my $cmd_dir_prefix = eval { @@ -60,6 +60,7 @@ use File::Find; use Getopt::Long qw/:config gnu_getopt no_ignore_case auto_abbrev/; use IPC::Open3; use Git; +use Memoize; # core since 5.8.0, Jul 2002 BEGIN { # import functions from Git into our packages, en masse @@ -73,6 +74,8 @@ BEGIN { *{"${package}::$_"} = \&{"Git::$_"}; } } + Memoize::memoize 'Git::config'; + Memoize::memoize 'Git::config_bool'; } my ($SVN); @@ -529,7 +532,7 @@ sub cmd_dcommit { $url = eval { command_oneline('config', '--get', "svn-remote.$gs->{repo_id}.commiturl") }; if (!$url) { - $url = $gs->full_url + $url = $gs->full_pushurl } } @@ -677,7 +680,7 @@ sub cmd_branch { $head ||= 'HEAD'; my (undef, $rev, undef, $gs) = working_head_info($head); - my $src = $gs->full_url; + my $src = $gs->full_pushurl; my $remote = Git::SVN::read_all_remotes()->{$gs->{repo_id}}; my $allglobs = $remote->{ $_tag ? 'tags' : 'branches' }; @@ -728,7 +731,7 @@ sub cmd_branch { $url = eval { command_oneline('config', '--get', "svn-remote.$gs->{repo_id}.commiturl") }; if (!$url) { - $url = $remote->{url}; + $url = $remote->{pushurl} || $remote->{url}; } } my $dst = join '/', $url, $lft, $branch_name, ($rgt || ()); @@ -782,6 +785,15 @@ sub cmd_find_rev { print "$result\n" if $result; } +sub auto_create_empty_directories { + my ($gs) = @_; + my $var = eval { command_oneline('config', '--get', '--bool', + "svn-remote.$gs->{repo_id}.automkdirs") }; + # By default, create empty directories by consulting the unhandled log, + # but allow setting it to 'false' to skip it. + return !($var && $var eq 'false'); +} + sub cmd_rebase { command_noisy(qw/update-index --refresh/); my ($url, $rev, $uuid, $gs) = working_head_info('HEAD'); @@ -805,7 +817,9 @@ sub cmd_rebase { $_fetch_all ? $gs->fetch_all : $gs->fetch; } command_noisy(rebase_cmd(), $gs->refname); - $gs->mkemptydirs; + if (auto_create_empty_directories($gs)) { + $gs->mkemptydirs; + } } sub cmd_show_ignore { @@ -1243,7 +1257,9 @@ sub post_fetch_checkout { command_noisy(qw/read-tree -m -u -v HEAD HEAD/); print STDERR "Checked out HEAD:\n ", $gs->full_url, " r", $gs->last_rev, "\n"; - $gs->mkemptydirs($gs->last_rev); + if (auto_create_empty_directories($gs)) { + $gs->mkemptydirs($gs->last_rev); + } } sub complete_svn_url { @@ -1832,6 +1848,8 @@ sub read_all_remotes { $r->{$1}->{svm} = {}; } elsif (m!^(.+)\.url=\s*(.*)\s*$!) { $r->{$1}->{url} = $2; + } elsif (m!^(.+)\.pushurl=\s*(.*)\s*$!) { + $r->{$1}->{pushurl} = $2; } elsif (m!^(.+)\.(branches|tags)=$svn_refspec$!) { my ($remote, $t, $local_ref, $remote_ref) = ($1, $2, $3, $4); @@ -2069,6 +2087,8 @@ sub new { $self->{url} = command_oneline('config', '--get', "svn-remote.$repo_id.url") or die "Failed to read \"svn-remote.$repo_id.url\" in config\n"; + $self->{pushurl} = eval { command_oneline('config', '--get', + "svn-remote.$repo_id.pushurl") }; $self->rebuild; $self; } @@ -2546,6 +2566,15 @@ sub full_url { $self->{url} . (length $self->{path} ? '/' . $self->{path} : ''); } +sub full_pushurl { + my ($self) = @_; + if ($self->{pushurl}) { + return $self->{pushurl} . (length $self->{path} ? '/' . + $self->{path} : ''); + } else { + return $self->full_url; + } +} sub set_commit_header_env { my ($log_entry) = @_; @@ -3096,8 +3125,12 @@ sub lookup_svn_merge { next; } - push @merged_commit_ranges, - "$bottom_commit^..$top_commit"; + if (scalar(command('rev-parse', "$bottom_commit^@"))) { + push @merged_commit_ranges, + "$bottom_commit^..$top_commit"; + } else { + push @merged_commit_ranges, "$top_commit"; + } if ( !defined $tip or $top > $tip ) { $tip = $top; @@ -3126,9 +3159,9 @@ sub check_cherry_pick { my $parents = shift; my @ranges = @_; my %commits = map { $_ => 1 } - _rev_list("--no-merges", $tip, "--not", $base, @$parents); + _rev_list("--no-merges", $tip, "--not", $base, @$parents, "--"); for my $range ( @ranges ) { - delete @commits{_rev_list($range)}; + delete @commits{_rev_list($range, "--")}; } for my $commit (keys %commits) { if (has_no_changes($commit)) { @@ -3198,6 +3231,8 @@ sub has_no_changes { Memoize::unmemoize 'check_cherry_pick'; Memoize::unmemoize 'has_no_changes'; } + + Memoize::memoize 'Git::SVN::repos_root'; } END { @@ -5735,7 +5770,7 @@ sub cmd_show_log { my (@k, $c, $d, $stat); my $esc_color = qr/(?:\033\[(?:(?:\d+;)*\d*)?m)*/; while (<$log>) { - if (/^${esc_color}commit -?($::sha1_short)/o) { + if (/^${esc_color}commit (?:- )?($::sha1_short)/o) { my $cmt = $1; if ($c && cmt_showable($c) && $c->{r} != $r_last) { $r_last = $c->{r}; diff --git a/SparkleShare/Mac/git/libexec/git-core/git-upload-pack b/SparkleShare/Mac/git/libexec/git-core/git-upload-pack index 593fb440..3cc4e6db 100755 Binary files a/SparkleShare/Mac/git/libexec/git-core/git-upload-pack and b/SparkleShare/Mac/git/libexec/git-core/git-upload-pack differ diff --git a/SparkleShare/Mac/git/libexec/git-core/perl/Git.pm b/SparkleShare/Mac/git/libexec/git-core/perl/Git.pm new file mode 100644 index 00000000..a86ab709 --- /dev/null +++ b/SparkleShare/Mac/git/libexec/git-core/perl/Git.pm @@ -0,0 +1,1378 @@ +=head1 NAME + +Git - Perl interface to the Git version control system + +=cut + + +package Git; + +use 5.008; +use strict; + + +BEGIN { + +our ($VERSION, @ISA, @EXPORT, @EXPORT_OK); + +# Totally unstable API. +$VERSION = '0.01'; + + +=head1 SYNOPSIS + + use Git; + + my $version = Git::command_oneline('version'); + + git_cmd_try { Git::command_noisy('update-server-info') } + '%s failed w/ code %d'; + + my $repo = Git->repository (Directory => '/srv/git/cogito.git'); + + + my @revs = $repo->command('rev-list', '--since=last monday', '--all'); + + my ($fh, $c) = $repo->command_output_pipe('rev-list', '--since=last monday', '--all'); + my $lastrev = <$fh>; chomp $lastrev; + $repo->command_close_pipe($fh, $c); + + my $lastrev = $repo->command_oneline( [ 'rev-list', '--all' ], + STDERR => 0 ); + + my $sha1 = $repo->hash_and_insert_object('file.txt'); + my $tempfile = tempfile(); + my $size = $repo->cat_blob($sha1, $tempfile); + +=cut + + +require Exporter; + +@ISA = qw(Exporter); + +@EXPORT = qw(git_cmd_try); + +# Methods which can be called as standalone functions as well: +@EXPORT_OK = qw(command command_oneline command_noisy + command_output_pipe command_input_pipe command_close_pipe + command_bidi_pipe command_close_bidi_pipe + version exec_path html_path hash_object git_cmd_try + remote_refs + temp_acquire temp_release temp_reset temp_path); + + +=head1 DESCRIPTION + +This module provides Perl scripts easy way to interface the Git version control +system. The modules have an easy and well-tested way to call arbitrary Git +commands; in the future, the interface will also provide specialized methods +for doing easily operations which are not totally trivial to do over +the generic command interface. + +While some commands can be executed outside of any context (e.g. 'version' +or 'init'), most operations require a repository context, which in practice +means getting an instance of the Git object using the repository() constructor. +(In the future, we will also get a new_repository() constructor.) All commands +called as methods of the object are then executed in the context of the +repository. + +Part of the "repository state" is also information about path to the attached +working copy (unless you work with a bare repository). You can also navigate +inside of the working copy using the C method. (Note that +the repository object is self-contained and will not change working directory +of your process.) + +TODO: In the future, we might also do + + my $remoterepo = $repo->remote_repository (Name => 'cogito', Branch => 'master'); + $remoterepo ||= Git->remote_repository ('http://git.or.cz/cogito.git/'); + my @refs = $remoterepo->refs(); + +Currently, the module merely wraps calls to external Git tools. In the future, +it will provide a much faster way to interact with Git by linking directly +to libgit. This should be completely opaque to the user, though (performance +increase notwithstanding). + +=cut + + +use Carp qw(carp croak); # but croak is bad - throw instead +use Error qw(:try); +use Cwd qw(abs_path cwd); +use IPC::Open2 qw(open2); +use Fcntl qw(SEEK_SET SEEK_CUR); +} + + +=head1 CONSTRUCTORS + +=over 4 + +=item repository ( OPTIONS ) + +=item repository ( DIRECTORY ) + +=item repository () + +Construct a new repository object. +C are passed in a hash like fashion, using key and value pairs. +Possible options are: + +B - Path to the Git repository. + +B - Path to the associated working copy; not strictly required +as many commands will happily crunch on a bare repository. + +B - Subdirectory in the working copy to work inside. +Just left undefined if you do not want to limit the scope of operations. + +B - Path to the Git working directory in its usual setup. +The C<.git> directory is searched in the directory and all the parent +directories; if found, C is set to the directory containing +it and C to the C<.git> directory itself. If no C<.git> +directory was found, the C is assumed to be a bare repository, +C is set to point at it and C is left undefined. +If the C<$GIT_DIR> environment variable is set, things behave as expected +as well. + +You should not use both C and either of C and +C - the results of that are undefined. + +Alternatively, a directory path may be passed as a single scalar argument +to the constructor; it is equivalent to setting only the C option +field. + +Calling the constructor with no options whatsoever is equivalent to +calling it with C<< Directory => '.' >>. In general, if you are building +a standard porcelain command, simply doing C<< Git->repository() >> should +do the right thing and setup the object to reflect exactly where the user +is right now. + +=cut + +sub repository { + my $class = shift; + my @args = @_; + my %opts = (); + my $self; + + if (defined $args[0]) { + if ($#args % 2 != 1) { + # Not a hash. + $#args == 0 or throw Error::Simple("bad usage"); + %opts = ( Directory => $args[0] ); + } else { + %opts = @args; + } + } + + if (not defined $opts{Repository} and not defined $opts{WorkingCopy} + and not defined $opts{Directory}) { + $opts{Directory} = '.'; + } + + if (defined $opts{Directory}) { + -d $opts{Directory} or throw Error::Simple("Directory not found: $opts{Directory} $!"); + + my $search = Git->repository(WorkingCopy => $opts{Directory}); + my $dir; + try { + $dir = $search->command_oneline(['rev-parse', '--git-dir'], + STDERR => 0); + } catch Git::Error::Command with { + $dir = undef; + }; + + if ($dir) { + $dir =~ m#^/# or $dir = $opts{Directory} . '/' . $dir; + $opts{Repository} = abs_path($dir); + + # If --git-dir went ok, this shouldn't die either. + my $prefix = $search->command_oneline('rev-parse', '--show-prefix'); + $dir = abs_path($opts{Directory}) . '/'; + if ($prefix) { + if (substr($dir, -length($prefix)) ne $prefix) { + throw Error::Simple("rev-parse confused me - $dir does not have trailing $prefix"); + } + substr($dir, -length($prefix)) = ''; + } + $opts{WorkingCopy} = $dir; + $opts{WorkingSubdir} = $prefix; + + } else { + # A bare repository? Let's see... + $dir = $opts{Directory}; + + unless (-d "$dir/refs" and -d "$dir/objects" and -e "$dir/HEAD") { + # Mimic git-rev-parse --git-dir error message: + throw Error::Simple("fatal: Not a git repository: $dir"); + } + my $search = Git->repository(Repository => $dir); + try { + $search->command('symbolic-ref', 'HEAD'); + } catch Git::Error::Command with { + # Mimic git-rev-parse --git-dir error message: + throw Error::Simple("fatal: Not a git repository: $dir"); + } + + $opts{Repository} = abs_path($dir); + } + + delete $opts{Directory}; + } + + $self = { opts => \%opts }; + bless $self, $class; +} + +=back + +=head1 METHODS + +=over 4 + +=item command ( COMMAND [, ARGUMENTS... ] ) + +=item command ( [ COMMAND, ARGUMENTS... ], { Opt => Val ... } ) + +Execute the given Git C (specify it without the 'git-' +prefix), optionally with the specified extra C. + +The second more elaborate form can be used if you want to further adjust +the command execution. Currently, only one option is supported: + +B - How to deal with the command's error output. By default (C) +it is delivered to the caller's C. A false value (0 or '') will cause +it to be thrown away. If you want to process it, you can get it in a filehandle +you specify, but you must be extremely careful; if the error output is not +very short and you want to read it in the same process as where you called +C, you are set up for a nice deadlock! + +The method can be called without any instance or on a specified Git repository +(in that case the command will be run in the repository context). + +In scalar context, it returns all the command output in a single string +(verbatim). + +In array context, it returns an array containing lines printed to the +command's stdout (without trailing newlines). + +In both cases, the command's stdin and stderr are the same as the caller's. + +=cut + +sub command { + my ($fh, $ctx) = command_output_pipe(@_); + + if (not defined wantarray) { + # Nothing to pepper the possible exception with. + _cmd_close($fh, $ctx); + + } elsif (not wantarray) { + local $/; + my $text = <$fh>; + try { + _cmd_close($fh, $ctx); + } catch Git::Error::Command with { + # Pepper with the output: + my $E = shift; + $E->{'-outputref'} = \$text; + throw $E; + }; + return $text; + + } else { + my @lines = <$fh>; + defined and chomp for @lines; + try { + _cmd_close($fh, $ctx); + } catch Git::Error::Command with { + my $E = shift; + $E->{'-outputref'} = \@lines; + throw $E; + }; + return @lines; + } +} + + +=item command_oneline ( COMMAND [, ARGUMENTS... ] ) + +=item command_oneline ( [ COMMAND, ARGUMENTS... ], { Opt => Val ... } ) + +Execute the given C in the same way as command() +does but always return a scalar string containing the first line +of the command's standard output. + +=cut + +sub command_oneline { + my ($fh, $ctx) = command_output_pipe(@_); + + my $line = <$fh>; + defined $line and chomp $line; + try { + _cmd_close($fh, $ctx); + } catch Git::Error::Command with { + # Pepper with the output: + my $E = shift; + $E->{'-outputref'} = \$line; + throw $E; + }; + return $line; +} + + +=item command_output_pipe ( COMMAND [, ARGUMENTS... ] ) + +=item command_output_pipe ( [ COMMAND, ARGUMENTS... ], { Opt => Val ... } ) + +Execute the given C in the same way as command() +does but return a pipe filehandle from which the command output can be +read. + +The function can return C<($pipe, $ctx)> in array context. +See C for details. + +=cut + +sub command_output_pipe { + _command_common_pipe('-|', @_); +} + + +=item command_input_pipe ( COMMAND [, ARGUMENTS... ] ) + +=item command_input_pipe ( [ COMMAND, ARGUMENTS... ], { Opt => Val ... } ) + +Execute the given C in the same way as command_output_pipe() +does but return an input pipe filehandle instead; the command output +is not captured. + +The function can return C<($pipe, $ctx)> in array context. +See C for details. + +=cut + +sub command_input_pipe { + _command_common_pipe('|-', @_); +} + + +=item command_close_pipe ( PIPE [, CTX ] ) + +Close the C as returned from C, checking +whether the command finished successfully. The optional C argument +is required if you want to see the command name in the error message, +and it is the second value returned by C when +called in array context. The call idiom is: + + my ($fh, $ctx) = $r->command_output_pipe('status'); + while (<$fh>) { ... } + $r->command_close_pipe($fh, $ctx); + +Note that you should not rely on whatever actually is in C; +currently it is simply the command name but in future the context might +have more complicated structure. + +=cut + +sub command_close_pipe { + my ($self, $fh, $ctx) = _maybe_self(@_); + $ctx ||= ''; + _cmd_close($fh, $ctx); +} + +=item command_bidi_pipe ( COMMAND [, ARGUMENTS... ] ) + +Execute the given C in the same way as command_output_pipe() +does but return both an input pipe filehandle and an output pipe filehandle. + +The function will return return C<($pid, $pipe_in, $pipe_out, $ctx)>. +See C for details. + +=cut + +sub command_bidi_pipe { + my ($pid, $in, $out); + my ($self) = _maybe_self(@_); + local %ENV = %ENV; + my $cwd_save = undef; + if ($self) { + shift; + $cwd_save = cwd(); + _setup_git_cmd_env($self); + } + $pid = open2($in, $out, 'git', @_); + chdir($cwd_save) if $cwd_save; + return ($pid, $in, $out, join(' ', @_)); +} + +=item command_close_bidi_pipe ( PID, PIPE_IN, PIPE_OUT [, CTX] ) + +Close the C and C as returned from C, +checking whether the command finished successfully. The optional C +argument is required if you want to see the command name in the error message, +and it is the fourth value returned by C. The call idiom +is: + + my ($pid, $in, $out, $ctx) = $r->command_bidi_pipe('cat-file --batch-check'); + print "000000000\n" $out; + while (<$in>) { ... } + $r->command_close_bidi_pipe($pid, $in, $out, $ctx); + +Note that you should not rely on whatever actually is in C; +currently it is simply the command name but in future the context might +have more complicated structure. + +=cut + +sub command_close_bidi_pipe { + local $?; + my ($pid, $in, $out, $ctx) = @_; + foreach my $fh ($in, $out) { + unless (close $fh) { + if ($!) { + carp "error closing pipe: $!"; + } elsif ($? >> 8) { + throw Git::Error::Command($ctx, $? >>8); + } + } + } + + waitpid $pid, 0; + + if ($? >> 8) { + throw Git::Error::Command($ctx, $? >>8); + } +} + + +=item command_noisy ( COMMAND [, ARGUMENTS... ] ) + +Execute the given C in the same way as command() does but do not +capture the command output - the standard output is not redirected and goes +to the standard output of the caller application. + +While the method is called command_noisy(), you might want to as well use +it for the most silent Git commands which you know will never pollute your +stdout but you want to avoid the overhead of the pipe setup when calling them. + +The function returns only after the command has finished running. + +=cut + +sub command_noisy { + my ($self, $cmd, @args) = _maybe_self(@_); + _check_valid_cmd($cmd); + + my $pid = fork; + if (not defined $pid) { + throw Error::Simple("fork failed: $!"); + } elsif ($pid == 0) { + _cmd_exec($self, $cmd, @args); + } + if (waitpid($pid, 0) > 0 and $?>>8 != 0) { + throw Git::Error::Command(join(' ', $cmd, @args), $? >> 8); + } +} + + +=item version () + +Return the Git version in use. + +=cut + +sub version { + my $verstr = command_oneline('--version'); + $verstr =~ s/^git version //; + $verstr; +} + + +=item exec_path () + +Return path to the Git sub-command executables (the same as +C). Useful mostly only internally. + +=cut + +sub exec_path { command_oneline('--exec-path') } + + +=item html_path () + +Return path to the Git html documentation (the same as +C). Useful mostly only internally. + +=cut + +sub html_path { command_oneline('--html-path') } + + +=item repo_path () + +Return path to the git repository. Must be called on a repository instance. + +=cut + +sub repo_path { $_[0]->{opts}->{Repository} } + + +=item wc_path () + +Return path to the working copy. Must be called on a repository instance. + +=cut + +sub wc_path { $_[0]->{opts}->{WorkingCopy} } + + +=item wc_subdir () + +Return path to the subdirectory inside of a working copy. Must be called +on a repository instance. + +=cut + +sub wc_subdir { $_[0]->{opts}->{WorkingSubdir} ||= '' } + + +=item wc_chdir ( SUBDIR ) + +Change the working copy subdirectory to work within. The C is +relative to the working copy root directory (not the current subdirectory). +Must be called on a repository instance attached to a working copy +and the directory must exist. + +=cut + +sub wc_chdir { + my ($self, $subdir) = @_; + $self->wc_path() + or throw Error::Simple("bare repository"); + + -d $self->wc_path().'/'.$subdir + or throw Error::Simple("subdir not found: $subdir $!"); + # Of course we will not "hold" the subdirectory so anyone + # can delete it now and we will never know. But at least we tried. + + $self->{opts}->{WorkingSubdir} = $subdir; +} + + +=item config ( VARIABLE ) + +Retrieve the configuration C in the same manner as C +does. In scalar context requires the variable to be set only one time +(exception is thrown otherwise), in array context returns allows the +variable to be set multiple times and returns all the values. + +This currently wraps command('config') so it is not so fast. + +=cut + +sub config { + my ($self, $var) = _maybe_self(@_); + + try { + my @cmd = ('config'); + unshift @cmd, $self if $self; + if (wantarray) { + return command(@cmd, '--get-all', $var); + } else { + return command_oneline(@cmd, '--get', $var); + } + } catch Git::Error::Command with { + my $E = shift; + if ($E->value() == 1) { + # Key not found. + return; + } else { + throw $E; + } + }; +} + + +=item config_bool ( VARIABLE ) + +Retrieve the bool configuration C. The return value +is usable as a boolean in perl (and C if it's not defined, +of course). + +This currently wraps command('config') so it is not so fast. + +=cut + +sub config_bool { + my ($self, $var) = _maybe_self(@_); + + try { + my @cmd = ('config', '--bool', '--get', $var); + unshift @cmd, $self if $self; + my $val = command_oneline(@cmd); + return undef unless defined $val; + return $val eq 'true'; + } catch Git::Error::Command with { + my $E = shift; + if ($E->value() == 1) { + # Key not found. + return undef; + } else { + throw $E; + } + }; +} + +=item config_int ( VARIABLE ) + +Retrieve the integer configuration C. The return value +is simple decimal number. An optional value suffix of 'k', 'm', +or 'g' in the config file will cause the value to be multiplied +by 1024, 1048576 (1024^2), or 1073741824 (1024^3) prior to output. +It would return C if configuration variable is not defined, + +This currently wraps command('config') so it is not so fast. + +=cut + +sub config_int { + my ($self, $var) = _maybe_self(@_); + + try { + my @cmd = ('config', '--int', '--get', $var); + unshift @cmd, $self if $self; + return command_oneline(@cmd); + } catch Git::Error::Command with { + my $E = shift; + if ($E->value() == 1) { + # Key not found. + return undef; + } else { + throw $E; + } + }; +} + +=item get_colorbool ( NAME ) + +Finds if color should be used for NAMEd operation from the configuration, +and returns boolean (true for "use color", false for "do not use color"). + +=cut + +sub get_colorbool { + my ($self, $var) = @_; + my $stdout_to_tty = (-t STDOUT) ? "true" : "false"; + my $use_color = $self->command_oneline('config', '--get-colorbool', + $var, $stdout_to_tty); + return ($use_color eq 'true'); +} + +=item get_color ( SLOT, COLOR ) + +Finds color for SLOT from the configuration, while defaulting to COLOR, +and returns the ANSI color escape sequence: + + print $repo->get_color("color.interactive.prompt", "underline blue white"); + print "some text"; + print $repo->get_color("", "normal"); + +=cut + +sub get_color { + my ($self, $slot, $default) = @_; + my $color = $self->command_oneline('config', '--get-color', $slot, $default); + if (!defined $color) { + $color = ""; + } + return $color; +} + +=item remote_refs ( REPOSITORY [, GROUPS [, REFGLOBS ] ] ) + +This function returns a hashref of refs stored in a given remote repository. +The hash is in the format C hash>. For tags, the C entry +contains the tag object while a C entry gives the tagged objects. + +C has the same meaning as the appropriate C +argument; either an URL or a remote name (if called on a repository instance). +C is an optional arrayref that can contain 'tags' to return all the +tags and/or 'heads' to return all the heads. C is an optional array +of strings containing a shell-like glob to further limit the refs returned in +the hash; the meaning is again the same as the appropriate C +argument. + +This function may or may not be called on a repository instance. In the former +case, remote names as defined in the repository are recognized as repository +specifiers. + +=cut + +sub remote_refs { + my ($self, $repo, $groups, $refglobs) = _maybe_self(@_); + my @args; + if (ref $groups eq 'ARRAY') { + foreach (@$groups) { + if ($_ eq 'heads') { + push (@args, '--heads'); + } elsif ($_ eq 'tags') { + push (@args, '--tags'); + } else { + # Ignore unknown groups for future + # compatibility + } + } + } + push (@args, $repo); + if (ref $refglobs eq 'ARRAY') { + push (@args, @$refglobs); + } + + my @self = $self ? ($self) : (); # Ultra trickery + my ($fh, $ctx) = Git::command_output_pipe(@self, 'ls-remote', @args); + my %refs; + while (<$fh>) { + chomp; + my ($hash, $ref) = split(/\t/, $_, 2); + $refs{$ref} = $hash; + } + Git::command_close_pipe(@self, $fh, $ctx); + return \%refs; +} + + +=item ident ( TYPE | IDENTSTR ) + +=item ident_person ( TYPE | IDENTSTR | IDENTARRAY ) + +This suite of functions retrieves and parses ident information, as stored +in the commit and tag objects or produced by C (thus +C can be either I or I; case is insignificant). + +The C method retrieves the ident information from C +and either returns it as a scalar string or as an array with the fields parsed. +Alternatively, it can take a prepared ident string (e.g. from the commit +object) and just parse it. + +C returns the person part of the ident - name and email; +it can take the same arguments as C or the array returned by C. + +The synopsis is like: + + my ($name, $email, $time_tz) = ident('author'); + "$name <$email>" eq ident_person('author'); + "$name <$email>" eq ident_person($name); + $time_tz =~ /^\d+ [+-]\d{4}$/; + +=cut + +sub ident { + my ($self, $type) = _maybe_self(@_); + my $identstr; + if (lc $type eq lc 'committer' or lc $type eq lc 'author') { + my @cmd = ('var', 'GIT_'.uc($type).'_IDENT'); + unshift @cmd, $self if $self; + $identstr = command_oneline(@cmd); + } else { + $identstr = $type; + } + if (wantarray) { + return $identstr =~ /^(.*) <(.*)> (\d+ [+-]\d{4})$/; + } else { + return $identstr; + } +} + +sub ident_person { + my ($self, @ident) = _maybe_self(@_); + $#ident == 0 and @ident = $self ? $self->ident($ident[0]) : ident($ident[0]); + return "$ident[0] <$ident[1]>"; +} + + +=item hash_object ( TYPE, FILENAME ) + +Compute the SHA1 object id of the given C considering it is +of the C object type (C, C, C). + +The method can be called without any instance or on a specified Git repository, +it makes zero difference. + +The function returns the SHA1 hash. + +=cut + +# TODO: Support for passing FILEHANDLE instead of FILENAME +sub hash_object { + my ($self, $type, $file) = _maybe_self(@_); + command_oneline('hash-object', '-t', $type, $file); +} + + +=item hash_and_insert_object ( FILENAME ) + +Compute the SHA1 object id of the given C and add the object to the +object database. + +The function returns the SHA1 hash. + +=cut + +# TODO: Support for passing FILEHANDLE instead of FILENAME +sub hash_and_insert_object { + my ($self, $filename) = @_; + + carp "Bad filename \"$filename\"" if $filename =~ /[\r\n]/; + + $self->_open_hash_and_insert_object_if_needed(); + my ($in, $out) = ($self->{hash_object_in}, $self->{hash_object_out}); + + unless (print $out $filename, "\n") { + $self->_close_hash_and_insert_object(); + throw Error::Simple("out pipe went bad"); + } + + chomp(my $hash = <$in>); + unless (defined($hash)) { + $self->_close_hash_and_insert_object(); + throw Error::Simple("in pipe went bad"); + } + + return $hash; +} + +sub _open_hash_and_insert_object_if_needed { + my ($self) = @_; + + return if defined($self->{hash_object_pid}); + + ($self->{hash_object_pid}, $self->{hash_object_in}, + $self->{hash_object_out}, $self->{hash_object_ctx}) = + $self->command_bidi_pipe(qw(hash-object -w --stdin-paths --no-filters)); +} + +sub _close_hash_and_insert_object { + my ($self) = @_; + + return unless defined($self->{hash_object_pid}); + + my @vars = map { 'hash_object_' . $_ } qw(pid in out ctx); + + command_close_bidi_pipe(@$self{@vars}); + delete @$self{@vars}; +} + +=item cat_blob ( SHA1, FILEHANDLE ) + +Prints the contents of the blob identified by C to C and +returns the number of bytes printed. + +=cut + +sub cat_blob { + my ($self, $sha1, $fh) = @_; + + $self->_open_cat_blob_if_needed(); + my ($in, $out) = ($self->{cat_blob_in}, $self->{cat_blob_out}); + + unless (print $out $sha1, "\n") { + $self->_close_cat_blob(); + throw Error::Simple("out pipe went bad"); + } + + my $description = <$in>; + if ($description =~ / missing$/) { + carp "$sha1 doesn't exist in the repository"; + return -1; + } + + if ($description !~ /^[0-9a-fA-F]{40} \S+ (\d+)$/) { + carp "Unexpected result returned from git cat-file"; + return -1; + } + + my $size = $1; + + my $blob; + my $bytesRead = 0; + + while (1) { + my $bytesLeft = $size - $bytesRead; + last unless $bytesLeft; + + my $bytesToRead = $bytesLeft < 1024 ? $bytesLeft : 1024; + my $read = read($in, $blob, $bytesToRead, $bytesRead); + unless (defined($read)) { + $self->_close_cat_blob(); + throw Error::Simple("in pipe went bad"); + } + + $bytesRead += $read; + } + + # Skip past the trailing newline. + my $newline; + my $read = read($in, $newline, 1); + unless (defined($read)) { + $self->_close_cat_blob(); + throw Error::Simple("in pipe went bad"); + } + unless ($read == 1 && $newline eq "\n") { + $self->_close_cat_blob(); + throw Error::Simple("didn't find newline after blob"); + } + + unless (print $fh $blob) { + $self->_close_cat_blob(); + throw Error::Simple("couldn't write to passed in filehandle"); + } + + return $size; +} + +sub _open_cat_blob_if_needed { + my ($self) = @_; + + return if defined($self->{cat_blob_pid}); + + ($self->{cat_blob_pid}, $self->{cat_blob_in}, + $self->{cat_blob_out}, $self->{cat_blob_ctx}) = + $self->command_bidi_pipe(qw(cat-file --batch)); +} + +sub _close_cat_blob { + my ($self) = @_; + + return unless defined($self->{cat_blob_pid}); + + my @vars = map { 'cat_blob_' . $_ } qw(pid in out ctx); + + command_close_bidi_pipe(@$self{@vars}); + delete @$self{@vars}; +} + + +{ # %TEMP_* Lexical Context + +my (%TEMP_FILEMAP, %TEMP_FILES); + +=item temp_acquire ( NAME ) + +Attempts to retreive the temporary file mapped to the string C. If an +associated temp file has not been created this session or was closed, it is +created, cached, and set for autoflush and binmode. + +Internally locks the file mapped to C. This lock must be released with +C when the temp file is no longer needed. Subsequent attempts +to retrieve temporary files mapped to the same C while still locked will +cause an error. This locking mechanism provides a weak guarantee and is not +threadsafe. It does provide some error checking to help prevent temp file refs +writing over one another. + +In general, the L returned should not be closed by consumers as +it defeats the purpose of this caching mechanism. If you need to close the temp +file handle, then you should use L or another temp file faculty +directly. If a handle is closed and then requested again, then a warning will +issue. + +=cut + +sub temp_acquire { + my $temp_fd = _temp_cache(@_); + + $TEMP_FILES{$temp_fd}{locked} = 1; + $temp_fd; +} + +=item temp_release ( NAME ) + +=item temp_release ( FILEHANDLE ) + +Releases a lock acquired through C. Can be called either with +the C mapping used when acquiring the temp file or with the C +referencing a locked temp file. + +Warns if an attempt is made to release a file that is not locked. + +The temp file will be truncated before being released. This can help to reduce +disk I/O where the system is smart enough to detect the truncation while data +is in the output buffers. Beware that after the temp file is released and +truncated, any operations on that file may fail miserably until it is +re-acquired. All contents are lost between each release and acquire mapped to +the same string. + +=cut + +sub temp_release { + my ($self, $temp_fd, $trunc) = _maybe_self(@_); + + if (exists $TEMP_FILEMAP{$temp_fd}) { + $temp_fd = $TEMP_FILES{$temp_fd}; + } + unless ($TEMP_FILES{$temp_fd}{locked}) { + carp "Attempt to release temp file '", + $temp_fd, "' that has not been locked"; + } + temp_reset($temp_fd) if $trunc and $temp_fd->opened; + + $TEMP_FILES{$temp_fd}{locked} = 0; + undef; +} + +sub _temp_cache { + my ($self, $name) = _maybe_self(@_); + + _verify_require(); + + my $temp_fd = \$TEMP_FILEMAP{$name}; + if (defined $$temp_fd and $$temp_fd->opened) { + if ($TEMP_FILES{$$temp_fd}{locked}) { + throw Error::Simple("Temp file with moniker '" . + $name . "' already in use"); + } + } else { + if (defined $$temp_fd) { + # then we're here because of a closed handle. + carp "Temp file '", $name, + "' was closed. Opening replacement."; + } + my $fname; + + my $tmpdir; + if (defined $self) { + $tmpdir = $self->repo_path(); + } + + ($$temp_fd, $fname) = File::Temp->tempfile( + 'Git_XXXXXX', UNLINK => 1, DIR => $tmpdir, + ) or throw Error::Simple("couldn't open new temp file"); + + $$temp_fd->autoflush; + binmode $$temp_fd; + $TEMP_FILES{$$temp_fd}{fname} = $fname; + } + $$temp_fd; +} + +sub _verify_require { + eval { require File::Temp; require File::Spec; }; + $@ and throw Error::Simple($@); +} + +=item temp_reset ( FILEHANDLE ) + +Truncates and resets the position of the C. + +=cut + +sub temp_reset { + my ($self, $temp_fd) = _maybe_self(@_); + + truncate $temp_fd, 0 + or throw Error::Simple("couldn't truncate file"); + sysseek($temp_fd, 0, SEEK_SET) and seek($temp_fd, 0, SEEK_SET) + or throw Error::Simple("couldn't seek to beginning of file"); + sysseek($temp_fd, 0, SEEK_CUR) == 0 and tell($temp_fd) == 0 + or throw Error::Simple("expected file position to be reset"); +} + +=item temp_path ( NAME ) + +=item temp_path ( FILEHANDLE ) + +Returns the filename associated with the given tempfile. + +=cut + +sub temp_path { + my ($self, $temp_fd) = _maybe_self(@_); + + if (exists $TEMP_FILEMAP{$temp_fd}) { + $temp_fd = $TEMP_FILEMAP{$temp_fd}; + } + $TEMP_FILES{$temp_fd}{fname}; +} + +sub END { + unlink values %TEMP_FILEMAP if %TEMP_FILEMAP; +} + +} # %TEMP_* Lexical Context + +=back + +=head1 ERROR HANDLING + +All functions are supposed to throw Perl exceptions in case of errors. +See the L module on how to catch those. Most exceptions are mere +L instances. + +However, the C, C and C +functions suite can throw C exceptions as well: those are +thrown when the external command returns an error code and contain the error +code as well as access to the captured command's output. The exception class +provides the usual C and C (command's exit code) methods and +in addition also a C method that returns either an array or a +string with the captured command output (depending on the original function +call context; C returns C) and $ which +returns the command and its arguments (but without proper quoting). + +Note that the C functions cannot throw this exception since +it has no idea whether the command failed or not. You will only find out +at the time you C the pipe; if you want to have that automated, +use C, which can throw the exception. + +=cut + +{ + package Git::Error::Command; + + @Git::Error::Command::ISA = qw(Error); + + sub new { + my $self = shift; + my $cmdline = '' . shift; + my $value = 0 + shift; + my $outputref = shift; + my(@args) = (); + + local $Error::Depth = $Error::Depth + 1; + + push(@args, '-cmdline', $cmdline); + push(@args, '-value', $value); + push(@args, '-outputref', $outputref); + + $self->SUPER::new(-text => 'command returned error', @args); + } + + sub stringify { + my $self = shift; + my $text = $self->SUPER::stringify; + $self->cmdline() . ': ' . $text . ': ' . $self->value() . "\n"; + } + + sub cmdline { + my $self = shift; + $self->{'-cmdline'}; + } + + sub cmd_output { + my $self = shift; + my $ref = $self->{'-outputref'}; + defined $ref or undef; + if (ref $ref eq 'ARRAY') { + return @$ref; + } else { # SCALAR + return $$ref; + } + } +} + +=over 4 + +=item git_cmd_try { CODE } ERRMSG + +This magical statement will automatically catch any C +exceptions thrown by C and make your program die with C +on its lips; the message will have %s substituted for the command line +and %d for the exit status. This statement is useful mostly for producing +more user-friendly error messages. + +In case of no exception caught the statement returns C's return value. + +Note that this is the only auto-exported function. + +=cut + +sub git_cmd_try(&$) { + my ($code, $errmsg) = @_; + my @result; + my $err; + my $array = wantarray; + try { + if ($array) { + @result = &$code; + } else { + $result[0] = &$code; + } + } catch Git::Error::Command with { + my $E = shift; + $err = $errmsg; + $err =~ s/\%s/$E->cmdline()/ge; + $err =~ s/\%d/$E->value()/ge; + # We can't croak here since Error.pm would mangle + # that to Error::Simple. + }; + $err and croak $err; + return $array ? @result : $result[0]; +} + + +=back + +=head1 COPYRIGHT + +Copyright 2006 by Petr Baudis Epasky@suse.czE. + +This module is free software; it may be used, copied, modified +and distributed under the terms of the GNU General Public Licence, +either version 2, or (at your option) any later version. + +=cut + + +# Take raw method argument list and return ($obj, @args) in case +# the method was called upon an instance and (undef, @args) if +# it was called directly. +sub _maybe_self { + UNIVERSAL::isa($_[0], 'Git') ? @_ : (undef, @_); +} + +# Check if the command id is something reasonable. +sub _check_valid_cmd { + my ($cmd) = @_; + $cmd =~ /^[a-z0-9A-Z_-]+$/ or throw Error::Simple("bad command: $cmd"); +} + +# Common backend for the pipe creators. +sub _command_common_pipe { + my $direction = shift; + my ($self, @p) = _maybe_self(@_); + my (%opts, $cmd, @args); + if (ref $p[0]) { + ($cmd, @args) = @{shift @p}; + %opts = ref $p[0] ? %{$p[0]} : @p; + } else { + ($cmd, @args) = @p; + } + _check_valid_cmd($cmd); + + my $fh; + if ($^O eq 'MSWin32') { + # ActiveState Perl + #defined $opts{STDERR} and + # warn 'ignoring STDERR option - running w/ ActiveState'; + $direction eq '-|' or + die 'input pipe for ActiveState not implemented'; + # the strange construction with *ACPIPE is just to + # explain the tie below that we want to bind to + # a handle class, not scalar. It is not known if + # it is something specific to ActiveState Perl or + # just a Perl quirk. + tie (*ACPIPE, 'Git::activestate_pipe', $cmd, @args); + $fh = *ACPIPE; + + } else { + my $pid = open($fh, $direction); + if (not defined $pid) { + throw Error::Simple("open failed: $!"); + } elsif ($pid == 0) { + if (defined $opts{STDERR}) { + close STDERR; + } + if ($opts{STDERR}) { + open (STDERR, '>&', $opts{STDERR}) + or die "dup failed: $!"; + } + _cmd_exec($self, $cmd, @args); + } + } + return wantarray ? ($fh, join(' ', $cmd, @args)) : $fh; +} + +# When already in the subprocess, set up the appropriate state +# for the given repository and execute the git command. +sub _cmd_exec { + my ($self, @args) = @_; + _setup_git_cmd_env($self); + _execv_git_cmd(@args); + die qq[exec "@args" failed: $!]; +} + +# set up the appropriate state for git command +sub _setup_git_cmd_env { + my $self = shift; + if ($self) { + $self->repo_path() and $ENV{'GIT_DIR'} = $self->repo_path(); + $self->repo_path() and $self->wc_path() + and $ENV{'GIT_WORK_TREE'} = $self->wc_path(); + $self->wc_path() and chdir($self->wc_path()); + $self->wc_subdir() and chdir($self->wc_subdir()); + } +} + +# Execute the given Git command ($_[0]) with arguments ($_[1..]) +# by searching for it at proper places. +sub _execv_git_cmd { exec('git', @_); } + +# Close pipe to a subprocess. +sub _cmd_close { + my ($fh, $ctx) = @_; + if (not close $fh) { + if ($!) { + # It's just close, no point in fatalities + carp "error closing pipe: $!"; + } elsif ($? >> 8) { + # The caller should pepper this. + throw Git::Error::Command($ctx, $? >> 8); + } + # else we might e.g. closed a live stream; the command + # dying of SIGPIPE would drive us here. + } +} + + +sub DESTROY { + my ($self) = @_; + $self->_close_hash_and_insert_object(); + $self->_close_cat_blob(); +} + + +# Pipe implementation for ActiveState Perl. + +package Git::activestate_pipe; +use strict; + +sub TIEHANDLE { + my ($class, @params) = @_; + # FIXME: This is probably horrible idea and the thing will explode + # at the moment you give it arguments that require some quoting, + # but I have no ActiveState clue... --pasky + # Let's just hope ActiveState Perl does at least the quoting + # correctly. + my @data = qx{git @params}; + bless { i => 0, data => \@data }, $class; +} + +sub READLINE { + my $self = shift; + if ($self->{i} >= scalar @{$self->{data}}) { + return undef; + } + my $i = $self->{i}; + if (wantarray) { + $self->{i} = $#{$self->{'data'}} + 1; + return splice(@{$self->{'data'}}, $i); + } + $self->{i} = $i + 1; + return $self->{'data'}->[ $i ]; +} + +sub CLOSE { + my $self = shift; + delete $self->{data}; + delete $self->{i}; +} + +sub EOF { + my $self = shift; + return ($self->{i} >= scalar @{$self->{data}}); +} + + +1; # Famous last words diff --git a/SparkleShare/Mac/git/libexec/git-core/perl/auto/Git/.packlist b/SparkleShare/Mac/git/libexec/git-core/perl/auto/Git/.packlist new file mode 100644 index 00000000..09dc3912 --- /dev/null +++ b/SparkleShare/Mac/git/libexec/git-core/perl/auto/Git/.packlist @@ -0,0 +1,2 @@ +/BinaryCache/Git/Git-19~1/Root/usr/share/git-core/perl/Git.pm +/BinaryCache/Git/Git-19~1/Root/usr/share/man/man3/Git.3pm diff --git a/SparkleShare/SparkleControllerBase.cs b/SparkleShare/SparkleControllerBase.cs index d643d717..9c160e63 100644 --- a/SparkleShare/SparkleControllerBase.cs +++ b/SparkleShare/SparkleControllerBase.cs @@ -113,7 +113,7 @@ namespace SparkleShare { if (FirstRun) SparkleConfig.DefaultConfig.SetConfigOption ("notifications", bool.TrueString); else - AddKey (); + ImportPrivateKey (); // Watch the SparkleShare folder FileSystemWatcher watcher = new FileSystemWatcher (SparkleConfig.DefaultConfig.FoldersPath) { @@ -247,7 +247,7 @@ namespace SparkleShare { if (name == null) return GetLog (); - string path = new string [] {SparkleConfig.DefaultConfig.FoldersPath, name}.Combine (); + string path = Path.Combine (SparkleConfig.DefaultConfig.FoldersPath, name); int log_size = 50; foreach (SparkleRepoBase repo in Repositories) { @@ -749,7 +749,7 @@ namespace SparkleShare { // Adds the user's SparkleShare key to the ssh-agent, // so all activity is done with this key - public void AddKey () + public void ImportPrivateKey () { string keys_path = Path.GetDirectoryName (SparkleConfig.DefaultConfig.FullPath); string key_file_name = "sparkleshare." + UserEmail + ".key"; diff --git a/SparkleShare/SparkleEventLogController.cs b/SparkleShare/SparkleEventLogController.cs index 99917216..457733ec 100755 --- a/SparkleShare/SparkleEventLogController.cs +++ b/SparkleShare/SparkleEventLogController.cs @@ -84,10 +84,12 @@ namespace SparkleShare { get { List change_sets = Program.Controller.GetLog (this.selected_folder); + string html = Program.Controller.GetHTMLLog (change_sets); + if (UpdateSizeInfoEvent != null) UpdateSizeInfoEvent (Size, HistorySize); - return Program.Controller.GetHTMLLog (change_sets); + return html; } } diff --git a/SparkleShare/SparkleSetupController.cs b/SparkleShare/SparkleSetupController.cs index 591eb003..1b0cc3c6 100755 --- a/SparkleShare/SparkleSetupController.cs +++ b/SparkleShare/SparkleSetupController.cs @@ -184,6 +184,7 @@ namespace SparkleShare { Program.Controller.UserEmail = email; Program.Controller.GenerateKeyPair (); + Program.Controller.ImportPrivateKey (); Program.Controller.UpdateState (); if (ChangePageEvent != null) diff --git a/SparkleShare/SparkleStatusIcon.cs b/SparkleShare/SparkleStatusIcon.cs index 252075a7..86d36f84 100644 --- a/SparkleShare/SparkleStatusIcon.cs +++ b/SparkleShare/SparkleStatusIcon.cs @@ -103,7 +103,10 @@ namespace SparkleShare { case IconState.Syncing: - StateText = _("Syncing…"); + StateText = _("Syncing… ") + + Controller.ProgressPercentage + "% " + + Controller.ProgressSpeed; + UpdateStateText (); if (!Animation.Enabled) @@ -363,4 +366,4 @@ namespace SparkleShare { SetProperty ("always-show-image", new GLib.Value (true)); } } -} \ No newline at end of file +} diff --git a/data/icons/idle0-active.png b/data/icons/process-syncing-sparkleshare-mac-i-active.png similarity index 100% rename from data/icons/idle0-active.png rename to data/icons/process-syncing-sparkleshare-mac-i-active.png diff --git a/data/icons/idle0.png b/data/icons/process-syncing-sparkleshare-mac-i.png similarity index 100% rename from data/icons/idle0.png rename to data/icons/process-syncing-sparkleshare-mac-i.png diff --git a/data/icons/idle1-active.png b/data/icons/process-syncing-sparkleshare-mac-ii-active.png similarity index 100% rename from data/icons/idle1-active.png rename to data/icons/process-syncing-sparkleshare-mac-ii-active.png diff --git a/data/icons/idle1.png b/data/icons/process-syncing-sparkleshare-mac-ii.png similarity index 100% rename from data/icons/idle1.png rename to data/icons/process-syncing-sparkleshare-mac-ii.png diff --git a/data/icons/idle2-active.png b/data/icons/process-syncing-sparkleshare-mac-iii-active.png similarity index 100% rename from data/icons/idle2-active.png rename to data/icons/process-syncing-sparkleshare-mac-iii-active.png diff --git a/data/icons/idle2.png b/data/icons/process-syncing-sparkleshare-mac-iii.png similarity index 100% rename from data/icons/idle2.png rename to data/icons/process-syncing-sparkleshare-mac-iii.png diff --git a/data/icons/idle3-active.png b/data/icons/process-syncing-sparkleshare-mac-iiii-active.png similarity index 100% rename from data/icons/idle3-active.png rename to data/icons/process-syncing-sparkleshare-mac-iiii-active.png diff --git a/data/icons/idle3.png b/data/icons/process-syncing-sparkleshare-mac-iiii.png similarity index 100% rename from data/icons/idle3.png rename to data/icons/process-syncing-sparkleshare-mac-iiii.png diff --git a/data/icons/idle4-active.png b/data/icons/process-syncing-sparkleshare-mac-iiiii-active.png similarity index 100% rename from data/icons/idle4-active.png rename to data/icons/process-syncing-sparkleshare-mac-iiiii-active.png diff --git a/data/icons/idle4.png b/data/icons/process-syncing-sparkleshare-mac-iiiii.png similarity index 100% rename from data/icons/idle4.png rename to data/icons/process-syncing-sparkleshare-mac-iiiii.png diff --git a/data/icons/process-syncing-sparkleshare-mono-dark-i-24.png b/data/icons/process-syncing-sparkleshare-mono-dark-i-24.png new file mode 100644 index 00000000..c9388360 Binary files /dev/null and b/data/icons/process-syncing-sparkleshare-mono-dark-i-24.png differ diff --git a/data/icons/process-syncing-sparkleshare-mono-dark-ii-24.png b/data/icons/process-syncing-sparkleshare-mono-dark-ii-24.png new file mode 100644 index 00000000..380ab888 Binary files /dev/null and b/data/icons/process-syncing-sparkleshare-mono-dark-ii-24.png differ diff --git a/data/icons/process-syncing-sparkleshare-mono-dark-iii-24.png b/data/icons/process-syncing-sparkleshare-mono-dark-iii-24.png new file mode 100644 index 00000000..81934abd Binary files /dev/null and b/data/icons/process-syncing-sparkleshare-mono-dark-iii-24.png differ diff --git a/data/icons/process-syncing-sparkleshare-mono-dark-iiii-24.png b/data/icons/process-syncing-sparkleshare-mono-dark-iiii-24.png new file mode 100644 index 00000000..9d236ff2 Binary files /dev/null and b/data/icons/process-syncing-sparkleshare-mono-dark-iiii-24.png differ diff --git a/data/icons/process-syncing-sparkleshare-mono-dark-iiiii-24.png b/data/icons/process-syncing-sparkleshare-mono-dark-iiiii-24.png new file mode 100644 index 00000000..30ac1794 Binary files /dev/null and b/data/icons/process-syncing-sparkleshare-mono-dark-iiiii-24.png differ diff --git a/data/icons/process-syncing-sparkleshare-mono-light-i-24.png b/data/icons/process-syncing-sparkleshare-mono-light-i-24.png new file mode 100644 index 00000000..2bd345c8 Binary files /dev/null and b/data/icons/process-syncing-sparkleshare-mono-light-i-24.png differ diff --git a/data/icons/process-syncing-sparkleshare-mono-light-ii-24.png b/data/icons/process-syncing-sparkleshare-mono-light-ii-24.png new file mode 100644 index 00000000..f980edb9 Binary files /dev/null and b/data/icons/process-syncing-sparkleshare-mono-light-ii-24.png differ diff --git a/data/icons/process-syncing-sparkleshare-mono-light-iii-24.png b/data/icons/process-syncing-sparkleshare-mono-light-iii-24.png new file mode 100644 index 00000000..bccefce1 Binary files /dev/null and b/data/icons/process-syncing-sparkleshare-mono-light-iii-24.png differ diff --git a/data/icons/process-syncing-sparkleshare-mono-light-iiii-24.png b/data/icons/process-syncing-sparkleshare-mono-light-iiii-24.png new file mode 100644 index 00000000..52c0a751 Binary files /dev/null and b/data/icons/process-syncing-sparkleshare-mono-light-iiii-24.png differ diff --git a/data/icons/process-syncing-sparkleshare-mono-light-iiiii-24.png b/data/icons/process-syncing-sparkleshare-mono-light-iiiii-24.png new file mode 100644 index 00000000..375f0d3e Binary files /dev/null and b/data/icons/process-syncing-sparkleshare-mono-light-iiiii-24.png differ diff --git a/data/icons/error-active.png b/data/icons/sparkleshare-syncing-error-mac-active.png similarity index 100% rename from data/icons/error-active.png rename to data/icons/sparkleshare-syncing-error-mac-active.png diff --git a/data/icons/error.png b/data/icons/sparkleshare-syncing-error-mac.png similarity index 100% rename from data/icons/error.png rename to data/icons/sparkleshare-syncing-error-mac.png diff --git a/data/icons/sparkleshare-syncing-error-mono-dark-24.png b/data/icons/sparkleshare-syncing-error-mono-dark-24.png new file mode 100644 index 00000000..920b4c45 Binary files /dev/null and b/data/icons/sparkleshare-syncing-error-mono-dark-24.png differ diff --git a/data/icons/sparkleshare-syncing-error-mono-light-24.png b/data/icons/sparkleshare-syncing-error-mono-light-24.png new file mode 100644 index 00000000..bf32f252 Binary files /dev/null and b/data/icons/sparkleshare-syncing-error-mono-light-24.png differ diff --git a/data/src/sparkleshare-gnome.svg b/data/src/sparkleshare-gnome.svg index e6c64277..88b1dbf5 100755 --- a/data/src/sparkleshare-gnome.svg +++ b/data/src/sparkleshare-gnome.svg @@ -16,7 +16,7 @@ inkscape:export-xdpi="90.000000" inkscape:export-ydpi="90.000000" inkscape:output_extension="org.inkscape.output.svg.inkscape" - inkscape:version="0.48.1 r9760" + inkscape:version="0.48.0 r9654" sodipodi:docname="sparkleshare-gnome.svg" sodipodi:version="0.32" style="display:inline;enable-background:new" @@ -30,9 +30,9 @@ guidetolerance="10000" height="300px" id="base" - inkscape:current-layer="layer20" - inkscape:cx="489.3933" - inkscape:cy="158.04102" + inkscape:current-layer="layer17" + inkscape:cx="577.69934" + inkscape:cy="231.48159" inkscape:document-units="px" inkscape:grid-bbox="true" inkscape:pageopacity="0.0" @@ -40,14 +40,14 @@ inkscape:showpageshadow="false" inkscape:snap-bbox="false" inkscape:snap-nodes="false" - inkscape:window-height="852" - inkscape:window-width="1440" - inkscape:window-x="0" - inkscape:window-y="0" - inkscape:zoom="2" + inkscape:window-height="756" + inkscape:window-width="1276" + inkscape:window-x="213" + inkscape:window-y="165" + inkscape:zoom="4" objecttolerance="10000" pagecolor="#ffffff" - showgrid="true" + showgrid="false" stroke="#ef2929" width="400px" showguides="false" @@ -201,13 +201,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -2216,181 +1775,6 @@ offset="1" id="stop10052" /> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -2403,17 +1787,6 @@ offset="1" id="stop10120" /> - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -2674,7 +1965,7 @@ sodipodi:nodetypes="cccccccccc" inkscape:connector-curvature="0" /> + x="539" + y="-206" /> @@ -3564,7 +2855,7 @@ + x="579" + y="-206" /> @@ -3658,7 +2949,7 @@ + x="528" + y="-198" /> - + x="524" + y="-196" /> + x="526" + y="-194" /> + x="524" + y="-193" /> + x="530" + y="-197" /> + x="619" + y="-206" /> + id="path7293" + inkscape:connector-curvature="0" /> + transform="translate(-14.003148,1.98544)"> - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Ubuntu Mac Windows 7