@@ -102,15 +102,18 @@ func downloadFile(filename, url string) error {
102
102
103
103
// upstream describes the upstream repo we are about to package.
104
104
type upstream struct {
105
+ rr * vcs.RepoRoot
105
106
tarPath string // path to the downloaded or generated orig tarball tempfile
106
107
compression string // compression method, either "gz" or "xz"
107
108
version string // Debian package upstream version number, e.g. 0.0~git20180204.1d24609
109
+ commitIsh string // commit-ish corresponding to upstream version to be packaged
110
+ remote string // git remote, set to short hostname if upstream git history is included
108
111
firstMain string // import path of the first main package within repo, if any
109
112
vendorDirs []string // all vendor sub directories, relative to the repo directory
110
113
repoDeps []string // the repository paths of all dependencies (e.g. github.com/zyedidia/glob)
111
114
hasGodeps bool // whether the Godeps/_workspace directory exists
112
115
hasRelease bool // whether any release tags exist, for debian/watch
113
- isRelease bool // whether we are packaging a tagged version or not
116
+ isRelease bool // whether what we end up packaging is a tagged release
114
117
}
115
118
116
119
func (u * upstream ) get (gopath , repo , rev string ) error {
@@ -122,6 +125,7 @@ func (u *upstream) get(gopath, repo, rev string) error {
122
125
if err != nil {
123
126
return err
124
127
}
128
+ u .rr = rr
125
129
dir := filepath .Join (gopath , "src" , rr .Root )
126
130
if rev != "" {
127
131
return rr .VCS .CreateAtRev (dir , rr .Repo , rev )
@@ -341,7 +345,7 @@ func makeUpstreamSourceTarball(repo, revision string, forcePrerelease bool) (*up
341
345
342
346
log .Printf ("Determining upstream version number\n " )
343
347
344
- u .version , u . hasRelease , u . isRelease , err = pkgVersionFromGit (repoDir , forcePrerelease )
348
+ u .version , err = pkgVersionFromGit (repoDir , & u , forcePrerelease )
345
349
if err != nil {
346
350
return nil , err
347
351
}
@@ -370,7 +374,8 @@ func runGitCommandIn(dir string, arg ...string) error {
370
374
return cmd .Run ()
371
375
}
372
376
373
- func createGitRepository (debsrc , gopkg , orig string , dep14 , pristineTar bool ) (string , error ) {
377
+ func createGitRepository (debsrc , gopkg , orig string , u * upstream ,
378
+ includeUpstreamHistory , allowUnknownHoster , dep14 , pristineTar bool ) (string , error ) {
374
379
wd , err := os .Getwd ()
375
380
if err != nil {
376
381
return "" , err
@@ -412,6 +417,21 @@ func createGitRepository(debsrc, gopkg, orig string, dep14, pristineTar bool) (s
412
417
return dir , err
413
418
}
414
419
420
+ if includeUpstreamHistory {
421
+ u .remote , err = shortHostName (gopkg , allowUnknownHoster )
422
+ if err != nil {
423
+ return dir , fmt .Errorf ("Unable to fetch upstream history: %q" , err )
424
+ }
425
+ log .Printf ("Adding %q as remote %q\n " , u .rr .Repo , u .remote )
426
+ if err := runGitCommandIn (dir , "remote" , "add" , u .remote , u .rr .Repo ); err != nil {
427
+ return dir , err
428
+ }
429
+ log .Printf ("Running \" git fetch %s\" \n " , u .remote )
430
+ if err := runGitCommandIn (dir , "fetch" , u .remote ); err != nil {
431
+ return dir , err
432
+ }
433
+ }
434
+
415
435
// Import upstream orig tarball
416
436
417
437
arg := []string {"import-orig" , "--no-interactive" }
@@ -421,6 +441,9 @@ func createGitRepository(debsrc, gopkg, orig string, dep14, pristineTar bool) (s
421
441
if pristineTar {
422
442
arg = append (arg , "--pristine-tar" )
423
443
}
444
+ if includeUpstreamHistory {
445
+ arg = append (arg , "--upstream-vcs-tag=" + u .commitIsh )
446
+ }
424
447
arg = append (arg , filepath .Join (wd , orig ))
425
448
cmd := exec .Command ("gbp" , arg ... )
426
449
cmd .Dir = dir
@@ -484,16 +507,11 @@ func normalizeDebianProgramName(str string) string {
484
507
return safe
485
508
}
486
509
487
- // This follows https://fedoraproject.org/wiki/PackagingDrafts/Go#Package_Names
488
- func debianNameFromGopkg (gopkg string , t packageType , allowUnknownHoster bool ) string {
510
+ func shortHostName (gopkg string , allowUnknownHoster bool ) (host string , err error ) {
489
511
parts := strings .Split (gopkg , "/" )
512
+ fqdn := parts [0 ]
490
513
491
- if t == typeProgram || t == typeProgramLibrary {
492
- return normalizeDebianProgramName (parts [len (parts )- 1 ])
493
- }
494
-
495
- host := parts [0 ]
496
- switch host {
514
+ switch fqdn {
497
515
case "github.com" :
498
516
host = "github"
499
517
case "code.google.com" :
@@ -526,12 +544,30 @@ func debianNameFromGopkg(gopkg string, t packageType, allowUnknownHoster bool) s
526
544
if allowUnknownHoster {
527
545
suffix , _ := publicsuffix .PublicSuffix (host )
528
546
host = host [:len (host )- len (suffix )- len ("." )]
529
- log .Printf ("WARNING: Using %q as canonical hostname for %q. If that is not okay, please file a bug against %s.\n " , host , parts [ 0 ] , os .Args [0 ])
547
+ log .Printf ("WARNING: Using %q as canonical hostname for %q. If that is not okay, please file a bug against %s.\n " , host , fqdn , os .Args [0 ])
530
548
} else {
531
- log . Fatalf ( "Cannot derive Debian package name: unknown hoster %q. See -help output for -allow_unknown_hoster \n " , host )
549
+ err = fmt . Errorf ( " unknown hoster %q" , fqdn )
532
550
}
533
551
}
552
+ return host , err
553
+ }
554
+
555
+ // debianNameFromGopkg maps a Go package repo path to a Debian package name,
556
+ // e.g. "golang.org/x/text" → "golang-golang-x-text".
557
+ // This follows https://fedoraproject.org/wiki/PackagingDrafts/Go#Package_Names
558
+ func debianNameFromGopkg (gopkg string , t packageType , allowUnknownHoster bool ) string {
559
+ parts := strings .Split (gopkg , "/" )
560
+
561
+ if t == typeProgram || t == typeProgramLibrary {
562
+ return normalizeDebianProgramName (parts [len (parts )- 1 ])
563
+ }
564
+
565
+ host , err := shortHostName (gopkg , allowUnknownHoster )
566
+ if err != nil {
567
+ log .Fatalf ("Cannot derive Debian package name: %v. See -help output for -allow_unknown_hoster\n " , err )
568
+ }
534
569
parts [0 ] = host
570
+
535
571
return strings .Trim ("golang-" + strings .ToLower (strings .Replace (strings .Join (parts , "-" ), "_" , "-" , - 1 )), "-" )
536
572
}
537
573
@@ -706,6 +742,13 @@ func execMake(args []string, usage func()) {
706
742
` * "library+program" (aliases: "lib+prog", "l+p", "both")` + "\n " +
707
743
` * "program+library" (aliases: "prog+lib", "p+l", "combined")` )
708
744
745
+ var includeUpstreamHistory bool
746
+ fs .BoolVar (& includeUpstreamHistory ,
747
+ "upstream-git-history" ,
748
+ true ,
749
+ "Include upstream git history (Debian pkg-go team new workflow).\n " +
750
+ "New in dh-make-golang 0.3.0, currently experimental." )
751
+
709
752
fs .StringVar (& wrapAndSort ,
710
753
"wrap-and-sort" ,
711
754
"a" ,
@@ -848,7 +891,7 @@ func execMake(args []string, usage func()) {
848
891
849
892
debversion := u .version + "-1"
850
893
851
- dir , err := createGitRepository (debsrc , gopkg , orig , dep14 , pristineTar )
894
+ dir , err := createGitRepository (debsrc , gopkg , orig , u , includeUpstreamHistory , allowUnknownHoster , dep14 , pristineTar )
852
895
if err != nil {
853
896
log .Fatalf ("Could not create git repository: %v\n " , err )
854
897
}
@@ -913,4 +956,18 @@ func execMake(args []string, usage func()) {
913
956
fmt .
Printf (
" git remote set-url origin [email protected] :go-team/packages/%s.git\n " ,
debsrc )
914
957
fmt .Printf (" gbp push\n " )
915
958
fmt .Printf ("\n " )
959
+
960
+ if includeUpstreamHistory {
961
+ fmt .Printf ("NOTE: Full upstream git history has been included as per pkg-go team's\n " )
962
+ fmt .Printf (" new workflow. This feature is new and somewhat experimental,\n " )
963
+ fmt .Printf (" and all feedback are welcome!\n " )
964
+ fmt .Printf (" (For old behavior, use --include-upstream-history=false)\n " )
965
+ fmt .Printf ("\n " )
966
+ fmt .Printf ("The upstream git history is being tracked with the remote named %q.\n " , u .remote )
967
+ fmt .Printf ("To upgrade to the latest upstream version, you may use something like:\n " )
968
+ fmt .Printf (" git fetch %-15v # note the latest tag or commit-ish\n " , u .remote )
969
+ fmt .Printf (" uscan --report-status # check we get the same tag or commit-ish\n " )
970
+ fmt .Printf (" gbp import-orig --sign-tags --uscan --upstream-vcs-tag=<commit-ish>\n " )
971
+ fmt .Printf ("\n " )
972
+ }
916
973
}
0 commit comments