BASH   70

dscs to git

Guest on 21st April 2022 01:25:03 AM

  1. "#!/bin/bash
  2.  
  3. set -e
  4.  
  5. pkg=$1
  6.  
  7. r="repos/$pkg"
  8.  
  9. if [ ! -d "$r" ]
  10. then
  11.  git init -q --bare "$r"
  12. fi
  13.  
  14. firstletter=${pkg:0:1}
  15. archive=/home/nomeata/mount/packages/$firstletter/$pkg/
  16.  
  17. test -d tmp || mkdir tmp
  18.  
  19. echo Importing sources...
  20.  
  21. for v in $(ls $archive)
  22. do
  23.  vc="$(echo "$v"|tr '~^:?*[' _)"
  24.  if ! git --git-dir=$r show-ref --quiet --verify -- "refs/trees/$vc"
  25.  then
  26.         echo $v
  27.         tmp=$(mktemp -u -d --tmpdir=tmp/ $pXXXXXXXX)
  28.         # sigh, too verbose and no --quiet
  29.         dpkg-source --no-copy -x $archive/$v/*dsc $tmp >/dev/null 2>/dev/null
  30.         git --git-dir=$r --work-tree=$tmp add .
  31.         tree=$(git --git-dir=$r --work-tree=$tmp write-tree)
  32.         git --git-dir=$r update-ref refs/trees/$vc $tree
  33.         rm -rf $tmp
  34.  fi
  35. done
  36.  
  37. echo Building graph of commits...
  38. echo > $r/commit-graph
  39. for v in $(ls $archive)
  40. do
  41.  vc="$(echo "$v"|tr '~^:?*[' _)"
  42.  for v2 in $(git --git-dir=$r show refs/trees/$vc:debian/changelog|dpkg-parsechangelog --format rfc822  -l- --all -S Version)
  43.  do
  44.    if test -d $archive/$v2
  45.    then
  46.      echo "$v2 $v" >> $r/commit-graph
  47.    fi
  48.  done
  49. done
  50. cat $r/commit-graph |head -n 20
  51.  
  52. echo Building commits...
  53. for v in $(tsort < $r/commit-graph)
  54. do
  55.  vc="$(echo "$v"|tr '~^:?*[' _)"
  56.  if ! git --git-dir=$r show-ref --quiet --verify -- "refs/tags/$vc"
  57.  then
  58.         echo "$v"
  59.         parents="$(grep " $v\$" $r/commit-graph|cut -d\  -f1|fgrep -x -v $v| tr '~^:?*[' _|sed -e 's,^,refs/tags/,'|tr '\n' ' ')"
  60.         #echo $parents
  61.  
  62.        if test -n "$parents"
  63.        then chosen_parents=$(git --git-dir=$r merge-base --independent $parents|sed -e 's,^,-p ,'|tr '\n' ' ')
  64.        else chosen_parents=""
  65.        fi
  66.         #echo chosen: $chosen_parents
  67.         commit=$(
  68.                 git --git-dir=$r show refs/trees/$vc:debian/changelog|dpkg-parsechangelog -Fdebian -l- -c1 -SChanges|sed '1{/^$/d}' | \
  69.                 GIT_AUTHOR_NAME="$(git --git-dir=$r show refs/trees/$vc:debian/changelog|dpkg-parsechangelog -Fdebian -l- -c1 -SMaintainer|cut -d\< -f1)" \
  70.                 GIT_AUTHOR_EMAIL="$(git --git-dir=$r show refs/trees/$vc:debian/changelog|dpkg-parsechangelog -Fdebian -l- -c1 -SMaintainer|cut -d\< -f2)" \
  71.                 GIT_AUTHOR_DATE="$(git --git-dir=$r show refs/trees/$vc:debian/changelog|dpkg-parsechangelog -Fdebian -l- -c1 -SDate)" \
  72.                 GIT_COMMITTER_DATE=$GIT_AUTHOR_DATE \
  73.                 git --git-dir=$r commit-tree $chosen_parents refs/trees/$vc     )
  74.         git --git-dir=$r update-ref refs/tags/$vc $commit
  75.         # assuming the latest commit comes last
  76.         git --git-dir=$r update-ref refs/heads/master $commit
  77.  fi
  78. done
  79.  
  80. git --git-dir=$r gc"
  81.  https://people.debian.org/~nomeata/dscs_to_git.sh#:~:text=%23!/bin/bash%0A%0Aset,dir%3D%24r%20gc

Raw Paste


Login or Register to edit or fork this paste. It's free.