@@ -83,6 +83,8 @@ exports.getEntrysInfo = (tree = [], repo) => {
83
83
const oid = await nodegit . Oid . fromString ( item . id ) ;
84
84
// submodule
85
85
if ( item . type === 'commit' ) {
86
+ let odb = await repo . odb ( ) ;
87
+ // odb = await odb.read(oid);
86
88
// console.log('item:', item.entry.sha())
87
89
// 过滤 entry 对象
88
90
delete item . entry ;
@@ -100,6 +102,7 @@ exports.getEntrysInfo = (tree = [], repo) => {
100
102
101
103
/**
102
104
* 获取每个问文件的 hash 和 message
105
+ * https://github.com/nodegit/nodegit/issues/1174
103
106
* @param {Array } tree 每个文件的JSON对象
104
107
* @param {Object } repo Nodegit 仓对象
105
108
* @param {String } firstCommitOnMasterSha 仓库的第一个commit hash
@@ -108,32 +111,79 @@ exports.getEntrysCommit = (tree = [], repo, firstCommitOnMasterSha) => {
108
111
if ( ! tree || tree . length === 0 ) return [ ] ;
109
112
return Promise . all ( tree . map ( async ( item ) => {
110
113
const props = { ...item } ;
111
- if ( item . path && ( item . type === 'commit' || item . type === 'blob' ) ) {
112
- // https://github.com/nodegit/nodegit/issues/220
113
- // 获取单个文件的提交
114
- const walker = await repo . createRevWalk ( ) ;
115
- walker . push ( firstCommitOnMasterSha ) ;
116
- walker . sorting ( nodegit . Revwalk . SORT . Time ) ;
117
- const history = await walker . fileHistoryWalk ( item . path , 1 ) ;
118
- history . forEach ( ( entry , index ) => {
119
- const commit = entry . commit ;
120
- if ( index === 0 ) {
121
- props . author = { } ;
122
- props . author . name = commit . author ( ) . name ( ) ;
123
- props . author . email = commit . author ( ) . email ( ) ;
124
- props . message = commit . message ( ) ;
125
- props . sha = commit . sha ( ) ;
126
- props . time = commit . time ( ) ;
127
- }
128
- } ) ;
129
- }
130
- if ( item . path === 'conf' && item . type === 'tree' ) {
114
+ // if (item.path) {
115
+ // let root = null;
116
+ // const walk = repo.createRevWalk();
117
+ // try {
118
+ // walk.pushGlob('refs/heads/*');
119
+ // // walk.pushRef('refs/heads/master')
120
+ // // walk.pushHead()
121
+ // walk.sorting(nodegit.Revwalk.SORT.TIME, nodegit.Revwalk.SORT.REVERSE);
122
+ // await (async function step() {
123
+ // let oid = null;
124
+ // try {
125
+ // oid = await walk.next();
126
+ // } catch (error) {
127
+ // return;
128
+ // }
129
+ // if (oid == null) {
130
+ // return;
131
+ // }
132
+ // const commit = await nodegit.Commit.lookup(repo, oid)
133
+ // let entry = null;
134
+ // try {
135
+ // entry = await commit.getEntry(item.path);
136
+ // }
137
+ // catch (err) {
138
+ // if (err.errno !== -3) {
139
+ // throw err;
140
+ // }
141
+ // }
142
+ // if (entry != null) {
143
+ // root = commit;
144
+ // if (entry.oid() === item.id) {
145
+ // return;
146
+ // }
147
+ // }
148
+ // await step();
149
+ // })()
150
+ // }
151
+ // finally {
152
+ // walk.free();
153
+ // }
154
+ // const string = root.message();
155
+ // const sha = root.sha();
156
+ // props.message = string;
157
+ // props.sha = sha;
158
+ // }
159
+
160
+ // if (item.path && (item.type === 'commit' || item.type === 'blob')) {
161
+ // // https://github.com/nodegit/nodegit/issues/220
162
+ // // 获取单个文件的提交
163
+ // const walker = await repo.createRevWalk();
164
+ // walker.push(firstCommitOnMasterSha);
165
+ // walker.sorting(nodegit.Revwalk.SORT.Time);
166
+ // const history = await walker.fileHistoryWalk(item.path, 500);
167
+ // history.forEach((entry, index) => {
168
+ // const commit = entry.commit;
169
+ // if (index === 0) {
170
+ // props.author = {};
171
+ // props.author.name = commit.author().name();
172
+ // props.author.email = commit.author().email();
173
+ // props.message = commit.message();
174
+ // props.sha = commit.sha();
175
+ // props.time = commit.time();
176
+ // }
177
+ // });
178
+ // }
179
+
180
+ // if (item.path === 'conf' && item.type === 'tree') {
181
+ // const treeEntrys = await repo.getTree(item.id);
182
+ // const treeEntry = treeEntrys.entryByIndex(0);
183
+ // const refreshIndex = await repo.refreshIndex();
184
+ // const indexEntryFolder = refreshIndex.getByPath(treeEntry.path());
185
+ // }
131
186
132
- const treeEntrys = await repo . getTree ( item . id ) ;
133
- const treeEntry = treeEntrys . entryByIndex ( 0 ) ;
134
- const refreshIndex = await repo . refreshIndex ( ) ;
135
- const indexEntryFolder = refreshIndex . getByPath ( treeEntry . path ( ) ) ;
136
- }
137
187
// const blob = await nodegit.Blob.lookup(repo, item.id);
138
188
// // const rawsize = await blob.rawsize()
139
189
// // const content = await blob.content()
0 commit comments