~ubuntu-branches/debian/sid/git/sid

« back to all changes in this revision

Viewing changes to debian/diff/0020-git-svn-add-join_paths-to-safely-concatenate-paths.diff

  • Committer: Package Import Robot
  • Author(s): Jonathan Nieder
  • Date: 2013-06-12 07:50:53 UTC
  • mfrom: (1.2.19) (2.1.31 experimental)
  • Revision ID: package-import@ubuntu.com-20130612075053-uue9xe0dq0rvm44y
Tags: 1:1.8.3.1-1
* merge branch debian-experimental
* new upstream point release (see RelNotes/1.8.3.1.txt).
* debian/watch: use xz-compressed tarballs from kernel.org.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
From f39fef0a43e4c755837593229a39828e45611e77 Mon Sep 17 00:00:00 2001
2
 
From: "Michael G. Schwern" <schwern@pobox.com>
3
 
Date: Sat, 28 Jul 2012 02:38:29 -0700
4
 
Subject: git-svn: add join_paths() to safely concatenate paths
5
 
 
6
 
Otherwise you might wind up with things like...
7
 
 
8
 
    my $path1 = undef;
9
 
    my $path2 = 'foo';
10
 
    my $path = $path1 . '/' . $path2;
11
 
 
12
 
creating '/foo'.  Or this...
13
 
 
14
 
    my $path1 = 'foo/';
15
 
    my $path2 = 'bar';
16
 
    my $path = $path1 . '/' . $path2;
17
 
 
18
 
creating 'foo//bar'.
19
 
 
20
 
Could have used File::Spec, but I'm shying away from it due to SVN
21
 
1.7's pickiness about paths.  Felt it would be better to have our own
22
 
we can control completely.
23
 
 
24
 
[ew: commit title]
25
 
[jn: drop unused unit test]
26
 
 
27
 
Signed-off-by: Eric Wong <normalperson@yhbt.net>
28
 
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
29
 
---
30
 
 git-svn.perl |   38 ++++++++++++++++++++++++++++++++++----
31
 
 1 file changed, 34 insertions(+), 4 deletions(-)
32
 
 
33
 
diff --git a/git-svn.perl b/git-svn.perl
34
 
index 045105b..e7d0fb8 100755
35
 
--- a/git-svn.perl
36
 
+++ b/git-svn.perl
37
 
@@ -1285,6 +1285,38 @@ sub _canonicalize_url_ourselves {
38
 
        return $url;
39
 
 }
40
 
 
41
 
+=head3 join_paths
42
 
+
43
 
+    my $new_path = join_paths(@paths);
44
 
+
45
 
+Appends @paths together into a single path.  Any empty paths are ignored.
46
 
+
47
 
+=cut
48
 
+
49
 
+sub join_paths {
50
 
+       my @paths = @_;
51
 
+
52
 
+       @paths = grep { defined $_ && length $_ } @paths;
53
 
+
54
 
+       return '' unless @paths;
55
 
+       return $paths[0] if @paths == 1;
56
 
+
57
 
+       my $new_path = shift @paths;
58
 
+       $new_path =~ s{/+$}{};
59
 
+
60
 
+       my $last_path = pop @paths;
61
 
+       $last_path =~ s{^/+}{};
62
 
+
63
 
+       for my $path (@paths) {
64
 
+               $path =~ s{^/+}{};
65
 
+               $path =~ s{/+$}{};
66
 
+               $new_path .= "/$path";
67
 
+       }
68
 
+
69
 
+       return $new_path .= "/$last_path";
70
 
+}
71
 
+
72
 
+
73
 
 # get_svnprops(PATH)
74
 
 # ------------------
75
 
 # Helper for cmd_propget and cmd_proplist below.
76
 
@@ -1298,7 +1330,7 @@ sub get_svnprops {
77
 
        $path = $cmd_dir_prefix . $path;
78
 
        fatal("No such file or directory: $path") unless -e $path;
79
 
        my $is_dir = -d $path ? 1 : 0;
80
 
-       $path = $gs->{path} . '/' . $path;
81
 
+       $path = join_paths($gs->{path}, $path);
82
 
 
83
 
        # canonicalize the path (otherwise libsvn will abort or fail to
84
 
        # find the file)
85
 
@@ -2342,9 +2374,7 @@ sub init_remote_config {
86
 
                        }
87
 
                        my $old_path = $self->path;
88
 
                        $url =~ s!^\Q$min_url\E(/|$)!!;
89
 
-                       if (length $old_path) {
90
 
-                               $url .= "/$old_path";
91
 
-                       }
92
 
+                       $url = ::join_paths($url, $old_path);
93
 
                        $self->path($url);
94
 
                        $url = $min_url;
95
 
                }
96
 
1.7.10.4
97