@@ -102,10 +102,12 @@ func downloadFile(filename, url string) error {
102102
103103// upstream describes the upstream repo we are about to package.
104104type upstream struct {
105+ rr * vcs.RepoRoot
105106 tarPath string // path to the downloaded or generated orig tarball tempfile
106107 compression string // compression method, either "gz" or "xz"
107108 version string // Debian package upstream version number, e.g. 0.0~git20180204.1d24609
108109 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
109111 firstMain string // import path of the first main package within repo, if any
110112 vendorDirs []string // all vendor sub directories, relative to the repo directory
111113 repoDeps []string // the repository paths of all dependencies (e.g. github.com/zyedidia/glob)
@@ -123,6 +125,7 @@ func (u *upstream) get(gopath, repo, rev string) error {
123125 if err != nil {
124126 return err
125127 }
128+ u .rr = rr
126129 dir := filepath .Join (gopath , "src" , rr .Root )
127130 if rev != "" {
128131 return rr .VCS .CreateAtRev (dir , rr .Repo , rev )
@@ -371,7 +374,8 @@ func runGitCommandIn(dir string, arg ...string) error {
371374 return cmd .Run ()
372375}
373376
374- 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 ) {
375379 wd , err := os .Getwd ()
376380 if err != nil {
377381 return "" , err
@@ -413,6 +417,21 @@ func createGitRepository(debsrc, gopkg, orig string, dep14, pristineTar bool) (s
413417 return dir , err
414418 }
415419
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+
416435 // Import upstream orig tarball
417436
418437 arg := []string {"import-orig" , "--no-interactive" }
@@ -422,6 +441,9 @@ func createGitRepository(debsrc, gopkg, orig string, dep14, pristineTar bool) (s
422441 if pristineTar {
423442 arg = append (arg , "--pristine-tar" )
424443 }
444+ if includeUpstreamHistory {
445+ arg = append (arg , "--upstream-vcs-tag=" + u .commitIsh )
446+ }
425447 arg = append (arg , filepath .Join (wd , orig ))
426448 cmd := exec .Command ("gbp" , arg ... )
427449 cmd .Dir = dir
@@ -530,7 +552,7 @@ func shortHostName(gopkg string, allowUnknownHoster bool) (host string, err erro
530552 return host , err
531553}
532554
533- // debianNameFromGopkg converts a Go package repo path to a Debian package name,
555+ // debianNameFromGopkg maps a Go package repo path to a Debian package name,
534556// e.g. "golang.org/x/text" → "golang-golang-x-text".
535557// This follows https://fedoraproject.org/wiki/PackagingDrafts/Go#Package_Names
536558func debianNameFromGopkg (gopkg string , t packageType , allowUnknownHoster bool ) string {
@@ -720,6 +742,13 @@ func execMake(args []string, usage func()) {
720742 ` * "library+program" (aliases: "lib+prog", "l+p", "both")` + "\n " +
721743 ` * "program+library" (aliases: "prog+lib", "p+l", "combined")` )
722744
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+
723752 fs .StringVar (& wrapAndSort ,
724753 "wrap-and-sort" ,
725754 "a" ,
@@ -862,7 +891,7 @@ func execMake(args []string, usage func()) {
862891
863892 debversion := u .version + "-1"
864893
865- dir , err := createGitRepository (debsrc , gopkg , orig , dep14 , pristineTar )
894+ dir , err := createGitRepository (debsrc , gopkg , orig , u , includeUpstreamHistory , allowUnknownHoster , dep14 , pristineTar )
866895 if err != nil {
867896 log .Fatalf ("Could not create git repository: %v\n " , err )
868897 }
@@ -927,4 +956,18 @@ func execMake(args []string, usage func()) {
927956 fmt .
Printf (
" git remote set-url origin [email protected] :go-team/packages/%s.git\n " ,
debsrc )
928957 fmt .Printf (" gbp push\n " )
929958 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+ }
930973}
0 commit comments