texlive[44137] Master/tlpkg: TLTREE: support git/svn and git directly

commits+preining at tug.org commits+preining at tug.org
Mon May 1 21:44:08 CEST 2017


Revision: 44137
          http://tug.org/svn/texlive?view=revision&revision=44137
Author:   preining
Date:     2017-05-01 21:44:08 +0200 (Mon, 01 May 2017)
Log Message:
-----------
TLTREE: support git/svn and git directly

Modified Paths:
--------------
    trunk/Master/tlpkg/TeXLive/TLTREE.pm
    trunk/Master/tlpkg/bin/tl-update-tlpdb

Added Paths:
-----------
    trunk/Master/tlpkg/bin/update-commit-svn-list.pl

Modified: trunk/Master/tlpkg/TeXLive/TLTREE.pm
===================================================================
--- trunk/Master/tlpkg/TeXLive/TLTREE.pm	2017-05-01 17:57:19 UTC (rev 44136)
+++ trunk/Master/tlpkg/TeXLive/TLTREE.pm	2017-05-01 19:44:08 UTC (rev 44137)
@@ -72,6 +72,98 @@
   $self->_initialize_lines(@lines);
 }
 
+
+sub init_from_git {
+  my $self = shift;
+  my $svnroot = $self->{'svnroot'};
+  my $retval = $?;
+  my %files;
+  my @lines;
+
+  my @foo = `cd $svnroot; git log --pretty=format:COMMIT=%h --name-only --diff-filter=A`;
+  if ($retval != 0) {
+    $retval /= 256 if $retval > 0;
+    tldie("TLTree: git log in $svnroot returned $retval, stopping.\n");
+  }
+  chomp(@foo);
+
+  my $curcom = "";
+  for my $l (@foo) {
+    if ($l eq "") {
+      $curcom = "";
+      next;
+    } elsif ($l =~ m/^COMMIT=([[:xdigit:]]*)$/) {
+      $curcom = $1;
+      $rev++;
+      next;
+    } else {
+      $files{$l} = $rev;
+    }
+  }
+
+  # now reverse the order
+  for my $f (keys %files) {
+    my $n = - ( $files{$f} - $rev ) + 1;
+    push @lines, "             $n $n dummy $f"
+  }
+  # TODO needs to be made better!
+  $self->{'revision'} = $rev;
+  $self->_initialize_lines(@lines);
+}
+
+sub init_from_gitsvn {
+  my $self = shift;
+  my $svnroot = $self->{'svnroot'};
+  my @foo = `cd $svnroot; git log --pretty=format:%h --name-only --diff-filter=A`;
+  chomp(@foo);
+  my $retval = $?;
+  if ($retval != 0) {
+    $retval /= 256 if $retval > 0;
+    tldie("TLTree: git log in $svnroot returned $retval, stopping.\n");
+  }
+  my %com2rev;
+  my @lines;
+  my $curcom = "";
+  my $currev = "";
+  for my $l (@foo) {
+    if ($l eq "") {
+      $currev = "";
+      $curcom = "";
+      next;
+    }
+    if ($curcom eq "") {
+      # now we should get a commit!
+      # we could also pattern match on 8 hex digits, but that costs time!
+      $curcom = $l;
+      $currev = `git svn find-rev $curcom`;
+      chomp($currev);
+      if (!$currev) {
+        # found a commit without svn rev, try to find it under the parents
+        my $foo = $curcom;
+        my $nr = 0;
+        while (1) {
+          $foo .= "^";
+          $nr++;
+          my $tr = `git svn find-rev $foo`;
+          chomp($tr);
+          if ($tr) {
+            # we add the number of parents to the currev
+            $currev = $tr + $nr;
+            last;
+          }
+        }
+      }
+      $com2rev{$curcom} = $currev;
+    } else {
+      # we got a file name
+      push @lines, "             $currev $currev dummy $l"
+    }
+  }
+  # TODO needs to be made better!
+  $self->{'revision'} = 1;
+  $self->_initialize_lines(@lines);
+}
+
 sub _initialize_lines {
   my $self = shift;
   my @lines = @_;

Modified: trunk/Master/tlpkg/bin/tl-update-tlpdb
===================================================================
--- trunk/Master/tlpkg/bin/tl-update-tlpdb	2017-05-01 17:57:19 UTC (rev 44136)
+++ trunk/Master/tlpkg/bin/tl-update-tlpdb	2017-05-01 19:44:08 UTC (rev 44137)
@@ -31,6 +31,8 @@
 my $opt_dry_run = 0;
 my $opt_fix_reverse_revisions = 0;  # needs svn commit
 my $opt_fromfiles = 0;
+my $opt_fromgit = 0;
+my $opt_fromgitsvn = 0;
 my $opt_no_commit = 0; # do/don't commit the changes
 my $opt_no_revision_check = 0;
 my $opt_nobinsplit = 0;
@@ -48,6 +50,8 @@
     "fix-reverse-revisions!"     => \$opt_fix_reverse_revisions,
     "keep-revisions"             => \$opt_keep_revisions,
     "from-files"                 => \$opt_fromfiles,
+    "from-git"                   => \$opt_fromgit,
+    "from-gitsvn"                => \$opt_fromgitsvn,
     "master=s"                   => \$opt_master,
     "no-bin-split!"              => \$opt_nobinsplit,
     "no-commit!"                 => \$opt_no_commit,
@@ -70,6 +74,10 @@
     die "$progname: Master $opt_master not a directory, goodbye.\n";
   }
 
