| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 3c9f55d commit 33fa178
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,6 +15,18 @@ General | |||
| 15 | 15 | * References should be parsed 'manually' to get around command invocation, but | |
| 16 | 16 | be sure to be able to read packed refs. | |
| 17 | 17 | ||
| 18 | + Object | ||
| 19 | + ------ | ||
| 20 | + * DataStream method should read the data itself. This would be easy once you have | ||
| 21 | + the actul loose object, but will be hard if it is in a pack. In a distant future, | ||
| 22 | + we might be able to do that or at least implement direct object reading for loose | ||
| 23 | + objects ( to safe a command call ). Currently object information comes from | ||
| 24 | + persistent commands anyway, so the penalty is not that high. The data_stream | ||
| 25 | + though is not based on persistent commands. | ||
| 26 | + It would be good to improve things there as cat-file keeps all the data in a buffer | ||
| 27 | + before it writes it. Hence it does not write to a stream directly, which can be | ||
| 28 | + bad if files are large, say 1GB :). | ||
| 29 | + | ||
| 18 | 30 | Config | |
| 19 | 31 | ------ | |
| 20 | 32 | * Expand .get* methods of GitConfigParser to support default value. If it is not None, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -144,6 +144,7 @@ def execute(self, command, | |||
| 144 | 144 | wrapper that will interrupt the process once it goes out of scope. If you | |
| 145 | 145 | use the command in iterators, you should pass the whole process instance | |
| 146 | 146 | instead of a single stream. | |
| 147 | + | ||
| 147 | 148 | ``output_stream`` | |
| 148 | 149 | If set to a file-like object, data produced by the git command will be | |
| 149 | 150 | output to the given stream directly. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -16,6 +16,9 @@ class Object(LazyMixin): | |||
| 16 | 16 | This Object also serves as a constructor for instances of the correct type:: | |
| 17 | 17 | ||
| 18 | 18 | inst = Object.new(repo,id) | |
| 19 | + inst.id # objects sha in hex | ||
| 20 | + inst.size # objects uncompressed data size | ||
| 21 | + inst.data # byte string containing the whole data of the object | ||
| 19 | 22 | """ | |
| 20 | 23 | TYPES = ("blob", "tree", "commit", "tag") | |
| 21 | 24 | __slots__ = ("repo", "id", "size", "data" ) | |
@@ -115,6 +118,15 @@ def __repr__(self): | |||
| 115 | 118 | """ | |
| 116 | 119 | return '<git.%s "%s">' % (self.__class__.__name__, self.id) | |
| 117 | 120 | ||
| 121 | + @property | ||
| 122 | + def data_stream(self): | ||
| 123 | + """ | ||
| 124 | + Returns | ||
| 125 | + File Object compatible stream to the uncompressed raw data of the object | ||
| 126 | + """ | ||
| 127 | + proc = self.repo.git.cat_file(self.type, self.id, as_process=True) | ||
| 128 | + return utils.ProcessStreamAdapter(proc, "stdout") | ||
| 129 | + | ||
| 118 | 130 | ||
| 119 | 131 | class IndexObject(Object): | |
| 120 | 132 | """ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -52,3 +52,21 @@ def parse_actor_and_date(line): | |||
| 52 | 52 | m = _re_actor_epoch.search(line) | |
| 53 | 53 | actor, epoch = m.groups() | |
| 54 | 54 | return (Actor._from_string(actor), int(epoch)) | |
| 55 | + | ||
| 56 | + | ||
| 57 | + | ||
| 58 | + class ProcessStreamAdapter(object): | ||
| 59 | + """ | ||
| 60 | + Class wireing all calls to the contained Process instance. | ||
| 61 | + | ||
| 62 | + Use this type to hide the underlying process to provide access only to a specified | ||
| 63 | + stream. The process is usually wrapped into an AutoInterrupt class to kill | ||
| 64 | + it if the instance goes out of scope. | ||
| 65 | + """ | ||
| 66 | + __slots__ = ("_proc", "_stream") | ||
| 67 | + def __init__(self, process, stream_name): | ||
| 68 | + self._proc = process | ||
| 69 | + self._stream = getattr(process, stream_name) | ||
| 70 | + | ||
| 71 | + def __getattr__(self, attr): | ||
| 72 | + return getattr(self._stream, attr) | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -48,6 +48,11 @@ def test_base_object(self): | |||
| 48 | 48 | assert not item.path.startswith("/") # must be relative | |
| 49 | 49 | assert isinstance(item.mode, int) | |
| 50 | 50 | # END index object check | |
| 51 | + | ||
| 52 | + # read from stream | ||
| 53 | + data_stream = item.data_stream | ||
| 54 | + data = data_stream.read() | ||
| 55 | + assert data | ||
| 51 | 56 | # END for each object type to create | |
| 52 | 57 | ||
| 53 | 58 | # each has a unique sha | |
| Back | FazBrowse Home | New Git URL |
0 commit comments