Index: patches/GIT.pl
===================================================================
--- patches/GIT.pl	(revision 0)
+++ patches/GIT.pl	(revision 0)
@@ -0,0 +1,304 @@
+#! /usr/bin/perl -w
+
+my $remove = 0;
+my $dest_dir = shift || die "GIT.pl: usage: GIT.pl DESTDIR";
+my @DRINK = "tea";
+
+# start git -- do a smart @GIT@ sed into apply.pl.in?
+my $git_debug = $ENV{"OOO_GIT"};
+$SIG{ __DIE__ } = sub { require Carp; Carp::confess( @_ ) } if $git_debug;
+my $program = "apply.pl";
+
+sub read_pipe
+{
+    my $command = shift;
+    print "PIPING: $command\n" if $git_debug;
+    open PIPE, "$command|" || die "$program: error piping: $command\n";
+    my @result = <PIPE>;
+    my $status = !close PIPE;
+    print "STATUS: $status\n" if $git_debug;
+    print "LOG[0..99]: " . join "", @result[0..($#result < 99 ? $#result : 99)] if $git_debug && $git_debug =~ /pipe/;
+    return $status, join "", @result;
+}
+
+sub svn_revision
+{
+    my ($status, $log) = read_pipe "svn info";
+    $log =~ m/^Revision: ([0-9]+)/m;
+    return $1;
+}
+    
+sub git_is_archive
+{
+    return -d "$dest_dir/.git";
+}
+
+sub git_system
+{
+    my $command = shift;
+    # return system "cd $dest_dir && $command";
+    print "EXECUTING: $command\n" if $git_debug;
+    my $status = system "cd $dest_dir && $command";
+    print "STATUS: $status\n" if $git_debug;
+    die "$program: error executing: $command\n" if $status;
+    # return $status;
+}
+
+sub git_pipe
+{
+    my $command = shift;
+    return read_pipe "cd $dest_dir && $command";
+}
+
+
+sub git_commit
+{
+    my $message = shift;
+    git_system "git add .";
+    git_system "git add -u .";
+    git_system "git commit -m '$message'";
+}
+
+sub git_init
+{
+    git_system "../../bin/create-gitignores.sh";
+    git_system "git init";
+    print "Creating GIT archive - [ go and have some @DRINK@ ] ...\n";
+    git_system "git add .";
+    $svn_revision = svn_revision;
+    git_commit "Initial svn:r$svn_revision unpatched.";
+    git_system "git branch pristine";
+    git_system "git branch patched";
+}
+
+sub git_on_branch
+{
+    my ($branch) = shift;
+    $branch =~ s/\+/\\+/g;
+    my ($status, $log) = git_pipe "git branch";
+    return $log =~ m/(^|\n)\* $branch\n/;
+}
+
+sub git_has_branch
+{
+    my ($branch) = shift;
+    $branch =~ s/\+/\\+/g;
+    my ($status, $log) = git_pipe "git branch";
+    return $log =~ m/(^|\n)(\*| ) $branch\n/;
+}
+
+sub git_is_modified
+{
+    my ($status, $log) = git_pipe "git status";
+    # FIXME: git-status' exit code cannot be used to determine status;
+    # comparing command output.
+    return 0 if $log
+	=~ /^# On branch.*\nnothing to commit \(working directory clean\)\n/;
+    return $log;
+}
+
+sub git_select_branch
+{
+    my $branch = shift;
+    my $pending_changes = git_is_modified;
+    if ($pending_changes)
+    {
+	print "$program: git directory $dest_dir unclean: pending changes\n";
+	print "***************************\n";
+	print "$pending_changes";
+	print "***************************\n";
+	die;
+    }
+    my ($status, $log) = git_pipe "git checkout $branch";
+    return if !$status;
+    die "$program: cannot select branch $branch:\n$log";
+}
+
+sub git_prepare
+{
+    git_init $dest_dir if !git_is_archive;
+#    git_select_branch "patched" if !git_on_branch "patched";
+#    git_command "git clean -f";
+    if (!git_on_branch "patched")
+    {
+	git_select_branch "patched";
+	git_system "git clean -f";
+    }
+}
+    
+sub git_postpare
+{
+    return if !git_is_modified;
+    git_system "git add .";
+    git_system "git add -u .";
+    $svn_revision = svn_revision;
+    my $un = $remove ? "un" : "";
+    git_commit "Update to svn:r$svn_revision ${un}patched.";
+    git_system "git checkout master";
+    git_system "git rebase patched" if !$remove;
+    #print "Now do something like\n";
+    #print "    cd $dest_dir && git rebase patched\n";
+}
+
+my $module_re = 0;
+sub git_get_branch
+{
+    # FIXME: group in branch using [Section], or more fine-grained using issue i#00000?
+    my $base = shift;
+    my $dir = shift;
+
+    return $1 if $base =~ /(writerfilter-qnametostr-NOOPTFILES)/;
+
+    return $dir if $dir and not "$dir" =~ /^[.]$|^[.][.]$|64bit|dev300|hotfixes/;
+    return $1 if $base =~ /^(cjk-character-units|cws-scsheetprotection|emf\+|fpicker-kde|jvmfwk-gij|lockfile|mono|sal-strintern-speed|sc-dataform|sc-datapilot|svg-import|transogl|unittesting|unxsplash|vba|wpgimporter|writerfilter)/;
+
+    return "emf+" if $base =~ /^(cairocanvas-alpha-pixmap-rewrite|vcl-grey-alpha-unix-sal-bitmap)/;
+    return "linkoo" if $base =~ /^(fix-linkoo|linkoo-)/;
+    return "ooxml" if $base =~ /^(win32-installer-register-moox-types)/;
+    return "vba" if $base =~ /^(default-autotext-and-form-name|sc-toggle-merge-center)/;
+
+    if (!$module_re)
+    {
+	my $modules = git_pipe "find . -mindepth 1 -maxdepth 1 -type d";
+	$modules =~ s@[.]/@@g;
+	$module_re = join "|", split " ", $modules;
+    }
+    $base =~ s/-($module_re)$//;
+    return $base;
+}
+
+sub git_get_depend
+{
+    my $branch = shift;
+
+    # FIMXE: return list of dependencies rather than "polluting" second depdendency's branch?
+#    Hmm, sc-toggle-merge-center happens while vba: until dependency list: aggregate into vba...
+#    return "sc-toggle-merge-center" if $branch =~ /^vba/; # ugh, vba-workbook-worksheet-events-dev300 depends on both
+#    return "cws-npower11" if $branch =~ /sc-toggle-merge-center/; # ugh, vba-workbook-worksheet-events-dev300 depends on both
+    
+    return "cws-npower10" if $branch =~ /cws-pflin10/; # ugh, basic-caller-support-dev300 depends on both
+    return "cws-pflin10" if $branch =~ /^cws-npower11/; # ugh, vba-error-object depends on both
+    return "cws-npower11" if $branch =~ /vba/; # ugh, vba-workbook-worksheet-events-dev300 depends on both
+
+    return "autocorrect-accidental-caps-lock" if $branch =~ /^internal-mesa-headers/; # ugh, vcl-linking-rander depends on both
+    return "cairo" if $branch =~ /^cairocanvas-fix-image-cache/; # ugh, cairocanvas-image-borders depends on both
+    return "cws-layoutdialogs" if $branch =~ /^buildfix-layoutdialogs/;
+    return "cws-layoutdialogs" if $branch =~ /^layout-plugin/;
+    return "form-control-visibility" if $branch =~ /^forms-radio-button-group-names/;
+    return "gnome-vfs-late-init" if $branch =~ /^unittesting/;
+    return "internal-mesa-headers" if $branch =~ /^vcl-linking-randr/;
+    return "layout-plugin" if $branch =~ /^layout-tab/;
+    return "link-as-needed" if $branch =~ /^emf\+/;
+    return "linkwarn-svtools-miscopts-bits" if $branch =~ /^ui-desktop-integration/;
+    return "lwp-filter-component" if $branch =~ /^ooxml/;
+    return "novell-win32-odma" if $branch =~ /^linkwarn-svtools-miscopts-bits/;
+    return "ooo64508.vcl.honourfontconfighinting" if $branch =~ /^ooo59127.vcl.honourcairofont/;
+    return "sc-dataform" if $branch =~ /^(sc-copy-on-merged-cells|sc-datapilot)/;
+    return "sc-datapilot" if $branch =~ /^sc-dp-gridlayout/;
+    return "sc-datapilot" if $branch =~ /^sc-paste-on-enter/; # ugh, cws-scsheetprotection depends on both
+    return "sc-export-shape-macro-bindings" if $branch =~ /^sc-export-shape-hlink-bindings/;
+    return "sc-hrc-ooo-build-resources" if $branch =~ /^sc-dataform/;
+    return "sc-natural-sort" if $branch =~ /sc-simple-sort-include-format-header/;
+    return "sc-paste-on-enter" if $branch =~ /^cws-scsheetprotection/;
+    return "sfx2-pre-and-postprocess-during-save-load" if $branch =~ /^sfx2-pre-and-postprocess-crash-fix/;
+    return "sfx2-remove-check-update-on-fileload" if $branch =~ /^sfx2-pre-and-postprocess-during-save-load/;
+    return "speed-symbolic-functions" if $branch =~ /^speed-bdirect/;
+    return "store-core" if $branch =~ /^speed-store-lck/;
+    return "tools-qa-urlobj-unittest" if $branch =~ /^gnome-vfs-late-init/; # ugh, unittesting-ucb depends on both
+    return "wpsimport" if $branch =~ /^wpgimport/;
+	
+    return "pristine";
+}
+
+sub git_count_commits
+{
+    return 0 + git_pipe "git log --pretty=oneline | wc -l";
+}
+
+sub git_patch_branch
+{
+    my $patch = shift;
+    $patch =~ /([^\/]+)\/([^\/]+)[.](diff|patch)$/;
+    my $dir = $1;
+    my $base = $2;
+    $base =~ s/[0-9]$// if $base !~ /chart2|helpcontent2|javainstaller2|scp2|sfx2|sj2|stlport5|testshl2|transex3|[0-9][0-9]+$/;
+    my $branch = git_get_branch $base, $dir;
+    my $depend = git_get_depend $branch;
+    print "DIR: $dir\n" if $git_debug;
+    print "BASE: $base\n" if $git_debug;
+    print "DEPEND: $depend\n" if $git_debug;
+    print "BRANCH: $branch\n" if $git_debug;
+    git_commit "Apply $patch.";
+    git_system "git branch $branch $depend" if !git_has_branch $branch;
+    git_select_branch $branch;
+    my $log = git_pipe "git log -1 patched";
+    $log =~ /^commit (.*)/;
+    my $commit = $1;
+    my $status = system "cd $dest_dir && git cherry-pick $commit";
+    if ($status)
+    {
+	print "FIXME: patch depends on earlier patches: $patch\n";
+	if (git_count_commits == 1)
+	{
+	    # Single-patch branch, or first patch of multiple-patch branch
+	    git_system "git reset --hard HEAD";
+	    git_system "git clean -f";
+	    git_system "git checkout patched";
+	    git_system "git branch -D $branch";
+	    git_system "git branch DEPENDENCY-$branch patched";
+	    git_system "git tag FIXME-branched-from-patched-$base DEPENDENCY-$branch";
+	}
+	else
+	{
+	    # Non-first patch in multiple-patch branch
+	    # Hitting this if our patch is not the first in this branch
+	    # would be extra ugly
+	    print "FIXME: conflict in multiple-patch branch: $branch, $patch\n";
+	    git_commit "Conflicts cherry-picking $commit ($patch).";
+	    git_system "git checkout patched";
+	    git_system "git branch -m $branch CONFLICTS-$base";
+	    git_system "git branch $branch patched";
+	    git_system "git tag FIXME-branched-from-patched-$base $branch";
+	}
+    }
+    git_select_branch "patched";
+}
+# end git
+
+read_pipe "exit-status 255";
+
+git_system "exit-status 0";
+#git_system "exit-status 1";
+#git_system "exit-status 255";
+
+git_patch_branch "/home/janneke/vc/ooo-HEAD/patches/dev300/./sc-simple-sort-include-format-header.diff";
+exit 0;
+    
+$dir = ".";
+$base = "sc-simple-sort-include-format-header";
+my $branch = git_get_branch $base, $dir;
+my $depend = git_get_depend $branch;
+
+print "DEPEND: $depend\n";
+print "\n";
+
+print "HAS: EMF+\n"  if git_has_branch "emf+";
+
+exit 0;
+
+$patch = "layout-tab-toolkit.diff";
+git_system "echo foo >> bar";
+sub git_patch_branch;
+git_patch_branch $patch if $ENV{"OOO_GIT"} =~ /branch/;
+git_system "git clean -f";
+
+read_pipe "exit-status 0";
+read_pipe "exit-status 1";
+
+exit 0;
+    
+{
+    git_prepare if $ENV{"OOO_GIT"};
+    git_postpare if $ENV{"OOO_GIT"};
+
+}
Index: patches/dev300/layout-tab-sfx2.diff
===================================================================
--- patches/dev300/layout-tab-sfx2.diff	(revision 12937)
+++ patches/dev300/layout-tab-sfx2.diff	(working copy)
@@ -1,3 +1,25 @@
+diff --git a/sfx2/inc/sfx2/macrconf.hxx b/sfx2/inc/sfx2/macrconf.hxx
+index 94bbf4b..4155b05 100644
+--- sfx2/inc/sfx2/macrconf.hxx
++++ sfx2/inc/sfx2/macrconf.hxx
+@@ -141,7 +141,7 @@ public:
+ 	sal_uInt16					GetSlotId(SfxMacroInfoPtr);
+ 	void					ReleaseSlotId(sal_uInt16 nId);
+ 	void					RegisterSlotId(sal_uInt16 nId);
+-	const SfxMacroInfoPtr 	GetMacroInfo(sal_uInt16 nId) const;
++    SfxMacroInfoPtr GetMacroInfo(sal_uInt16 nId) const;
+ 	sal_Bool					ExecuteMacro(sal_uInt16 nId, const String& rArgs ) const;
+ 	sal_Bool					ExecuteMacro( SfxObjectShell*, const SvxMacro*, const String& ) const;
+ 	sal_Bool					CheckMacro(sal_uInt16 nId) const;
+@@ -149,7 +149,7 @@ public:
+ 
+ //#if 0 // _SOLAR__PRIVATE
+ 	SAL_DLLPRIVATE static void Release_Impl();
+-	SAL_DLLPRIVATE const SfxMacroInfoPtr GetMacroInfo_Impl( const SvxMacro *pMacro ) const;
++    SAL_DLLPRIVATE SfxMacroInfoPtr GetMacroInfo_Impl( const SvxMacro *pMacro ) const;
+ 	DECL_DLLPRIVATE_LINK( CallbackHdl_Impl, SfxMacroConfig*);
+ 	DECL_DLLPRIVATE_LINK( EventHdl_Impl, SfxMacroInfo*);
+ //#endif
 diff --git a/sfx2/inc/sfx2/tabdlg.hxx b/sfx2/inc/sfx2/tabdlg.hxx
 index d5b930e..6087aba 100644
 --- sfx2/inc/sfx2/tabdlg.hxx
@@ -60,6 +82,28 @@
  
  	const OKButton& 	GetOKButton() const { return aOKBtn; }
  	OKButton&			GetOKButton() { return aOKBtn; }
+diff --git a/sfx2/source/control/macrconf.cxx b/sfx2/source/control/macrconf.cxx
+index 0a2a595..1ab851b 100644
+--- sfx2/source/control/macrconf.cxx
++++ sfx2/source/control/macrconf.cxx
+@@ -662,7 +662,7 @@ void SfxMacroConfig::RegisterSlotId(sal_uInt16 nId)
+ 
+ //==========================================================================
+ 
+-const SfxMacroInfoPtr SfxMacroConfig::GetMacroInfo(sal_uInt16 nId) const
++SfxMacroInfoPtr SfxMacroConfig::GetMacroInfo(sal_uInt16 nId) const
+ {
+ 	sal_uInt16 nCount = pImp->aArr.Count();
+ 	for (sal_uInt16 i=0; i<nCount; i++)
+@@ -674,7 +674,7 @@ const SfxMacroInfoPtr SfxMacroConfig::GetMacroInfo(sal_uInt16 nId) const
+ 
+ //==========================================================================
+ 
+-const SfxMacroInfoPtr SfxMacroConfig::GetMacroInfo_Impl( const SvxMacro *pMacro ) const
++SfxMacroInfoPtr SfxMacroConfig::GetMacroInfo_Impl( const SvxMacro *pMacro ) const
+ {
+ 	sal_uInt16 nCount = pImp->aArr.Count();
+ 	for (sal_uInt16 i=0; i<nCount; i++)
 diff --git a/sfx2/source/dialog/tabdlg.cxx b/sfx2/source/dialog/tabdlg.cxx
 index 57a8e89..9db6fba 100644
 --- sfx2/source/dialog/tabdlg.cxx
Index: patches/apply.pl.in
===================================================================
--- patches/apply.pl.in	(revision 12937)
+++ patches/apply.pl.in	(working copy)
@@ -6,7 +6,7 @@
 sub get_search_paths()
 {
     my @paths = ();
-    my @search = split /:/, $options{'PATCHPATH'};
+    my @search = split /:/, $options{'PATCHPATH'}; #/
 
     for my $stem (@search) {
 	push @paths, "$patch_dir/$stem";
@@ -725,6 +725,9 @@
         print "copy $patch_file -> $patch_copy\n" unless $quiet;
 
         copy($patch, $patch_copy) || die "Can't copy $patch to $patch_copy $!";
+
+	sub git_patch_branch;
+	git_patch_branch $patch if $ENV{"OOO_GIT"} =~ /branch/;
     }
 
     if (keys %existing_patches) {
@@ -992,9 +995,270 @@
     print "Total no issue: $total_no_issue\n";
 }
 
+
+# start git -- do a smart @GIT@ sed into apply.pl.in?
+my $git_debug = $ENV{"OOO_GIT"};
+$SIG{ __DIE__ } = sub { require Carp; Carp::confess( @_ ) } if $git_debug;
+my $program = "apply.pl";
+
+sub read_pipe
+{
+    my $command = shift;
+    print "PIPING: $command\n" if $git_debug;
+    open PIPE, "$command|" || die "$program: error piping: $command\n";
+    my @result = <PIPE>;
+    my $status = !close PIPE;
+    print "STATUS: $status\n" if $git_debug;
+    print "LOG[0..99]: " . join "", @result[0..($#result < 99 ? $#result : 99)] if $git_debug && $git_debug =~ /pipe/;
+    return $status, join "", @result;
+}
+
+sub svn_revision
+{
+    my ($status, $log) = read_pipe "svn info";
+    $log =~ m/^Revision: ([0-9]+)/m;
+    return $1;
+}
+    
+sub git_is_archive
+{
+    return -d "$dest_dir/.git";
+}
+
+sub git_system
+{
+    my $command = shift;
+    # return system "cd $dest_dir && $command";
+    print "EXECUTING: $command\n" if $git_debug;
+    my $status = system "cd $dest_dir && $command";
+    print "STATUS: $status\n" if $git_debug;
+    die "$program: error executing: $command\n" if $status;
+    # return $status;
+}
+
+sub git_pipe
+{
+    my $command = shift;
+    return read_pipe "cd $dest_dir && $command";
+}
+
+
+sub git_commit
+{
+    my $message = shift;
+    git_system "git add .";
+    git_system "git add -u .";
+    git_system "git commit -m '$message'";
+}
+
+sub git_init
+{
+    git_system "../../bin/create-gitignores.sh";
+    git_system "git init";
+    print "Creating GIT archive - [ go and have some @DRINK@ ] ...\n";
+    git_system "git add .";
+    $svn_revision = svn_revision;
+    git_commit "Initial svn:r$svn_revision unpatched.";
+    git_system "git branch pristine";
+    git_system "git branch patched";
+}
+
+sub git_on_branch
+{
+    my ($branch) = shift;
+    $branch =~ s/\+/\\+/g;
+    my ($status, $log) = git_pipe "git branch";
+    return $log =~ m/(^|\n)\* $branch\n/;
+}
+
+sub git_has_branch
+{
+    my ($branch) = shift;
+    $branch =~ s/\+/\\+/g;
+    my ($status, $log) = git_pipe "git branch";
+    return $log =~ m/(^|\n)(\*| ) $branch\n/;
+}
+
+sub git_is_modified
+{
+    my ($status, $log) = git_pipe "git status";
+    # FIXME: git-status' exit code cannot be used to determine status;
+    # comparing command output.
+    return 0 if $log
+	=~ /^# On branch.*\nnothing to commit \(working directory clean\)\n/;
+    return $log;
+}
+
+sub git_select_branch
+{
+    my $branch = shift;
+    my $pending_changes = git_is_modified;
+    if ($pending_changes)
+    {
+	print "$program: git directory $dest_dir unclean: pending changes\n";
+	print "***************************\n";
+	print "$pending_changes";
+	print "***************************\n";
+	die;
+    }
+    my ($status, $log) = git_pipe "git checkout $branch";
+    return if !$status;
+    die "$program: cannot select branch $branch:\n$log";
+}
+
+sub git_prepare
+{
+    git_init $dest_dir if !git_is_archive;
+#    git_select_branch "patched" if !git_on_branch "patched";
+#    git_command "git clean -f";
+    if (!git_on_branch "patched")
+    {
+	git_select_branch "patched";
+	git_system "git clean -f";
+    }
+}
+    
+sub git_postpare
+{
+    return if !git_is_modified;
+    git_system "git add .";
+    git_system "git add -u .";
+    $svn_revision = svn_revision;
+    my $un = $remove ? "un" : "";
+    git_commit "Update to svn:r$svn_revision ${un}patched.";
+    git_system "git checkout master";
+    git_system "git rebase patched" if !$remove;
+    #print "Now do something like\n";
+    #print "    cd $dest_dir && git rebase patched\n";
+}
+
+my $module_re = 0;
+sub git_get_branch
+{
+    # FIXME: group in branch using [Section], or more fine-grained using issue i#00000?
+    my $base = shift;
+    my $dir = shift;
+
+    return $1 if $base =~ /(writerfilter-qnametostr-NOOPTFILES)/;
+
+    return $dir if $dir and not "$dir" =~ /^[.]$|^[.][.]$|64bit|dev300|hotfixes/;
+    return $1 if $base =~ /^(cjk-character-units|cws-scsheetprotection|emf\+|fpicker-kde|jvmfwk-gij|lockfile|mono|sal-strintern-speed|sc-dataform|sc-datapilot|svg-import|transogl|unittesting|unxsplash|vba|wpgimporter|writerfilter)/;
+
+    return "emf+" if $base =~ /^(cairocanvas-alpha-pixmap-rewrite|vcl-grey-alpha-unix-sal-bitmap)/;
+    return "linkoo" if $base =~ /^(fix-linkoo|linkoo-)/;
+    return "ooxml" if $base =~ /^(win32-installer-register-moox-types)/;
+    return "vba" if $base =~ /^(default-autotext-and-form-name|sc-toggle-merge-center)/;
+
+    if (!$module_re)
+    {
+	my $modules = git_pipe "find . -mindepth 1 -maxdepth 1 -type d";
+	$modules =~ s@[.]/@@g;
+	$module_re = join "|", split " ", $modules;
+    }
+    $base =~ s/-($module_re)$//;
+    return $base;
+}
+
+sub git_get_depend
+{
+    my $branch = shift;
+
+    # FIMXE: return list of dependencies rather than "polluting" second depdendency's branch?
+#    Hmm, sc-toggle-merge-center happens while vba: until dependency list: aggregate into vba...
+#    return "sc-toggle-merge-center" if $branch =~ /^vba/; # ugh, vba-workbook-worksheet-events-dev300 depends on both
+#    return "cws-npower11" if $branch =~ /sc-toggle-merge-center/; # ugh, vba-workbook-worksheet-events-dev300 depends on both
+    
+    return "cws-npower11" if $branch =~ /vba/; # ugh, vba-workbook-worksheet-events-dev300 depends on both
+
+    return "autocorrect-accidental-caps-lock" if $branch =~ /^internal-mesa-headers/; # ugh, vcl-linking-rander depends on both
+    return "cairo" if $branch =~ /^cairocanvas-fix-image-cache/; # ugh, cairocanvas-image-borders depends on both
+    return "cws-layoutdialogs" if $branch =~ /^buildfix-layoutdialogs/;
+    return "cws-layoutdialogs" if $branch =~ /^layout-plugin/;
+    return "cws-pflin10" if $branch =~ /^cws-npower11/; # ugh, vba-error-object depends on both
+    return "form-control-visibility" if $branch =~ /^forms-radio-button-group-names/;
+    return "gnome-vfs-late-init" if $branch =~ /^unittesting/;
+    return "internal-mesa-headers" if $branch =~ /^vcl-linking-randr/;
+    return "layout-plugin" if $branch =~ /^layout-tab/;
+    return "link-as-needed" if $branch =~ /^emf\+/;
+    return "linkwarn-svtools-miscopts-bits" if $branch =~ /^ui-desktop-integration/;
+    return "lwp-filter-component" if $branch =~ /^ooxml/;
+    return "novell-win32-odma" if $branch =~ /^linkwarn-svtools-miscopts-bits/;
+    return "ooo64508.vcl.honourfontconfighinting" if $branch =~ /^ooo59127.vcl.honourcairofont/;
+    return "sc-dataform" if $branch =~ /^(sc-copy-on-merged-cells|sc-datapilot)/;
+    return "sc-datapilot" if $branch =~ /^sc-dp-gridlayout/;
+    return "sc-datapilot" if $branch =~ /^sc-paste-on-enter/; # ugh, cws-scsheetprotection depends on both
+    return "sc-export-shape-macro-bindings" if $branch =~ /^sc-export-shape-hlink-bindings/;
+    return "sc-hrc-ooo-build-resources" if $branch =~ /^sc-dataform/;
+    return "sc-natural-sort" if $branch =~ /sc-simple-sort-include-format-header/;
+    return "sc-paste-on-enter" if $branch =~ /^cws-scsheetprotection/;
+    return "sfx2-pre-and-postprocess-during-save-load" if $branch =~ /^sfx2-pre-and-postprocess-crash-fix/;
+    return "sfx2-remove-check-update-on-fileload" if $branch =~ /^sfx2-pre-and-postprocess-during-save-load/;
+    return "speed-symbolic-functions" if $branch =~ /^speed-bdirect/;
+    return "store-core" if $branch =~ /^speed-store-lck/;
+    return "tools-qa-urlobj-unittest" if $branch =~ /^gnome-vfs-late-init/; # ugh, unittesting-ucb depends on both
+    return "wpsimport" if $branch =~ /^wpgimport/;
+	
+    return "pristine";
+}
+
+sub git_count_commits
+{
+    return 0 + git_pipe "git log --pretty=oneline | wc -l";
+}
+
+sub git_patch_branch
+{
+    my $patch = shift;
+    $patch =~ /([^\/]+)\/([^\/]+)[.](diff|patch)$/;
+    my $dir = $1;
+    my $base = $2;
+    $base =~ s/[0-9]$// if $base !~ /chart2|helpcontent2|javainstaller2|scp2|sfx2|sj2|stlport5|testshl2|transex3|[0-9][0-9]+$/;
+    my $branch = git_get_branch $base, $dir;
+    my $depend = git_get_depend $branch;
+    print "DIR: $dir\n" if $git_debug;
+    print "BASE: $base\n" if $git_debug;
+    print "DEPEND: $depend\n" if $git_debug;
+    print "BRANCH: $branch\n" if $git_debug;
+    git_commit "Apply $patch.";
+    git_system "git branch $branch $depend" if !git_has_branch $branch;
+    git_select_branch $branch;
+    my $log = git_pipe "git log -1 patched";
+    $log =~ /^commit (.*)/;
+    my $commit = $1;
+    my $status = system "cd $dest_dir && git cherry-pick $commit";
+    if ($status)
+    {
+	print "FIXME: patch depends on earlier patches: $patch\n";
+	if (git_count_commits == 1)
+	{
+	    # Single-patch branch, or first patch of multiple-patch branch
+	    git_system "git reset --hard HEAD";
+	    git_system "git clean -f";
+	    git_system "git checkout patched";
+	    git_system "git branch -D $branch";
+	    git_system "git branch DEPENDENCY-$branch patched";
+	    git_system "git tag FIXME-branched-from-patched-$base DEPENDENCY-$branch";
+	}
+	else
+	{
+	    # Non-first patch in multiple-patch branch
+	    # Hitting this if our patch is not the first in this branch
+	    # would be extra ugly
+	    print "FIXME: conflict in multiple-patch branch: $branch, $patch\n";
+	    git_commit "Conflicts cherry-picking $commit ($patch).";
+	    git_system "git checkout patched";
+	    git_system "git branch -m $branch CONFLICTS-$base";
+	    git_system "git branch $branch patched";
+	    git_system "git tag FIXME-branched-from-patched-$base $branch";
+	}
+    }
+    git_select_branch "patched";
+}
+# end git
+
 (@ARGV > 1) ||
     die "Syntax:\n".
-    "apply <path-to-patchdir> <src root> --tag=<src680-m90> [--distro=<Debian> [--distro=<Binfilter> [...]]] [--quiet] [--dry-run] [ patch flags ]\n" .
+    "apply <path-to-patchdir> <src root> --tag=<src680-m90> [--distro=<Debian> [--distro=<Binfilter> [...]]] [--quiet] [--dry-run] [--with-git] [ patch flags ]\n" .
     "apply <path-to-patchdir> --series-from=<Debian>\n" .
     "apply <path-to-patchdir> --add-developer\n" .
     "apply <path-to-patchdir> --find-unused\n" .
@@ -1066,6 +1330,8 @@
 	    $tag = $1;
 	} elsif ($a =~ m/--dry-run/g) {
 	    $dry_run = 1;
+	} elsif ($a =~ m/--with-git/g) {
+	    $ENV{"OOO_GIT"} = $a;
 	} else {
 	    push @arguments, $a;
 	}
@@ -1115,11 +1381,15 @@
 	$base_cmd = 'sed \'s/^\(@.*\)\r$/\1/\' | ' . $base_cmd;
     }
 
+    git_prepare if $ENV{"OOO_GIT"};
+
     if ($remove) {
 	remove_patches();
     } else {
 	apply_patches();
     }
+
+    git_postpare if $ENV{"OOO_GIT"};
 }
 
 # vim: ts=4 sw=4 noet
Index: bin/create-gitignores.sh
===================================================================
--- bin/create-gitignores.sh	(revision 12937)
+++ bin/create-gitignores.sh	(working copy)
@@ -15,22 +15,43 @@
         [ -d "$D" ] && echo "$B" >> "$D/.gitignore"
     fi
 done << EOF
-/applied_patches
+*-
+*-HEAD
+*-git
+*-patched
+*-pristine
+*.bak
+*.css
+*.cxx-*
+*.git
+*.hxx-*
+*.orig
+*.patched
+*.pristine
+*.pyc
+*.xcu
+*~
+.\#*
 /Linux*Env.Set*
 /bootstrap
 /makefile.mk
+/solver
+CVS
+TAGS
+\#*
+localize.sdf
 unxlng*.pro
-localize.sdf
-/solver
-*.orig
 config_office/autom4te.cache/
 config_office/config.log
 config_office/config.parms
 config_office/config.status
 config_office/configure
 config_office/set_soenv
+config_office/visibility.cxx
+config_office/visibility.s
 config_office/warn
 default_images/introabout/intro-save.bmp
+default_images/introabout/intro.bmp
 default_images/svx/res/openabout_ark.png
 default_images/svx/res/openabout_translateorgza.png
 default_images/sw/res/go-oo-team.png
@@ -88,11 +109,16 @@
 dmake/win95/.deps/
 dmake/win95/microsft/.deps/
 instsetoo_native/res/banner_nld.bmp
+instsetoo_native/res/banner_ooop.bmp
 instsetoo_native/res/nologoinstall_nld.bmp
+instsetoo_native/res/nologoinstall_ooop.bmp
 instsetoo_native/util/OpenOffice
+sd/xml/transitions-ogl.xml
 setup_native/source/win32/nsis/ooobanner_nld.bmp
+setup_native/source/win32/nsis/ooobanner_ooop.bmp
 setup_native/source/win32/nsis/ooobitmap_nld.bmp
+setup_native/source/win32/nsis/ooobitmap_ooop.bmp
 setup_native/source/win32/nsis/ooosetup_nld.ico
-solenv/unxlngx6/
+solenv/unxlngx*/
 svx/res/
 EOF
Index: Makefile.shared
===================================================================
--- Makefile.shared	(revision 12937)
+++ Makefile.shared	(working copy)
@@ -31,6 +31,9 @@
 		if test -n "$(OOO_ADDITIONAL_SECTIONS)" ; then \
 			FLAGS="$$FLAGS --additional-sections=$(OOO_ADDITIONAL_SECTIONS)"; \
 		fi ; \
+		if test -n "$(OOO_GIT)" ; then \
+			FLAGS="$$FLAGS --with-git=$(OOO_GIT)"; \
+		fi ; \
 		chmod +x $(TOOLSDIR)/patches/apply.pl && $(TOOLSDIR)/patches/apply.pl $(APPLY_DIR) $(OOBUILDDIR) $$FLAGS -f -R ; \
 	fi
 	cd $(top_srcdir)/bin ; ./unpack
@@ -97,6 +100,9 @@
 	if test -n "$(OOO_ADDITIONAL_SECTIONS)" ; then \
 		FLAGS="$$FLAGS --additional-sections=$(OOO_ADDITIONAL_SECTIONS)"; \
 	fi ; \
+	if test -n "$(OOO_GIT)" ; then \
+	   	FLAGS="$$FLAGS --with-git=$(OOO_GIT)"; \
+	fi ; \
 	chmod +x $(TOOLSDIR)/patches/apply.pl && $(TOOLSDIR)/patches/apply.pl $(APPLY_DIR) $(OOBUILDDIR) $$FLAGS --tag=$(CVSTAG) ;
 	$(TOOLSDIR)/bin/transform --apply $(TOOLSDIR) $(OOBUILDDIR)
 	$(TOOLSDIR)/bin/fix-deps $(OOBUILDDIR)
Index: configure.in
===================================================================
--- configure.in	(revision 12937)
+++ configure.in	(working copy)
@@ -328,6 +328,11 @@
 			  Example: --with-drink=coffee],
 ,)
 
+AC_ARG_WITH(git,
+[
+  --with-git              Use GIT to manage your patches],
+,)
+
 dnl
 dnl Items here only to make --help work nicely:
 dnl 
@@ -1098,6 +1103,19 @@
 fi
 AC_MSG_RESULT([$build_product])
 
+AC_MSG_CHECKING([whether to use GIT])
+if test -z "$with_git" -o "$with_git" = "no"; then
+    unset OOO_GIT
+    AC_MSG_RESULT([no])
+else
+    OOO_GIT=git
+    if test "z$with_git" != "zyes"; then
+        OOO_GIT=$with_git
+    fi
+    AC_MSG_RESULT([$OOO_GIT])
+fi
+AC_SUBST(OOO_GIT)
+
 UPSTREAM_NAME=
 UPSTREAM_SOURCE=
 UPSTREAM_URI=

