Esempio n. 1
0
 def unstage(self, repo, paths=None):
     from dulwich import porcelain
     from dulwich.index import index_entry_from_stat
 # if tree_entry does not exist, this was an add, so remove index entry to undo
 # if index_ entry does not exist, this was a remove.. add back in
     if paths:
         for path in paths:
             # print path
             full_path = os.path.join(repo.path, path)
             index = repo.open_index()
             tree_id = repo.object_store[repo.head()]._tree
             try:
                 tree_entry = repo.object_store[tree_id]._entries[path]
             except KeyError:
                 try:
                     del(index[path])
                     index.write()
                 except KeyError:
                     console.hud_alert('file not in index...')
                 return
             try:
                 index_entry = list(index[path])
             except KeyError:
                 if os.path.exists(full_path):
                     index_entry = list(index_entry_from_stat(posix.lstat(full_path), tree_entry[1], 0))
                 else:
                     index_entry = [[0] * 11, tree_entry[1], 0]
             index_entry[4] = tree_entry[0]  # mode
             index_entry[7] = len(repo.object_store[tree_entry[1]].data)  # size
             index_entry[8] = tree_entry[1]  # sha
             index_entry[0] = repo.object_store[repo.head()].commit_time  # ctime
             index_entry[1] = repo.object_store[repo.head()].commit_time  # mtime
             index[path] = index_entry
             index.write()
Esempio n. 2
0
 def unstage(self,repo,paths=None):
     from dulwich import porcelain
     from dulwich.index import index_entry_from_stat
 # if tree_entry does not exist, this was an add, so remove index entry to undo
 # if index_ entry does not exist, this was a remove.. add back in
     if paths:
         for path in paths:
             #print path
             full_path = os.path.join(repo.path, path)
             index=repo.open_index()
             tree_id=repo.object_store[repo.head()]._tree
             try:
                 tree_entry=repo.object_store[tree_id]._entries[path]
             except KeyError:
                 try:
                     del(index[path])
                     index.write()
                 except KeyError:
                     console.hud_alert('file not in index...')
                 return
             try:
                 index_entry=list(index[path])
             except KeyError:
                 if os.path.exists(full_path):
                     index_entry=list(index_entry_from_stat(posix.lstat(full_path),tree_entry[1]  ,0    ))
                 else:
                     index_entry=[[0]*11,tree_entry[1],0]
             index_entry[4]=tree_entry[0] #mode
             index_entry[7]=len(repo.object_store [tree_entry[1]].data) #size
             index_entry[8]=tree_entry[1] #sha
             index_entry[0]=repo.object_store[repo.head()].commit_time #ctime
             index_entry[1]=repo.object_store[repo.head()].commit_time #mtime
             index[path]=index_entry
             index.write()
Esempio n. 3
0
File: git.py Progetto: zx110101/00
def unstage(commit='HEAD', paths=[]):
    repo = _get_repo().repo
    for somepath in paths:
        #print path
        path = _get_repo().relpath(somepath)
        full_path = os.path.join(repo.path, path)

        index = repo.open_index()
        tree_id = repo[commit]._tree
        try:
            tree_entry = repo[tree_id].lookup_path(lambda x: repo[x], path)
        except KeyError:
            #if tree_entry didnt exist, this file was being added, so remove index entry
            try:
                del (index[path])
                index.write()
            except KeyError:
                print('file not in index.', path)
            return

        try:
            index_entry = list(index[path])
        except KeyError:
            #if index_entry doesnt exist, this file was being removed.  readd it
            if os.path.exists(full_path):
                index_entry = list(
                    index_entry_from_stat(posix.lstat(full_path),
                                          tree_entry[1], 0))
            else:
                index_entry = [[0] * 11, tree_entry[1], 0]

        #update index entry stats to reflect commit
        index_entry[4] = tree_entry[0]  #mode
        index_entry[7] = len(repo[tree_entry[1]].data)  #size
        index_entry[8] = tree_entry[1]  #sha
        index_entry[0] = repo[commit].commit_time  #ctime
        index_entry[1] = repo[commit].commit_time  #mtime
        index[path] = index_entry
        index.write()
