From patchwork Sat May 2 09:29:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lukas Pupka-Lipinski X-Patchwork-Id: 11523795 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8F3B881 for ; Sat, 2 May 2020 09:35:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7BD332137B for ; Sat, 2 May 2020 09:35:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726764AbgEBJfz (ORCPT ); Sat, 2 May 2020 05:35:55 -0400 Received: from smtp3.goneo.de ([85.220.129.37]:40896 "EHLO smtp3.goneo.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726548AbgEBJfz (ORCPT ); Sat, 2 May 2020 05:35:55 -0400 X-Greylist: delayed 360 seconds by postgrey-1.27 at vger.kernel.org; Sat, 02 May 2020 05:35:52 EDT Received: from localhost (localhost [127.0.0.1]) by smtp3.goneo.de (Postfix) with ESMTP id 7509923F8A5; Sat, 2 May 2020 11:29:51 +0200 (CEST) X-Virus-Scanned: by goneo X-Spam-Flag: NO X-Spam-Score: -2.9 X-Spam-Level: X-Spam-Status: No, score=-2.9 tagged_above=-999 tests=[ALL_TRUSTED=-1, AWL=0.000, BAYES_00=-1.9] autolearn=ham Received: from smtp3.goneo.de ([127.0.0.1]) by localhost (smtp3.goneo.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Jp9Vyx0bnP06; Sat, 2 May 2020 11:29:49 +0200 (CEST) Received: from [192.168.177.59] (ip-94-114-210-38.unity-media.net [94.114.210.38]) by smtp3.goneo.de (Postfix) with ESMTPA id 870EA23F113; Sat, 2 May 2020 11:29:49 +0200 (CEST) To: Eric Wong Cc: git@vger.kernel.org From: Lukas Pupka-Lipinski Subject: [PATCH]v2 GitSVN: Multi line support of ignore-path, include-paths and skiping of empty commits Message-ID: <9e582571-4b82-a46f-5eb2-14d80a4c865e@lpl-mind.de> Date: Sat, 2 May 2020 11:29:49 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0 MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Hi Eric, I used the ignore-paths option to ignore a lot of stuff I don’t need. The ignore pattern works well, but it could and up in empty commits. So just the message without any modifications / changes. The patch below skip a commit if all changes are ignored by the ignore-paths option. In order to use this feature I includes the option to read configuration for ignore-path, include-paths in several lines. So that the user is not limited by the max. char. per line definition. In Addition this patch includes the optimizations which are mansion from your side. Signed-off-by: Lukas Pupka-Lipinski --- diff --git a/perl/Git/SVN.pm b/perl/Git/SVN.pm index 4b28b87784..fa87687306 100644 --- a/perl/Git/SVN.pm +++ b/perl/Git/SVN.pm @@ -1188,6 +1188,22 @@ sub find_parent_branch { return undef; } +############################################################ + +=item do_fetch() + +Fetch an Commit and returns a log entry + +Input: $path - array of strings (Paths) in a commit + $rev - Revision number + +Output: $log_entry if successfull + null if skipped + (die) on fetch error + +=cut + +############################################################ sub do_fetch { my ($self, $paths, $rev) = @_; my $ed; @@ -1212,6 +1228,11 @@ sub do_fetch { } $ed = Git::SVN::Fetcher->new($self); } + my $skip = $ed->is_empty_commit($paths); + if ($skip){ + print "skip commit $rev\n"; + return; + } unless ($self->ra->gs_do_update($last_rev, $rev, $self, $ed)) { die "SVN connection failed somewhere...\n"; } diff --git a/perl/Git/SVN/Fetcher.pm b/perl/Git/SVN/Fetcher.pm index 64e900a0e9..c414aa879f 100644 --- a/perl/Git/SVN/Fetcher.pm +++ b/perl/Git/SVN/Fetcher.pm @@ -31,15 +31,17 @@ sub new { # override options set in an [svn-remote "..."] section $repo_id = $git_svn->{repo_id}; my $k = "svn-remote.$repo_id.ignore-paths"; - my $v = eval { command_oneline('config', '--get', $k) }; - $self->{ignore_regex} = $v; + my @config = eval { command('config', '--get-all', $k) }; + chomp(@config); # Replace all \n\r on the end + $self->{ignore_regex} = join('', @config); $k = "svn-remote.$repo_id.include-paths"; - $v = eval { command_oneline('config', '--get', $k) }; - $self->{include_regex} = $v; + @config = eval { command_oneline('config', '--get-all', $k) }; + chomp(@config); # Replace all \n\r on the end + $self->{include_regex} = join('', @config); $k = "svn-remote.$repo_id.preserve-empty-dirs"; - $v = eval { command_oneline('config', '--get', '--bool', $k) }; + my $v = eval { command_oneline('config', '--get', '--bool', $k) }; if ($v && $v eq 'true') { $_preserve_empty_dirs = 1; $k = "svn-remote.$repo_id.placeholder-filename"; @@ -137,6 +139,37 @@ sub is_path_ignored { return 0; } +############################################################ + +=item is_empty_commit() + +Return 1 if all given $paths are ignored, so that this commit end up in an empty commit + +Input: $path - array of strings (Paths) in a commit + +Output: { 1 if true, 0 if false } + +=cut + +############################################################ +sub is_empty_commit{ + my ($self, $paths) = @_; + my $path = ""; + unless (defined($self->{include_regex})){ + return 0; + } + + foreach $path (keys %$paths){ + unless (defined $path && -d $path ){ + my $ignored = $self->is_path_ignored($path); + if (!$ignored){ + return 0; + } + } + } + return 1; +} + sub set_path_strip { my ($self, $path) = @_; $self->{path_strip} = qr/^\Q$path\E(\/|$)/ if length $path; diff --git a/perl/Git/SVN/Ra.pm b/perl/Git/SVN/Ra.pm index 56ad9870bc..63be69dc12 100644 --- a/perl/Git/SVN/Ra.pm +++ b/perl/Git/SVN/Ra.pm @@ -475,6 +475,8 @@ sub gs_fetch_loop_common { my $log_entry = $gs->do_fetch($paths, $r); if ($log_entry) { $gs->do_git_commit($log_entry); + }else{ + next; } $Git::SVN::INDEX_FILES{$gs->{index}} = 1; } diff --git a/perl/Git/SVN.pm b/perl/Git/SVN.pm index 4b28b87784..fa87687306 100644 --- a/perl/Git/SVN.pm +++ b/perl/Git/SVN.pm @@ -1188,6 +1188,22 @@ sub find_parent_branch {      return undef;  } +############################################################ + +=item do_fetch() + +Fetch an Commit and returns a log entry + +Input:  $path - array of strings (Paths) in a commit +        $rev - Revision number + +Output: $log_entry if successfull +        null if skipped +        (die) on fetch error + +=cut + +############################################################  sub do_fetch {      my ($self, $paths, $rev) = @_;      my $ed; @@ -1212,6 +1228,11 @@ sub do_fetch {          }          $ed = Git::SVN::Fetcher->new($self);      } +    my $skip = $ed->is_empty_commit($paths); +    if ($skip){ +        print "skip commit $rev\n"; +        return; +    }      unless ($self->ra->gs_do_update($last_rev, $rev, $self, $ed)) {          die "SVN connection failed somewhere...\n";      } diff --git a/perl/Git/SVN/Fetcher.pm b/perl/Git/SVN/Fetcher.pm index 64e900a0e9..c414aa879f 100644 --- a/perl/Git/SVN/Fetcher.pm +++ b/perl/Git/SVN/Fetcher.pm @@ -31,15 +31,17 @@ sub new {      # override options set in an [svn-remote "..."] section      $repo_id = $git_svn->{repo_id};      my $k = "svn-remote.$repo_id.ignore-paths"; -    my $v = eval { command_oneline('config', '--get', $k) }; -    $self->{ignore_regex} = $v; +    my @config = eval { command('config', '--get-all', $k) }; +    chomp(@config); # Replace all \n\r on the end +    $self->{ignore_regex} = join('', @config);      $k = "svn-remote.$repo_id.include-paths"; -    $v = eval { command_oneline('config', '--get', $k) }; -    $self->{include_regex} = $v; +    @config = eval { command_oneline('config', '--get-all', $k) }; +    chomp(@config); # Replace all \n\r on the end +    $self->{include_regex} = join('', @config);      $k = "svn-remote.$repo_id.preserve-empty-dirs"; -    $v = eval { command_oneline('config', '--get', '--bool', $k) }; +    my $v = eval { command_oneline('config', '--get', '--bool', $k) };      if ($v && $v eq 'true') {          $_preserve_empty_dirs = 1;          $k = "svn-remote.$repo_id.placeholder-filename"; @@ -137,6 +139,37 @@ sub is_path_ignored {      return 0;  } +############################################################ + +=item is_empty_commit() + +Return 1 if all given $paths are ignored, so that this commit end up in an empty commit + +Input:  $path - array of strings (Paths) in a commit + +Output: { 1 if true, 0 if false } + +=cut + +############################################################ +sub is_empty_commit{ +    my ($self, $paths) = @_; +    my $path = ""; +    unless (defined($self->{include_regex})){ +        return 0; +    } + +    foreach $path (keys %$paths){ +        unless (defined $path && -d $path ){ +            my $ignored = $self->is_path_ignored($path); +            if (!$ignored){ +                return 0; +            } +        } +    } +    return 1; +} +  sub set_path_strip {      my ($self, $path) = @_;      $self->{path_strip} = qr/^\Q$path\E(\/|$)/ if length $path; diff --git a/perl/Git/SVN/Ra.pm b/perl/Git/SVN/Ra.pm index 56ad9870bc..63be69dc12 100644 --- a/perl/Git/SVN/Ra.pm +++ b/perl/Git/SVN/Ra.pm @@ -475,6 +475,8 @@ sub gs_fetch_loop_common {                  my $log_entry = $gs->do_fetch($paths, $r);                  if ($log_entry) {                      $gs->do_git_commit($log_entry); +                }else{ +                    next;                  }                  $Git::SVN::INDEX_FILES{$gs->{index}} = 1;              }