All of lore.kernel.org
 help / color / mirror / Atom feed
From: Denys Dmytriyenko <denys@ti.com>
To: Chase Maupin <Chase.Maupin@ti.com>
Cc: meta-arago@arago-project.org
Subject: Re: [PATCH 1/4] sourceipk: allow packaging shallow git clone
Date: Tue, 15 Jul 2014 13:33:37 -0400	[thread overview]
Message-ID: <20140715173337.GG15788@edge> (raw)
In-Reply-To: <1405423715-21885-2-git-send-email-Chase.Maupin@ti.com>

On Tue, Jul 15, 2014 at 06:28:32AM -0500, Chase Maupin wrote:
> * Add another flag SRCIPK_SHALLOW_CLONE that will do a shallow
>   clone of depth 1 to reduce the size of the git history.
>     * The full history can be fetched again using either of the
>       following commands based on the version of git being used
>         - git pull --unshallow (New git versions)
>         - git pull (older git versions)
> * Clean up some of the variable names to make it more clear what
>   they are storing.
> * Create a generic function to determine the fetch reporitory
> 
> Signed-off-by: Chase Maupin <Chase.Maupin@ti.com>
> ---
>  meta-arago-distro/classes/sourceipk.bbclass |  100 ++++++++++++++++++++++++---
>  1 file changed, 89 insertions(+), 11 deletions(-)
> 
> diff --git a/meta-arago-distro/classes/sourceipk.bbclass b/meta-arago-distro/classes/sourceipk.bbclass
> index 20dda76..33878ac 100644
> --- a/meta-arago-distro/classes/sourceipk.bbclass
> +++ b/meta-arago-distro/classes/sourceipk.bbclass
> @@ -61,32 +61,111 @@ SRCIPK_INCLUDE_EXTRAFILES ?= "1"
>  
>  SRCIPK_PRESERVE_GIT ?= "false"
>  
> -adjust_git() {
> +# Create a shallow clone of the git repository to reduce the size of
> +# the sourceipk
> +SRCIPK_SHALLOW_CLONE ?= "false"
> +
> +# This function will return the fetch URL for a git repository passed as
> +# the first parameter.
> +get_remote() {
> +    git_repo="$1"
> +
> +    if [ "$git_repo" == "" ]
> +    then
> +        echo "git_repo not passed to get_remote"
> +        exit 1
> +    fi
> +
> +    cd $git_repo
> +
> +    # Get the remote repository fetch URL
> +    remote=`git remote -v | grep "(fetch)" | cut -d ' ' -f 1   | cut -c 7- | tr -d ' '`
> +
> +    # Since the echo'ed value of this statment is the returned value redirect
> +    # the output of this command to /dev/null
> +    cd - > /dev/null
> +
> +    # echo back the remote repository URL as the output of this function
> +    echo $remote
> +
> +    return 0
> +}
> +
> +# Some git repositories are very large and we do not want to ship the
> +# full history.  Instead we want to limit history to reduce the size while
> +# still keeping the git repository in place.  The full history can be
> +# fetched using git pull --unshallow or just git pull
> +# NOTE: This function depends on a git version >= 1.7.10.  It will work
> +#       with older versions but the size will be larger because rather
> +#       than just a single branch the limited history will be a depth of
> +#       1 for all branches and tags.
> +limit_git_history() {
> +    # By default limit the history to 1 commit since the user can always
> +    # use git pull --unshallow to fetch the rest of history.  The depth
> +    # level of 1 is set to keep from tracking through all merges and
> +    # pulling excess history
> +    commits="1"
> +
> +    # Temporary directory to make shallow clones in
> +    gitshallowclone="${WORKDIR}/temp-git-shallow-clone"
> +
> +    # Change directory to the git repository to be safe
> +    cd $tmp_dir/${SRCIPK_INSTALL_DIR}
> +
> +    # Create a temporary directory to hold the shallow git clone
> +    mkdir -p $gitshallowclone
>  
> +    remote=`get_remote $PWD`
> +
> +    git clone --depth $commits --branch ${BRANCH} file://$remote $gitshallowclone
> +
> +    # remove original kernel clone since we will replace it with the shallow
> +    # clone
> +    rm -rf $tmp_dir/${SRCIPK_INSTALL_DIR}/.git
> +
> +    # replace the original kernel git data with the shallow clone git data
> +    mv $gitshallowclone/.git $tmp_dir/${SRCIPK_INSTALL_DIR}/
> +    rm -rf $gitshallowclone
> +
> +    cd -
> +}
> +
> +adjust_git() {
>      orig_dir="$PWD"
>  
>      cd $tmp_dir/${SRCIPK_INSTALL_DIR}
>  
>      if [ -d ".git" ]
>      then
> +        # Get the location of the local repository
> +        local_repo=`get_remote $PWD`
>  
> -        # Grab path to cloned local repository
> -        old=`git remote -v | grep "(fetch)" | cut -d ' ' -f 1   | cut -c 7- | tr -d ' '`
> -
> -        if [ -d $old -a "${SRCIPK_PRESERVE_GIT}" = "true" ]
> +        if [ -d $local_repo -a "${SRCIPK_PRESERVE_GIT}" = "true" ]
>          then
> -            cd $old
> +            cd $local_repo
> +
> +            # If SRCIPK_SHALLOW_CLONE is true then make a shallow copy of the
> +            # git repository and then fix up the git URLs
> +            if [ "${SRCIPK_SHALLOW_CLONE}" == "true" ]
> +            then
> +                limit_git_history
> +            fi
>  
>              # Grab actual url used to create the repository
> -            orig=`git remote -v | grep "(fetch)" | cut -d ' ' -f 1   | cut -c 7- | tr -d ' '`
> +            remote_repo=`get_remote $PWD`
>  
>              cd -
>  
> -            git remote set-url origin $orig $old
> +            git remote set-url origin $remote_repo $local_repo
>  
> -            # Repackage the repository so its a proper clone of the original (remote) git repository
> +            # Repackage the repository so its a proper clone of the original
> +            # (remote) git repository
>              git repack -a -d



> -            rm .git/objects/info/alternates
> +
> +            if [ -e .git/objects/info/alternates ]
> +            then
> +                rm .git/objects/info/alternates
> +            fi

If you are worried about the file not being present:

rm -f .git/objects/info/alternates

Otherwise looks reasonable.


>  
>          else
>              rm -rf .git
> @@ -95,7 +174,6 @@ adjust_git() {
>      fi
>  
>      cd $orig_dir
> -
>  }
>  
>  # Create a README file that describes the contents of the source ipk
> -- 
> 1.7.9.5
> 
> _______________________________________________
> meta-arago mailing list
> meta-arago@arago-project.org
> http://arago-project.org/cgi-bin/mailman/listinfo/meta-arago


  reply	other threads:[~2014-07-15 17:33 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-15 11:28 [PATCH 0/4] Allow shallow git clones Chase Maupin
2014-07-15 11:28 ` [PATCH 1/4] sourceipk: allow packaging shallow git clone Chase Maupin
2014-07-15 17:33   ` Denys Dmytriyenko [this message]
2014-07-16 14:19   ` Cooper Jr., Franklin
2014-07-17 17:23     ` Maupin, Chase
2014-07-18 15:03     ` Maupin, Chase
2014-07-15 11:28 ` [PATCH 2/4] arago-source-ipk: do a shallow clone of the kernel Chase Maupin
2014-07-15 11:28 ` [PATCH 3/4] arago: unset ASSUME_PROVIDED for git-native Chase Maupin
2014-07-15 17:28   ` Denys Dmytriyenko
2014-07-17 17:05     ` Denys Dmytriyenko
2014-07-18 15:52       ` Maupin, Chase
2014-07-18 17:55         ` Denys Dmytriyenko
2014-07-18 18:16           ` Maupin, Chase
2014-07-15 11:28 ` [PATCH 4/4] linux-ti-staging: update bbappend for 3.14 version Chase Maupin
2014-07-16 14:30   ` Cooper Jr., Franklin
2014-07-16 15:01     ` Denys Dmytriyenko
2014-07-16 15:13       ` Cooper Jr., Franklin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140715173337.GG15788@edge \
    --to=denys@ti.com \
    --cc=Chase.Maupin@ti.com \
    --cc=meta-arago@arago-project.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.