Esempio n. 4
0
def unstage(commit='HEAD',paths=[]):
    repo=_get_repo().repo
    for somepath in paths:
        #print path
        path=_get_repo().relpath(somepath)
        full_path = os.path.join(repo.path, path)

        index=repo.open_index()
        tree_id=repo[commit]._tree
        try:
            tree_entry=repo[tree_id].lookup_path(lambda x:repo[x],path)
        except KeyError:
            #if tree_entry didnt exist, this file was being added, so remove index entry
            try:
                del(index[path])
                index.write()
            except KeyError:
                print 'file not in index.',path
            return
            
        try:
            index_entry=list(index[path])
        except KeyError:
            #if index_entry doesnt exist, this file was being removed.  readd it
            if os.path.exists(full_path):
                index_entry=list(index_entry_from_stat(posix.lstat(full_path),tree_entry[1]  ,0    ))
            else:
                index_entry=[[0]*11,tree_entry[1],0]
                
        #update index entry stats to reflect commit
        index_entry[4]=tree_entry[0] #mode
        index_entry[7]=len(repo[tree_entry[1]].data) #size
        index_entry[8]=tree_entry[1] #sha
        index_entry[0]=repo[commit].commit_time #ctime
        index_entry[1]=repo[commit].commit_time #mtime
        index[path]=index_entry
        index.write()
Esempio n. 5
0
def islink(path):
	try:
		st = posix.lstat(path)
	except (posix.error, NameError):
		return 0
	return stat.S_ISLNK(st[stat.ST_MODE])
Esempio n. 6
0
def islink(path):
	try:
		st = posix.lstat(path)
	except (posix.error, AttributeError):
		return 0
	return stat.S_ISLNK(st[stat.ST_MODE])
