Is it possible to remote count object and size of git repository?

后端 未结 5 717

Assume that somewhere in the web exists public git repository. I want to clone it but firstly i need to be sure what is size of it (how much objects & kbytes like in

5条回答
  •  误落风尘
    2020-12-25 11:46

    I think there are a couple problems with this question: git count-objects doesn't truly represent the size of a repository (even git count-object -v doesn't really); if you're using anything other than the dumb http transport, a new pack will be created for your clone when you make it; and (as VonC pointed out) anything you do to analyze a remote repo won't take into account the working copy size.

    That being said, if they are using the dumb http transport (github, for example, is not), you could write a shell script that used curl to query the sizes of all the objects and packs. That might get you closer, but it's making more http requests that you'll just have to make again to actually do the clone.

    It is possible to figure out what git-fetch would send across the wire (to a smart http transport) and send that to analyze the results, but it's not really a nice thing to do. Essentially you're asking the target server to pack up results that you're just going to download and throw away, so that you can download them again to save them.

    Something like these steps can be used to this effect:

    url=https://github.com/gitster/git.git
    git ls-remote $url |
      grep '[[:space:]]\(HEAD\|refs/heads/master\|refs/tags\)' |
      grep -v '\^{}$' | awk '{print "0032want " $1}' > binarydata
    echo 00000009done >> binarydata
    curl -s -X POST --data-binary @binarydata \
      -H "Content-Type: application/x-git-upload-pack-request" \
      -H "Accept-Encoding: deflate, gzip" \
      -H "Accept: application/x-git-upload-pack-result" \
      -A "git/1.7.9" $url/git-upload-pack | wc -c
    

    At the end of all of this, the remote server will have packed up master/HEAD and all the tags for you and you will have downloaded the entire pack file just to see how big it will be when you download it during your clone.

    When you finally do a clone, the working copy will be created as well, so the entire directory will be larger than these commands spit out, but the pack file generally is the largest part of a working copy with any significant history.

提交回复
热议问题