+  if ($opt_fromfiles + $opt_fromgit + $opt_fromgitsvn > 1) {
+    die "$progname: only one option --from[lines|git|gitsvn] can be given.\n";
+  }
+
   $opt_catalogue = "/home/httpd/html/catalogue"
     if ! $opt_catalogue;
 
@@ -317,6 +325,10 @@
   my $tltree = TeXLive::TLTREE->new ("svnroot" => $opt_master);
   if ($opt_fromfiles) {
     $tltree->init_from_files;
+  } elsif ($opt_fromgit) {
+    $tltree->init_from_git;
+  } elsif ($opt_fromgitsvn) {
+    $tltree->init_from_gitsvn;
   } else {
     $tltree->init_from_svn;
   }

Added: trunk/Master/tlpkg/bin/update-commit-svn-list.pl
===================================================================
--- trunk/Master/tlpkg/bin/update-commit-svn-list.pl	                        (rev 0)
+++ trunk/Master/tlpkg/bin/update-commit-svn-list.pl	2017-05-01 19:44:08 UTC (rev 44137)
@@ -0,0 +1,63 @@
+#!/usr/bin/perl 
+
+$^W = 1;
+
+use strict;
+
+if ($#ARGV < 1) {
+  die("usage: $0 git-dir commit-rev-file");
+}
+
+my $svnroot = $ARGV[0];
+my $comrevfile = $ARGV[1];
+
+init_from_git($svnroot, $comrevfile);
+
+sub find_last_done_com {
+  my $lastrev = "";
+  my $comrevfile = shift;
+  if (open (COMREV, "<$comrevfile")) {
+    my $foo = <COMREV>;
+    chomp($foo);
+    ($lastrev, undef) = split(" ", $foo);
+    close(COMREV);
+  }
+  return $lastrev;
+}
+
+sub init_from_git {
+  my ($svnroot, $comrevfile) = @_;
+
+  my $lastrev = find_last_done_com($comrevfile);
+  printf STDERR "calling cd $svnroot; git --no-pager log --pretty=format:%%h $lastrev..HEAD\n";
+  my @foo = `cd $svnroot; git --no-pager log --pretty=format:%h $lastrev..HEAD`;
+  chomp(@foo);
+  my $retval = $?;
+  if ($retval != 0) {
+    $retval /= 256 if $retval > 0;
+    die("TLTree: git log in $svnroot returned $retval, stopping.\n");
+  }
+  for my $c (@foo) {
+    print STDERR "calling cd $svnroot; git --no-pager svn find-rev $c\n";
+    my $r = `cd $svnroot; git --no-pager svn find-rev $c`;
+    chomp($r);
+    if (!$r) {
+      # found a commit without svn rev, try to find it under the parents
+      my $foo = $c;
+      my $nr = 0;
+      while (1) {
+        $foo .= "^";
+        $nr++;
+        my $tr = `cd $svnroot; git --no-pager svn find-rev $foo`;
+        chomp($tr);
+        if ($tr) {
+          # we add the number of parents to the currev
+          $r = "$c+$nr";	# that is NOT addition!
+          last;
+        }
+      }
+    }
+    print "$c $r\n";
+  }
+}
+


Property changes on: trunk/Master/tlpkg/bin/update-commit-svn-list.pl
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property


More information about the tex-live-commits mailing list