Esempio n. 7
0
  def Eval(self, node):
    #print('!!', node.tag)

    if node.tag == bool_expr_e.WordTest:
      s = self._EvalCompoundWord(node.w)
      return bool(s)

    if node.tag == bool_expr_e.LogicalNot:
      b = self.Eval(node.child)
      return not b

    if node.tag == bool_expr_e.LogicalAnd:
      # Short-circuit evaluation
      if self.Eval(node.left):
        return self.Eval(node.right)
      else:
        return False

    if node.tag == bool_expr_e.LogicalOr:
      if self.Eval(node.left):
        return True
      else:
        return self.Eval(node.right)

    if node.tag == bool_expr_e.BoolUnary:
      op_id = node.op_id
      s = self._EvalCompoundWord(node.child)

      # Now dispatch on arg type
      arg_type = BOOL_ARG_TYPES[op_id]  # could be static in the LST?

      if arg_type == bool_arg_type_e.Path:
        # Only use lstat if we're testing for a symlink.
        if op_id in (Id.BoolUnary_h, Id.BoolUnary_L):
          try:
            mode = posix.lstat(s).st_mode
          except OSError:
            return False

          return stat.S_ISLNK(mode)

        try:
          mode = posix.stat(s).st_mode
        except OSError:
          # TODO: Signal extra debug information?
          #log("Error from stat(%r): %s" % (s, e))
          return False

        if op_id in (Id.BoolUnary_e, Id.BoolUnary_a):  # -a is alias for -e
          return True

        if op_id == Id.BoolUnary_f:
          return stat.S_ISREG(mode)

        if op_id == Id.BoolUnary_d:
          return stat.S_ISDIR(mode)

        if op_id == Id.BoolUnary_x:
          return posix.access(s, posix.X_OK)

        if op_id == Id.BoolUnary_r:
          return posix.access(s, posix.R_OK)

        if op_id == Id.BoolUnary_w:
          return posix.access(s, posix.W_OK)

        raise NotImplementedError(op_id)

      if arg_type == bool_arg_type_e.Str:
        if op_id == Id.BoolUnary_z:
          return not bool(s)
        if op_id == Id.BoolUnary_n:
          return bool(s)

        raise NotImplementedError(op_id)

      if arg_type == bool_arg_type_e.Other:
        if op_id == Id.BoolUnary_t:
          try:
            fd = int(s)
          except ValueError:
            # TODO: Need location information of [
            e_die('Invalid file descriptor %r', s)
          return posix.isatty(fd)

        raise NotImplementedError(op_id)

      raise NotImplementedError(arg_type)

    if node.tag == bool_expr_e.BoolBinary:
      op_id = node.op_id

      s1 = self._EvalCompoundWord(node.left)
      # Whether to glob escape
      do_fnmatch = op_id in (Id.BoolBinary_GlobEqual, Id.BoolBinary_GlobDEqual,
                             Id.BoolBinary_GlobNEqual)
      do_ere = (op_id == Id.BoolBinary_EqualTilde)
      s2 = self._EvalCompoundWord(node.right, do_fnmatch=do_fnmatch,
                                  do_ere=do_ere)

      # Now dispatch on arg type
      arg_type = BOOL_ARG_TYPES[op_id]

      if arg_type == bool_arg_type_e.Path:
        st1 = posix.stat(s1)
        st2 = posix.stat(s2)

        # TODO: test newer than (mtime)
        if op_id == Id.BoolBinary_nt:
          return st1[stat.ST_MTIME] > st2[stat.ST_MTIME]
        if op_id == Id.BoolBinary_ot:
          return st1[stat.ST_MTIME] < st2[stat.ST_MTIME]

        raise NotImplementedError(op_id)

      if arg_type == bool_arg_type_e.Int:
        # NOTE: We assume they are constants like [[ 3 -eq 3 ]].
        # Bash also allows [[ 1+2 -eq 3 ]].
        i1 = self._StringToIntegerOrError(s1, blame_word=node.left)
        i2 = self._StringToIntegerOrError(s2, blame_word=node.right)

        if op_id == Id.BoolBinary_eq:
          return i1 == i2
        if op_id == Id.BoolBinary_ne:
          return i1 != i2
        if op_id == Id.BoolBinary_gt:
          return i1 > i2
        if op_id == Id.BoolBinary_ge:
          return i1 >= i2
        if op_id == Id.BoolBinary_lt:
          return i1 < i2
        if op_id == Id.BoolBinary_le:
          return i1 <= i2

        raise NotImplementedError(op_id)

      if arg_type == bool_arg_type_e.Str:

        if op_id in (Id.BoolBinary_GlobEqual, Id.BoolBinary_GlobDEqual):
          #log('Matching %s against pattern %s', s1, s2)

          # TODO: Respect extended glob?  * and ! and ? are quoted improperly.
          # But @ and + are OK.
          return libc.fnmatch(s2, s1)

        if op_id == Id.BoolBinary_GlobNEqual:
          return not libc.fnmatch(s2, s1)

        if op_id in (Id.BoolBinary_Equal, Id.BoolBinary_DEqual):
          return s1 == s2

        if op_id == Id.BoolBinary_NEqual:
          return s1 != s2

        if op_id == Id.BoolBinary_EqualTilde:
          #log('Matching %r against regex %r', s1, s2)
          try:
            matches = libc.regex_match(s2, s1)
          except RuntimeError:
            # 2 means a parse error.  Note this is a fatal error in OSH but not
            # in bash.
            e_die("Invalid regex %r", s2, word=node.right, status=2)

          if matches is None:
            return False

          self._SetRegexMatches(matches)
          return True

        if op_id == Id.Redir_Less:  # pun
          return s1 < s2

        if op_id == Id.Redir_Great:  # pun
          return s1 > s2

        raise NotImplementedError(op_id)

    raise AssertionError(node.tag)