Mercurial and Git clients can push and pull from this alias URL to interact with this repository. You can change to which repository an alias points by going to the Aliases link on the project page.
# object_store.py -- Object store for git objects # Copyright (C) 2008 Jelmer Vernooij <jelmer@samba.org># # This program is free software; you can redistribute it and/or# modify it under the terms of the GNU General Public License# as published by the Free Software Foundation; either version 2# or (at your option) a later version of the License.# # This program is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the# GNU General Public License for more details.# # You should have received a copy of the GNU General Public License# along with this program; if not, write to the Free Software# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
-from objects import (
+from dulwich.objects import (
+ hex_to_sha, ShaFile,
- hex_to_sha, )
-import os, tempfile-from pack import (
+from dulwich.pack import (
iter_sha1,
load_packs,
write_pack_index_v2,
PackData,
)
++import osimport tempfile
import urllib2
+PACKDIR = 'pack'
class ObjectStore(object):
def__init__(self,path):self.path=pathself._packs=Nonedefpack_dir(self):returnos.path.join(self.path,PACKDIR)def__contains__(self,sha):# TODO: This can be more efficienttry:self[sha]returnTrueexceptKeyError:returnFalse@propertydefpacks(self):"""List with pack objects."""ifself._packsisNone:self._packs=list(load_packs(self.pack_dir()))returnself._packsdef_get_shafile_path(self,sha):dir=sha[:2]file=sha[2:]# Check from object dirreturnos.path.join(self.path,dir,file)def_get_shafile(self,sha):path=self._get_shafile_path(sha)ifos.path.exists(path):returnShaFile.from_file(path)returnNonedef_add_shafile(self,sha,o):path=self._get_shafile_path(sha)f=os.path.open(path,'w')try:f.write(o._header())f.write(o._text)finally:f.close()defget_raw(self,sha):"""Obtain the raw text for an object. :param sha: Sha for the object. :return: tuple with object type and object contents. """forpackinself.packs:ifshainpack:returnpack.get_raw(sha,self.get_raw)# FIXME: Are pack deltas ever against on-disk shafiles ?ret=self._get_shafile(sha)ifretisnotNone:returnret.as_raw_string()raiseKeyError(sha)def__getitem__(self,sha):assertlen(sha)==40,"Incorrect length sha: %s"%str(sha)ret=self._get_shafile(sha)ifretisnotNone:returnret# Check from packstype,uncomp=self.get_raw(sha)returnShaFile.from_raw_string(type,uncomp)defadd_objects(self,num_objects,objects):# TODO: If numb_objects is high enough, write a pack?forsha,oinobjects:self._add_shafile(sha,o)defmove_in_thin_pack(self,path):"""Move a specific file containing a pack into the pack directory. :note: The file should be on the same file system as the packs directory. :param path: Path to the pack file. """p=PackData(path)temppath=os.path.join(self.pack_dir(),sha_to_hex(urllib2.randombytes(20))+".temppack")write_pack(temppath,p.iterobjects(self.get_raw),len(p))pack_sha=PackIndex(temppath+".idx").objects_sha1()os.rename(temppath+".pack",os.path.join(self.pack_dir(),"pack-%s.pack"%pack_sha))os.rename(temppath+".idx",os.path.join(self.pack_dir(),"pack-%s.idx"%pack_sha))defmove_in_pack(self,path):"""Move a specific file containing a pack into the pack directory. :note: The file should be on the same file system as the packs directory. :param path: Path to the pack file. """p=PackData(path)entries=p.sorted_entries()basename=os.path.join(self.pack_dir(),"pack-%s"%iter_sha1(entry[0]forentryinentries))write_pack_index_v2(basename+".idx",entries,p.calculate_checksum())os.rename(path,basename+".pack")defadd_thin_pack(self):"""Add a new thin pack to this object store. Thin packs are packs that contain deltas with parents that exist in a different pack. """fd,path=tempfile.mkstemp(dir=self.pack_dir(),suffix=".pack")f=os.fdopen(fd,'w')defcommit():ifos.path.getsize(path)>0:self.move_in_thin_pack(path)returnf,commitdefadd_pack(self):"""Add a new pack to this object store. :return: Fileobject to write to and a commit function to call when the pack is finished. """fd,path=tempfile.mkstemp(dir=self.pack_dir(),suffix=".pack")f=os.fdopen(fd,'w')defcommit():ifos.path.getsize(path)>0:self.move_in_pack(path)returnf,commitdefadd_objects(self,objects):iflen(objects)==0:returnf,commit=self.add_pack()write_pack_data(f,objects,len(objects))commit()
Attach a Trello Card
Add a tag
Your session has expired
You are no longer logged in. Please log in and try your request again.
Filter RSS Feed
This RSS feed URL allows you to see the contents of your current filter using any feed reader.
This link includes a special authentication token. If you share the URL with anyone else, they can see this RSS feed's activity. You can disable these tokens when needed.
Your current filter is unsaved; changing it won't affect this RSS feed.