diff --git a/SparkleShare/Mac/README.md b/SparkleShare/Mac/README.md
index 60dc6c42..4ea7997f 100644
--- a/SparkleShare/Mac/README.md
+++ b/SparkleShare/Mac/README.md
@@ -24,7 +24,16 @@ Install git, automake, libtool and intltool
```bash
$ sudo port install git-core automake intltool libtool
```
-
+
+Get a Git install, and place both the `bin` and `libexec` directories in `SparkleShare/Mac/git`.
+The exact commands depend on where you installed/have Git. Assuming it's in `/usr/local`:
+
+```bash
+$ mkdir SparkleShare/Mac/git
+$ cp -R /usr/local/git/bin SparkleShare/Mac/git
+$ cp -R /usr/local/git/libexec SparkleShare/Mac/git
+```
+
Start the first part of the build:
```bash
diff --git a/SparkleShare/Mac/git/LICENSE b/SparkleShare/Mac/git/LICENSE
deleted file mode 100644
index fe81dd87..00000000
--- a/SparkleShare/Mac/git/LICENSE
+++ /dev/null
@@ -1,370 +0,0 @@
-From https://github.com/gitster/git:
-
-////////////////////////////////////////////////////////////////
-
- GIT - the stupid content tracker
-
-////////////////////////////////////////////////////////////////
-
-"git" can mean anything, depending on your mood.
-
- - random three-letter combination that is pronounceable, and not
- actually used by any common UNIX command. The fact that it is a
- mispronunciation of "get" may or may not be relevant.
- - stupid. contemptible and despicable. simple. Take your pick from the
- dictionary of slang.
- - "global information tracker": you're in a good mood, and it actually
- works for you. Angels sing, and a light suddenly fills the room.
- - "goddamn idiotic truckload of sh*t": when it breaks
-
-Git is a fast, scalable, distributed revision control system with an
-unusually rich command set that provides both high-level operations
-and full access to internals.
-
-Git is an Open Source project covered by the GNU General Public License.
-It was originally written by Linus Torvalds with help of a group of
-hackers around the net. It is currently maintained by Junio C Hamano.
-
-////////////////////////////////////////////////////////////////
-
-
- GNU GENERAL PUBLIC LICENSE
- Version 2, June 1991
-
- Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
- Preamble
-
- The licenses for most software are designed to take away your
-freedom to share and change it. By contrast, the GNU General Public
-License is intended to guarantee your freedom to share and change free
-software--to make sure the software is free for all its users. This
-General Public License applies to most of the Free Software
-Foundation's software and to any other program whose authors commit to
-using it. (Some other Free Software Foundation software is covered by
-the GNU Lesser General Public License instead.) You can apply it to
-your programs, too.
-
- When we speak of free software, we are referring to freedom, not
-price. Our General Public Licenses are designed to make sure that you
-have the freedom to distribute copies of free software (and charge for
-this service if you wish), that you receive source code or can get it
-if you want it, that you can change the software or use pieces of it
-in new free programs; and that you know you can do these things.
-
- To protect your rights, we need to make restrictions that forbid
-anyone to deny you these rights or to ask you to surrender the rights.
-These restrictions translate to certain responsibilities for you if you
-distribute copies of the software, or if you modify it.
-
- For example, if you distribute copies of such a program, whether
-gratis or for a fee, you must give the recipients all the rights that
-you have. You must make sure that they, too, receive or can get the
-source code. And you must show them these terms so they know their
-rights.
-
- We protect your rights with two steps: (1) copyright the software, and
-(2) offer you this license which gives you legal permission to copy,
-distribute and/or modify the software.
-
- Also, for each author's protection and ours, we want to make certain
-that everyone understands that there is no warranty for this free
-software. If the software is modified by someone else and passed on, we
-want its recipients to know that what they have is not the original, so
-that any problems introduced by others will not reflect on the original
-authors' reputations.
-
- Finally, any free program is threatened constantly by software
-patents. We wish to avoid the danger that redistributors of a free
-program will individually obtain patent licenses, in effect making the
-program proprietary. To prevent this, we have made it clear that any
-patent must be licensed for everyone's free use or not licensed at all.
-
- The precise terms and conditions for copying, distribution and
-modification follow.
-
- GNU GENERAL PUBLIC LICENSE
- TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-
- 0. This License applies to any program or other work which contains
-a notice placed by the copyright holder saying it may be distributed
-under the terms of this General Public License. The "Program", below,
-refers to any such program or work, and a "work based on the Program"
-means either the Program or any derivative work under copyright law:
-that is to say, a work containing the Program or a portion of it,
-either verbatim or with modifications and/or translated into another
-language. (Hereinafter, translation is included without limitation in
-the term "modification".) Each licensee is addressed as "you".
-
-Activities other than copying, distribution and modification are not
-covered by this License; they are outside its scope. The act of
-running the Program is not restricted, and the output from the Program
-is covered only if its contents constitute a work based on the
-Program (independent of having been made by running the Program).
-Whether that is true depends on what the Program does.
-
- 1. You may copy and distribute verbatim copies of the Program's
-source code as you receive it, in any medium, provided that you
-conspicuously and appropriately publish on each copy an appropriate
-copyright notice and disclaimer of warranty; keep intact all the
-notices that refer to this License and to the absence of any warranty;
-and give any other recipients of the Program a copy of this License
-along with the Program.
-
-You may charge a fee for the physical act of transferring a copy, and
-you may at your option offer warranty protection in exchange for a fee.
-
- 2. You may modify your copy or copies of the Program or any portion
-of it, thus forming a work based on the Program, and copy and
-distribute such modifications or work under the terms of Section 1
-above, provided that you also meet all of these conditions:
-
- a) You must cause the modified files to carry prominent notices
- stating that you changed the files and the date of any change.
-
- b) You must cause any work that you distribute or publish, that in
- whole or in part contains or is derived from the Program or any
- part thereof, to be licensed as a whole at no charge to all third
- parties under the terms of this License.
-
- c) If the modified program normally reads commands interactively
- when run, you must cause it, when started running for such
- interactive use in the most ordinary way, to print or display an
- announcement including an appropriate copyright notice and a
- notice that there is no warranty (or else, saying that you provide
- a warranty) and that users may redistribute the program under
- these conditions, and telling the user how to view a copy of this
- License. (Exception: if the Program itself is interactive but
- does not normally print such an announcement, your work based on
- the Program is not required to print an announcement.)
-
-These requirements apply to the modified work as a whole. If
-identifiable sections of that work are not derived from the Program,
-and can be reasonably considered independent and separate works in
-themselves, then this License, and its terms, do not apply to those
-sections when you distribute them as separate works. But when you
-distribute the same sections as part of a whole which is a work based
-on the Program, the distribution of the whole must be on the terms of
-this License, whose permissions for other licensees extend to the
-entire whole, and thus to each and every part regardless of who wrote it.
-
-Thus, it is not the intent of this section to claim rights or contest
-your rights to work written entirely by you; rather, the intent is to
-exercise the right to control the distribution of derivative or
-collective works based on the Program.
-
-In addition, mere aggregation of another work not based on the Program
-with the Program (or with a work based on the Program) on a volume of
-a storage or distribution medium does not bring the other work under
-the scope of this License.
-
- 3. You may copy and distribute the Program (or a work based on it,
-under Section 2) in object code or executable form under the terms of
-Sections 1 and 2 above provided that you also do one of the following:
-
- a) Accompany it with the complete corresponding machine-readable
- source code, which must be distributed under the terms of Sections
- 1 and 2 above on a medium customarily used for software interchange; or,
-
- b) Accompany it with a written offer, valid for at least three
- years, to give any third party, for a charge no more than your
- cost of physically performing source distribution, a complete
- machine-readable copy of the corresponding source code, to be
- distributed under the terms of Sections 1 and 2 above on a medium
- customarily used for software interchange; or,
-
- c) Accompany it with the information you received as to the offer
- to distribute corresponding source code. (This alternative is
- allowed only for noncommercial distribution and only if you
- received the program in object code or executable form with such
- an offer, in accord with Subsection b above.)
-
-The source code for a work means the preferred form of the work for
-making modifications to it. For an executable work, complete source
-code means all the source code for all modules it contains, plus any
-associated interface definition files, plus the scripts used to
-control compilation and installation of the executable. However, as a
-special exception, the source code distributed need not include
-anything that is normally distributed (in either source or binary
-form) with the major components (compiler, kernel, and so on) of the
-operating system on which the executable runs, unless that component
-itself accompanies the executable.
-
-If distribution of executable or object code is made by offering
-access to copy from a designated place, then offering equivalent
-access to copy the source code from the same place counts as
-distribution of the source code, even though third parties are not
-compelled to copy the source along with the object code.
-
- 4. You may not copy, modify, sublicense, or distribute the Program
-except as expressly provided under this License. Any attempt
-otherwise to copy, modify, sublicense or distribute the Program is
-void, and will automatically terminate your rights under this License.
-However, parties who have received copies, or rights, from you under
-this License will not have their licenses terminated so long as such
-parties remain in full compliance.
-
- 5. You are not required to accept this License, since you have not
-signed it. However, nothing else grants you permission to modify or
-distribute the Program or its derivative works. These actions are
-prohibited by law if you do not accept this License. Therefore, by
-modifying or distributing the Program (or any work based on the
-Program), you indicate your acceptance of this License to do so, and
-all its terms and conditions for copying, distributing or modifying
-the Program or works based on it.
-
- 6. Each time you redistribute the Program (or any work based on the
-Program), the recipient automatically receives a license from the
-original licensor to copy, distribute or modify the Program subject to
-these terms and conditions. You may not impose any further
-restrictions on the recipients' exercise of the rights granted herein.
-You are not responsible for enforcing compliance by third parties to
-this License.
-
- 7. If, as a consequence of a court judgment or allegation of patent
-infringement or for any other reason (not limited to patent issues),
-conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License. If you cannot
-distribute so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you
-may not distribute the Program at all. For example, if a patent
-license would not permit royalty-free redistribution of the Program by
-all those who receive copies directly or indirectly through you, then
-the only way you could satisfy both it and this License would be to
-refrain entirely from distribution of the Program.
-
-If any portion of this section is held invalid or unenforceable under
-any particular circumstance, the balance of the section is intended to
-apply and the section as a whole is intended to apply in other
-circumstances.
-
-It is not the purpose of this section to induce you to infringe any
-patents or other property right claims or to contest validity of any
-such claims; this section has the sole purpose of protecting the
-integrity of the free software distribution system, which is
-implemented by public license practices. Many people have made
-generous contributions to the wide range of software distributed
-through that system in reliance on consistent application of that
-system; it is up to the author/donor to decide if he or she is willing
-to distribute software through any other system and a licensee cannot
-impose that choice.
-
-This section is intended to make thoroughly clear what is believed to
-be a consequence of the rest of this License.
-
- 8. If the distribution and/or use of the Program is restricted in
-certain countries either by patents or by copyrighted interfaces, the
-original copyright holder who places the Program under this License
-may add an explicit geographical distribution limitation excluding
-those countries, so that distribution is permitted only in or among
-countries not thus excluded. In such case, this License incorporates
-the limitation as if written in the body of this License.
-
- 9. The Free Software Foundation may publish revised and/or new versions
-of the General Public License from time to time. Such new versions will
-be similar in spirit to the present version, but may differ in detail to
-address new problems or concerns.
-
-Each version is given a distinguishing version number. If the Program
-specifies a version number of this License which applies to it and "any
-later version", you have the option of following the terms and conditions
-either of that version or of any later version published by the Free
-Software Foundation. If the Program does not specify a version number of
-this License, you may choose any version ever published by the Free Software
-Foundation.
-
- 10. If you wish to incorporate parts of the Program into other free
-programs whose distribution conditions are different, write to the author
-to ask for permission. For software which is copyrighted by the Free
-Software Foundation, write to the Free Software Foundation; we sometimes
-make exceptions for this. Our decision will be guided by the two goals
-of preserving the free status of all derivatives of our free software and
-of promoting the sharing and reuse of software generally.
-
- NO WARRANTY
-
- 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
-FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
-OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
-PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
-OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
-TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
-PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
-REPAIR OR CORRECTION.
-
- 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
-REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
-INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
-OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
-TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
-YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
-PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGES.
-
- END OF TERMS AND CONDITIONS
-
- How to Apply These Terms to Your New Programs
-
- If you develop a new program, and you want it to be of the greatest
-possible use to the public, the best way to achieve this is to make it
-free software which everyone can redistribute and change under these terms.
-
- To do so, attach the following notices to the program. It is safest
-to attach them to the start of each source file to most effectively
-convey the exclusion of warranty; and each file should have at least
-the "copyright" line and a pointer to where the full notice is found.
-
-
- Copyright (C)
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-
-Also add information on how to contact you by electronic and paper mail.
-
-If the program is interactive, make it output a short notice like this
-when it starts in an interactive mode:
-
- Gnomovision version 69, Copyright (C) year name of author
- Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
- This is free software, and you are welcome to redistribute it
- under certain conditions; type `show c' for details.
-
-The hypothetical commands `show w' and `show c' should show the appropriate
-parts of the General Public License. Of course, the commands you use may
-be called something other than `show w' and `show c'; they could even be
-mouse-clicks or menu items--whatever suits your program.
-
-You should also get your employer (if you work as a programmer) or your
-school, if any, to sign a "copyright disclaimer" for the program, if
-necessary. Here is a sample; alter the names:
-
- Yoyodyne, Inc., hereby disclaims all copyright interest in the program
- `Gnomovision' (which makes passes at compilers) written by James Hacker.
-
- , 1 April 1989
- Ty Coon, President of Vice
-
-This General Public License does not permit incorporating your program into
-proprietary programs. If your program is a subroutine library, you may
-consider it more useful to permit linking proprietary applications with the
-library. If this is what you want to do, use the GNU Lesser General
-Public License instead of this License.
-
diff --git a/SparkleShare/Mac/git/bin/git b/SparkleShare/Mac/git/bin/git
deleted file mode 100755
index 0e604ec9..00000000
Binary files a/SparkleShare/Mac/git/bin/git and /dev/null differ
diff --git a/SparkleShare/Mac/git/bin/git-cvsserver b/SparkleShare/Mac/git/bin/git-cvsserver
deleted file mode 100755
index cafb11f4..00000000
--- a/SparkleShare/Mac/git/bin/git-cvsserver
+++ /dev/null
@@ -1,3696 +0,0 @@
-#!/usr/bin/perl
-use lib (split(/:/, $ENV{GITPERLLIB} || "/usr/local/git/lib/perl5/site_perl"));
-
-####
-#### This application is a CVS emulation layer for git.
-#### It is intended for clients to connect over SSH.
-#### See the documentation for more details.
-####
-#### Copyright The Open University UK - 2006.
-####
-#### Authors: Martyn Smith
-#### Martin Langhoff
-####
-####
-#### Released under the GNU Public License, version 2.
-####
-####
-
-use 5.008;
-use strict;
-use warnings;
-use bytes;
-
-use Fcntl;
-use File::Temp qw/tempdir tempfile/;
-use File::Path qw/rmtree/;
-use File::Basename;
-use Getopt::Long qw(:config require_order no_ignore_case);
-
-my $VERSION = '1.7.6.1';
-
-my $log = GITCVS::log->new();
-my $cfg;
-
-my $DATE_LIST = {
- Jan => "01",
- Feb => "02",
- Mar => "03",
- Apr => "04",
- May => "05",
- Jun => "06",
- Jul => "07",
- Aug => "08",
- Sep => "09",
- Oct => "10",
- Nov => "11",
- Dec => "12",
-};
-
-# Enable autoflush for STDOUT (otherwise the whole thing falls apart)
-$| = 1;
-
-#### Definition and mappings of functions ####
-
-my $methods = {
- 'Root' => \&req_Root,
- 'Valid-responses' => \&req_Validresponses,
- 'valid-requests' => \&req_validrequests,
- 'Directory' => \&req_Directory,
- 'Entry' => \&req_Entry,
- 'Modified' => \&req_Modified,
- 'Unchanged' => \&req_Unchanged,
- 'Questionable' => \&req_Questionable,
- 'Argument' => \&req_Argument,
- 'Argumentx' => \&req_Argument,
- 'expand-modules' => \&req_expandmodules,
- 'add' => \&req_add,
- 'remove' => \&req_remove,
- 'co' => \&req_co,
- 'update' => \&req_update,
- 'ci' => \&req_ci,
- 'diff' => \&req_diff,
- 'log' => \&req_log,
- 'rlog' => \&req_log,
- 'tag' => \&req_CATCHALL,
- 'status' => \&req_status,
- 'admin' => \&req_CATCHALL,
- 'history' => \&req_CATCHALL,
- 'watchers' => \&req_EMPTY,
- 'editors' => \&req_EMPTY,
- 'noop' => \&req_EMPTY,
- 'annotate' => \&req_annotate,
- 'Global_option' => \&req_Globaloption,
- #'annotate' => \&req_CATCHALL,
-};
-
-##############################################
-
-
-# $state holds all the bits of information the clients sends us that could
-# potentially be useful when it comes to actually _doing_ something.
-my $state = { prependdir => '' };
-
-# Work is for managing temporary working directory
-my $work =
- {
- state => undef, # undef, 1 (empty), 2 (with stuff)
- workDir => undef,
- index => undef,
- emptyDir => undef,
- tmpDir => undef
- };
-
-$log->info("--------------- STARTING -----------------");
-
-my $usage =
- "Usage: git cvsserver [options] [pserver|server] [ ...]\n".
- " --base-path : Prepend to requested CVSROOT\n".
- " Can be read from GIT_CVSSERVER_BASE_PATH\n".
- " --strict-paths : Don't allow recursing into subdirectories\n".
- " --export-all : Don't check for gitcvs.enabled in config\n".
- " --version, -V : Print version information and exit\n".
- " --help, -h, -H : Print usage information and exit\n".
- "\n".
- " ... is a list of allowed directories. If no directories\n".
- "are given, all are allowed. This is an additional restriction, gitcvs\n".
- "access still needs to be enabled by the gitcvs.enabled config option.\n".
- "Alternately, one directory may be specified in GIT_CVSSERVER_ROOT.\n";
-
-my @opts = ( 'help|h|H', 'version|V',
- 'base-path=s', 'strict-paths', 'export-all' );
-GetOptions( $state, @opts )
- or die $usage;
-
-if ($state->{version}) {
- print "git-cvsserver version $VERSION\n";
- exit;
-}
-if ($state->{help}) {
- print $usage;
- exit;
-}
-
-my $TEMP_DIR = tempdir( CLEANUP => 1 );
-$log->debug("Temporary directory is '$TEMP_DIR'");
-
-$state->{method} = 'ext';
-if (@ARGV) {
- if ($ARGV[0] eq 'pserver') {
- $state->{method} = 'pserver';
- shift @ARGV;
- } elsif ($ARGV[0] eq 'server') {
- shift @ARGV;
- }
-}
-
-# everything else is a directory
-$state->{allowed_roots} = [ @ARGV ];
-
-# don't export the whole system unless the users requests it
-if ($state->{'export-all'} && !@{$state->{allowed_roots}}) {
- die "--export-all can only be used together with an explicit whitelist\n";
-}
-
-# Environment handling for running under git-shell
-if (exists $ENV{GIT_CVSSERVER_BASE_PATH}) {
- if ($state->{'base-path'}) {
- die "Cannot specify base path both ways.\n";
- }
- my $base_path = $ENV{GIT_CVSSERVER_BASE_PATH};
- $state->{'base-path'} = $base_path;
- $log->debug("Picked up base path '$base_path' from environment.\n");
-}
-if (exists $ENV{GIT_CVSSERVER_ROOT}) {
- if (@{$state->{allowed_roots}}) {
- die "Cannot specify roots both ways: @ARGV\n";
- }
- my $allowed_root = $ENV{GIT_CVSSERVER_ROOT};
- $state->{allowed_roots} = [ $allowed_root ];
- $log->debug("Picked up allowed root '$allowed_root' from environment.\n");
-}
-
-# if we are called with a pserver argument,
-# deal with the authentication cat before entering the
-# main loop
-if ($state->{method} eq 'pserver') {
- my $line = ; chomp $line;
- unless( $line =~ /^BEGIN (AUTH|VERIFICATION) REQUEST$/) {
- die "E Do not understand $line - expecting BEGIN AUTH REQUEST\n";
- }
- my $request = $1;
- $line = ; chomp $line;
- unless (req_Root('root', $line)) { # reuse Root
- print "E Invalid root $line \n";
- exit 1;
- }
- $line = ; chomp $line;
- my $user = $line;
- $line = ; chomp $line;
- my $password = $line;
-
- if ($user eq 'anonymous') {
- # "A" will be 1 byte, use length instead in case the
- # encryption method ever changes (yeah, right!)
- if (length($password) > 1 ) {
- print "E Don't supply a password for the `anonymous' user\n";
- print "I HATE YOU\n";
- exit 1;
- }
-
- # Fall through to LOVE
- } else {
- # Trying to authenticate a user
- if (not exists $cfg->{gitcvs}->{authdb}) {
- print "E the repo config file needs a [gitcvs] section with an 'authdb' parameter set to the filename of the authentication database\n";
- print "I HATE YOU\n";
- exit 1;
- }
-
- my $authdb = $cfg->{gitcvs}->{authdb};
-
- unless (-e $authdb) {
- print "E The authentication database specified in [gitcvs.authdb] does not exist\n";
- print "I HATE YOU\n";
- exit 1;
- }
-
- my $auth_ok;
- open my $passwd, "<", $authdb or die $!;
- while (<$passwd>) {
- if (m{^\Q$user\E:(.*)}) {
- if (crypt($user, descramble($password)) eq $1) {
- $auth_ok = 1;
- }
- };
- }
- close $passwd;
-
- unless ($auth_ok) {
- print "I HATE YOU\n";
- exit 1;
- }
-
- # Fall through to LOVE
- }
-
- # For checking whether the user is anonymous on commit
- $state->{user} = $user;
-
- $line = ; chomp $line;
- unless ($line eq "END $request REQUEST") {
- die "E Do not understand $line -- expecting END $request REQUEST\n";
- }
- print "I LOVE YOU\n";
- exit if $request eq 'VERIFICATION'; # cvs login
- # and now back to our regular programme...
-}
-
-# Keep going until the client closes the connection
-while ()
-{
- chomp;
-
- # Check to see if we've seen this method, and call appropriate function.
- if ( /^([\w-]+)(?:\s+(.*))?$/ and defined($methods->{$1}) )
- {
- # use the $methods hash to call the appropriate sub for this command
- #$log->info("Method : $1");
- &{$methods->{$1}}($1,$2);
- } else {
- # log fatal because we don't understand this function. If this happens
- # we're fairly screwed because we don't know if the client is expecting
- # a response. If it is, the client will hang, we'll hang, and the whole
- # thing will be custard.
- $log->fatal("Don't understand command $_\n");
- die("Unknown command $_");
- }
-}
-
-$log->debug("Processing time : user=" . (times)[0] . " system=" . (times)[1]);
-$log->info("--------------- FINISH -----------------");
-
-chdir '/';
-exit 0;
-
-# Magic catchall method.
-# This is the method that will handle all commands we haven't yet
-# implemented. It simply sends a warning to the log file indicating a
-# command that hasn't been implemented has been invoked.
-sub req_CATCHALL
-{
- my ( $cmd, $data ) = @_;
- $log->warn("Unhandled command : req_$cmd : $data");
-}
-
-# This method invariably succeeds with an empty response.
-sub req_EMPTY
-{
- print "ok\n";
-}
-
-# Root pathname \n
-# Response expected: no. Tell the server which CVSROOT to use. Note that
-# pathname is a local directory and not a fully qualified CVSROOT variable.
-# pathname must already exist; if creating a new root, use the init
-# request, not Root. pathname does not include the hostname of the server,
-# how to access the server, etc.; by the time the CVS protocol is in use,
-# connection, authentication, etc., are already taken care of. The Root
-# request must be sent only once, and it must be sent before any requests
-# other than Valid-responses, valid-requests, UseUnchanged, Set or init.
-sub req_Root
-{
- my ( $cmd, $data ) = @_;
- $log->debug("req_Root : $data");
-
- unless ($data =~ m#^/#) {
- print "error 1 Root must be an absolute pathname\n";
- return 0;
- }
-
- my $cvsroot = $state->{'base-path'} || '';
- $cvsroot =~ s#/+$##;
- $cvsroot .= $data;
-
- if ($state->{CVSROOT}
- && ($state->{CVSROOT} ne $cvsroot)) {
- print "error 1 Conflicting roots specified\n";
- return 0;
- }
-
- $state->{CVSROOT} = $cvsroot;
-
- $ENV{GIT_DIR} = $state->{CVSROOT} . "/";
-
- if (@{$state->{allowed_roots}}) {
- my $allowed = 0;
- foreach my $dir (@{$state->{allowed_roots}}) {
- next unless $dir =~ m#^/#;
- $dir =~ s#/+$##;
- if ($state->{'strict-paths'}) {
- if ($ENV{GIT_DIR} =~ m#^\Q$dir\E/?$#) {
- $allowed = 1;
- last;
- }
- } elsif ($ENV{GIT_DIR} =~ m#^\Q$dir\E(/?$|/)#) {
- $allowed = 1;
- last;
- }
- }
-
- unless ($allowed) {
- print "E $ENV{GIT_DIR} does not seem to be a valid GIT repository\n";
- print "E \n";
- print "error 1 $ENV{GIT_DIR} is not a valid repository\n";
- return 0;
- }
- }
-
- unless (-d $ENV{GIT_DIR} && -e $ENV{GIT_DIR}.'HEAD') {
- print "E $ENV{GIT_DIR} does not seem to be a valid GIT repository\n";
- print "E \n";
- print "error 1 $ENV{GIT_DIR} is not a valid repository\n";
- return 0;
- }
-
- my @gitvars = `git config -l`;
- if ($?) {
- print "E problems executing git-config on the server -- this is not a git repository or the PATH is not set correctly.\n";
- print "E \n";
- print "error 1 - problem executing git-config\n";
- return 0;
- }
- foreach my $line ( @gitvars )
- {
- next unless ( $line =~ /^(gitcvs)\.(?:(ext|pserver)\.)?([\w-]+)=(.*)$/ );
- unless ($2) {
- $cfg->{$1}{$3} = $4;
- } else {
- $cfg->{$1}{$2}{$3} = $4;
- }
- }
-
- my $enabled = ($cfg->{gitcvs}{$state->{method}}{enabled}
- || $cfg->{gitcvs}{enabled});
- unless ($state->{'export-all'} ||
- ($enabled && $enabled =~ /^\s*(1|true|yes)\s*$/i)) {
- print "E GITCVS emulation needs to be enabled on this repo\n";
- print "E the repo config file needs a [gitcvs] section added, and the parameter 'enabled' set to 1\n";
- print "E \n";
- print "error 1 GITCVS emulation disabled\n";
- return 0;
- }
-
- my $logfile = $cfg->{gitcvs}{$state->{method}}{logfile} || $cfg->{gitcvs}{logfile};
- if ( $logfile )
- {
- $log->setfile($logfile);
- } else {
- $log->nofile();
- }
-
- return 1;
-}
-
-# Global_option option \n
-# Response expected: no. Transmit one of the global options `-q', `-Q',
-# `-l', `-t', `-r', or `-n'. option must be one of those strings, no
-# variations (such as combining of options) are allowed. For graceful
-# handling of valid-requests, it is probably better to make new global
-# options separate requests, rather than trying to add them to this
-# request.
-sub req_Globaloption
-{
- my ( $cmd, $data ) = @_;
- $log->debug("req_Globaloption : $data");
- $state->{globaloptions}{$data} = 1;
-}
-
-# Valid-responses request-list \n
-# Response expected: no. Tell the server what responses the client will
-# accept. request-list is a space separated list of tokens.
-sub req_Validresponses
-{
- my ( $cmd, $data ) = @_;
- $log->debug("req_Validresponses : $data");
-
- # TODO : re-enable this, currently it's not particularly useful
- #$state->{validresponses} = [ split /\s+/, $data ];
-}
-
-# valid-requests \n
-# Response expected: yes. Ask the server to send back a Valid-requests
-# response.
-sub req_validrequests
-{
- my ( $cmd, $data ) = @_;
-
- $log->debug("req_validrequests");
-
- $log->debug("SEND : Valid-requests " . join(" ",keys %$methods));
- $log->debug("SEND : ok");
-
- print "Valid-requests " . join(" ",keys %$methods) . "\n";
- print "ok\n";
-}
-
-# Directory local-directory \n
-# Additional data: repository \n. Response expected: no. Tell the server
-# what directory to use. The repository should be a directory name from a
-# previous server response. Note that this both gives a default for Entry
-# and Modified and also for ci and the other commands; normal usage is to
-# send Directory for each directory in which there will be an Entry or
-# Modified, and then a final Directory for the original directory, then the
-# command. The local-directory is relative to the top level at which the
-# command is occurring (i.e. the last Directory which is sent before the
-# command); to indicate that top level, `.' should be sent for
-# local-directory.
-sub req_Directory
-{
- my ( $cmd, $data ) = @_;
-
- my $repository = ;
- chomp $repository;
-
-
- $state->{localdir} = $data;
- $state->{repository} = $repository;
- $state->{path} = $repository;
- $state->{path} =~ s/^\Q$state->{CVSROOT}\E\///;
- $state->{module} = $1 if ($state->{path} =~ s/^(.*?)(\/|$)//);
- $state->{path} .= "/" if ( $state->{path} =~ /\S/ );
-
- $state->{directory} = $state->{localdir};
- $state->{directory} = "" if ( $state->{directory} eq "." );
- $state->{directory} .= "/" if ( $state->{directory} =~ /\S/ );
-
- if ( (not defined($state->{prependdir}) or $state->{prependdir} eq '') and $state->{localdir} eq "." and $state->{path} =~ /\S/ )
- {
- $log->info("Setting prepend to '$state->{path}'");
- $state->{prependdir} = $state->{path};
- foreach my $entry ( keys %{$state->{entries}} )
- {
- $state->{entries}{$state->{prependdir} . $entry} = $state->{entries}{$entry};
- delete $state->{entries}{$entry};
- }
- }
-
- if ( defined ( $state->{prependdir} ) )
- {
- $log->debug("Prepending '$state->{prependdir}' to state|directory");
- $state->{directory} = $state->{prependdir} . $state->{directory}
- }
- $log->debug("req_Directory : localdir=$data repository=$repository path=$state->{path} directory=$state->{directory} module=$state->{module}");
-}
-
-# Entry entry-line \n
-# Response expected: no. Tell the server what version of a file is on the
-# local machine. The name in entry-line is a name relative to the directory
-# most recently specified with Directory. If the user is operating on only
-# some files in a directory, Entry requests for only those files need be
-# included. If an Entry request is sent without Modified, Is-modified, or
-# Unchanged, it means the file is lost (does not exist in the working
-# directory). If both Entry and one of Modified, Is-modified, or Unchanged
-# are sent for the same file, Entry must be sent first. For a given file,
-# one can send Modified, Is-modified, or Unchanged, but not more than one
-# of these three.
-sub req_Entry
-{
- my ( $cmd, $data ) = @_;
-
- #$log->debug("req_Entry : $data");
-
- my @data = split(/\//, $data);
-
- $state->{entries}{$state->{directory}.$data[1]} = {
- revision => $data[2],
- conflict => $data[3],
- options => $data[4],
- tag_or_date => $data[5],
- };
-
- $log->info("Received entry line '$data' => '" . $state->{directory} . $data[1] . "'");
-}
-
-# Questionable filename \n
-# Response expected: no. Additional data: no. Tell the server to check
-# whether filename should be ignored, and if not, next time the server
-# sends responses, send (in a M response) `?' followed by the directory and
-# filename. filename must not contain `/'; it needs to be a file in the
-# directory named by the most recent Directory request.
-sub req_Questionable
-{
- my ( $cmd, $data ) = @_;
-
- $log->debug("req_Questionable : $data");
- $state->{entries}{$state->{directory}.$data}{questionable} = 1;
-}
-
-# add \n
-# Response expected: yes. Add a file or directory. This uses any previous
-# Argument, Directory, Entry, or Modified requests, if they have been sent.
-# The last Directory sent specifies the working directory at the time of
-# the operation. To add a directory, send the directory to be added using
-# Directory and Argument requests.
-sub req_add
-{
- my ( $cmd, $data ) = @_;
-
- argsplit("add");
-
- my $updater = GITCVS::updater->new($state->{CVSROOT}, $state->{module}, $log);
- $updater->update();
-
- argsfromdir($updater);
-
- my $addcount = 0;
-
- foreach my $filename ( @{$state->{args}} )
- {
- $filename = filecleanup($filename);
-
- my $meta = $updater->getmeta($filename);
- my $wrev = revparse($filename);
-
- if ($wrev && $meta && ($wrev < 0))
- {
- # previously removed file, add back
- $log->info("added file $filename was previously removed, send 1.$meta->{revision}");
-
- print "MT +updated\n";
- print "MT text U \n";
- print "MT fname $filename\n";
- print "MT newline\n";
- print "MT -updated\n";
-
- unless ( $state->{globaloptions}{-n} )
- {
- my ( $filepart, $dirpart ) = filenamesplit($filename,1);
-
- print "Created $dirpart\n";
- print $state->{CVSROOT} . "/$state->{module}/$filename\n";
-
- # this is an "entries" line
- my $kopts = kopts_from_path($filename,"sha1",$meta->{filehash});
- $log->debug("/$filepart/1.$meta->{revision}//$kopts/");
- print "/$filepart/1.$meta->{revision}//$kopts/\n";
- # permissions
- $log->debug("SEND : u=$meta->{mode},g=$meta->{mode},o=$meta->{mode}");
- print "u=$meta->{mode},g=$meta->{mode},o=$meta->{mode}\n";
- # transmit file
- transmitfile($meta->{filehash});
- }
-
- next;
- }
-
- unless ( defined ( $state->{entries}{$filename}{modified_filename} ) )
- {
- print "E cvs add: nothing known about `$filename'\n";
- next;
- }
- # TODO : check we're not squashing an already existing file
- if ( defined ( $state->{entries}{$filename}{revision} ) )
- {
- print "E cvs add: `$filename' has already been entered\n";
- next;
- }
-
- my ( $filepart, $dirpart ) = filenamesplit($filename, 1);
-
- print "E cvs add: scheduling file `$filename' for addition\n";
-
- print "Checked-in $dirpart\n";
- print "$filename\n";
- my $kopts = kopts_from_path($filename,"file",
- $state->{entries}{$filename}{modified_filename});
- print "/$filepart/0//$kopts/\n";
-
- my $requestedKopts = $state->{opt}{k};
- if(defined($requestedKopts))
- {
- $requestedKopts = "-k$requestedKopts";
- }
- else
- {
- $requestedKopts = "";
- }
- if( $kopts ne $requestedKopts )
- {
- $log->warn("Ignoring requested -k='$requestedKopts'"
- . " for '$filename'; detected -k='$kopts' instead");
- #TODO: Also have option to send warning to user?
- }
-
- $addcount++;
- }
-
- if ( $addcount == 1 )
- {
- print "E cvs add: use `cvs commit' to add this file permanently\n";
- }
- elsif ( $addcount > 1 )
- {
- print "E cvs add: use `cvs commit' to add these files permanently\n";
- }
-
- print "ok\n";
-}
-
-# remove \n
-# Response expected: yes. Remove a file. This uses any previous Argument,
-# Directory, Entry, or Modified requests, if they have been sent. The last
-# Directory sent specifies the working directory at the time of the
-# operation. Note that this request does not actually do anything to the
-# repository; the only effect of a successful remove request is to supply
-# the client with a new entries line containing `-' to indicate a removed
-# file. In fact, the client probably could perform this operation without
-# contacting the server, although using remove may cause the server to
-# perform a few more checks. The client sends a subsequent ci request to
-# actually record the removal in the repository.
-sub req_remove
-{
- my ( $cmd, $data ) = @_;
-
- argsplit("remove");
-
- # Grab a handle to the SQLite db and do any necessary updates
- my $updater = GITCVS::updater->new($state->{CVSROOT}, $state->{module}, $log);
- $updater->update();
-
- #$log->debug("add state : " . Dumper($state));
-
- my $rmcount = 0;
-
- foreach my $filename ( @{$state->{args}} )
- {
- $filename = filecleanup($filename);
-
- if ( defined ( $state->{entries}{$filename}{unchanged} ) or defined ( $state->{entries}{$filename}{modified_filename} ) )
- {
- print "E cvs remove: file `$filename' still in working directory\n";
- next;
- }
-
- my $meta = $updater->getmeta($filename);
- my $wrev = revparse($filename);
-
- unless ( defined ( $wrev ) )
- {
- print "E cvs remove: nothing known about `$filename'\n";
- next;
- }
-
- if ( defined($wrev) and $wrev < 0 )
- {
- print "E cvs remove: file `$filename' already scheduled for removal\n";
- next;
- }
-
- unless ( $wrev == $meta->{revision} )
- {
- # TODO : not sure if the format of this message is quite correct.
- print "E cvs remove: Up to date check failed for `$filename'\n";
- next;
- }
-
-
- my ( $filepart, $dirpart ) = filenamesplit($filename, 1);
-
- print "E cvs remove: scheduling `$filename' for removal\n";
-
- print "Checked-in $dirpart\n";
- print "$filename\n";
- my $kopts = kopts_from_path($filename,"sha1",$meta->{filehash});
- print "/$filepart/-1.$wrev//$kopts/\n";
-
- $rmcount++;
- }
-
- if ( $rmcount == 1 )
- {
- print "E cvs remove: use `cvs commit' to remove this file permanently\n";
- }
- elsif ( $rmcount > 1 )
- {
- print "E cvs remove: use `cvs commit' to remove these files permanently\n";
- }
-
- print "ok\n";
-}
-
-# Modified filename \n
-# Response expected: no. Additional data: mode, \n, file transmission. Send
-# the server a copy of one locally modified file. filename is a file within
-# the most recent directory sent with Directory; it must not contain `/'.
-# If the user is operating on only some files in a directory, only those
-# files need to be included. This can also be sent without Entry, if there
-# is no entry for the file.
-sub req_Modified
-{
- my ( $cmd, $data ) = @_;
-
- my $mode = ;
- defined $mode
- or (print "E end of file reading mode for $data\n"), return;
- chomp $mode;
- my $size = ;
- defined $size
- or (print "E end of file reading size of $data\n"), return;
- chomp $size;
-
- # Grab config information
- my $blocksize = 8192;
- my $bytesleft = $size;
- my $tmp;
-
- # Get a filehandle/name to write it to
- my ( $fh, $filename ) = tempfile( DIR => $TEMP_DIR );
-
- # Loop over file data writing out to temporary file.
- while ( $bytesleft )
- {
- $blocksize = $bytesleft if ( $bytesleft < $blocksize );
- read STDIN, $tmp, $blocksize;
- print $fh $tmp;
- $bytesleft -= $blocksize;
- }
-
- close $fh
- or (print "E failed to write temporary, $filename: $!\n"), return;
-
- # Ensure we have something sensible for the file mode
- if ( $mode =~ /u=(\w+)/ )
- {
- $mode = $1;
- } else {
- $mode = "rw";
- }
-
- # Save the file data in $state
- $state->{entries}{$state->{directory}.$data}{modified_filename} = $filename;
- $state->{entries}{$state->{directory}.$data}{modified_mode} = $mode;
- $state->{entries}{$state->{directory}.$data}{modified_hash} = `git hash-object $filename`;
- $state->{entries}{$state->{directory}.$data}{modified_hash} =~ s/\s.*$//s;
-
- #$log->debug("req_Modified : file=$data mode=$mode size=$size");
-}
-
-# Unchanged filename \n
-# Response expected: no. Tell the server that filename has not been
-# modified in the checked out directory. The filename is a file within the
-# most recent directory sent with Directory; it must not contain `/'.
-sub req_Unchanged
-{
- my ( $cmd, $data ) = @_;
-
- $state->{entries}{$state->{directory}.$data}{unchanged} = 1;
-
- #$log->debug("req_Unchanged : $data");
-}
-
-# Argument text \n
-# Response expected: no. Save argument for use in a subsequent command.
-# Arguments accumulate until an argument-using command is given, at which
-# point they are forgotten.
-# Argumentx text \n
-# Response expected: no. Append \n followed by text to the current argument
-# being saved.
-sub req_Argument
-{
- my ( $cmd, $data ) = @_;
-
- # Argumentx means: append to last Argument (with a newline in front)
-
- $log->debug("$cmd : $data");
-
- if ( $cmd eq 'Argumentx') {
- ${$state->{arguments}}[$#{$state->{arguments}}] .= "\n" . $data;
- } else {
- push @{$state->{arguments}}, $data;
- }
-}
-
-# expand-modules \n
-# Response expected: yes. Expand the modules which are specified in the
-# arguments. Returns the data in Module-expansion responses. Note that the
-# server can assume that this is checkout or export, not rtag or rdiff; the
-# latter do not access the working directory and thus have no need to
-# expand modules on the client side. Expand may not be the best word for
-# what this request does. It does not necessarily tell you all the files
-# contained in a module, for example. Basically it is a way of telling you
-# which working directories the server needs to know about in order to
-# handle a checkout of the specified modules. For example, suppose that the
-# server has a module defined by
-# aliasmodule -a 1dir
-# That is, one can check out aliasmodule and it will take 1dir in the
-# repository and check it out to 1dir in the working directory. Now suppose
-# the client already has this module checked out and is planning on using
-# the co request to update it. Without using expand-modules, the client
-# would have two bad choices: it could either send information about all
-# working directories under the current directory, which could be
-# unnecessarily slow, or it could be ignorant of the fact that aliasmodule
-# stands for 1dir, and neglect to send information for 1dir, which would
-# lead to incorrect operation. With expand-modules, the client would first
-# ask for the module to be expanded:
-sub req_expandmodules
-{
- my ( $cmd, $data ) = @_;
-
- argsplit();
-
- $log->debug("req_expandmodules : " . ( defined($data) ? $data : "[NULL]" ) );
-
- unless ( ref $state->{arguments} eq "ARRAY" )
- {
- print "ok\n";
- return;
- }
-
- foreach my $module ( @{$state->{arguments}} )
- {
- $log->debug("SEND : Module-expansion $module");
- print "Module-expansion $module\n";
- }
-
- print "ok\n";
- statecleanup();
-}
-
-# co \n
-# Response expected: yes. Get files from the repository. This uses any
-# previous Argument, Directory, Entry, or Modified requests, if they have
-# been sent. Arguments to this command are module names; the client cannot
-# know what directories they correspond to except by (1) just sending the
-# co request, and then seeing what directory names the server sends back in
-# its responses, and (2) the expand-modules request.
-sub req_co
-{
- my ( $cmd, $data ) = @_;
-
- argsplit("co");
-
- # Provide list of modules, if -c was used.
- if (exists $state->{opt}{c}) {
- my $showref = `git show-ref --heads`;
- for my $line (split '\n', $showref) {
- if ( $line =~ m% refs/heads/(.*)$% ) {
- print "M $1\t$1\n";
- }
- }
- print "ok\n";
- return 1;
- }
-
- my $module = $state->{args}[0];
- $state->{module} = $module;
- my $checkout_path = $module;
-
- # use the user specified directory if we're given it
- $checkout_path = $state->{opt}{d} if ( exists ( $state->{opt}{d} ) );
-
- $log->debug("req_co : " . ( defined($data) ? $data : "[NULL]" ) );
-
- $log->info("Checking out module '$module' ($state->{CVSROOT}) to '$checkout_path'");
-
- $ENV{GIT_DIR} = $state->{CVSROOT} . "/";
-
- # Grab a handle to the SQLite db and do any necessary updates
- my $updater = GITCVS::updater->new($state->{CVSROOT}, $module, $log);
- $updater->update();
-
- $checkout_path =~ s|/$||; # get rid of trailing slashes
-
- # Eclipse seems to need the Clear-sticky command
- # to prepare the 'Entries' file for the new directory.
- print "Clear-sticky $checkout_path/\n";
- print $state->{CVSROOT} . "/$module/\n";
- print "Clear-static-directory $checkout_path/\n";
- print $state->{CVSROOT} . "/$module/\n";
- print "Clear-sticky $checkout_path/\n"; # yes, twice
- print $state->{CVSROOT} . "/$module/\n";
- print "Template $checkout_path/\n";
- print $state->{CVSROOT} . "/$module/\n";
- print "0\n";
-
- # instruct the client that we're checking out to $checkout_path
- print "E cvs checkout: Updating $checkout_path\n";
-
- my %seendirs = ();
- my $lastdir ='';
-
- # recursive
- sub prepdir {
- my ($dir, $repodir, $remotedir, $seendirs) = @_;
- my $parent = dirname($dir);
- $dir =~ s|/+$||;
- $repodir =~ s|/+$||;
- $remotedir =~ s|/+$||;
- $parent =~ s|/+$||;
- $log->debug("announcedir $dir, $repodir, $remotedir" );
-
- if ($parent eq '.' || $parent eq './') {
- $parent = '';
- }
- # recurse to announce unseen parents first
- if (length($parent) && !exists($seendirs->{$parent})) {
- prepdir($parent, $repodir, $remotedir, $seendirs);
- }
- # Announce that we are going to modify at the parent level
- if ($parent) {
- print "E cvs checkout: Updating $remotedir/$parent\n";
- } else {
- print "E cvs checkout: Updating $remotedir\n";
- }
- print "Clear-sticky $remotedir/$parent/\n";
- print "$repodir/$parent/\n";
-
- print "Clear-static-directory $remotedir/$dir/\n";
- print "$repodir/$dir/\n";
- print "Clear-sticky $remotedir/$parent/\n"; # yes, twice
- print "$repodir/$parent/\n";
- print "Template $remotedir/$dir/\n";
- print "$repodir/$dir/\n";
- print "0\n";
-
- $seendirs->{$dir} = 1;
- }
-
- foreach my $git ( @{$updater->gethead} )
- {
- # Don't want to check out deleted files
- next if ( $git->{filehash} eq "deleted" );
-
- my $fullName = $git->{name};
- ( $git->{name}, $git->{dir} ) = filenamesplit($git->{name});
-
- if (length($git->{dir}) && $git->{dir} ne './'
- && $git->{dir} ne $lastdir ) {
- unless (exists($seendirs{$git->{dir}})) {
- prepdir($git->{dir}, $state->{CVSROOT} . "/$module/",
- $checkout_path, \%seendirs);
- $lastdir = $git->{dir};
- $seendirs{$git->{dir}} = 1;
- }
- print "E cvs checkout: Updating /$checkout_path/$git->{dir}\n";
- }
-
- # modification time of this file
- print "Mod-time $git->{modified}\n";
-
- # print some information to the client
- if ( defined ( $git->{dir} ) and $git->{dir} ne "./" )
- {
- print "M U $checkout_path/$git->{dir}$git->{name}\n";
- } else {
- print "M U $checkout_path/$git->{name}\n";
- }
-
- # instruct client we're sending a file to put in this path
- print "Created $checkout_path/" . ( defined ( $git->{dir} ) and $git->{dir} ne "./" ? $git->{dir} . "/" : "" ) . "\n";
-
- print $state->{CVSROOT} . "/$module/" . ( defined ( $git->{dir} ) and $git->{dir} ne "./" ? $git->{dir} . "/" : "" ) . "$git->{name}\n";
-
- # this is an "entries" line
- my $kopts = kopts_from_path($fullName,"sha1",$git->{filehash});
- print "/$git->{name}/1.$git->{revision}//$kopts/\n";
- # permissions
- print "u=$git->{mode},g=$git->{mode},o=$git->{mode}\n";
-
- # transmit file
- transmitfile($git->{filehash});
- }
-
- print "ok\n";
-
- statecleanup();
-}
-
-# update \n
-# Response expected: yes. Actually do a cvs update command. This uses any
-# previous Argument, Directory, Entry, or Modified requests, if they have
-# been sent. The last Directory sent specifies the working directory at the
-# time of the operation. The -I option is not used--files which the client
-# can decide whether to ignore are not mentioned and the client sends the
-# Questionable request for others.
-sub req_update
-{
- my ( $cmd, $data ) = @_;
-
- $log->debug("req_update : " . ( defined($data) ? $data : "[NULL]" ));
-
- argsplit("update");
-
- #
- # It may just be a client exploring the available heads/modules
- # in that case, list them as top level directories and leave it
- # at that. Eclipse uses this technique to offer you a list of
- # projects (heads in this case) to checkout.
- #
- if ($state->{module} eq '') {
- my $showref = `git show-ref --heads`;
- print "E cvs update: Updating .\n";
- for my $line (split '\n', $showref) {
- if ( $line =~ m% refs/heads/(.*)$% ) {
- print "E cvs update: New directory `$1'\n";
- }
- }
- print "ok\n";
- return 1;
- }
-
-
- # Grab a handle to the SQLite db and do any necessary updates
- my $updater = GITCVS::updater->new($state->{CVSROOT}, $state->{module}, $log);
-
- $updater->update();
-
- argsfromdir($updater);
-
- #$log->debug("update state : " . Dumper($state));
-
- my $last_dirname = "///";
-
- # foreach file specified on the command line ...
- foreach my $filename ( @{$state->{args}} )
- {
- $filename = filecleanup($filename);
-
- $log->debug("Processing file $filename");
-
- unless ( $state->{globaloptions}{-Q} || $state->{globaloptions}{-q} )
- {
- my $cur_dirname = dirname($filename);
- if ( $cur_dirname ne $last_dirname )
- {
- $last_dirname = $cur_dirname;
- if ( $cur_dirname eq "" )
- {
- $cur_dirname = ".";
- }
- print "E cvs update: Updating $cur_dirname\n";
- }
- }
-
- # if we have a -C we should pretend we never saw modified stuff
- if ( exists ( $state->{opt}{C} ) )
- {
- delete $state->{entries}{$filename}{modified_hash};
- delete $state->{entries}{$filename}{modified_filename};
- $state->{entries}{$filename}{unchanged} = 1;
- }
-
- my $meta;
- if ( defined($state->{opt}{r}) and $state->{opt}{r} =~ /^1\.(\d+)/ )
- {
- $meta = $updater->getmeta($filename, $1);
- } else {
- $meta = $updater->getmeta($filename);
- }
-
- # If -p was given, "print" the contents of the requested revision.
- if ( exists ( $state->{opt}{p} ) ) {
- if ( defined ( $meta->{revision} ) ) {
- $log->info("Printing '$filename' revision " . $meta->{revision});
-
- transmitfile($meta->{filehash}, { print => 1 });
- }
-
- next;
- }
-
- if ( ! defined $meta )
- {
- $meta = {
- name => $filename,
- revision => 0,
- filehash => 'added'
- };
- }
-
- my $oldmeta = $meta;
-
- my $wrev = revparse($filename);
-
- # If the working copy is an old revision, lets get that version too for comparison.
- if ( defined($wrev) and $wrev != $meta->{revision} )
- {
- $oldmeta = $updater->getmeta($filename, $wrev);
- }
-
- #$log->debug("Target revision is $meta->{revision}, current working revision is $wrev");
-
- # Files are up to date if the working copy and repo copy have the same revision,
- # and the working copy is unmodified _and_ the user hasn't specified -C
- next if ( defined ( $wrev )
- and defined($meta->{revision})
- and $wrev == $meta->{revision}
- and $state->{entries}{$filename}{unchanged}
- and not exists ( $state->{opt}{C} ) );
-
- # If the working copy and repo copy have the same revision,
- # but the working copy is modified, tell the client it's modified
- if ( defined ( $wrev )
- and defined($meta->{revision})
- and $wrev == $meta->{revision}
- and defined($state->{entries}{$filename}{modified_hash})
- and not exists ( $state->{opt}{C} ) )
- {
- $log->info("Tell the client the file is modified");
- print "MT text M \n";
- print "MT fname $filename\n";
- print "MT newline\n";
- next;
- }
-
- if ( $meta->{filehash} eq "deleted" )
- {
- my ( $filepart, $dirpart ) = filenamesplit($filename,1);
-
- $log->info("Removing '$filename' from working copy (no longer in the repo)");
-
- print "E cvs update: `$filename' is no longer in the repository\n";
- # Don't want to actually _DO_ the update if -n specified
- unless ( $state->{globaloptions}{-n} ) {
- print "Removed $dirpart\n";
- print "$filepart\n";
- }
- }
- elsif ( not defined ( $state->{entries}{$filename}{modified_hash} )
- or $state->{entries}{$filename}{modified_hash} eq $oldmeta->{filehash}
- or $meta->{filehash} eq 'added' )
- {
- # normal update, just send the new revision (either U=Update,
- # or A=Add, or R=Remove)
- if ( defined($wrev) && $wrev < 0 )
- {
- $log->info("Tell the client the file is scheduled for removal");
- print "MT text R \n";
- print "MT fname $filename\n";
- print "MT newline\n";
- next;
- }
- elsif ( (!defined($wrev) || $wrev == 0) && (!defined($meta->{revision}) || $meta->{revision} == 0) )
- {
- $log->info("Tell the client the file is scheduled for addition");
- print "MT text A \n";
- print "MT fname $filename\n";
- print "MT newline\n";
- next;
-
- }
- else {
- $log->info("Updating '$filename' to ".$meta->{revision});
- print "MT +updated\n";
- print "MT text U \n";
- print "MT fname $filename\n";
- print "MT newline\n";
- print "MT -updated\n";
- }
-
- my ( $filepart, $dirpart ) = filenamesplit($filename,1);
-
- # Don't want to actually _DO_ the update if -n specified
- unless ( $state->{globaloptions}{-n} )
- {
- if ( defined ( $wrev ) )
- {
- # instruct client we're sending a file to put in this path as a replacement
- print "Update-existing $dirpart\n";
- $log->debug("Updating existing file 'Update-existing $dirpart'");
- } else {
- # instruct client we're sending a file to put in this path as a new file
- print "Clear-static-directory $dirpart\n";
- print $state->{CVSROOT} . "/$state->{module}/$dirpart\n";
- print "Clear-sticky $dirpart\n";
- print $state->{CVSROOT} . "/$state->{module}/$dirpart\n";
-
- $log->debug("Creating new file 'Created $dirpart'");
- print "Created $dirpart\n";
- }
- print $state->{CVSROOT} . "/$state->{module}/$filename\n";
-
- # this is an "entries" line
- my $kopts = kopts_from_path($filename,"sha1",$meta->{filehash});
- $log->debug("/$filepart/1.$meta->{revision}//$kopts/");
- print "/$filepart/1.$meta->{revision}//$kopts/\n";
-
- # permissions
- $log->debug("SEND : u=$meta->{mode},g=$meta->{mode},o=$meta->{mode}");
- print "u=$meta->{mode},g=$meta->{mode},o=$meta->{mode}\n";
-
- # transmit file
- transmitfile($meta->{filehash});
- }
- } else {
- $log->info("Updating '$filename'");
- my ( $filepart, $dirpart ) = filenamesplit($meta->{name},1);
-
- my $mergeDir = setupTmpDir();
-
- my $file_local = $filepart . ".mine";
- my $mergedFile = "$mergeDir/$file_local";
- system("ln","-s",$state->{entries}{$filename}{modified_filename}, $file_local);
- my $file_old = $filepart . "." . $oldmeta->{revision};
- transmitfile($oldmeta->{filehash}, { targetfile => $file_old });
- my $file_new = $filepart . "." . $meta->{revision};
- transmitfile($meta->{filehash}, { targetfile => $file_new });
-
- # we need to merge with the local changes ( M=successful merge, C=conflict merge )
- $log->info("Merging $file_local, $file_old, $file_new");
- print "M Merging differences between 1.$oldmeta->{revision} and 1.$meta->{revision} into $filename\n";
-
- $log->debug("Temporary directory for merge is $mergeDir");
-
- my $return = system("git", "merge-file", $file_local, $file_old, $file_new);
- $return >>= 8;
-
- cleanupTmpDir();
-
- if ( $return == 0 )
- {
- $log->info("Merged successfully");
- print "M M $filename\n";
- $log->debug("Merged $dirpart");
-
- # Don't want to actually _DO_ the update if -n specified
- unless ( $state->{globaloptions}{-n} )
- {
- print "Merged $dirpart\n";
- $log->debug($state->{CVSROOT} . "/$state->{module}/$filename");
- print $state->{CVSROOT} . "/$state->{module}/$filename\n";
- my $kopts = kopts_from_path("$dirpart/$filepart",
- "file",$mergedFile);
- $log->debug("/$filepart/1.$meta->{revision}//$kopts/");
- print "/$filepart/1.$meta->{revision}//$kopts/\n";
- }
- }
- elsif ( $return == 1 )
- {
- $log->info("Merged with conflicts");
- print "E cvs update: conflicts found in $filename\n";
- print "M C $filename\n";
-
- # Don't want to actually _DO_ the update if -n specified
- unless ( $state->{globaloptions}{-n} )
- {
- print "Merged $dirpart\n";
- print $state->{CVSROOT} . "/$state->{module}/$filename\n";
- my $kopts = kopts_from_path("$dirpart/$filepart",
- "file",$mergedFile);
- print "/$filepart/1.$meta->{revision}/+/$kopts/\n";
- }
- }
- else
- {
- $log->warn("Merge failed");
- next;
- }
-
- # Don't want to actually _DO_ the update if -n specified
- unless ( $state->{globaloptions}{-n} )
- {
- # permissions
- $log->debug("SEND : u=$meta->{mode},g=$meta->{mode},o=$meta->{mode}");
- print "u=$meta->{mode},g=$meta->{mode},o=$meta->{mode}\n";
-
- # transmit file, format is single integer on a line by itself (file
- # size) followed by the file contents
- # TODO : we should copy files in blocks
- my $data = `cat $mergedFile`;
- $log->debug("File size : " . length($data));
- print length($data) . "\n";
- print $data;
- }
- }
-
- }
-
- print "ok\n";
-}
-
-sub req_ci
-{
- my ( $cmd, $data ) = @_;
-
- argsplit("ci");
-
- #$log->debug("State : " . Dumper($state));
-
- $log->info("req_ci : " . ( defined($data) ? $data : "[NULL]" ));
-
- if ( $state->{method} eq 'pserver' and $state->{user} eq 'anonymous' )
- {
- print "error 1 anonymous user cannot commit via pserver\n";
- cleanupWorkTree();
- exit;
- }
-
- if ( -e $state->{CVSROOT} . "/index" )
- {
- $log->warn("file 'index' already exists in the git repository");
- print "error 1 Index already exists in git repo\n";
- cleanupWorkTree();
- exit;
- }
-
- # Grab a handle to the SQLite db and do any necessary updates
- my $updater = GITCVS::updater->new($state->{CVSROOT}, $state->{module}, $log);
- $updater->update();
-
- # Remember where the head was at the beginning.
- my $parenthash = `git show-ref -s refs/heads/$state->{module}`;
- chomp $parenthash;
- if ($parenthash !~ /^[0-9a-f]{40}$/) {
- print "error 1 pserver cannot find the current HEAD of module";
- cleanupWorkTree();
- exit;
- }
-
- setupWorkTree($parenthash);
-
- $log->info("Lockless commit start, basing commit on '$work->{workDir}', index file is '$work->{index}'");
-
- $log->info("Created index '$work->{index}' for head $state->{module} - exit status $?");
-
- my @committedfiles = ();
- my %oldmeta;
-
- # foreach file specified on the command line ...
- foreach my $filename ( @{$state->{args}} )
- {
- my $committedfile = $filename;
- $filename = filecleanup($filename);
-
- next unless ( exists $state->{entries}{$filename}{modified_filename} or not $state->{entries}{$filename}{unchanged} );
-
- my $meta = $updater->getmeta($filename);
- $oldmeta{$filename} = $meta;
-
- my $wrev = revparse($filename);
-
- my ( $filepart, $dirpart ) = filenamesplit($filename);
-
- # do a checkout of the file if it is part of this tree
- if ($wrev) {
- system('git', 'checkout-index', '-f', '-u', $filename);
- unless ($? == 0) {
- die "Error running git-checkout-index -f -u $filename : $!";
- }
- }
-
- my $addflag = 0;
- my $rmflag = 0;
- $rmflag = 1 if ( defined($wrev) and $wrev < 0 );
- $addflag = 1 unless ( -e $filename );
-
- # Do up to date checking
- unless ( $addflag or $wrev == $meta->{revision} or ( $rmflag and -$wrev == $meta->{revision} ) )
- {
- # fail everything if an up to date check fails
- print "error 1 Up to date check failed for $filename\n";
- cleanupWorkTree();
- exit;
- }
-
- push @committedfiles, $committedfile;
- $log->info("Committing $filename");
-
- system("mkdir","-p",$dirpart) unless ( -d $dirpart );
-
- unless ( $rmflag )
- {
- $log->debug("rename $state->{entries}{$filename}{modified_filename} $filename");
- rename $state->{entries}{$filename}{modified_filename},$filename;
-
- # Calculate modes to remove
- my $invmode = "";
- foreach ( qw (r w x) ) { $invmode .= $_ unless ( $state->{entries}{$filename}{modified_mode} =~ /$_/ ); }
-
- $log->debug("chmod u+" . $state->{entries}{$filename}{modified_mode} . "-" . $invmode . " $filename");
- system("chmod","u+" . $state->{entries}{$filename}{modified_mode} . "-" . $invmode, $filename);
- }
-
- if ( $rmflag )
- {
- $log->info("Removing file '$filename'");
- unlink($filename);
- system("git", "update-index", "--remove", $filename);
- }
- elsif ( $addflag )
- {
- $log->info("Adding file '$filename'");
- system("git", "update-index", "--add", $filename);
- } else {
- $log->info("Updating file '$filename'");
- system("git", "update-index", $filename);
- }
- }
-
- unless ( scalar(@committedfiles) > 0 )
- {
- print "E No files to commit\n";
- print "ok\n";
- cleanupWorkTree();
- return;
- }
-
- my $treehash = `git write-tree`;
- chomp $treehash;
-
- $log->debug("Treehash : $treehash, Parenthash : $parenthash");
-
- # write our commit message out if we have one ...
- my ( $msg_fh, $msg_filename ) = tempfile( DIR => $TEMP_DIR );
- print $msg_fh $state->{opt}{m};# if ( exists ( $state->{opt}{m} ) );
- if ( defined ( $cfg->{gitcvs}{commitmsgannotation} ) ) {
- if ($cfg->{gitcvs}{commitmsgannotation} !~ /^\s*$/ ) {
- print $msg_fh "\n\n".$cfg->{gitcvs}{commitmsgannotation}."\n"
- }
- } else {
- print $msg_fh "\n\nvia git-CVS emulator\n";
- }
- close $msg_fh;
-
- my $commithash = `git commit-tree $treehash -p $parenthash < $msg_filename`;
- chomp($commithash);
- $log->info("Commit hash : $commithash");
-
- unless ( $commithash =~ /[a-zA-Z0-9]{40}/ )
- {
- $log->warn("Commit failed (Invalid commit hash)");
- print "error 1 Commit failed (unknown reason)\n";
- cleanupWorkTree();
- exit;
- }
-
- ### Emulate git-receive-pack by running hooks/update
- my @hook = ( $ENV{GIT_DIR}.'hooks/update', "refs/heads/$state->{module}",
- $parenthash, $commithash );
- if( -x $hook[0] ) {
- unless( system( @hook ) == 0 )
- {
- $log->warn("Commit failed (update hook declined to update ref)");
- print "error 1 Commit failed (update hook declined)\n";
- cleanupWorkTree();
- exit;
- }
- }
-
- ### Update the ref
- if (system(qw(git update-ref -m), "cvsserver ci",
- "refs/heads/$state->{module}", $commithash, $parenthash)) {
- $log->warn("update-ref for $state->{module} failed.");
- print "error 1 Cannot commit -- update first\n";
- cleanupWorkTree();
- exit;
- }
-
- ### Emulate git-receive-pack by running hooks/post-receive
- my $hook = $ENV{GIT_DIR}.'hooks/post-receive';
- if( -x $hook ) {
- open(my $pipe, "| $hook") || die "can't fork $!";
-
- local $SIG{PIPE} = sub { die 'pipe broke' };
-
- print $pipe "$parenthash $commithash refs/heads/$state->{module}\n";
-
- close $pipe || die "bad pipe: $! $?";
- }
-
- $updater->update();
-
- ### Then hooks/post-update
- $hook = $ENV{GIT_DIR}.'hooks/post-update';
- if (-x $hook) {
- system($hook, "refs/heads/$state->{module}");
- }
-
- # foreach file specified on the command line ...
- foreach my $filename ( @committedfiles )
- {
- $filename = filecleanup($filename);
-
- my $meta = $updater->getmeta($filename);
- unless (defined $meta->{revision}) {
- $meta->{revision} = 1;
- }
-
- my ( $filepart, $dirpart ) = filenamesplit($filename, 1);
-
- $log->debug("Checked-in $dirpart : $filename");
-
- print "M $state->{CVSROOT}/$state->{module}/$filename,v <-- $dirpart$filepart\n";
- if ( defined $meta->{filehash} && $meta->{filehash} eq "deleted" )
- {
- print "M new revision: delete; previous revision: 1.$oldmeta{$filename}{revision}\n";
- print "Remove-entry $dirpart\n";
- print "$filename\n";
- } else {
- if ($meta->{revision} == 1) {
- print "M initial revision: 1.1\n";
- } else {
- print "M new revision: 1.$meta->{revision}; previous revision: 1.$oldmeta{$filename}{revision}\n";
- }
- print "Checked-in $dirpart\n";
- print "$filename\n";
- my $kopts = kopts_from_path($filename,"sha1",$meta->{filehash});
- print "/$filepart/1.$meta->{revision}//$kopts/\n";
- }
- }
-
- cleanupWorkTree();
- print "ok\n";
-}
-
-sub req_status
-{
- my ( $cmd, $data ) = @_;
-
- argsplit("status");
-
- $log->info("req_status : " . ( defined($data) ? $data : "[NULL]" ));
- #$log->debug("status state : " . Dumper($state));
-
- # Grab a handle to the SQLite db and do any necessary updates
- my $updater = GITCVS::updater->new($state->{CVSROOT}, $state->{module}, $log);
- $updater->update();
-
- # if no files were specified, we need to work out what files we should be providing status on ...
- argsfromdir($updater);
-
- # foreach file specified on the command line ...
- foreach my $filename ( @{$state->{args}} )
- {
- $filename = filecleanup($filename);
-
- next if exists($state->{opt}{l}) && index($filename, '/', length($state->{prependdir})) >= 0;
-
- my $meta = $updater->getmeta($filename);
- my $oldmeta = $meta;
-
- my $wrev = revparse($filename);
-
- # If the working copy is an old revision, lets get that version too for comparison.
- if ( defined($wrev) and $wrev != $meta->{revision} )
- {
- $oldmeta = $updater->getmeta($filename, $wrev);
- }
-
- # TODO : All possible statuses aren't yet implemented
- my $status;
- # Files are up to date if the working copy and repo copy have the same revision, and the working copy is unmodified
- $status = "Up-to-date" if ( defined ( $wrev ) and defined($meta->{revision}) and $wrev == $meta->{revision}
- and
- ( ( $state->{entries}{$filename}{unchanged} and ( not defined ( $state->{entries}{$filename}{conflict} ) or $state->{entries}{$filename}{conflict} !~ /^\+=/ ) )
- or ( defined($state->{entries}{$filename}{modified_hash}) and $state->{entries}{$filename}{modified_hash} eq $meta->{filehash} ) )
- );
-
- # Need checkout if the working copy has an older revision than the repo copy, and the working copy is unmodified
- $status ||= "Needs Checkout" if ( defined ( $wrev ) and defined ( $meta->{revision} ) and $meta->{revision} > $wrev
- and
- ( $state->{entries}{$filename}{unchanged}
- or ( defined($state->{entries}{$filename}{modified_hash}) and $state->{entries}{$filename}{modified_hash} eq $oldmeta->{filehash} ) )
- );
-
- # Need checkout if it exists in the repo but doesn't have a working copy
- $status ||= "Needs Checkout" if ( not defined ( $wrev ) and defined ( $meta->{revision} ) );
-
- # Locally modified if working copy and repo copy have the same revision but there are local changes
- $status ||= "Locally Modified" if ( defined ( $wrev ) and defined($meta->{revision}) and $wrev == $meta->{revision} and $state->{entries}{$filename}{modified_filename} );
-
- # Needs Merge if working copy revision is less than repo copy and there are local changes
- $status ||= "Needs Merge" if ( defined ( $wrev ) and defined ( $meta->{revision} ) and $meta->{revision} > $wrev and $state->{entries}{$filename}{modified_filename} );
-
- $status ||= "Locally Added" if ( defined ( $state->{entries}{$filename}{revision} ) and not defined ( $meta->{revision} ) );
- $status ||= "Locally Removed" if ( defined ( $wrev ) and defined ( $meta->{revision} ) and -$wrev == $meta->{revision} );
- $status ||= "Unresolved Conflict" if ( defined ( $state->{entries}{$filename}{conflict} ) and $state->{entries}{$filename}{conflict} =~ /^\+=/ );
- $status ||= "File had conflicts on merge" if ( 0 );
-
- $status ||= "Unknown";
-
- my ($filepart) = filenamesplit($filename);
-
- print "M ===================================================================\n";
- print "M File: $filepart\tStatus: $status\n";
- if ( defined($state->{entries}{$filename}{revision}) )
- {
- print "M Working revision:\t" . $state->{entries}{$filename}{revision} . "\n";
- } else {
- print "M Working revision:\tNo entry for $filename\n";
- }
- if ( defined($meta->{revision}) )
- {
- print "M Repository revision:\t1." . $meta->{revision} . "\t$state->{CVSROOT}/$state->{module}/$filename,v\n";
- print "M Sticky Tag:\t\t(none)\n";
- print "M Sticky Date:\t\t(none)\n";
- print "M Sticky Options:\t\t(none)\n";
- } else {
- print "M Repository revision:\tNo revision control file\n";
- }
- print "M\n";
- }
-
- print "ok\n";
-}
-
-sub req_diff
-{
- my ( $cmd, $data ) = @_;
-
- argsplit("diff");
-
- $log->debug("req_diff : " . ( defined($data) ? $data : "[NULL]" ));
- #$log->debug("status state : " . Dumper($state));
-
- my ($revision1, $revision2);
- if ( defined ( $state->{opt}{r} ) and ref $state->{opt}{r} eq "ARRAY" )
- {
- $revision1 = $state->{opt}{r}[0];
- $revision2 = $state->{opt}{r}[1];
- } else {
- $revision1 = $state->{opt}{r};
- }
-
- $revision1 =~ s/^1\.// if ( defined ( $revision1 ) );
- $revision2 =~ s/^1\.// if ( defined ( $revision2 ) );
-
- $log->debug("Diffing revisions " . ( defined($revision1) ? $revision1 : "[NULL]" ) . " and " . ( defined($revision2) ? $revision2 : "[NULL]" ) );
-
- # Grab a handle to the SQLite db and do any necessary updates
- my $updater = GITCVS::updater->new($state->{CVSROOT}, $state->{module}, $log);
- $updater->update();
-
- # if no files were specified, we need to work out what files we should be providing status on ...
- argsfromdir($updater);
-
- # foreach file specified on the command line ...
- foreach my $filename ( @{$state->{args}} )
- {
- $filename = filecleanup($filename);
-
- my ( $fh, $file1, $file2, $meta1, $meta2, $filediff );
-
- my $wrev = revparse($filename);
-
- # We need _something_ to diff against
- next unless ( defined ( $wrev ) );
-
- # if we have a -r switch, use it
- if ( defined ( $revision1 ) )
- {
- ( undef, $file1 ) = tempfile( DIR => $TEMP_DIR, OPEN => 0 );
- $meta1 = $updater->getmeta($filename, $revision1);
- unless ( defined ( $meta1 ) and $meta1->{filehash} ne "deleted" )
- {
- print "E File $filename at revision 1.$revision1 doesn't exist\n";
- next;
- }
- transmitfile($meta1->{filehash}, { targetfile => $file1 });
- }
- # otherwise we just use the working copy revision
- else
- {
- ( undef, $file1 ) = tempfile( DIR => $TEMP_DIR, OPEN => 0 );
- $meta1 = $updater->getmeta($filename, $wrev);
- transmitfile($meta1->{filehash}, { targetfile => $file1 });
- }
-
- # if we have a second -r switch, use it too
- if ( defined ( $revision2 ) )
- {
- ( undef, $file2 ) = tempfile( DIR => $TEMP_DIR, OPEN => 0 );
- $meta2 = $updater->getmeta($filename, $revision2);
-
- unless ( defined ( $meta2 ) and $meta2->{filehash} ne "deleted" )
- {
- print "E File $filename at revision 1.$revision2 doesn't exist\n";
- next;
- }
-
- transmitfile($meta2->{filehash}, { targetfile => $file2 });
- }
- # otherwise we just use the working copy
- else
- {
- $file2 = $state->{entries}{$filename}{modified_filename};
- }
-
- # if we have been given -r, and we don't have a $file2 yet, lets get one
- if ( defined ( $revision1 ) and not defined ( $file2 ) )
- {
- ( undef, $file2 ) = tempfile( DIR => $TEMP_DIR, OPEN => 0 );
- $meta2 = $updater->getmeta($filename, $wrev);
- transmitfile($meta2->{filehash}, { targetfile => $file2 });
- }
-
- # We need to have retrieved something useful
- next unless ( defined ( $meta1 ) );
-
- # Files to date if the working copy and repo copy have the same revision, and the working copy is unmodified
- next if ( not defined ( $meta2 ) and $wrev == $meta1->{revision}
- and
- ( ( $state->{entries}{$filename}{unchanged} and ( not defined ( $state->{entries}{$filename}{conflict} ) or $state->{entries}{$filename}{conflict} !~ /^\+=/ ) )
- or ( defined($state->{entries}{$filename}{modified_hash}) and $state->{entries}{$filename}{modified_hash} eq $meta1->{filehash} ) )
- );
-
- # Apparently we only show diffs for locally modified files
- next unless ( defined($meta2) or defined ( $state->{entries}{$filename}{modified_filename} ) );
-
- print "M Index: $filename\n";
- print "M ===================================================================\n";
- print "M RCS file: $state->{CVSROOT}/$state->{module}/$filename,v\n";
- print "M retrieving revision 1.$meta1->{revision}\n" if ( defined ( $meta1 ) );
- print "M retrieving revision 1.$meta2->{revision}\n" if ( defined ( $meta2 ) );
- print "M diff ";
- foreach my $opt ( keys %{$state->{opt}} )
- {
- if ( ref $state->{opt}{$opt} eq "ARRAY" )
- {
- foreach my $value ( @{$state->{opt}{$opt}} )
- {
- print "-$opt $value ";
- }
- } else {
- print "-$opt ";
- print "$state->{opt}{$opt} " if ( defined ( $state->{opt}{$opt} ) );
- }
- }
- print "$filename\n";
-
- $log->info("Diffing $filename -r $meta1->{revision} -r " . ( $meta2->{revision} or "workingcopy" ));
-
- ( $fh, $filediff ) = tempfile ( DIR => $TEMP_DIR );
-
- if ( exists $state->{opt}{u} )
- {
- system("diff -u -L '$filename revision 1.$meta1->{revision}' -L '$filename " . ( defined($meta2->{revision}) ? "revision 1.$meta2->{revision}" : "working copy" ) . "' $file1 $file2 > $filediff");
- } else {
- system("diff $file1 $file2 > $filediff");
- }
-
- while ( <$fh> )
- {
- print "M $_";
- }
- close $fh;
- }
-
- print "ok\n";
-}
-
-sub req_log
-{
- my ( $cmd, $data ) = @_;
-
- argsplit("log");
-
- $log->debug("req_log : " . ( defined($data) ? $data : "[NULL]" ));
- #$log->debug("log state : " . Dumper($state));
-
- my ( $minrev, $maxrev );
- if ( defined ( $state->{opt}{r} ) and $state->{opt}{r} =~ /([\d.]+)?(::?)([\d.]+)?/ )
- {
- my $control = $2;
- $minrev = $1;
- $maxrev = $3;
- $minrev =~ s/^1\.// if ( defined ( $minrev ) );
- $maxrev =~ s/^1\.// if ( defined ( $maxrev ) );
- $minrev++ if ( defined($minrev) and $control eq "::" );
- }
-
- # Grab a handle to the SQLite db and do any necessary updates
- my $updater = GITCVS::updater->new($state->{CVSROOT}, $state->{module}, $log);
- $updater->update();
-
- # if no files were specified, we need to work out what files we should be providing status on ...
- argsfromdir($updater);
-
- # foreach file specified on the command line ...
- foreach my $filename ( @{$state->{args}} )
- {
- $filename = filecleanup($filename);
-
- my $headmeta = $updater->getmeta($filename);
-
- my $revisions = $updater->getlog($filename);
- my $totalrevisions = scalar(@$revisions);
-
- if ( defined ( $minrev ) )
- {
- $log->debug("Removing revisions less than $minrev");
- while ( scalar(@$revisions) > 0 and $revisions->[-1]{revision} < $minrev )
- {
- pop @$revisions;
- }
- }
- if ( defined ( $maxrev ) )
- {
- $log->debug("Removing revisions greater than $maxrev");
- while ( scalar(@$revisions) > 0 and $revisions->[0]{revision} > $maxrev )
- {
- shift @$revisions;
- }
- }
-
- next unless ( scalar(@$revisions) );
-
- print "M \n";
- print "M RCS file: $state->{CVSROOT}/$state->{module}/$filename,v\n";
- print "M Working file: $filename\n";
- print "M head: 1.$headmeta->{revision}\n";
- print "M branch:\n";
- print "M locks: strict\n";
- print "M access list:\n";
- print "M symbolic names:\n";
- print "M keyword substitution: kv\n";
- print "M total revisions: $totalrevisions;\tselected revisions: " . scalar(@$revisions) . "\n";
- print "M description:\n";
-
- foreach my $revision ( @$revisions )
- {
- print "M ----------------------------\n";
- print "M revision 1.$revision->{revision}\n";
- # reformat the date for log output
- $revision->{modified} = sprintf('%04d/%02d/%02d %s', $3, $DATE_LIST->{$2}, $1, $4 ) if ( $revision->{modified} =~ /(\d+)\s+(\w+)\s+(\d+)\s+(\S+)/ and defined($DATE_LIST->{$2}) );
- $revision->{author} = cvs_author($revision->{author});
- print "M date: $revision->{modified}; author: $revision->{author}; state: " . ( $revision->{filehash} eq "deleted" ? "dead" : "Exp" ) . "; lines: +2 -3\n";
- my $commitmessage = $updater->commitmessage($revision->{commithash});
- $commitmessage =~ s/^/M /mg;
- print $commitmessage . "\n";
- }
- print "M =============================================================================\n";
- }
-
- print "ok\n";
-}
-
-sub req_annotate
-{
- my ( $cmd, $data ) = @_;
-
- argsplit("annotate");
-
- $log->info("req_annotate : " . ( defined($data) ? $data : "[NULL]" ));
- #$log->debug("status state : " . Dumper($state));
-
- # Grab a handle to the SQLite db and do any necessary updates
- my $updater = GITCVS::updater->new($state->{CVSROOT}, $state->{module}, $log);
- $updater->update();
-
- # if no files were specified, we need to work out what files we should be providing annotate on ...
- argsfromdir($updater);
-
- # we'll need a temporary checkout dir
- setupWorkTree();
-
- $log->info("Temp checkoutdir creation successful, basing annotate session work on '$work->{workDir}', index file is '$ENV{GIT_INDEX_FILE}'");
-
- # foreach file specified on the command line ...
- foreach my $filename ( @{$state->{args}} )
- {
- $filename = filecleanup($filename);
-
- my $meta = $updater->getmeta($filename);
-
- next unless ( $meta->{revision} );
-
- # get all the commits that this file was in
- # in dense format -- aka skip dead revisions
- my $revisions = $updater->gethistorydense($filename);
- my $lastseenin = $revisions->[0][2];
-
- # populate the temporary index based on the latest commit were we saw
- # the file -- but do it cheaply without checking out any files
- # TODO: if we got a revision from the client, use that instead
- # to look up the commithash in sqlite (still good to default to
- # the current head as we do now)
- system("git", "read-tree", $lastseenin);
- unless ($? == 0)
- {
- print "E error running git-read-tree $lastseenin $ENV{GIT_INDEX_FILE} $!\n";
- return;
- }
- $log->info("Created index '$ENV{GIT_INDEX_FILE}' with commit $lastseenin - exit status $?");
-
- # do a checkout of the file
- system('git', 'checkout-index', '-f', '-u', $filename);
- unless ($? == 0) {
- print "E error running git-checkout-index -f -u $filename : $!\n";
- return;
- }
-
- $log->info("Annotate $filename");
-
- # Prepare a file with the commits from the linearized
- # history that annotate should know about. This prevents
- # git-jsannotate telling us about commits we are hiding
- # from the client.
-
- my $a_hints = "$work->{workDir}/.annotate_hints";
- if (!open(ANNOTATEHINTS, '>', $a_hints)) {
- print "E failed to open '$a_hints' for writing: $!\n";
- return;
- }
- for (my $i=0; $i < @$revisions; $i++)
- {
- print ANNOTATEHINTS $revisions->[$i][2];
- if ($i+1 < @$revisions) { # have we got a parent?
- print ANNOTATEHINTS ' ' . $revisions->[$i+1][2];
- }
- print ANNOTATEHINTS "\n";
- }
-
- print ANNOTATEHINTS "\n";
- close ANNOTATEHINTS
- or (print "E failed to write $a_hints: $!\n"), return;
-
- my @cmd = (qw(git annotate -l -S), $a_hints, $filename);
- if (!open(ANNOTATE, "-|", @cmd)) {
- print "E error invoking ". join(' ',@cmd) .": $!\n";
- return;
- }
- my $metadata = {};
- print "E Annotations for $filename\n";
- print "E ***************\n";
- while ( )
- {
- if (m/^([a-zA-Z0-9]{40})\t\([^\)]*\)(.*)$/i)
- {
- my $commithash = $1;
- my $data = $2;
- unless ( defined ( $metadata->{$commithash} ) )
- {
- $metadata->{$commithash} = $updater->getmeta($filename, $commithash);
- $metadata->{$commithash}{author} = cvs_author($metadata->{$commithash}{author});
- $metadata->{$commithash}{modified} = sprintf("%02d-%s-%02d", $1, $2, $3) if ( $metadata->{$commithash}{modified} =~ /^(\d+)\s(\w+)\s\d\d(\d\d)/ );
- }
- printf("M 1.%-5d (%-8s %10s): %s\n",
- $metadata->{$commithash}{revision},
- $metadata->{$commithash}{author},
- $metadata->{$commithash}{modified},
- $data
- );
- } else {
- $log->warn("Error in annotate output! LINE: $_");
- print "E Annotate error \n";
- next;
- }
- }
- close ANNOTATE;
- }
-
- # done; get out of the tempdir
- cleanupWorkTree();
-
- print "ok\n";
-
-}
-
-# This method takes the state->{arguments} array and produces two new arrays.
-# The first is $state->{args} which is everything before the '--' argument, and
-# the second is $state->{files} which is everything after it.
-sub argsplit
-{
- $state->{args} = [];
- $state->{files} = [];
- $state->{opt} = {};
-
- return unless( defined($state->{arguments}) and ref $state->{arguments} eq "ARRAY" );
-
- my $type = shift;
-
- if ( defined($type) )
- {
- my $opt = {};
- $opt = { A => 0, N => 0, P => 0, R => 0, c => 0, f => 0, l => 0, n => 0, p => 0, s => 0, r => 1, D => 1, d => 1, k => 1, j => 1, } if ( $type eq "co" );
- $opt = { v => 0, l => 0, R => 0 } if ( $type eq "status" );
- $opt = { A => 0, P => 0, C => 0, d => 0, f => 0, l => 0, R => 0, p => 0, k => 1, r => 1, D => 1, j => 1, I => 1, W => 1 } if ( $type eq "update" );
- $opt = { l => 0, R => 0, k => 1, D => 1, D => 1, r => 2 } if ( $type eq "diff" );
- $opt = { c => 0, R => 0, l => 0, f => 0, F => 1, m => 1, r => 1 } if ( $type eq "ci" );
- $opt = { k => 1, m => 1 } if ( $type eq "add" );
- $opt = { f => 0, l => 0, R => 0 } if ( $type eq "remove" );
- $opt = { l => 0, b => 0, h => 0, R => 0, t => 0, N => 0, S => 0, r => 1, d => 1, s => 1, w => 1 } if ( $type eq "log" );
-
-
- while ( scalar ( @{$state->{arguments}} ) > 0 )
- {
- my $arg = shift @{$state->{arguments}};
-
- next if ( $arg eq "--" );
- next unless ( $arg =~ /\S/ );
-
- # if the argument looks like a switch
- if ( $arg =~ /^-(\w)(.*)/ )
- {
- # if it's a switch that takes an argument
- if ( $opt->{$1} )
- {
- # If this switch has already been provided
- if ( $opt->{$1} > 1 and exists ( $state->{opt}{$1} ) )
- {
- $state->{opt}{$1} = [ $state->{opt}{$1} ];
- if ( length($2) > 0 )
- {
- push @{$state->{opt}{$1}},$2;
- } else {
- push @{$state->{opt}{$1}}, shift @{$state->{arguments}};
- }
- } else {
- # if there's extra data in the arg, use that as the argument for the switch
- if ( length($2) > 0 )
- {
- $state->{opt}{$1} = $2;
- } else {
- $state->{opt}{$1} = shift @{$state->{arguments}};
- }
- }
- } else {
- $state->{opt}{$1} = undef;
- }
- }
- else
- {
- push @{$state->{args}}, $arg;
- }
- }
- }
- else
- {
- my $mode = 0;
-
- foreach my $value ( @{$state->{arguments}} )
- {
- if ( $value eq "--" )
- {
- $mode++;
- next;
- }
- push @{$state->{args}}, $value if ( $mode == 0 );
- push @{$state->{files}}, $value if ( $mode == 1 );
- }
- }
-}
-
-# This method uses $state->{directory} to populate $state->{args} with a list of filenames
-sub argsfromdir
-{
- my $updater = shift;
-
- $state->{args} = [] if ( scalar(@{$state->{args}}) == 1 and $state->{args}[0] eq "." );
-
- return if ( scalar ( @{$state->{args}} ) > 1 );
-
- my @gethead = @{$updater->gethead};
-
- # push added files
- foreach my $file (keys %{$state->{entries}}) {
- if ( exists $state->{entries}{$file}{revision} &&
- $state->{entries}{$file}{revision} == 0 )
- {
- push @gethead, { name => $file, filehash => 'added' };
- }
- }
-
- if ( scalar(@{$state->{args}}) == 1 )
- {
- my $arg = $state->{args}[0];
- $arg .= $state->{prependdir} if ( defined ( $state->{prependdir} ) );
-
- $log->info("Only one arg specified, checking for directory expansion on '$arg'");
-
- foreach my $file ( @gethead )
- {
- next if ( $file->{filehash} eq "deleted" and not defined ( $state->{entries}{$file->{name}} ) );
- next unless ( $file->{name} =~ /^$arg\// or $file->{name} eq $arg );
- push @{$state->{args}}, $file->{name};
- }
-
- shift @{$state->{args}} if ( scalar(@{$state->{args}}) > 1 );
- } else {
- $log->info("Only one arg specified, populating file list automatically");
-
- $state->{args} = [];
-
- foreach my $file ( @gethead )
- {
- next if ( $file->{filehash} eq "deleted" and not defined ( $state->{entries}{$file->{name}} ) );
- next unless ( $file->{name} =~ s/^$state->{prependdir}// );
- push @{$state->{args}}, $file->{name};
- }
- }
-}
-
-# This method cleans up the $state variable after a command that uses arguments has run
-sub statecleanup
-{
- $state->{files} = [];
- $state->{args} = [];
- $state->{arguments} = [];
- $state->{entries} = {};
-}
-
-sub revparse
-{
- my $filename = shift;
-
- return undef unless ( defined ( $state->{entries}{$filename}{revision} ) );
-
- return $1 if ( $state->{entries}{$filename}{revision} =~ /^1\.(\d+)/ );
- return -$1 if ( $state->{entries}{$filename}{revision} =~ /^-1\.(\d+)/ );
-
- return undef;
-}
-
-# This method takes a file hash and does a CVS "file transfer". Its
-# exact behaviour depends on a second, optional hash table argument:
-# - If $options->{targetfile}, dump the contents to that file;
-# - If $options->{print}, use M/MT to transmit the contents one line
-# at a time;
-# - Otherwise, transmit the size of the file, followed by the file
-# contents.
-sub transmitfile
-{
- my $filehash = shift;
- my $options = shift;
-
- if ( defined ( $filehash ) and $filehash eq "deleted" )
- {
- $log->warn("filehash is 'deleted'");
- return;
- }
-
- die "Need filehash" unless ( defined ( $filehash ) and $filehash =~ /^[a-zA-Z0-9]{40}$/ );
-
- my $type = `git cat-file -t $filehash`;
- chomp $type;
-
- die ( "Invalid type '$type' (expected 'blob')" ) unless ( defined ( $type ) and $type eq "blob" );
-
- my $size = `git cat-file -s $filehash`;
- chomp $size;
-
- $log->debug("transmitfile($filehash) size=$size, type=$type");
-
- if ( open my $fh, '-|', "git", "cat-file", "blob", $filehash )
- {
- if ( defined ( $options->{targetfile} ) )
- {
- my $targetfile = $options->{targetfile};
- open NEWFILE, ">", $targetfile or die("Couldn't open '$targetfile' for writing : $!");
- print NEWFILE $_ while ( <$fh> );
- close NEWFILE or die("Failed to write '$targetfile': $!");
- } elsif ( defined ( $options->{print} ) && $options->{print} ) {
- while ( <$fh> ) {
- if( /\n\z/ ) {
- print 'M ', $_;
- } else {
- print 'MT text ', $_, "\n";
- }
- }
- } else {
- print "$size\n";
- print while ( <$fh> );
- }
- close $fh or die ("Couldn't close filehandle for transmitfile(): $!");
- } else {
- die("Couldn't execute git-cat-file");
- }
-}
-
-# This method takes a file name, and returns ( $dirpart, $filepart ) which
-# refers to the directory portion and the file portion of the filename
-# respectively
-sub filenamesplit
-{
- my $filename = shift;
- my $fixforlocaldir = shift;
-
- my ( $filepart, $dirpart ) = ( $filename, "." );
- ( $filepart, $dirpart ) = ( $2, $1 ) if ( $filename =~ /(.*)\/(.*)/ );
- $dirpart .= "/";
-
- if ( $fixforlocaldir )
- {
- $dirpart =~ s/^$state->{prependdir}//;
- }
-
- return ( $filepart, $dirpart );
-}
-
-sub filecleanup
-{
- my $filename = shift;
-
- return undef unless(defined($filename));
- if ( $filename =~ /^\// )
- {
- print "E absolute filenames '$filename' not supported by server\n";
- return undef;
- }
-
- $filename =~ s/^\.\///g;
- $filename = $state->{prependdir} . $filename;
- return $filename;
-}
-
-sub validateGitDir
-{
- if( !defined($state->{CVSROOT}) )
- {
- print "error 1 CVSROOT not specified\n";
- cleanupWorkTree();
- exit;
- }
- if( $ENV{GIT_DIR} ne ($state->{CVSROOT} . '/') )
- {
- print "error 1 Internally inconsistent CVSROOT\n";
- cleanupWorkTree();
- exit;
- }
-}
-
-# Setup working directory in a work tree with the requested version
-# loaded in the index.
-sub setupWorkTree
-{
- my ($ver) = @_;
-
- validateGitDir();
-
- if( ( defined($work->{state}) && $work->{state} != 1 ) ||
- defined($work->{tmpDir}) )
- {
- $log->warn("Bad work tree state management");
- print "error 1 Internal setup multiple work trees without cleanup\n";
- cleanupWorkTree();
- exit;
- }
-
- $work->{workDir} = tempdir ( DIR => $TEMP_DIR );
-
- if( !defined($work->{index}) )
- {
- (undef, $work->{index}) = tempfile ( DIR => $TEMP_DIR, OPEN => 0 );
- }
-
- chdir $work->{workDir} or
- die "Unable to chdir to $work->{workDir}\n";
-
- $log->info("Setting up GIT_WORK_TREE as '.' in '$work->{workDir}', index file is '$work->{index}'");
-
- $ENV{GIT_WORK_TREE} = ".";
- $ENV{GIT_INDEX_FILE} = $work->{index};
- $work->{state} = 2;
-
- if($ver)
- {
- system("git","read-tree",$ver);
- unless ($? == 0)
- {
- $log->warn("Error running git-read-tree");
- die "Error running git-read-tree $ver in $work->{workDir} $!\n";
- }
- }
- # else # req_annotate reads tree for each file
-}
-
-# Ensure current directory is in some kind of working directory,
-# with a recent version loaded in the index.
-sub ensureWorkTree
-{
- if( defined($work->{tmpDir}) )
- {
- $log->warn("Bad work tree state management [ensureWorkTree()]");
- print "error 1 Internal setup multiple dirs without cleanup\n";
- cleanupWorkTree();
- exit;
- }
- if( $work->{state} )
- {
- return;
- }
-
- validateGitDir();
-
- if( !defined($work->{emptyDir}) )
- {
- $work->{emptyDir} = tempdir ( DIR => $TEMP_DIR, OPEN => 0);
- }
- chdir $work->{emptyDir} or
- die "Unable to chdir to $work->{emptyDir}\n";
-
- my $ver = `git show-ref -s refs/heads/$state->{module}`;
- chomp $ver;
- if ($ver !~ /^[0-9a-f]{40}$/)
- {
- $log->warn("Error from git show-ref -s refs/head$state->{module}");
- print "error 1 cannot find the current HEAD of module";
- cleanupWorkTree();
- exit;
- }
-
- if( !defined($work->{index}) )
- {
- (undef, $work->{index}) = tempfile ( DIR => $TEMP_DIR, OPEN => 0 );
- }
-
- $ENV{GIT_WORK_TREE} = ".";
- $ENV{GIT_INDEX_FILE} = $work->{index};
- $work->{state} = 1;
-
- system("git","read-tree",$ver);
- unless ($? == 0)
- {
- die "Error running git-read-tree $ver $!\n";
- }
-}
-
-# Cleanup working directory that is not needed any longer.
-sub cleanupWorkTree
-{
- if( ! $work->{state} )
- {
- return;
- }
-
- chdir "/" or die "Unable to chdir '/'\n";
-
- if( defined($work->{workDir}) )
- {
- rmtree( $work->{workDir} );
- undef $work->{workDir};
- }
- undef $work->{state};
-}
-
-# Setup a temporary directory (not a working tree), typically for
-# merging dirty state as in req_update.
-sub setupTmpDir
-{
- $work->{tmpDir} = tempdir ( DIR => $TEMP_DIR );
- chdir $work->{tmpDir} or die "Unable to chdir $work->{tmpDir}\n";
-
- return $work->{tmpDir};
-}
-
-# Clean up a previously setupTmpDir. Restore previous work tree if
-# appropriate.
-sub cleanupTmpDir
-{
- if ( !defined($work->{tmpDir}) )
- {
- $log->warn("cleanup tmpdir that has not been setup");
- die "Cleanup tmpDir that has not been setup\n";
- }
- if( defined($work->{state}) )
- {
- if( $work->{state} == 1 )
- {
- chdir $work->{emptyDir} or
- die "Unable to chdir to $work->{emptyDir}\n";
- }
- elsif( $work->{state} == 2 )
- {
- chdir $work->{workDir} or
- die "Unable to chdir to $work->{emptyDir}\n";
- }
- else
- {
- $log->warn("Inconsistent work dir state");
- die "Inconsistent work dir state\n";
- }
- }
- else
- {
- chdir "/" or die "Unable to chdir '/'\n";
- }
-}
-
-# Given a path, this function returns a string containing the kopts
-# that should go into that path's Entries line. For example, a binary
-# file should get -kb.
-sub kopts_from_path
-{
- my ($path, $srcType, $name) = @_;
-
- if ( defined ( $cfg->{gitcvs}{usecrlfattr} ) and
- $cfg->{gitcvs}{usecrlfattr} =~ /\s*(1|true|yes)\s*$/i )
- {
- my ($val) = check_attr( "text", $path );
- if ( $val eq "unspecified" )
- {
- $val = check_attr( "crlf", $path );
- }
- if ( $val eq "unset" )
- {
- return "-kb"
- }
- elsif ( check_attr( "eol", $path ) ne "unspecified" ||
- $val eq "set" || $val eq "input" )
- {
- return "";
- }
- else
- {
- $log->info("Unrecognized check_attr crlf $path : $val");
- }
- }
-
- if ( defined ( $cfg->{gitcvs}{allbinary} ) )
- {
- if( ($cfg->{gitcvs}{allbinary} =~ /^\s*(1|true|yes)\s*$/i) )
- {
- return "-kb";
- }
- elsif( ($cfg->{gitcvs}{allbinary} =~ /^\s*guess\s*$/i) )
- {
- if( $srcType eq "sha1Or-k" &&
- !defined($name) )
- {
- my ($ret)=$state->{entries}{$path}{options};
- if( !defined($ret) )
- {
- $ret=$state->{opt}{k};
- if(defined($ret))
- {
- $ret="-k$ret";
- }
- else
- {
- $ret="";
- }
- }
- if( ! ($ret=~/^(|-kb|-kkv|-kkvl|-kk|-ko|-kv)$/) )
- {
- print "E Bad -k option\n";
- $log->warn("Bad -k option: $ret");
- die "Error: Bad -k option: $ret\n";
- }
-
- return $ret;
- }
- else
- {
- if( is_binary($srcType,$name) )
- {
- $log->debug("... as binary");
- return "-kb";
- }
- else
- {
- $log->debug("... as text");
- }
- }
- }
- }
- # Return "" to give no special treatment to any path
- return "";
-}
-
-sub check_attr
-{
- my ($attr,$path) = @_;
- ensureWorkTree();
- if ( open my $fh, '-|', "git", "check-attr", $attr, "--", $path )
- {
- my $val = <$fh>;
- close $fh;
- $val =~ s/.*: ([^:\r\n]*)\s*$/$1/;
- return $val;
- }
- else
- {
- return undef;
- }
-}
-
-# This should have the same heuristics as convert.c:is_binary() and related.
-# Note that the bare CR test is done by callers in convert.c.
-sub is_binary
-{
- my ($srcType,$name) = @_;
- $log->debug("is_binary($srcType,$name)");
-
- # Minimize amount of interpreted code run in the inner per-character
- # loop for large files, by totalling each character value and
- # then analyzing the totals.
- my @counts;
- my $i;
- for($i=0;$i<256;$i++)
- {
- $counts[$i]=0;
- }
-
- my $fh = open_blob_or_die($srcType,$name);
- my $line;
- while( defined($line=<$fh>) )
- {
- # Any '\0' and bare CR are considered binary.
- if( $line =~ /\0|(\r[^\n])/ )
- {
- close($fh);
- return 1;
- }
-
- # Count up each character in the line:
- my $len=length($line);
- for($i=0;$i<$len;$i++)
- {
- $counts[ord(substr($line,$i,1))]++;
- }
- }
- close $fh;
-
- # Don't count CR and LF as either printable/nonprintable
- $counts[ord("\n")]=0;
- $counts[ord("\r")]=0;
-
- # Categorize individual character count into printable and nonprintable:
- my $printable=0;
- my $nonprintable=0;
- for($i=0;$i<256;$i++)
- {
- if( $i < 32 &&
- $i != ord("\b") &&
- $i != ord("\t") &&
- $i != 033 && # ESC
- $i != 014 ) # FF
- {
- $nonprintable+=$counts[$i];
- }
- elsif( $i==127 ) # DEL
- {
- $nonprintable+=$counts[$i];
- }
- else
- {
- $printable+=$counts[$i];
- }
- }
-
- return ($printable >> 7) < $nonprintable;
-}
-
-# Returns open file handle. Possible invocations:
-# - open_blob_or_die("file",$filename);
-# - open_blob_or_die("sha1",$filehash);
-sub open_blob_or_die
-{
- my ($srcType,$name) = @_;
- my ($fh);
- if( $srcType eq "file" )
- {
- if( !open $fh,"<",$name )
- {
- $log->warn("Unable to open file $name: $!");
- die "Unable to open file $name: $!\n";
- }
- }
- elsif( $srcType eq "sha1" || $srcType eq "sha1Or-k" )
- {
- unless ( defined ( $name ) and $name =~ /^[a-zA-Z0-9]{40}$/ )
- {
- $log->warn("Need filehash");
- die "Need filehash\n";
- }
-
- my $type = `git cat-file -t $name`;
- chomp $type;
-
- unless ( defined ( $type ) and $type eq "blob" )
- {
- $log->warn("Invalid type '$type' for '$name'");
- die ( "Invalid type '$type' (expected 'blob')" )
- }
-
- my $size = `git cat-file -s $name`;
- chomp $size;
-
- $log->debug("open_blob_or_die($name) size=$size, type=$type");
-
- unless( open $fh, '-|', "git", "cat-file", "blob", $name )
- {
- $log->warn("Unable to open sha1 $name");
- die "Unable to open sha1 $name\n";
- }
- }
- else
- {
- $log->warn("Unknown type of blob source: $srcType");
- die "Unknown type of blob source: $srcType\n";
- }
- return $fh;
-}
-
-# Generate a CVS author name from Git author information, by taking the local
-# part of the email address and replacing characters not in the Portable
-# Filename Character Set (see IEEE Std 1003.1-2001, 3.276) by underscores. CVS
-# Login names are Unix login names, which should be restricted to this
-# character set.
-sub cvs_author
-{
- my $author_line = shift;
- (my $author) = $author_line =~ /<([^@>]*)/;
-
- $author =~ s/[^-a-zA-Z0-9_.]/_/g;
- $author =~ s/^-/_/;
-
- $author;
-}
-
-
-sub descramble
-{
- # This table is from src/scramble.c in the CVS source
- my @SHIFTS = (
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
- 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
- 114,120, 53, 79, 96,109, 72,108, 70, 64, 76, 67,116, 74, 68, 87,
- 111, 52, 75,119, 49, 34, 82, 81, 95, 65,112, 86,118,110,122,105,
- 41, 57, 83, 43, 46,102, 40, 89, 38,103, 45, 50, 42,123, 91, 35,
- 125, 55, 54, 66,124,126, 59, 47, 92, 71,115, 78, 88,107,106, 56,
- 36,121,117,104,101,100, 69, 73, 99, 63, 94, 93, 39, 37, 61, 48,
- 58,113, 32, 90, 44, 98, 60, 51, 33, 97, 62, 77, 84, 80, 85,223,
- 225,216,187,166,229,189,222,188,141,249,148,200,184,136,248,190,
- 199,170,181,204,138,232,218,183,255,234,220,247,213,203,226,193,
- 174,172,228,252,217,201,131,230,197,211,145,238,161,179,160,212,
- 207,221,254,173,202,146,224,151,140,196,205,130,135,133,143,246,
- 192,159,244,239,185,168,215,144,139,165,180,157,147,186,214,176,
- 227,231,219,169,175,156,206,198,129,164,150,210,154,177,134,127,
- 182,128,158,208,162,132,167,209,149,241,153,251,237,236,171,195,
- 243,233,253,240,194,250,191,155,142,137,245,235,163,242,178,152
- );
- my ($str) = @_;
-
- # This should never happen, the same password format (A) has been
- # used by CVS since the beginning of time
- {
- my $fmt = substr($str, 0, 1);
- die "invalid password format `$fmt'" unless $fmt eq 'A';
- }
-
- my @str = unpack "C*", substr($str, 1);
- my $ret = join '', map { chr $SHIFTS[$_] } @str;
- return $ret;
-}
-
-
-package GITCVS::log;
-
-####
-#### Copyright The Open University UK - 2006.
-####
-#### Authors: Martyn Smith
-#### Martin Langhoff
-####
-####
-
-use strict;
-use warnings;
-
-=head1 NAME
-
-GITCVS::log
-
-=head1 DESCRIPTION
-
-This module provides very crude logging with a similar interface to
-Log::Log4perl
-
-=head1 METHODS
-
-=cut
-
-=head2 new
-
-Creates a new log object, optionally you can specify a filename here to
-indicate the file to log to. If no log file is specified, you can specify one
-later with method setfile, or indicate you no longer want logging with method
-nofile.
-
-Until one of these methods is called, all log calls will buffer messages ready
-to write out.
-
-=cut
-sub new
-{
- my $class = shift;
- my $filename = shift;
-
- my $self = {};
-
- bless $self, $class;
-
- if ( defined ( $filename ) )
- {
- open $self->{fh}, ">>", $filename or die("Couldn't open '$filename' for writing : $!");
- }
-
- return $self;
-}
-
-=head2 setfile
-
-This methods takes a filename, and attempts to open that file as the log file.
-If successful, all buffered data is written out to the file, and any further
-logging is written directly to the file.
-
-=cut
-sub setfile
-{
- my $self = shift;
- my $filename = shift;
-
- if ( defined ( $filename ) )
- {
- open $self->{fh}, ">>", $filename or die("Couldn't open '$filename' for writing : $!");
- }
-
- return unless ( defined ( $self->{buffer} ) and ref $self->{buffer} eq "ARRAY" );
-
- while ( my $line = shift @{$self->{buffer}} )
- {
- print {$self->{fh}} $line;
- }
-}
-
-=head2 nofile
-
-This method indicates no logging is going to be used. It flushes any entries in
-the internal buffer, and sets a flag to ensure no further data is put there.
-
-=cut
-sub nofile
-{
- my $self = shift;
-
- $self->{nolog} = 1;
-
- return unless ( defined ( $self->{buffer} ) and ref $self->{buffer} eq "ARRAY" );
-
- $self->{buffer} = [];
-}
-
-=head2 _logopen
-
-Internal method. Returns true if the log file is open, false otherwise.
-
-=cut
-sub _logopen
-{
- my $self = shift;
-
- return 1 if ( defined ( $self->{fh} ) and ref $self->{fh} eq "GLOB" );
- return 0;
-}
-
-=head2 debug info warn fatal
-
-These four methods are wrappers to _log. They provide the actual interface for
-logging data.
-
-=cut
-sub debug { my $self = shift; $self->_log("debug", @_); }
-sub info { my $self = shift; $self->_log("info" , @_); }
-sub warn { my $self = shift; $self->_log("warn" , @_); }
-sub fatal { my $self = shift; $self->_log("fatal", @_); }
-
-=head2 _log
-
-This is an internal method called by the logging functions. It generates a
-timestamp and pushes the logged line either to file, or internal buffer.
-
-=cut
-sub _log
-{
- my $self = shift;
- my $level = shift;
-
- return if ( $self->{nolog} );
-
- my @time = localtime;
- my $timestring = sprintf("%4d-%02d-%02d %02d:%02d:%02d : %-5s",
- $time[5] + 1900,
- $time[4] + 1,
- $time[3],
- $time[2],
- $time[1],
- $time[0],
- uc $level,
- );
-
- if ( $self->_logopen )
- {
- print {$self->{fh}} $timestring . " - " . join(" ",@_) . "\n";
- } else {
- push @{$self->{buffer}}, $timestring . " - " . join(" ",@_) . "\n";
- }
-}
-
-=head2 DESTROY
-
-This method simply closes the file handle if one is open
-
-=cut
-sub DESTROY
-{
- my $self = shift;
-
- if ( $self->_logopen )
- {
- close $self->{fh};
- }
-}
-
-package GITCVS::updater;
-
-####
-#### Copyright The Open University UK - 2006.
-####
-#### Authors: Martyn Smith
-#### Martin Langhoff
-####
-####
-
-use strict;
-use warnings;
-use DBI;
-
-=head1 METHODS
-
-=cut
-
-=head2 new
-
-=cut
-sub new
-{
- my $class = shift;
- my $config = shift;
- my $module = shift;
- my $log = shift;
-
- die "Need to specify a git repository" unless ( defined($config) and -d $config );
- die "Need to specify a module" unless ( defined($module) );
-
- $class = ref($class) || $class;
-
- my $self = {};
-
- bless $self, $class;
-
- $self->{valid_tables} = {'revision' => 1,
- 'revision_ix1' => 1,
- 'revision_ix2' => 1,
- 'head' => 1,
- 'head_ix1' => 1,
- 'properties' => 1,
- 'commitmsgs' => 1};
-
- $self->{module} = $module;
- $self->{git_path} = $config . "/";
-
- $self->{log} = $log;
-
- die "Git repo '$self->{git_path}' doesn't exist" unless ( -d $self->{git_path} );
-
- $self->{dbdriver} = $cfg->{gitcvs}{$state->{method}}{dbdriver} ||
- $cfg->{gitcvs}{dbdriver} || "SQLite";
- $self->{dbname} = $cfg->{gitcvs}{$state->{method}}{dbname} ||
- $cfg->{gitcvs}{dbname} || "%Ggitcvs.%m.sqlite";
- $self->{dbuser} = $cfg->{gitcvs}{$state->{method}}{dbuser} ||
- $cfg->{gitcvs}{dbuser} || "";
- $self->{dbpass} = $cfg->{gitcvs}{$state->{method}}{dbpass} ||
- $cfg->{gitcvs}{dbpass} || "";
- $self->{dbtablenameprefix} = $cfg->{gitcvs}{$state->{method}}{dbtablenameprefix} ||
- $cfg->{gitcvs}{dbtablenameprefix} || "";
- my %mapping = ( m => $module,
- a => $state->{method},
- u => getlogin || getpwuid($<) || $<,
- G => $self->{git_path},
- g => mangle_dirname($self->{git_path}),
- );
- $self->{dbname} =~ s/%([mauGg])/$mapping{$1}/eg;
- $self->{dbuser} =~ s/%([mauGg])/$mapping{$1}/eg;
- $self->{dbtablenameprefix} =~ s/%([mauGg])/$mapping{$1}/eg;
- $self->{dbtablenameprefix} = mangle_tablename($self->{dbtablenameprefix});
-
- die "Invalid char ':' in dbdriver" if $self->{dbdriver} =~ /:/;
- die "Invalid char ';' in dbname" if $self->{dbname} =~ /;/;
- $self->{dbh} = DBI->connect("dbi:$self->{dbdriver}:dbname=$self->{dbname}",
- $self->{dbuser},
- $self->{dbpass});
- die "Error connecting to database\n" unless defined $self->{dbh};
-
- $self->{tables} = {};
- foreach my $table ( keys %{$self->{dbh}->table_info(undef,undef,undef,'TABLE')->fetchall_hashref('TABLE_NAME')} )
- {
- $self->{tables}{$table} = 1;
- }
-
- # Construct the revision table if required
- unless ( $self->{tables}{$self->tablename("revision")} )
- {
- my $tablename = $self->tablename("revision");
- my $ix1name = $self->tablename("revision_ix1");
- my $ix2name = $self->tablename("revision_ix2");
- $self->{dbh}->do("
- CREATE TABLE $tablename (
- name TEXT NOT NULL,
- revision INTEGER NOT NULL,
- filehash TEXT NOT NULL,
- commithash TEXT NOT NULL,
- author TEXT NOT NULL,
- modified TEXT NOT NULL,
- mode TEXT NOT NULL
- )
- ");
- $self->{dbh}->do("
- CREATE INDEX $ix1name
- ON $tablename (name,revision)
- ");
- $self->{dbh}->do("
- CREATE INDEX $ix2name
- ON $tablename (name,commithash)
- ");
- }
-
- # Construct the head table if required
- unless ( $self->{tables}{$self->tablename("head")} )
- {
- my $tablename = $self->tablename("head");
- my $ix1name = $self->tablename("head_ix1");
- $self->{dbh}->do("
- CREATE TABLE $tablename (
- name TEXT NOT NULL,
- revision INTEGER NOT NULL,
- filehash TEXT NOT NULL,
- commithash TEXT NOT NULL,
- author TEXT NOT NULL,
- modified TEXT NOT NULL,
- mode TEXT NOT NULL
- )
- ");
- $self->{dbh}->do("
- CREATE INDEX $ix1name
- ON $tablename (name)
- ");
- }
-
- # Construct the properties table if required
- unless ( $self->{tables}{$self->tablename("properties")} )
- {
- my $tablename = $self->tablename("properties");
- $self->{dbh}->do("
- CREATE TABLE $tablename (
- key TEXT NOT NULL PRIMARY KEY,
- value TEXT
- )
- ");
- }
-
- # Construct the commitmsgs table if required
- unless ( $self->{tables}{$self->tablename("commitmsgs")} )
- {
- my $tablename = $self->tablename("commitmsgs");
- $self->{dbh}->do("
- CREATE TABLE $tablename (
- key TEXT NOT NULL PRIMARY KEY,
- value TEXT
- )
- ");
- }
-
- return $self;
-}
-
-=head2 tablename
-
-=cut
-sub tablename
-{
- my $self = shift;
- my $name = shift;
-
- if (exists $self->{valid_tables}{$name}) {
- return $self->{dbtablenameprefix} . $name;
- } else {
- return undef;
- }
-}
-
-=head2 update
-
-=cut
-sub update
-{
- my $self = shift;
-
- # first lets get the commit list
- $ENV{GIT_DIR} = $self->{git_path};
-
- my $commitsha1 = `git rev-parse $self->{module}`;
- chomp $commitsha1;
-
- my $commitinfo = `git cat-file commit $self->{module} 2>&1`;
- unless ( $commitinfo =~ /tree\s+[a-zA-Z0-9]{40}/ )
- {
- die("Invalid module '$self->{module}'");
- }
-
-
- my $git_log;
- my $lastcommit = $self->_get_prop("last_commit");
-
- if (defined $lastcommit && $lastcommit eq $commitsha1) { # up-to-date
- return 1;
- }
-
- # Start exclusive lock here...
- $self->{dbh}->begin_work() or die "Cannot lock database for BEGIN";
-
- # TODO: log processing is memory bound
- # if we can parse into a 2nd file that is in reverse order
- # we can probably do something really efficient
- my @git_log_params = ('--pretty', '--parents', '--topo-order');
-
- if (defined $lastcommit) {
- push @git_log_params, "$lastcommit..$self->{module}";
- } else {
- push @git_log_params, $self->{module};
- }
- # git-rev-list is the backend / plumbing version of git-log
- open(GITLOG, '-|', 'git', 'rev-list', @git_log_params) or die "Cannot call git-rev-list: $!";
-
- my @commits;
-
- my %commit = ();
-
- while ( )
- {
- chomp;
- if (m/^commit\s+(.*)$/) {
- # on ^commit lines put the just seen commit in the stack
- # and prime things for the next one
- if (keys %commit) {
- my %copy = %commit;
- unshift @commits, \%copy;
- %commit = ();
- }
- my @parents = split(m/\s+/, $1);
- $commit{hash} = shift @parents;
- $commit{parents} = \@parents;
- } elsif (m/^(\w+?):\s+(.*)$/ && !exists($commit{message})) {
- # on rfc822-like lines seen before we see any message,
- # lowercase the entry and put it in the hash as key-value
- $commit{lc($1)} = $2;
- } else {
- # message lines - skip initial empty line
- # and trim whitespace
- if (!exists($commit{message}) && m/^\s*$/) {
- # define it to mark the end of headers
- $commit{message} = '';
- next;
- }
- s/^\s+//; s/\s+$//; # trim ws
- $commit{message} .= $_ . "\n";
- }
- }
- close GITLOG;
-
- unshift @commits, \%commit if ( keys %commit );
-
- # Now all the commits are in the @commits bucket
- # ordered by time DESC. for each commit that needs processing,
- # determine whether it's following the last head we've seen or if
- # it's on its own branch, grab a file list, and add whatever's changed
- # NOTE: $lastcommit refers to the last commit from previous run
- # $lastpicked is the last commit we picked in this run
- my $lastpicked;
- my $head = {};
- if (defined $lastcommit) {
- $lastpicked = $lastcommit;
- }
-
- my $committotal = scalar(@commits);
- my $commitcount = 0;
-
- # Load the head table into $head (for cached lookups during the update process)
- foreach my $file ( @{$self->gethead()} )
- {
- $head->{$file->{name}} = $file;
- }
-
- foreach my $commit ( @commits )
- {
- $self->{log}->debug("GITCVS::updater - Processing commit $commit->{hash} (" . (++$commitcount) . " of $committotal)");
- if (defined $lastpicked)
- {
- if (!in_array($lastpicked, @{$commit->{parents}}))
- {
- # skip, we'll see this delta
- # as part of a merge later
- # warn "skipping off-track $commit->{hash}\n";
- next;
- } elsif (@{$commit->{parents}} > 1) {
- # it is a merge commit, for each parent that is
- # not $lastpicked, see if we can get a log
- # from the merge-base to that parent to put it
- # in the message as a merge summary.
- my @parents = @{$commit->{parents}};
- foreach my $parent (@parents) {
- # git-merge-base can potentially (but rarely) throw
- # several candidate merge bases. let's assume
- # that the first one is the best one.
- if ($parent eq $lastpicked) {
- next;
- }
- my $base = eval {
- safe_pipe_capture('git', 'merge-base',
- $lastpicked, $parent);
- };
- # The two branches may not be related at all,
- # in which case merge base simply fails to find
- # any, but that's Ok.
- next if ($@);
-
- chomp $base;
- if ($base) {
- my @merged;
- # print "want to log between $base $parent \n";
- open(GITLOG, '-|', 'git', 'log', '--pretty=medium', "$base..$parent")
- or die "Cannot call git-log: $!";
- my $mergedhash;
- while () {
- chomp;
- if (!defined $mergedhash) {
- if (m/^commit\s+(.+)$/) {
- $mergedhash = $1;
- } else {
- next;
- }
- } else {
- # grab the first line that looks non-rfc822
- # aka has content after leading space
- if (m/^\s+(\S.*)$/) {
- my $title = $1;
- $title = substr($title,0,100); # truncate
- unshift @merged, "$mergedhash $title";
- undef $mergedhash;
- }
- }
- }
- close GITLOG;
- if (@merged) {
- $commit->{mergemsg} = $commit->{message};
- $commit->{mergemsg} .= "\nSummary of merged commits:\n\n";
- foreach my $summary (@merged) {
- $commit->{mergemsg} .= "\t$summary\n";
- }
- $commit->{mergemsg} .= "\n\n";
- # print "Message for $commit->{hash} \n$commit->{mergemsg}";
- }
- }
- }
- }
- }
-
- # convert the date to CVS-happy format
- $commit->{date} = "$2 $1 $4 $3 $5" if ( $commit->{date} =~ /^\w+\s+(\w+)\s+(\d+)\s+(\d+:\d+:\d+)\s+(\d+)\s+([+-]\d+)$/ );
-
- if ( defined ( $lastpicked ) )
- {
- my $filepipe = open(FILELIST, '-|', 'git', 'diff-tree', '-z', '-r', $lastpicked, $commit->{hash}) or die("Cannot call git-diff-tree : $!");
- local ($/) = "\0";
- while ( )
- {
- chomp;
- unless ( /^:\d{6}\s+\d{3}(\d)\d{2}\s+[a-zA-Z0-9]{40}\s+([a-zA-Z0-9]{40})\s+(\w)$/o )
- {
- die("Couldn't process git-diff-tree line : $_");
- }
- my ($mode, $hash, $change) = ($1, $2, $3);
- my $name = ;
- chomp($name);
-
- # $log->debug("File mode=$mode, hash=$hash, change=$change, name=$name");
-
- my $git_perms = "";
- $git_perms .= "r" if ( $mode & 4 );
- $git_perms .= "w" if ( $mode & 2 );
- $git_perms .= "x" if ( $mode & 1 );
- $git_perms = "rw" if ( $git_perms eq "" );
-
- if ( $change eq "D" )
- {
- #$log->debug("DELETE $name");
- $head->{$name} = {
- name => $name,
- revision => $head->{$name}{revision} + 1,
- filehash => "deleted",
- commithash => $commit->{hash},
- modified => $commit->{date},
- author => $commit->{author},
- mode => $git_perms,
- };
- $self->insert_rev($name, $head->{$name}{revision}, $hash, $commit->{hash}, $commit->{date}, $commit->{author}, $git_perms);
- }
- elsif ( $change eq "M" || $change eq "T" )
- {
- #$log->debug("MODIFIED $name");
- $head->{$name} = {
- name => $name,
- revision => $head->{$name}{revision} + 1,
- filehash => $hash,
- commithash => $commit->{hash},
- modified => $commit->{date},
- author => $commit->{author},
- mode => $git_perms,
- };
- $self->insert_rev($name, $head->{$name}{revision}, $hash, $commit->{hash}, $commit->{date}, $commit->{author}, $git_perms);
- }
- elsif ( $change eq "A" )
- {
- #$log->debug("ADDED $name");
- $head->{$name} = {
- name => $name,
- revision => $head->{$name}{revision} ? $head->{$name}{revision}+1 : 1,
- filehash => $hash,
- commithash => $commit->{hash},
- modified => $commit->{date},
- author => $commit->{author},
- mode => $git_perms,
- };
- $self->insert_rev($name, $head->{$name}{revision}, $hash, $commit->{hash}, $commit->{date}, $commit->{author}, $git_perms);
- }
- else
- {
- $log->warn("UNKNOWN FILE CHANGE mode=$mode, hash=$hash, change=$change, name=$name");
- die;
- }
- }
- close FILELIST;
- } else {
- # this is used to detect files removed from the repo
- my $seen_files = {};
-
- my $filepipe = open(FILELIST, '-|', 'git', 'ls-tree', '-z', '-r', $commit->{hash}) or die("Cannot call git-ls-tree : $!");
- local $/ = "\0";
- while ( )
- {
- chomp;
- unless ( /^(\d+)\s+(\w+)\s+([a-zA-Z0-9]+)\t(.*)$/o )
- {
- die("Couldn't process git-ls-tree line : $_");
- }
-
- my ( $git_perms, $git_type, $git_hash, $git_filename ) = ( $1, $2, $3, $4 );
-
- $seen_files->{$git_filename} = 1;
-
- my ( $oldhash, $oldrevision, $oldmode ) = (
- $head->{$git_filename}{filehash},
- $head->{$git_filename}{revision},
- $head->{$git_filename}{mode}
- );
-
- if ( $git_perms =~ /^\d\d\d(\d)\d\d/o )
- {
- $git_perms = "";
- $git_perms .= "r" if ( $1 & 4 );
- $git_perms .= "w" if ( $1 & 2 );
- $git_perms .= "x" if ( $1 & 1 );
- } else {
- $git_perms = "rw";
- }
-
- # unless the file exists with the same hash, we need to update it ...
- unless ( defined($oldhash) and $oldhash eq $git_hash and defined($oldmode) and $oldmode eq $git_perms )
- {
- my $newrevision = ( $oldrevision or 0 ) + 1;
-
- $head->{$git_filename} = {
- name => $git_filename,
- revision => $newrevision,
- filehash => $git_hash,
- commithash => $commit->{hash},
- modified => $commit->{date},
- author => $commit->{author},
- mode => $git_perms,
- };
-
-
- $self->insert_rev($git_filename, $newrevision, $git_hash, $commit->{hash}, $commit->{date}, $commit->{author}, $git_perms);
- }
- }
- close FILELIST;
-
- # Detect deleted files
- foreach my $file ( keys %$head )
- {
- unless ( exists $seen_files->{$file} or $head->{$file}{filehash} eq "deleted" )
- {
- $head->{$file}{revision}++;
- $head->{$file}{filehash} = "deleted";
- $head->{$file}{commithash} = $commit->{hash};
- $head->{$file}{modified} = $commit->{date};
- $head->{$file}{author} = $commit->{author};
-
- $self->insert_rev($file, $head->{$file}{revision}, $head->{$file}{filehash}, $commit->{hash}, $commit->{date}, $commit->{author}, $head->{$file}{mode});
- }
- }
- # END : "Detect deleted files"
- }
-
-
- if (exists $commit->{mergemsg})
- {
- $self->insert_mergelog($commit->{hash}, $commit->{mergemsg});
- }
-
- $lastpicked = $commit->{hash};
-
- $self->_set_prop("last_commit", $commit->{hash});
- }
-
- $self->delete_head();
- foreach my $file ( keys %$head )
- {
- $self->insert_head(
- $file,
- $head->{$file}{revision},
- $head->{$file}{filehash},
- $head->{$file}{commithash},
- $head->{$file}{modified},
- $head->{$file}{author},
- $head->{$file}{mode},
- );
- }
- # invalidate the gethead cache
- $self->{gethead_cache} = undef;
-
-
- # Ending exclusive lock here
- $self->{dbh}->commit() or die "Failed to commit changes to SQLite";
-}
-
-sub insert_rev
-{
- my $self = shift;
- my $name = shift;
- my $revision = shift;
- my $filehash = shift;
- my $commithash = shift;
- my $modified = shift;
- my $author = shift;
- my $mode = shift;
- my $tablename = $self->tablename("revision");
-
- my $insert_rev = $self->{dbh}->prepare_cached("INSERT INTO $tablename (name, revision, filehash, commithash, modified, author, mode) VALUES (?,?,?,?,?,?,?)",{},1);
- $insert_rev->execute($name, $revision, $filehash, $commithash, $modified, $author, $mode);
-}
-
-sub insert_mergelog
-{
- my $self = shift;
- my $key = shift;
- my $value = shift;
- my $tablename = $self->tablename("commitmsgs");
-
- my $insert_mergelog = $self->{dbh}->prepare_cached("INSERT INTO $tablename (key, value) VALUES (?,?)",{},1);
- $insert_mergelog->execute($key, $value);
-}
-
-sub delete_head
-{
- my $self = shift;
- my $tablename = $self->tablename("head");
-
- my $delete_head = $self->{dbh}->prepare_cached("DELETE FROM $tablename",{},1);
- $delete_head->execute();
-}
-
-sub insert_head
-{
- my $self = shift;
- my $name = shift;
- my $revision = shift;
- my $filehash = shift;
- my $commithash = shift;
- my $modified = shift;
- my $author = shift;
- my $mode = shift;
- my $tablename = $self->tablename("head");
-
- my $insert_head = $self->{dbh}->prepare_cached("INSERT INTO $tablename (name, revision, filehash, commithash, modified, author, mode) VALUES (?,?,?,?,?,?,?)",{},1);
- $insert_head->execute($name, $revision, $filehash, $commithash, $modified, $author, $mode);
-}
-
-sub _headrev
-{
- my $self = shift;
- my $filename = shift;
- my $tablename = $self->tablename("head");
-
- my $db_query = $self->{dbh}->prepare_cached("SELECT filehash, revision, mode FROM $tablename WHERE name=?",{},1);
- $db_query->execute($filename);
- my ( $hash, $revision, $mode ) = $db_query->fetchrow_array;
-
- return ( $hash, $revision, $mode );
-}
-
-sub _get_prop
-{
- my $self = shift;
- my $key = shift;
- my $tablename = $self->tablename("properties");
-
- my $db_query = $self->{dbh}->prepare_cached("SELECT value FROM $tablename WHERE key=?",{},1);
- $db_query->execute($key);
- my ( $value ) = $db_query->fetchrow_array;
-
- return $value;
-}
-
-sub _set_prop
-{
- my $self = shift;
- my $key = shift;
- my $value = shift;
- my $tablename = $self->tablename("properties");
-
- my $db_query = $self->{dbh}->prepare_cached("UPDATE $tablename SET value=? WHERE key=?",{},1);
- $db_query->execute($value, $key);
-
- unless ( $db_query->rows )
- {
- $db_query = $self->{dbh}->prepare_cached("INSERT INTO $tablename (key, value) VALUES (?,?)",{},1);
- $db_query->execute($key, $value);
- }
-
- return $value;
-}
-
-=head2 gethead
-
-=cut
-
-sub gethead
-{
- my $self = shift;
- my $tablename = $self->tablename("head");
-
- return $self->{gethead_cache} if ( defined ( $self->{gethead_cache} ) );
-
- my $db_query = $self->{dbh}->prepare_cached("SELECT name, filehash, mode, revision, modified, commithash, author FROM $tablename ORDER BY name ASC",{},1);
- $db_query->execute();
-
- my $tree = [];
- while ( my $file = $db_query->fetchrow_hashref )
- {
- push @$tree, $file;
- }
-
- $self->{gethead_cache} = $tree;
-
- return $tree;
-}
-
-=head2 getlog
-
-=cut
-
-sub getlog
-{
- my $self = shift;
- my $filename = shift;
- my $tablename = $self->tablename("revision");
-
- my $db_query = $self->{dbh}->prepare_cached("SELECT name, filehash, author, mode, revision, modified, commithash FROM $tablename WHERE name=? ORDER BY revision DESC",{},1);
- $db_query->execute($filename);
-
- my $tree = [];
- while ( my $file = $db_query->fetchrow_hashref )
- {
- push @$tree, $file;
- }
-
- return $tree;
-}
-
-=head2 getmeta
-
-This function takes a filename (with path) argument and returns a hashref of
-metadata for that file.
-
-=cut
-
-sub getmeta
-{
- my $self = shift;
- my $filename = shift;
- my $revision = shift;
- my $tablename_rev = $self->tablename("revision");
- my $tablename_head = $self->tablename("head");
-
- my $db_query;
- if ( defined($revision) and $revision =~ /^\d+$/ )
- {
- $db_query = $self->{dbh}->prepare_cached("SELECT * FROM $tablename_rev WHERE name=? AND revision=?",{},1);
- $db_query->execute($filename, $revision);
- }
- elsif ( defined($revision) and $revision =~ /^[a-zA-Z0-9]{40}$/ )
- {
- $db_query = $self->{dbh}->prepare_cached("SELECT * FROM $tablename_rev WHERE name=? AND commithash=?",{},1);
- $db_query->execute($filename, $revision);
- } else {
- $db_query = $self->{dbh}->prepare_cached("SELECT * FROM $tablename_head WHERE name=?",{},1);
- $db_query->execute($filename);
- }
-
- return $db_query->fetchrow_hashref;
-}
-
-=head2 commitmessage
-
-this function takes a commithash and returns the commit message for that commit
-
-=cut
-sub commitmessage
-{
- my $self = shift;
- my $commithash = shift;
- my $tablename = $self->tablename("commitmsgs");
-
- die("Need commithash") unless ( defined($commithash) and $commithash =~ /^[a-zA-Z0-9]{40}$/ );
-
- my $db_query;
- $db_query = $self->{dbh}->prepare_cached("SELECT value FROM $tablename WHERE key=?",{},1);
- $db_query->execute($commithash);
-
- my ( $message ) = $db_query->fetchrow_array;
-
- if ( defined ( $message ) )
- {
- $message .= " " if ( $message =~ /\n$/ );
- return $message;
- }
-
- my @lines = safe_pipe_capture("git", "cat-file", "commit", $commithash);
- shift @lines while ( $lines[0] =~ /\S/ );
- $message = join("",@lines);
- $message .= " " if ( $message =~ /\n$/ );
- return $message;
-}
-
-=head2 gethistory
-
-This function takes a filename (with path) argument and returns an arrayofarrays
-containing revision,filehash,commithash ordered by revision descending
-
-=cut
-sub gethistory
-{
- my $self = shift;
- my $filename = shift;
- my $tablename = $self->tablename("revision");
-
- my $db_query;
- $db_query = $self->{dbh}->prepare_cached("SELECT revision, filehash, commithash FROM $tablename WHERE name=? ORDER BY revision DESC",{},1);
- $db_query->execute($filename);
-
- return $db_query->fetchall_arrayref;
-}
-
-=head2 gethistorydense
-
-This function takes a filename (with path) argument and returns an arrayofarrays
-containing revision,filehash,commithash ordered by revision descending.
-
-This version of gethistory skips deleted entries -- so it is useful for annotate.
-The 'dense' part is a reference to a '--dense' option available for git-rev-list
-and other git tools that depend on it.
-
-=cut
-sub gethistorydense
-{
- my $self = shift;
- my $filename = shift;
- my $tablename = $self->tablename("revision");
-
- my $db_query;
- $db_query = $self->{dbh}->prepare_cached("SELECT revision, filehash, commithash FROM $tablename WHERE name=? AND filehash!='deleted' ORDER BY revision DESC",{},1);
- $db_query->execute($filename);
-
- return $db_query->fetchall_arrayref;
-}
-
-=head2 in_array()
-
-from Array::PAT - mimics the in_array() function
-found in PHP. Yuck but works for small arrays.
-
-=cut
-sub in_array
-{
- my ($check, @array) = @_;
- my $retval = 0;
- foreach my $test (@array){
- if($check eq $test){
- $retval = 1;
- }
- }
- return $retval;
-}
-
-=head2 safe_pipe_capture
-
-an alternative to `command` that allows input to be passed as an array
-to work around shell problems with weird characters in arguments
-
-=cut
-sub safe_pipe_capture {
-
- my @output;
-
- if (my $pid = open my $child, '-|') {
- @output = (<$child>);
- close $child or die join(' ',@_).": $! $?";
- } else {
- exec(@_) or die "$! $?"; # exec() can fail the executable can't be found
- }
- return wantarray ? @output : join('',@output);
-}
-
-=head2 mangle_dirname
-
-create a string from a directory name that is suitable to use as
-part of a filename, mainly by converting all chars except \w.- to _
-
-=cut
-sub mangle_dirname {
- my $dirname = shift;
- return unless defined $dirname;
-
- $dirname =~ s/[^\w.-]/_/g;
-
- return $dirname;
-}
-
-=head2 mangle_tablename
-
-create a string from a that is suitable to use as part of an SQL table
-name, mainly by converting all chars except \w to _
-
-=cut
-sub mangle_tablename {
- my $tablename = shift;
- return unless defined $tablename;
-
- $tablename =~ s/[^\w_]/_/g;
-
- return $tablename;
-}
-
-1;
diff --git a/SparkleShare/Mac/git/bin/git-receive-pack b/SparkleShare/Mac/git/bin/git-receive-pack
deleted file mode 120000
index 0899c299..00000000
--- a/SparkleShare/Mac/git/bin/git-receive-pack
+++ /dev/null
@@ -1 +0,0 @@
-git
\ No newline at end of file
diff --git a/SparkleShare/Mac/git/bin/git-shell b/SparkleShare/Mac/git/bin/git-shell
deleted file mode 100755
index 647fe452..00000000
Binary files a/SparkleShare/Mac/git/bin/git-shell and /dev/null differ
diff --git a/SparkleShare/Mac/git/bin/git-upload-archive b/SparkleShare/Mac/git/bin/git-upload-archive
deleted file mode 120000
index 0899c299..00000000
--- a/SparkleShare/Mac/git/bin/git-upload-archive
+++ /dev/null
@@ -1 +0,0 @@
-git
\ No newline at end of file
diff --git a/SparkleShare/Mac/git/bin/git-upload-pack b/SparkleShare/Mac/git/bin/git-upload-pack
deleted file mode 100755
index 3cc4e6db..00000000
Binary files a/SparkleShare/Mac/git/bin/git-upload-pack and /dev/null differ
diff --git a/SparkleShare/Mac/git/bin/gitk b/SparkleShare/Mac/git/bin/gitk
deleted file mode 100755
index 4cde0c49..00000000
--- a/SparkleShare/Mac/git/bin/gitk
+++ /dev/null
@@ -1,11702 +0,0 @@
-#!/bin/sh
-# Tcl ignores the next line -*- tcl -*- \
-exec wish "$0" -- "$@"
-
-# Copyright © 2005-2009 Paul Mackerras. All rights reserved.
-# This program 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.
-
-package require Tk
-
-proc gitdir {} {
- global env
- if {[info exists env(GIT_DIR)]} {
- return $env(GIT_DIR)
- } else {
- return [exec git rev-parse --git-dir]
- }
-}
-
-# A simple scheduler for compute-intensive stuff.
-# The aim is to make sure that event handlers for GUI actions can
-# run at least every 50-100 ms. Unfortunately fileevent handlers are
-# run before X event handlers, so reading from a fast source can
-# make the GUI completely unresponsive.
-proc run args {
- global isonrunq runq currunq
-
- set script $args
- if {[info exists isonrunq($script)]} return
- if {$runq eq {} && ![info exists currunq]} {
- after idle dorunq
- }
- lappend runq [list {} $script]
- set isonrunq($script) 1
-}
-
-proc filerun {fd script} {
- fileevent $fd readable [list filereadable $fd $script]
-}
-
-proc filereadable {fd script} {
- global runq currunq
-
- fileevent $fd readable {}
- if {$runq eq {} && ![info exists currunq]} {
- after idle dorunq
- }
- lappend runq [list $fd $script]
-}
-
-proc nukefile {fd} {
- global runq
-
- for {set i 0} {$i < [llength $runq]} {} {
- if {[lindex $runq $i 0] eq $fd} {
- set runq [lreplace $runq $i $i]
- } else {
- incr i
- }
- }
-}
-
-proc dorunq {} {
- global isonrunq runq currunq
-
- set tstart [clock clicks -milliseconds]
- set t0 $tstart
- while {[llength $runq] > 0} {
- set fd [lindex $runq 0 0]
- set script [lindex $runq 0 1]
- set currunq [lindex $runq 0]
- set runq [lrange $runq 1 end]
- set repeat [eval $script]
- unset currunq
- set t1 [clock clicks -milliseconds]
- set t [expr {$t1 - $t0}]
- if {$repeat ne {} && $repeat} {
- if {$fd eq {} || $repeat == 2} {
- # script returns 1 if it wants to be readded
- # file readers return 2 if they could do more straight away
- lappend runq [list $fd $script]
- } else {
- fileevent $fd readable [list filereadable $fd $script]
- }
- } elseif {$fd eq {}} {
- unset isonrunq($script)
- }
- set t0 $t1
- if {$t1 - $tstart >= 80} break
- }
- if {$runq ne {}} {
- after idle dorunq
- }
-}
-
-proc reg_instance {fd} {
- global commfd leftover loginstance
-
- set i [incr loginstance]
- set commfd($i) $fd
- set leftover($i) {}
- return $i
-}
-
-proc unmerged_files {files} {
- global nr_unmerged
-
- # find the list of unmerged files
- set mlist {}
- set nr_unmerged 0
- if {[catch {
- set fd [open "| git ls-files -u" r]
- } err]} {
- show_error {} . "[mc "Couldn't get list of unmerged files:"] $err"
- exit 1
- }
- while {[gets $fd line] >= 0} {
- set i [string first "\t" $line]
- if {$i < 0} continue
- set fname [string range $line [expr {$i+1}] end]
- if {[lsearch -exact $mlist $fname] >= 0} continue
- incr nr_unmerged
- if {$files eq {} || [path_filter $files $fname]} {
- lappend mlist $fname
- }
- }
- catch {close $fd}
- return $mlist
-}
-
-proc parseviewargs {n arglist} {
- global vdatemode vmergeonly vflags vdflags vrevs vfiltered vorigargs env
- global worddiff git_version
-
- set vdatemode($n) 0
- set vmergeonly($n) 0
- set glflags {}
- set diffargs {}
- set nextisval 0
- set revargs {}
- set origargs $arglist
- set allknown 1
- set filtered 0
- set i -1
- foreach arg $arglist {
- incr i
- if {$nextisval} {
- lappend glflags $arg
- set nextisval 0
- continue
- }
- switch -glob -- $arg {
- "-d" -
- "--date-order" {
- set vdatemode($n) 1
- # remove from origargs in case we hit an unknown option
- set origargs [lreplace $origargs $i $i]
- incr i -1
- }
- "-[puabwcrRBMC]" -
- "--no-renames" - "--full-index" - "--binary" - "--abbrev=*" -
- "--find-copies-harder" - "-l*" - "--ext-diff" - "--no-ext-diff" -
- "--src-prefix=*" - "--dst-prefix=*" - "--no-prefix" -
- "-O*" - "--text" - "--full-diff" - "--ignore-space-at-eol" -
- "--ignore-space-change" - "-U*" - "--unified=*" {
- # These request or affect diff output, which we don't want.
- # Some could be used to set our defaults for diff display.
- lappend diffargs $arg
- }
- "--raw" - "--patch-with-raw" - "--patch-with-stat" -
- "--name-only" - "--name-status" - "--color" -
- "--log-size" - "--pretty=*" - "--decorate" - "--abbrev-commit" -
- "--cc" - "-z" - "--header" - "--parents" - "--boundary" -
- "--no-color" - "-g" - "--walk-reflogs" - "--no-walk" -
- "--timestamp" - "relative-date" - "--date=*" - "--stdin" -
- "--objects" - "--objects-edge" - "--reverse" {
- # These cause our parsing of git log's output to fail, or else
- # they're options we want to set ourselves, so ignore them.
- }
- "--color-words*" - "--word-diff=color" {
- # These trigger a word diff in the console interface,
- # so help the user by enabling our own support
- if {[package vcompare $git_version "1.7.2"] >= 0} {
- set worddiff [mc "Color words"]
- }
- }
- "--word-diff*" {
- if {[package vcompare $git_version "1.7.2"] >= 0} {
- set worddiff [mc "Markup words"]
- }
- }
- "--stat=*" - "--numstat" - "--shortstat" - "--summary" -
- "--check" - "--exit-code" - "--quiet" - "--topo-order" -
- "--full-history" - "--dense" - "--sparse" -
- "--follow" - "--left-right" - "--encoding=*" {
- # These are harmless, and some are even useful
- lappend glflags $arg
- }
- "--diff-filter=*" - "--no-merges" - "--unpacked" -
- "--max-count=*" - "--skip=*" - "--since=*" - "--after=*" -
- "--until=*" - "--before=*" - "--max-age=*" - "--min-age=*" -
- "--author=*" - "--committer=*" - "--grep=*" - "-[iE]" -
- "--remove-empty" - "--first-parent" - "--cherry-pick" -
- "-S*" - "--pickaxe-all" - "--pickaxe-regex" -
- "--simplify-by-decoration" {
- # These mean that we get a subset of the commits
- set filtered 1
- lappend glflags $arg
- }
- "-n" {
- # This appears to be the only one that has a value as a
- # separate word following it
- set filtered 1
- set nextisval 1
- lappend glflags $arg
- }
- "--not" - "--all" {
- lappend revargs $arg
- }
- "--merge" {
- set vmergeonly($n) 1
- # git rev-parse doesn't understand --merge
- lappend revargs --gitk-symmetric-diff-marker MERGE_HEAD...HEAD
- }
- "--no-replace-objects" {
- set env(GIT_NO_REPLACE_OBJECTS) "1"
- }
- "-*" {
- # Other flag arguments including -
- if {[string is digit -strict [string range $arg 1 end]]} {
- set filtered 1
- } else {
- # a flag argument that we don't recognize;
- # that means we can't optimize
- set allknown 0
- }
- lappend glflags $arg
- }
- default {
- # Non-flag arguments specify commits or ranges of commits
- if {[string match "*...*" $arg]} {
- lappend revargs --gitk-symmetric-diff-marker
- }
- lappend revargs $arg
- }
- }
- }
- set vdflags($n) $diffargs
- set vflags($n) $glflags
- set vrevs($n) $revargs
- set vfiltered($n) $filtered
- set vorigargs($n) $origargs
- return $allknown
-}
-
-proc parseviewrevs {view revs} {
- global vposids vnegids
-
- if {$revs eq {}} {
- set revs HEAD
- }
- if {[catch {set ids [eval exec git rev-parse $revs]} err]} {
- # we get stdout followed by stderr in $err
- # for an unknown rev, git rev-parse echoes it and then errors out
- set errlines [split $err "\n"]
- set badrev {}
- for {set l 0} {$l < [llength $errlines]} {incr l} {
- set line [lindex $errlines $l]
- if {!([string length $line] == 40 && [string is xdigit $line])} {
- if {[string match "fatal:*" $line]} {
- if {[string match "fatal: ambiguous argument*" $line]
- && $badrev ne {}} {
- if {[llength $badrev] == 1} {
- set err "unknown revision $badrev"
- } else {
- set err "unknown revisions: [join $badrev ", "]"
- }
- } else {
- set err [join [lrange $errlines $l end] "\n"]
- }
- break
- }
- lappend badrev $line
- }
- }
- error_popup "[mc "Error parsing revisions:"] $err"
- return {}
- }
- set ret {}
- set pos {}
- set neg {}
- set sdm 0
- foreach id [split $ids "\n"] {
- if {$id eq "--gitk-symmetric-diff-marker"} {
- set sdm 4
- } elseif {[string match "^*" $id]} {
- if {$sdm != 1} {
- lappend ret $id
- if {$sdm == 3} {
- set sdm 0
- }
- }
- lappend neg [string range $id 1 end]
- } else {
- if {$sdm != 2} {
- lappend ret $id
- } else {
- lset ret end $id...[lindex $ret end]
- }
- lappend pos $id
- }
- incr sdm -1
- }
- set vposids($view) $pos
- set vnegids($view) $neg
- return $ret
-}
-
-# Start off a git log process and arrange to read its output
-proc start_rev_list {view} {
- global startmsecs commitidx viewcomplete curview
- global tclencoding
- global viewargs viewargscmd viewfiles vfilelimit
- global showlocalchanges
- global viewactive viewinstances vmergeonly
- global mainheadid viewmainheadid viewmainheadid_orig
- global vcanopt vflags vrevs vorigargs
- global show_notes
-
- set startmsecs [clock clicks -milliseconds]
- set commitidx($view) 0
- # these are set this way for the error exits
- set viewcomplete($view) 1
- set viewactive($view) 0
- varcinit $view
-
- set args $viewargs($view)
- if {$viewargscmd($view) ne {}} {
- if {[catch {
- set str [exec sh -c $viewargscmd($view)]
- } err]} {
- error_popup "[mc "Error executing --argscmd command:"] $err"
- return 0
- }
- set args [concat $args [split $str "\n"]]
- }
- set vcanopt($view) [parseviewargs $view $args]
-
- set files $viewfiles($view)
- if {$vmergeonly($view)} {
- set files [unmerged_files $files]
- if {$files eq {}} {
- global nr_unmerged
- if {$nr_unmerged == 0} {
- error_popup [mc "No files selected: --merge specified but\
- no files are unmerged."]
- } else {
- error_popup [mc "No files selected: --merge specified but\
- no unmerged files are within file limit."]
- }
- return 0
- }
- }
- set vfilelimit($view) $files
-
- if {$vcanopt($view)} {
- set revs [parseviewrevs $view $vrevs($view)]
- if {$revs eq {}} {
- return 0
- }
- set args [concat $vflags($view) $revs]
- } else {
- set args $vorigargs($view)
- }
-
- if {[catch {
- set fd [open [concat | git log --no-color -z --pretty=raw $show_notes \
- --parents --boundary $args "--" $files] r]
- } err]} {
- error_popup "[mc "Error executing git log:"] $err"
- return 0
- }
- set i [reg_instance $fd]
- set viewinstances($view) [list $i]
- set viewmainheadid($view) $mainheadid
- set viewmainheadid_orig($view) $mainheadid
- if {$files ne {} && $mainheadid ne {}} {
- get_viewmainhead $view
- }
- if {$showlocalchanges && $viewmainheadid($view) ne {}} {
- interestedin $viewmainheadid($view) dodiffindex
- }
- fconfigure $fd -blocking 0 -translation lf -eofchar {}
- if {$tclencoding != {}} {
- fconfigure $fd -encoding $tclencoding
- }
- filerun $fd [list getcommitlines $fd $i $view 0]
- nowbusy $view [mc "Reading"]
- set viewcomplete($view) 0
- set viewactive($view) 1
- return 1
-}
-
-proc stop_instance {inst} {
- global commfd leftover
-
- set fd $commfd($inst)
- catch {
- set pid [pid $fd]
-
- if {$::tcl_platform(platform) eq {windows}} {
- exec kill -f $pid
- } else {
- exec kill $pid
- }
- }
- catch {close $fd}
- nukefile $fd
- unset commfd($inst)
- unset leftover($inst)
-}
-
-proc stop_backends {} {
- global commfd
-
- foreach inst [array names commfd] {
- stop_instance $inst
- }
-}
-
-proc stop_rev_list {view} {
- global viewinstances
-
- foreach inst $viewinstances($view) {
- stop_instance $inst
- }
- set viewinstances($view) {}
-}
-
-proc reset_pending_select {selid} {
- global pending_select mainheadid selectheadid
-
- if {$selid ne {}} {
- set pending_select $selid
- } elseif {$selectheadid ne {}} {
- set pending_select $selectheadid
- } else {
- set pending_select $mainheadid
- }
-}
-
-proc getcommits {selid} {
- global canv curview need_redisplay viewactive
-
- initlayout
- if {[start_rev_list $curview]} {
- reset_pending_select $selid
- show_status [mc "Reading commits..."]
- set need_redisplay 1
- } else {
- show_status [mc "No commits selected"]
- }
-}
-
-proc updatecommits {} {
- global curview vcanopt vorigargs vfilelimit viewinstances
- global viewactive viewcomplete tclencoding
- global startmsecs showneartags showlocalchanges
- global mainheadid viewmainheadid viewmainheadid_orig pending_select
- global isworktree
- global varcid vposids vnegids vflags vrevs
- global show_notes
-
- set isworktree [expr {[exec git rev-parse --is-inside-work-tree] == "true"}]
- rereadrefs
- set view $curview
- if {$mainheadid ne $viewmainheadid_orig($view)} {
- if {$showlocalchanges} {
- dohidelocalchanges
- }
- set viewmainheadid($view) $mainheadid
- set viewmainheadid_orig($view) $mainheadid
- if {$vfilelimit($view) ne {}} {
- get_viewmainhead $view
- }
- }
- if {$showlocalchanges} {
- doshowlocalchanges
- }
- if {$vcanopt($view)} {
- set oldpos $vposids($view)
- set oldneg $vnegids($view)
- set revs [parseviewrevs $view $vrevs($view)]
- if {$revs eq {}} {
- return
- }
- # note: getting the delta when negative refs change is hard,
- # and could require multiple git log invocations, so in that
- # case we ask git log for all the commits (not just the delta)
- if {$oldneg eq $vnegids($view)} {
- set newrevs {}
- set npos 0
- # take out positive refs that we asked for before or
- # that we have already seen
- foreach rev $revs {
- if {[string length $rev] == 40} {
- if {[lsearch -exact $oldpos $rev] < 0
- && ![info exists varcid($view,$rev)]} {
- lappend newrevs $rev
- incr npos
- }
- } else {
- lappend $newrevs $rev
- }
- }
- if {$npos == 0} return
- set revs $newrevs
- set vposids($view) [lsort -unique [concat $oldpos $vposids($view)]]
- }
- set args [concat $vflags($view) $revs --not $oldpos]
- } else {
- set args $vorigargs($view)
- }
- if {[catch {
- set fd [open [concat | git log --no-color -z --pretty=raw $show_notes \
- --parents --boundary $args "--" $vfilelimit($view)] r]
- } err]} {
- error_popup "[mc "Error executing git log:"] $err"
- return
- }
- if {$viewactive($view) == 0} {
- set startmsecs [clock clicks -milliseconds]
- }
- set i [reg_instance $fd]
- lappend viewinstances($view) $i
- fconfigure $fd -blocking 0 -translation lf -eofchar {}
- if {$tclencoding != {}} {
- fconfigure $fd -encoding $tclencoding
- }
- filerun $fd [list getcommitlines $fd $i $view 1]
- incr viewactive($view)
- set viewcomplete($view) 0
- reset_pending_select {}
- nowbusy $view [mc "Reading"]
- if {$showneartags} {
- getallcommits
- }
-}
-
-proc reloadcommits {} {
- global curview viewcomplete selectedline currentid thickerline
- global showneartags treediffs commitinterest cached_commitrow
- global targetid
-
- set selid {}
- if {$selectedline ne {}} {
- set selid $currentid
- }
-
- if {!$viewcomplete($curview)} {
- stop_rev_list $curview
- }
- resetvarcs $curview
- set selectedline {}
- catch {unset currentid}
- catch {unset thickerline}
- catch {unset treediffs}
- readrefs
- changedrefs
- if {$showneartags} {
- getallcommits
- }
- clear_display
- catch {unset commitinterest}
- catch {unset cached_commitrow}
- catch {unset targetid}
- setcanvscroll
- getcommits $selid
- return 0
-}
-
-# This makes a string representation of a positive integer which
-# sorts as a string in numerical order
-proc strrep {n} {
- if {$n < 16} {
- return [format "%x" $n]
- } elseif {$n < 256} {
- return [format "x%.2x" $n]
- } elseif {$n < 65536} {
- return [format "y%.4x" $n]
- }
- return [format "z%.8x" $n]
-}
-
-# Procedures used in reordering commits from git log (without
-# --topo-order) into the order for display.
-
-proc varcinit {view} {
- global varcstart vupptr vdownptr vleftptr vbackptr varctok varcrow
- global vtokmod varcmod vrowmod varcix vlastins
-
- set varcstart($view) {{}}
- set vupptr($view) {0}
- set vdownptr($view) {0}
- set vleftptr($view) {0}
- set vbackptr($view) {0}
- set varctok($view) {{}}
- set varcrow($view) {{}}
- set vtokmod($view) {}
- set varcmod($view) 0
- set vrowmod($view) 0
- set varcix($view) {{}}
- set vlastins($view) {0}
-}
-
-proc resetvarcs {view} {
- global varcid varccommits parents children vseedcount ordertok
-
- foreach vid [array names varcid $view,*] {
- unset varcid($vid)
- unset children($vid)
- unset parents($vid)
- }
- # some commits might have children but haven't been seen yet
- foreach vid [array names children $view,*] {
- unset children($vid)
- }
- foreach va [array names varccommits $view,*] {
- unset varccommits($va)
- }
- foreach vd [array names vseedcount $view,*] {
- unset vseedcount($vd)
- }
- catch {unset ordertok}
-}
-
-# returns a list of the commits with no children
-proc seeds {v} {
- global vdownptr vleftptr varcstart
-
- set ret {}
- set a [lindex $vdownptr($v) 0]
- while {$a != 0} {
- lappend ret [lindex $varcstart($v) $a]
- set a [lindex $vleftptr($v) $a]
- }
- return $ret
-}
-
-proc newvarc {view id} {
- global varcid varctok parents children vdatemode
- global vupptr vdownptr vleftptr vbackptr varcrow varcix varcstart
- global commitdata commitinfo vseedcount varccommits vlastins
-
- set a [llength $varctok($view)]
- set vid $view,$id
- if {[llength $children($vid)] == 0 || $vdatemode($view)} {
- if {![info exists commitinfo($id)]} {
- parsecommit $id $commitdata($id) 1
- }
- set cdate [lindex $commitinfo($id) 4]
- if {![string is integer -strict $cdate]} {
- set cdate 0
- }
- if {![info exists vseedcount($view,$cdate)]} {
- set vseedcount($view,$cdate) -1
- }
- set c [incr vseedcount($view,$cdate)]
- set cdate [expr {$cdate ^ 0xffffffff}]
- set tok "s[strrep $cdate][strrep $c]"
- } else {
- set tok {}
- }
- set ka 0
- if {[llength $children($vid)] > 0} {
- set kid [lindex $children($vid) end]
- set k $varcid($view,$kid)
- if {[string compare [lindex $varctok($view) $k] $tok] > 0} {
- set ki $kid
- set ka $k
- set tok [lindex $varctok($view) $k]
- }
- }
- if {$ka != 0} {
- set i [lsearch -exact $parents($view,$ki) $id]
- set j [expr {[llength $parents($view,$ki)] - 1 - $i}]
- append tok [strrep $j]
- }
- set c [lindex $vlastins($view) $ka]
- if {$c == 0 || [string compare $tok [lindex $varctok($view) $c]] < 0} {
- set c $ka
- set b [lindex $vdownptr($view) $ka]
- } else {
- set b [lindex $vleftptr($view) $c]
- }
- while {$b != 0 && [string compare $tok [lindex $varctok($view) $b]] >= 0} {
- set c $b
- set b [lindex $vleftptr($view) $c]
- }
- if {$c == $ka} {
- lset vdownptr($view) $ka $a
- lappend vbackptr($view) 0
- } else {
- lset vleftptr($view) $c $a
- lappend vbackptr($view) $c
- }
- lset vlastins($view) $ka $a
- lappend vupptr($view) $ka
- lappend vleftptr($view) $b
- if {$b != 0} {
- lset vbackptr($view) $b $a
- }
- lappend varctok($view) $tok
- lappend varcstart($view) $id
- lappend vdownptr($view) 0
- lappend varcrow($view) {}
- lappend varcix($view) {}
- set varccommits($view,$a) {}
- lappend vlastins($view) 0
- return $a
-}
-
-proc splitvarc {p v} {
- global varcid varcstart varccommits varctok vtokmod
- global vupptr vdownptr vleftptr vbackptr varcix varcrow vlastins
-
- set oa $varcid($v,$p)
- set otok [lindex $varctok($v) $oa]
- set ac $varccommits($v,$oa)
- set i [lsearch -exact $varccommits($v,$oa) $p]
- if {$i <= 0} return
- set na [llength $varctok($v)]
- # "%" sorts before "0"...
- set tok "$otok%[strrep $i]"
- lappend varctok($v) $tok
- lappend varcrow($v) {}
- lappend varcix($v) {}
- set varccommits($v,$oa) [lrange $ac 0 [expr {$i - 1}]]
- set varccommits($v,$na) [lrange $ac $i end]
- lappend varcstart($v) $p
- foreach id $varccommits($v,$na) {
- set varcid($v,$id) $na
- }
- lappend vdownptr($v) [lindex $vdownptr($v) $oa]
- lappend vlastins($v) [lindex $vlastins($v) $oa]
- lset vdownptr($v) $oa $na
- lset vlastins($v) $oa 0
- lappend vupptr($v) $oa
- lappend vleftptr($v) 0
- lappend vbackptr($v) 0
- for {set b [lindex $vdownptr($v) $na]} {$b != 0} {set b [lindex $vleftptr($v) $b]} {
- lset vupptr($v) $b $na
- }
- if {[string compare $otok $vtokmod($v)] <= 0} {
- modify_arc $v $oa
- }
-}
-
-proc renumbervarc {a v} {
- global parents children varctok varcstart varccommits
- global vupptr vdownptr vleftptr vbackptr vlastins varcid vtokmod vdatemode
-
- set t1 [clock clicks -milliseconds]
- set todo {}
- set isrelated($a) 1
- set kidchanged($a) 1
- set ntot 0
- while {$a != 0} {
- if {[info exists isrelated($a)]} {
- lappend todo $a
- set id [lindex $varccommits($v,$a) end]
- foreach p $parents($v,$id) {
- if {[info exists varcid($v,$p)]} {
- set isrelated($varcid($v,$p)) 1
- }
- }
- }
- incr ntot
- set b [lindex $vdownptr($v) $a]
- if {$b == 0} {
- while {$a != 0} {
- set b [lindex $vleftptr($v) $a]
- if {$b != 0} break
- set a [lindex $vupptr($v) $a]
- }
- }
- set a $b
- }
- foreach a $todo {
- if {![info exists kidchanged($a)]} continue
- set id [lindex $varcstart($v) $a]
- if {[llength $children($v,$id)] > 1} {
- set children($v,$id) [lsort -command [list vtokcmp $v] \
- $children($v,$id)]
- }
- set oldtok [lindex $varctok($v) $a]
- if {!$vdatemode($v)} {
- set tok {}
- } else {
- set tok $oldtok
- }
- set ka 0
- set kid [last_real_child $v,$id]
- if {$kid ne {}} {
- set k $varcid($v,$kid)
- if {[string compare [lindex $varctok($v) $k] $tok] > 0} {
- set ki $kid
- set ka $k
- set tok [lindex $varctok($v) $k]
- }
- }
- if {$ka != 0} {
- set i [lsearch -exact $parents($v,$ki) $id]
- set j [expr {[llength $parents($v,$ki)] - 1 - $i}]
- append tok [strrep $j]
- }
- if {$tok eq $oldtok} {
- continue
- }
- set id [lindex $varccommits($v,$a) end]
- foreach p $parents($v,$id) {
- if {[info exists varcid($v,$p)]} {
- set kidchanged($varcid($v,$p)) 1
- } else {
- set sortkids($p) 1
- }
- }
- lset varctok($v) $a $tok
- set b [lindex $vupptr($v) $a]
- if {$b != $ka} {
- if {[string compare [lindex $varctok($v) $ka] $vtokmod($v)] < 0} {
- modify_arc $v $ka
- }
- if {[string compare [lindex $varctok($v) $b] $vtokmod($v)] < 0} {
- modify_arc $v $b
- }
- set c [lindex $vbackptr($v) $a]
- set d [lindex $vleftptr($v) $a]
- if {$c == 0} {
- lset vdownptr($v) $b $d
- } else {
- lset vleftptr($v) $c $d
- }
- if {$d != 0} {
- lset vbackptr($v) $d $c
- }
- if {[lindex $vlastins($v) $b] == $a} {
- lset vlastins($v) $b $c
- }
- lset vupptr($v) $a $ka
- set c [lindex $vlastins($v) $ka]
- if {$c == 0 || \
- [string compare $tok [lindex $varctok($v) $c]] < 0} {
- set c $ka
- set b [lindex $vdownptr($v) $ka]
- } else {
- set b [lindex $vleftptr($v) $c]
- }
- while {$b != 0 && \
- [string compare $tok [lindex $varctok($v) $b]] >= 0} {
- set c $b
- set b [lindex $vleftptr($v) $c]
- }
- if {$c == $ka} {
- lset vdownptr($v) $ka $a
- lset vbackptr($v) $a 0
- } else {
- lset vleftptr($v) $c $a
- lset vbackptr($v) $a $c
- }
- lset vleftptr($v) $a $b
- if {$b != 0} {
- lset vbackptr($v) $b $a
- }
- lset vlastins($v) $ka $a
- }
- }
- foreach id [array names sortkids] {
- if {[llength $children($v,$id)] > 1} {
- set children($v,$id) [lsort -command [list vtokcmp $v] \
- $children($v,$id)]
- }
- }
- set t2 [clock clicks -milliseconds]
- #puts "renumbervarc did [llength $todo] of $ntot arcs in [expr {$t2-$t1}]ms"
-}
-
-# Fix up the graph after we have found out that in view $v,
-# $p (a commit that we have already seen) is actually the parent
-# of the last commit in arc $a.
-proc fix_reversal {p a v} {
- global varcid varcstart varctok vupptr
-
- set pa $varcid($v,$p)
- if {$p ne [lindex $varcstart($v) $pa]} {
- splitvarc $p $v
- set pa $varcid($v,$p)
- }
- # seeds always need to be renumbered
- if {[lindex $vupptr($v) $pa] == 0 ||
- [string compare [lindex $varctok($v) $a] \
- [lindex $varctok($v) $pa]] > 0} {
- renumbervarc $pa $v
- }
-}
-
-proc insertrow {id p v} {
- global cmitlisted children parents varcid varctok vtokmod
- global varccommits ordertok commitidx numcommits curview
- global targetid targetrow
-
- readcommit $id
- set vid $v,$id
- set cmitlisted($vid) 1
- set children($vid) {}
- set parents($vid) [list $p]
- set a [newvarc $v $id]
- set varcid($vid) $a
- if {[string compare [lindex $varctok($v) $a] $vtokmod($v)] < 0} {
- modify_arc $v $a
- }
- lappend varccommits($v,$a) $id
- set vp $v,$p
- if {[llength [lappend children($vp) $id]] > 1} {
- set children($vp) [lsort -command [list vtokcmp $v] $children($vp)]
- catch {unset ordertok}
- }
- fix_reversal $p $a $v
- incr commitidx($v)
- if {$v == $curview} {
- set numcommits $commitidx($v)
- setcanvscroll
- if {[info exists targetid]} {
- if {![comes_before $targetid $p]} {
- incr targetrow
- }
- }
- }
-}
-
-proc insertfakerow {id p} {
- global varcid varccommits parents children cmitlisted
- global commitidx varctok vtokmod targetid targetrow curview numcommits
-
- set v $curview
- set a $varcid($v,$p)
- set i [lsearch -exact $varccommits($v,$a) $p]
- if {$i < 0} {
- puts "oops: insertfakerow can't find [shortids $p] on arc $a"
- return
- }
- set children($v,$id) {}
- set parents($v,$id) [list $p]
- set varcid($v,$id) $a
- lappend children($v,$p) $id
- set cmitlisted($v,$id) 1
- set numcommits [incr commitidx($v)]
- # note we deliberately don't update varcstart($v) even if $i == 0
- set varccommits($v,$a) [linsert $varccommits($v,$a) $i $id]
- modify_arc $v $a $i
- if {[info exists targetid]} {
- if {![comes_before $targetid $p]} {
- incr targetrow
- }
- }
- setcanvscroll
- drawvisible
-}
-
-proc removefakerow {id} {
- global varcid varccommits parents children commitidx
- global varctok vtokmod cmitlisted currentid selectedline
- global targetid curview numcommits
-
- set v $curview
- if {[llength $parents($v,$id)] != 1} {
- puts "oops: removefakerow [shortids $id] has [llength $parents($v,$id)] parents"
- return
- }
- set p [lindex $parents($v,$id) 0]
- set a $varcid($v,$id)
- set i [lsearch -exact $varccommits($v,$a) $id]
- if {$i < 0} {
- puts "oops: removefakerow can't find [shortids $id] on arc $a"
- return
- }
- unset varcid($v,$id)
- set varccommits($v,$a) [lreplace $varccommits($v,$a) $i $i]
- unset parents($v,$id)
- unset children($v,$id)
- unset cmitlisted($v,$id)
- set numcommits [incr commitidx($v) -1]
- set j [lsearch -exact $children($v,$p) $id]
- if {$j >= 0} {
- set children($v,$p) [lreplace $children($v,$p) $j $j]
- }
- modify_arc $v $a $i
- if {[info exist currentid] && $id eq $currentid} {
- unset currentid
- set selectedline {}
- }
- if {[info exists targetid] && $targetid eq $id} {
- set targetid $p
- }
- setcanvscroll
- drawvisible
-}
-
-proc real_children {vp} {
- global children nullid nullid2
-
- set kids {}
- foreach id $children($vp) {
- if {$id ne $nullid && $id ne $nullid2} {
- lappend kids $id
- }
- }
- return $kids
-}
-
-proc first_real_child {vp} {
- global children nullid nullid2
-
- foreach id $children($vp) {
- if {$id ne $nullid && $id ne $nullid2} {
- return $id
- }
- }
- return {}
-}
-
-proc last_real_child {vp} {
- global children nullid nullid2
-
- set kids $children($vp)
- for {set i [llength $kids]} {[incr i -1] >= 0} {} {
- set id [lindex $kids $i]
- if {$id ne $nullid && $id ne $nullid2} {
- return $id
- }
- }
- return {}
-}
-
-proc vtokcmp {v a b} {
- global varctok varcid
-
- return [string compare [lindex $varctok($v) $varcid($v,$a)] \
- [lindex $varctok($v) $varcid($v,$b)]]
-}
-
-# This assumes that if lim is not given, the caller has checked that
-# arc a's token is less than $vtokmod($v)
-proc modify_arc {v a {lim {}}} {
- global varctok vtokmod varcmod varcrow vupptr curview vrowmod varccommits
-
- if {$lim ne {}} {
- set c [string compare [lindex $varctok($v) $a] $vtokmod($v)]
- if {$c > 0} return
- if {$c == 0} {
- set r [lindex $varcrow($v) $a]
- if {$r ne {} && $vrowmod($v) <= $r + $lim} return
- }
- }
- set vtokmod($v) [lindex $varctok($v) $a]
- set varcmod($v) $a
- if {$v == $curview} {
- while {$a != 0 && [lindex $varcrow($v) $a] eq {}} {
- set a [lindex $vupptr($v) $a]
- set lim {}
- }
- set r 0
- if {$a != 0} {
- if {$lim eq {}} {
- set lim [llength $varccommits($v,$a)]
- }
- set r [expr {[lindex $varcrow($v) $a] + $lim}]
- }
- set vrowmod($v) $r
- undolayout $r
- }
-}
-
-proc update_arcrows {v} {
- global vtokmod varcmod vrowmod varcrow commitidx currentid selectedline
- global varcid vrownum varcorder varcix varccommits
- global vupptr vdownptr vleftptr varctok
- global displayorder parentlist curview cached_commitrow
-
- if {$vrowmod($v) == $commitidx($v)} return
- if {$v == $curview} {
- if {[llength $displayorder] > $vrowmod($v)} {
- set displayorder [lrange $displayorder 0 [expr {$vrowmod($v) - 1}]]
- set parentlist [lrange $parentlist 0 [expr {$vrowmod($v) - 1}]]
- }
- catch {unset cached_commitrow}
- }
- set narctot [expr {[llength $varctok($v)] - 1}]
- set a $varcmod($v)
- while {$a != 0 && [lindex $varcix($v) $a] eq {}} {
- # go up the tree until we find something that has a row number,
- # or we get to a seed
- set a [lindex $vupptr($v) $a]
- }
- if {$a == 0} {
- set a [lindex $vdownptr($v) 0]
- if {$a == 0} return
- set vrownum($v) {0}
- set varcorder($v) [list $a]
- lset varcix($v) $a 0
- lset varcrow($v) $a 0
- set arcn 0
- set row 0
- } else {
- set arcn [lindex $varcix($v) $a]
- if {[llength $vrownum($v)] > $arcn + 1} {
- set vrownum($v) [lrange $vrownum($v) 0 $arcn]
- set varcorder($v) [lrange $varcorder($v) 0 $arcn]
- }
- set row [lindex $varcrow($v) $a]
- }
- while {1} {
- set p $a
- incr row [llength $varccommits($v,$a)]
- # go down if possible
- set b [lindex $vdownptr($v) $a]
- if {$b == 0} {
- # if not, go left, or go up until we can go left
- while {$a != 0} {
- set b [lindex $vleftptr($v) $a]
- if {$b != 0} break
- set a [lindex $vupptr($v) $a]
- }
- if {$a == 0} break
- }
- set a $b
- incr arcn
- lappend vrownum($v) $row
- lappend varcorder($v) $a
- lset varcix($v) $a $arcn
- lset varcrow($v) $a $row
- }
- set vtokmod($v) [lindex $varctok($v) $p]
- set varcmod($v) $p
- set vrowmod($v) $row
- if {[info exists currentid]} {
- set selectedline [rowofcommit $currentid]
- }
-}
-
-# Test whether view $v contains commit $id
-proc commitinview {id v} {
- global varcid
-
- return [info exists varcid($v,$id)]
-}
-
-# Return the row number for commit $id in the current view
-proc rowofcommit {id} {
- global varcid varccommits varcrow curview cached_commitrow
- global varctok vtokmod
-
- set v $curview
- if {![info exists varcid($v,$id)]} {
- puts "oops rowofcommit no arc for [shortids $id]"
- return {}
- }
- set a $varcid($v,$id)
- if {[string compare [lindex $varctok($v) $a] $vtokmod($v)] >= 0} {
- update_arcrows $v
- }
- if {[info exists cached_commitrow($id)]} {
- return $cached_commitrow($id)
- }
- set i [lsearch -exact $varccommits($v,$a) $id]
- if {$i < 0} {
- puts "oops didn't find commit [shortids $id] in arc $a"
- return {}
- }
- incr i [lindex $varcrow($v) $a]
- set cached_commitrow($id) $i
- return $i
-}
-
-# Returns 1 if a is on an earlier row than b, otherwise 0
-proc comes_before {a b} {
- global varcid varctok curview
-
- set v $curview
- if {$a eq $b || ![info exists varcid($v,$a)] || \
- ![info exists varcid($v,$b)]} {
- return 0
- }
- if {$varcid($v,$a) != $varcid($v,$b)} {
- return [expr {[string compare [lindex $varctok($v) $varcid($v,$a)] \
- [lindex $varctok($v) $varcid($v,$b)]] < 0}]
- }
- return [expr {[rowofcommit $a] < [rowofcommit $b]}]
-}
-
-proc bsearch {l elt} {
- if {[llength $l] == 0 || $elt <= [lindex $l 0]} {
- return 0
- }
- set lo 0
- set hi [llength $l]
- while {$hi - $lo > 1} {
- set mid [expr {int(($lo + $hi) / 2)}]
- set t [lindex $l $mid]
- if {$elt < $t} {
- set hi $mid
- } elseif {$elt > $t} {
- set lo $mid
- } else {
- return $mid
- }
- }
- return $lo
-}
-
-# Make sure rows $start..$end-1 are valid in displayorder and parentlist
-proc make_disporder {start end} {
- global vrownum curview commitidx displayorder parentlist
- global varccommits varcorder parents vrowmod varcrow
- global d_valid_start d_valid_end
-
- if {$end > $vrowmod($curview)} {
- update_arcrows $curview
- }
- set ai [bsearch $vrownum($curview) $start]
- set start [lindex $vrownum($curview) $ai]
- set narc [llength $vrownum($curview)]
- for {set r $start} {$ai < $narc && $r < $end} {incr ai} {
- set a [lindex $varcorder($curview) $ai]
- set l [llength $displayorder]
- set al [llength $varccommits($curview,$a)]
- if {$l < $r + $al} {
- if {$l < $r} {
- set pad [ntimes [expr {$r - $l}] {}]
- set displayorder [concat $displayorder $pad]
- set parentlist [concat $parentlist $pad]
- } elseif {$l > $r} {
- set displayorder [lrange $displayorder 0 [expr {$r - 1}]]
- set parentlist [lrange $parentlist 0 [expr {$r - 1}]]
- }
- foreach id $varccommits($curview,$a) {
- lappend displayorder $id
- lappend parentlist $parents($curview,$id)
- }
- } elseif {[lindex $displayorder [expr {$r + $al - 1}]] eq {}} {
- set i $r
- foreach id $varccommits($curview,$a) {
- lset displayorder $i $id
- lset parentlist $i $parents($curview,$id)
- incr i
- }
- }
- incr r $al
- }
-}
-
-proc commitonrow {row} {
- global displayorder
-
- set id [lindex $displayorder $row]
- if {$id eq {}} {
- make_disporder $row [expr {$row + 1}]
- set id [lindex $displayorder $row]
- }
- return $id
-}
-
-proc closevarcs {v} {
- global varctok varccommits varcid parents children
- global cmitlisted commitidx vtokmod
-
- set missing_parents 0
- set scripts {}
- set narcs [llength $varctok($v)]
- for {set a 1} {$a < $narcs} {incr a} {
- set id [lindex $varccommits($v,$a) end]
- foreach p $parents($v,$id) {
- if {[info exists varcid($v,$p)]} continue
- # add p as a new commit
- incr missing_parents
- set cmitlisted($v,$p) 0
- set parents($v,$p) {}
- if {[llength $children($v,$p)] == 1 &&
- [llength $parents($v,$id)] == 1} {
- set b $a
- } else {
- set b [newvarc $v $p]
- }
- set varcid($v,$p) $b
- if {[string compare [lindex $varctok($v) $b] $vtokmod($v)] < 0} {
- modify_arc $v $b
- }
- lappend varccommits($v,$b) $p
- incr commitidx($v)
- set scripts [check_interest $p $scripts]
- }
- }
- if {$missing_parents > 0} {
- foreach s $scripts {
- eval $s
- }
- }
-}
-
-# Use $rwid as a substitute for $id, i.e. reparent $id's children to $rwid
-# Assumes we already have an arc for $rwid.
-proc rewrite_commit {v id rwid} {
- global children parents varcid varctok vtokmod varccommits
-
- foreach ch $children($v,$id) {
- # make $rwid be $ch's parent in place of $id
- set i [lsearch -exact $parents($v,$ch) $id]
- if {$i < 0} {
- puts "oops rewrite_commit didn't find $id in parent list for $ch"
- }
- set parents($v,$ch) [lreplace $parents($v,$ch) $i $i $rwid]
- # add $ch to $rwid's children and sort the list if necessary
- if {[llength [lappend children($v,$rwid) $ch]] > 1} {
- set children($v,$rwid) [lsort -command [list vtokcmp $v] \
- $children($v,$rwid)]
- }
- # fix the graph after joining $id to $rwid
- set a $varcid($v,$ch)
- fix_reversal $rwid $a $v
- # parentlist is wrong for the last element of arc $a
- # even if displayorder is right, hence the 3rd arg here
- modify_arc $v $a [expr {[llength $varccommits($v,$a)] - 1}]
- }
-}
-
-# Mechanism for registering a command to be executed when we come
-# across a particular commit. To handle the case when only the
-# prefix of the commit is known, the commitinterest array is now
-# indexed by the first 4 characters of the ID. Each element is a
-# list of id, cmd pairs.
-proc interestedin {id cmd} {
- global commitinterest
-
- lappend commitinterest([string range $id 0 3]) $id $cmd
-}
-
-proc check_interest {id scripts} {
- global commitinterest
-
- set prefix [string range $id 0 3]
- if {[info exists commitinterest($prefix)]} {
- set newlist {}
- foreach {i script} $commitinterest($prefix) {
- if {[string match "$i*" $id]} {
- lappend scripts [string map [list "%I" $id "%P" $i] $script]
- } else {
- lappend newlist $i $script
- }
- }
- if {$newlist ne {}} {
- set commitinterest($prefix) $newlist
- } else {
- unset commitinterest($prefix)
- }
- }
- return $scripts
-}
-
-proc getcommitlines {fd inst view updating} {
- global cmitlisted leftover
- global commitidx commitdata vdatemode
- global parents children curview hlview
- global idpending ordertok
- global varccommits varcid varctok vtokmod vfilelimit
-
- set stuff [read $fd 500000]
- # git log doesn't terminate the last commit with a null...
- if {$stuff == {} && $leftover($inst) ne {} && [eof $fd]} {
- set stuff "\0"
- }
- if {$stuff == {}} {
- if {![eof $fd]} {
- return 1
- }
- global commfd viewcomplete viewactive viewname
- global viewinstances
- unset commfd($inst)
- set i [lsearch -exact $viewinstances($view) $inst]
- if {$i >= 0} {
- set viewinstances($view) [lreplace $viewinstances($view) $i $i]
- }
- # set it blocking so we wait for the process to terminate
- fconfigure $fd -blocking 1
- if {[catch {close $fd} err]} {
- set fv {}
- if {$view != $curview} {
- set fv " for the \"$viewname($view)\" view"
- }
- if {[string range $err 0 4] == "usage"} {
- set err "Gitk: error reading commits$fv:\
- bad arguments to git log."
- if {$viewname($view) eq "Command line"} {
- append err \
- " (Note: arguments to gitk are passed to git log\
- to allow selection of commits to be displayed.)"
- }
- } else {
- set err "Error reading commits$fv: $err"
- }
- error_popup $err
- }
- if {[incr viewactive($view) -1] <= 0} {
- set viewcomplete($view) 1
- # Check if we have seen any ids listed as parents that haven't
- # appeared in the list
- closevarcs $view
- notbusy $view
- }
- if {$view == $curview} {
- run chewcommits
- }
- return 0
- }
- set start 0
- set gotsome 0
- set scripts {}
- while 1 {
- set i [string first "\0" $stuff $start]
- if {$i < 0} {
- append leftover($inst) [string range $stuff $start end]
- break
- }
- if {$start == 0} {
- set cmit $leftover($inst)
- append cmit [string range $stuff 0 [expr {$i - 1}]]
- set leftover($inst) {}
- } else {
- set cmit [string range $stuff $start [expr {$i - 1}]]
- }
- set start [expr {$i + 1}]
- set j [string first "\n" $cmit]
- set ok 0
- set listed 1
- if {$j >= 0 && [string match "commit *" $cmit]} {
- set ids [string range $cmit 7 [expr {$j - 1}]]
- if {[string match {[-^<>]*} $ids]} {
- switch -- [string index $ids 0] {
- "-" {set listed 0}
- "^" {set listed 2}
- "<" {set listed 3}
- ">" {set listed 4}
- }
- set ids [string range $ids 1 end]
- }
- set ok 1
- foreach id $ids {
- if {[string length $id] != 40} {
- set ok 0
- break
- }
- }
- }
- if {!$ok} {
- set shortcmit $cmit
- if {[string length $shortcmit] > 80} {
- set shortcmit "[string range $shortcmit 0 80]..."
- }
- error_popup "[mc "Can't parse git log output:"] {$shortcmit}"
- exit 1
- }
- set id [lindex $ids 0]
- set vid $view,$id
-
- if {!$listed && $updating && ![info exists varcid($vid)] &&
- $vfilelimit($view) ne {}} {
- # git log doesn't rewrite parents for unlisted commits
- # when doing path limiting, so work around that here
- # by working out the rewritten parent with git rev-list
- # and if we already know about it, using the rewritten
- # parent as a substitute parent for $id's children.
- if {![catch {
- set rwid [exec git rev-list --first-parent --max-count=1 \
- $id -- $vfilelimit($view)]
- }]} {
- if {$rwid ne {} && [info exists varcid($view,$rwid)]} {
- # use $rwid in place of $id
- rewrite_commit $view $id $rwid
- continue
- }
- }
- }
-
- set a 0
- if {[info exists varcid($vid)]} {
- if {$cmitlisted($vid) || !$listed} continue
- set a $varcid($vid)
- }
- if {$listed} {
- set olds [lrange $ids 1 end]
- } else {
- set olds {}
- }
- set commitdata($id) [string range $cmit [expr {$j + 1}] end]
- set cmitlisted($vid) $listed
- set parents($vid) $olds
- if {![info exists children($vid)]} {
- set children($vid) {}
- } elseif {$a == 0 && [llength $children($vid)] == 1} {
- set k [lindex $children($vid) 0]
- if {[llength $parents($view,$k)] == 1 &&
- (!$vdatemode($view) ||
- $varcid($view,$k) == [llength $varctok($view)] - 1)} {
- set a $varcid($view,$k)
- }
- }
- if {$a == 0} {
- # new arc
- set a [newvarc $view $id]
- }
- if {[string compare [lindex $varctok($view) $a] $vtokmod($view)] < 0} {
- modify_arc $view $a
- }
- if {![info exists varcid($vid)]} {
- set varcid($vid) $a
- lappend varccommits($view,$a) $id
- incr commitidx($view)
- }
-
- set i 0
- foreach p $olds {
- if {$i == 0 || [lsearch -exact $olds $p] >= $i} {
- set vp $view,$p
- if {[llength [lappend children($vp) $id]] > 1 &&
- [vtokcmp $view [lindex $children($vp) end-1] $id] > 0} {
- set children($vp) [lsort -command [list vtokcmp $view] \
- $children($vp)]
- catch {unset ordertok}
- }
- if {[info exists varcid($view,$p)]} {
- fix_reversal $p $a $view
- }
- }
- incr i
- }
-
- set scripts [check_interest $id $scripts]
- set gotsome 1
- }
- if {$gotsome} {
- global numcommits hlview
-
- if {$view == $curview} {
- set numcommits $commitidx($view)
- run chewcommits
- }
- if {[info exists hlview] && $view == $hlview} {
- # we never actually get here...
- run vhighlightmore
- }
- foreach s $scripts {
- eval $s
- }
- }
- return 2
-}
-
-proc chewcommits {} {
- global curview hlview viewcomplete
- global pending_select
-
- layoutmore
- if {$viewcomplete($curview)} {
- global commitidx varctok
- global numcommits startmsecs
-
- if {[info exists pending_select]} {
- update
- reset_pending_select {}
-
- if {[commitinview $pending_select $curview]} {
- selectline [rowofcommit $pending_select] 1
- } else {
- set row [first_real_row]
- selectline $row 1
- }
- }
- if {$commitidx($curview) > 0} {
- #set ms [expr {[clock clicks -milliseconds] - $startmsecs}]
- #puts "overall $ms ms for $numcommits commits"
- #puts "[llength $varctok($view)] arcs, $commitidx($view) commits"
- } else {
- show_status [mc "No commits selected"]
- }
- notbusy layout
- }
- return 0
-}
-
-proc do_readcommit {id} {
- global tclencoding
-
- # Invoke git-log to handle automatic encoding conversion
- set fd [open [concat | git log --no-color --pretty=raw -1 $id] r]
- # Read the results using i18n.logoutputencoding
- fconfigure $fd -translation lf -eofchar {}
- if {$tclencoding != {}} {
- fconfigure $fd -encoding $tclencoding
- }
- set contents [read $fd]
- close $fd
- # Remove the heading line
- regsub {^commit [0-9a-f]+\n} $contents {} contents
-
- return $contents
-}
-
-proc readcommit {id} {
- if {[catch {set contents [do_readcommit $id]}]} return
- parsecommit $id $contents 1
-}
-
-proc parsecommit {id contents listed} {
- global commitinfo cdate
-
- set inhdr 1
- set comment {}
- set headline {}
- set auname {}
- set audate {}
- set comname {}
- set comdate {}
- set hdrend [string first "\n\n" $contents]
- if {$hdrend < 0} {
- # should never happen...
- set hdrend [string length $contents]
- }
- set header [string range $contents 0 [expr {$hdrend - 1}]]
- set comment [string range $contents [expr {$hdrend + 2}] end]
- foreach line [split $header "\n"] {
- set line [split $line " "]
- set tag [lindex $line 0]
- if {$tag == "author"} {
- set audate [lindex $line end-1]
- set auname [join [lrange $line 1 end-2] " "]
- } elseif {$tag == "committer"} {
- set comdate [lindex $line end-1]
- set comname [join [lrange $line 1 end-2] " "]
- }
- }
- set headline {}
- # take the first non-blank line of the comment as the headline
- set headline [string trimleft $comment]
- set i [string first "\n" $headline]
- if {$i >= 0} {
- set headline [string range $headline 0 $i]
- }
- set headline [string trimright $headline]
- set i [string first "\r" $headline]
- if {$i >= 0} {
- set headline [string trimright [string range $headline 0 $i]]
- }
- if {!$listed} {
- # git log indents the comment by 4 spaces;
- # if we got this via git cat-file, add the indentation
- set newcomment {}
- foreach line [split $comment "\n"] {
- append newcomment " "
- append newcomment $line
- append newcomment "\n"
- }
- set comment $newcomment
- }
- if {$comdate != {}} {
- set cdate($id) $comdate
- }
- set commitinfo($id) [list $headline $auname $audate \
- $comname $comdate $comment]
-}
-
-proc getcommit {id} {
- global commitdata commitinfo
-
- if {[info exists commitdata($id)]} {
- parsecommit $id $commitdata($id) 1
- } else {
- readcommit $id
- if {![info exists commitinfo($id)]} {
- set commitinfo($id) [list [mc "No commit information available"]]
- }
- }
- return 1
-}
-
-# Expand an abbreviated commit ID to a list of full 40-char IDs that match
-# and are present in the current view.
-# This is fairly slow...
-proc longid {prefix} {
- global varcid curview
-
- set ids {}
- foreach match [array names varcid "$curview,$prefix*"] {
- lappend ids [lindex [split $match ","] 1]
- }
- return $ids
-}
-
-proc readrefs {} {
- global tagids idtags headids idheads tagobjid
- global otherrefids idotherrefs mainhead mainheadid
- global selecthead selectheadid
- global hideremotes
-
- foreach v {tagids idtags headids idheads otherrefids idotherrefs} {
- catch {unset $v}
- }
- set refd [open [list | git show-ref -d] r]
- while {[gets $refd line] >= 0} {
- if {[string index $line 40] ne " "} continue
- set id [string range $line 0 39]
- set ref [string range $line 41 end]
- if {![string match "refs/*" $ref]} continue
- set name [string range $ref 5 end]
- if {[string match "remotes/*" $name]} {
- if {![string match "*/HEAD" $name] && !$hideremotes} {
- set headids($name) $id
- lappend idheads($id) $name
- }
- } elseif {[string match "heads/*" $name]} {
- set name [string range $name 6 end]
- set headids($name) $id
- lappend idheads($id) $name
- } elseif {[string match "tags/*" $name]} {
- # this lets refs/tags/foo^{} overwrite refs/tags/foo,
- # which is what we want since the former is the commit ID
- set name [string range $name 5 end]
- if {[string match "*^{}" $name]} {
- set name [string range $name 0 end-3]
- } else {
- set tagobjid($name) $id
- }
- set tagids($name) $id
- lappend idtags($id) $name
- } else {
- set otherrefids($name) $id
- lappend idotherrefs($id) $name
- }
- }
- catch {close $refd}
- set mainhead {}
- set mainheadid {}
- catch {
- set mainheadid [exec git rev-parse HEAD]
- set thehead [exec git symbolic-ref HEAD]
- if {[string match "refs/heads/*" $thehead]} {
- set mainhead [string range $thehead 11 end]
- }
- }
- set selectheadid {}
- if {$selecthead ne {}} {
- catch {
- set selectheadid [exec git rev-parse --verify $selecthead]
- }
- }
-}
-
-# skip over fake commits
-proc first_real_row {} {
- global nullid nullid2 numcommits
-
- for {set row 0} {$row < $numcommits} {incr row} {
- set id [commitonrow $row]
- if {$id ne $nullid && $id ne $nullid2} {
- break
- }
- }
- return $row
-}
-
-# update things for a head moved to a child of its previous location
-proc movehead {id name} {
- global headids idheads
-
- removehead $headids($name) $name
- set headids($name) $id
- lappend idheads($id) $name
-}
-
-# update things when a head has been removed
-proc removehead {id name} {
- global headids idheads
-
- if {$idheads($id) eq $name} {
- unset idheads($id)
- } else {
- set i [lsearch -exact $idheads($id) $name]
- if {$i >= 0} {
- set idheads($id) [lreplace $idheads($id) $i $i]
- }
- }
- unset headids($name)
-}
-
-proc ttk_toplevel {w args} {
- global use_ttk
- eval [linsert $args 0 ::toplevel $w]
- if {$use_ttk} {
- place [ttk::frame $w._toplevel_background] -x 0 -y 0 -relwidth 1 -relheight 1
- }
- return $w
-}
-
-proc make_transient {window origin} {
- global have_tk85
-
- # In MacOS Tk 8.4 transient appears to work by setting
- # overrideredirect, which is utterly useless, since the
- # windows get no border, and are not even kept above
- # the parent.
- if {!$have_tk85 && [tk windowingsystem] eq {aqua}} return
-
- wm transient $window $origin
-
- # Windows fails to place transient windows normally, so
- # schedule a callback to center them on the parent.
- if {[tk windowingsystem] eq {win32}} {
- after idle [list tk::PlaceWindow $window widget $origin]
- }
-}
-
-proc show_error {w top msg {mc mc}} {
- global NS
- if {![info exists NS]} {set NS ""}
- if {[wm state $top] eq "withdrawn"} { wm deiconify $top }
- message $w.m -text $msg -justify center -aspect 400
- pack $w.m -side top -fill x -padx 20 -pady 20
- ${NS}::button $w.ok -default active -text [$mc OK] -command "destroy $top"
- pack $w.ok -side bottom -fill x
- bind $top "grab $top; focus $top"
- bind $top "destroy $top"
- bind $top "destroy $top"
- bind $top "destroy $top"
- tkwait window $top
-}
-
-proc error_popup {msg {owner .}} {
- if {[tk windowingsystem] eq "win32"} {
- tk_messageBox -icon error -type ok -title [wm title .] \
- -parent $owner -message $msg
- } else {
- set w .error
- ttk_toplevel $w
- make_transient $w $owner
- show_error $w $w $msg
- }
-}
-
-proc confirm_popup {msg {owner .}} {
- global confirm_ok NS
- set confirm_ok 0
- set w .confirm
- ttk_toplevel $w
- make_transient $w $owner
- message $w.m -text $msg -justify center -aspect 400
- pack $w.m -side top -fill x -padx 20 -pady 20
- ${NS}::button $w.ok -text [mc OK] -command "set confirm_ok 1; destroy $w"
- pack $w.ok -side left -fill x
- ${NS}::button $w.cancel -text [mc Cancel] -command "destroy $w"
- pack $w.cancel -side right -fill x
- bind $w "grab $w; focus $w"
- bind $w "set confirm_ok 1; destroy $w"
- bind $w "set confirm_ok 1; destroy $w"
- bind $w "destroy $w"
- tk::PlaceWindow $w widget $owner
- tkwait window $w
- return $confirm_ok
-}
-
-proc setoptions {} {
- if {[tk windowingsystem] ne "win32"} {
- option add *Panedwindow.showHandle 1 startupFile
- option add *Panedwindow.sashRelief raised startupFile
- if {[tk windowingsystem] ne "aqua"} {
- option add *Menu.font uifont startupFile
- }
- } else {
- option add *Menu.TearOff 0 startupFile
- }
- option add *Button.font uifont startupFile
- option add *Checkbutton.font uifont startupFile
- option add *Radiobutton.font uifont startupFile
- option add *Menubutton.font uifont startupFile
- option add *Label.font uifont startupFile
- option add *Message.font uifont startupFile
- option add *Entry.font textfont startupFile
- option add *Text.font textfont startupFile
- option add *Labelframe.font uifont startupFile
- option add *Spinbox.font textfont startupFile
- option add *Listbox.font mainfont startupFile
-}
-
-# Make a menu and submenus.
-# m is the window name for the menu, items is the list of menu items to add.
-# Each item is a list {mc label type description options...}
-# mc is ignored; it's so we can put mc there to alert xgettext
-# label is the string that appears in the menu
-# type is cascade, command or radiobutton (should add checkbutton)
-# description depends on type; it's the sublist for cascade, the
-# command to invoke for command, or {variable value} for radiobutton
-proc makemenu {m items} {
- menu $m
- if {[tk windowingsystem] eq {aqua}} {
- set Meta1 Cmd
- } else {
- set Meta1 Ctrl
- }
- foreach i $items {
- set name [mc [lindex $i 1]]
- set type [lindex $i 2]
- set thing [lindex $i 3]
- set params [list $type]
- if {$name ne {}} {
- set u [string first "&" [string map {&& x} $name]]
- lappend params -label [string map {&& & & {}} $name]
- if {$u >= 0} {
- lappend params -underline $u
- }
- }
- switch -- $type {
- "cascade" {
- set submenu [string tolower [string map {& ""} [lindex $i 1]]]
- lappend params -menu $m.$submenu
- }
- "command" {
- lappend params -command $thing
- }
- "radiobutton" {
- lappend params -variable [lindex $thing 0] \
- -value [lindex $thing 1]
- }
- }
- set tail [lrange $i 4 end]
- regsub -all {\yMeta1\y} $tail $Meta1 tail
- eval $m add $params $tail
- if {$type eq "cascade"} {
- makemenu $m.$submenu $thing
- }
- }
-}
-
-# translate string and remove ampersands
-proc mca {str} {
- return [string map {&& & & {}} [mc $str]]
-}
-
-proc makedroplist {w varname args} {
- global use_ttk
- if {$use_ttk} {
- set width 0
- foreach label $args {
- set cx [string length $label]
- if {$cx > $width} {set width $cx}
- }
- set gm [ttk::combobox $w -width $width -state readonly\
- -textvariable $varname -values $args]
- } else {
- set gm [eval [linsert $args 0 tk_optionMenu $w $varname]]
- }
- return $gm
-}
-
-proc makewindow {} {
- global canv canv2 canv3 linespc charspc ctext cflist cscroll
- global tabstop
- global findtype findtypemenu findloc findstring fstring geometry
- global entries sha1entry sha1string sha1but
- global diffcontextstring diffcontext
- global ignorespace
- global maincursor textcursor curtextcursor
- global rowctxmenu fakerowmenu mergemax wrapcomment
- global highlight_files gdttype
- global searchstring sstring
- global bgcolor fgcolor bglist fglist diffcolors selectbgcolor
- global headctxmenu progresscanv progressitem progresscoords statusw
- global fprogitem fprogcoord lastprogupdate progupdatepending
- global rprogitem rprogcoord rownumsel numcommits
- global have_tk85 use_ttk NS
- global git_version
- global worddiff
-
- # The "mc" arguments here are purely so that xgettext
- # sees the following string as needing to be translated
- set file {
- mc "File" cascade {
- {mc "Update" command updatecommits -accelerator F5}
- {mc "Reload" command reloadcommits -accelerator Meta1-F5}
- {mc "Reread references" command rereadrefs}
- {mc "List references" command showrefs -accelerator F2}
- {xx "" separator}
- {mc "Start git gui" command {exec git gui &}}
- {xx "" separator}
- {mc "Quit" command doquit -accelerator Meta1-Q}
- }}
- set edit {
- mc "Edit" cascade {
- {mc "Preferences" command doprefs}
- }}
- set view {
- mc "View" cascade {
- {mc "New view..." command {newview 0} -accelerator Shift-F4}
- {mc "Edit view..." command editview -state disabled -accelerator F4}
- {mc "Delete view" command delview -state disabled}
- {xx "" separator}
- {mc "All files" radiobutton {selectedview 0} -command {showview 0}}
- }}
- if {[tk windowingsystem] ne "aqua"} {
- set help {
- mc "Help" cascade {
- {mc "About gitk" command about}
- {mc "Key bindings" command keys}
- }}
- set bar [list $file $edit $view $help]
- } else {
- proc ::tk::mac::ShowPreferences {} {doprefs}
- proc ::tk::mac::Quit {} {doquit}
- lset file end [lreplace [lindex $file end] end-1 end]
- set apple {
- xx "Apple" cascade {
- {mc "About gitk" command about}
- {xx "" separator}
- }}
- set help {
- mc "Help" cascade {
- {mc "Key bindings" command keys}
- }}
- set bar [list $apple $file $view $help]
- }
- makemenu .bar $bar
- . configure -menu .bar
-
- if {$use_ttk} {
- # cover the non-themed toplevel with a themed frame.
- place [ttk::frame ._main_background] -x 0 -y 0 -relwidth 1 -relheight 1
- }
-
- # the gui has upper and lower half, parts of a paned window.
- ${NS}::panedwindow .ctop -orient vertical
-
- # possibly use assumed geometry
- if {![info exists geometry(pwsash0)]} {
- set geometry(topheight) [expr {15 * $linespc}]
- set geometry(topwidth) [expr {80 * $charspc}]
- set geometry(botheight) [expr {15 * $linespc}]
- set geometry(botwidth) [expr {50 * $charspc}]
- set geometry(pwsash0) [list [expr {40 * $charspc}] 2]
- set geometry(pwsash1) [list [expr {60 * $charspc}] 2]
- }
-
- # the upper half will have a paned window, a scroll bar to the right, and some stuff below
- ${NS}::frame .tf -height $geometry(topheight) -width $geometry(topwidth)
- ${NS}::frame .tf.histframe
- ${NS}::panedwindow .tf.histframe.pwclist -orient horizontal
- if {!$use_ttk} {
- .tf.histframe.pwclist configure -sashpad 0 -handlesize 4
- }
-
- # create three canvases
- set cscroll .tf.histframe.csb
- set canv .tf.histframe.pwclist.canv
- canvas $canv \
- -selectbackground $selectbgcolor \
- -background $bgcolor -bd 0 \
- -yscrollincr $linespc -yscrollcommand "scrollcanv $cscroll"
- .tf.histframe.pwclist add $canv
- set canv2 .tf.histframe.pwclist.canv2
- canvas $canv2 \
- -selectbackground $selectbgcolor \
- -background $bgcolor -bd 0 -yscrollincr $linespc
- .tf.histframe.pwclist add $canv2
- set canv3 .tf.histframe.pwclist.canv3
- canvas $canv3 \
- -selectbackground $selectbgcolor \
- -background $bgcolor -bd 0 -yscrollincr $linespc
- .tf.histframe.pwclist add $canv3
- if {$use_ttk} {
- bind .tf.histframe.pwclist